Client:OAuth2: fix url validations

This commit is contained in:
Timofey Boyko 2023-11-21 14:49:58 +03:00
parent f3ce27d404
commit 9fab8360ce
2 changed files with 17 additions and 14 deletions

View File

@ -11,12 +11,11 @@ import SelectedItem from "@docspace/components/selected-item";
import {
StyledChipsContainer,
StyledHeaderRow,
StyledInputGroup,
StyledInputRow,
} from "../ClientForm.styled";
import InputGroup from "./InputGroup";
import { WEBSITE_REGEXP } from "..";
import { isValidUrl } from "..";
interface MultiInputGroupProps {
t: any;
@ -58,10 +57,9 @@ const MultiInputGroup = ({
if (timer.current) {
clearTimeout(timer.current);
}
console.log(value, "call");
if (value) {
console.log(value);
if (WEBSITE_REGEXP.test(value)) {
if (isValidUrl(value)) {
setIsError(false);
} else {
timer.current = setTimeout(() => {
@ -73,7 +71,6 @@ const MultiInputGroup = ({
}
}, [value]);
console.log(WEBSITE_REGEXP.test(value));
return (
<StyledInputGroup>
<InputGroup

View File

@ -21,8 +21,14 @@ import { StyledContainer } from "./ClientForm.styled";
import { ClientFormProps, ClientStore } from "./ClientForm.types";
import ClientFormLoader from "./Loader";
export const WEBSITE_REGEXP =
/(http|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/g;
export function isValidUrl(url: string) {
try {
new URL(url);
return true;
} catch (err) {
return false;
}
}
const ClientForm = ({
id,
@ -242,7 +248,7 @@ const ClientForm = ({
if (
form[key] &&
!errorFields.includes(key) &&
!WEBSITE_REGEXP.test(form[key])
!isValidUrl(form[key])
) {
isValid = false;
@ -257,7 +263,7 @@ const ClientForm = ({
if (
errorFields.includes(key) &&
(!form[key] || WEBSITE_REGEXP.test(form[key]))
(!form[key] || isValidUrl(form[key]))
) {
setErrorFields((value) => {
return value.filter((n) => n !== key);
@ -285,7 +291,7 @@ const ClientForm = ({
if (
form[key] &&
!errorFields.includes(key) &&
!WEBSITE_REGEXP.test(form[key])
!isValidUrl(form[key])
) {
isValid = false;
@ -300,7 +306,7 @@ const ClientForm = ({
if (
errorFields.includes(key) &&
(!form[key] || WEBSITE_REGEXP.test(form[key]))
(!form[key] || isValidUrl(form[key]))
) {
setErrorFields((value) => {
return value.filter((n) => n !== key);
@ -316,7 +322,7 @@ const ClientForm = ({
if (
form[key] &&
!errorFields.includes(key) &&
!WEBSITE_REGEXP.test(form[key])
!isValidUrl(form[key])
) {
isValid = false;
@ -331,7 +337,7 @@ const ClientForm = ({
if (
errorFields.includes(key) &&
(!form[key] || WEBSITE_REGEXP.test(form[key]))
(!form[key] || isValidUrl(form[key]))
) {
setErrorFields((value) => {
return value.filter((n) => n !== key);