fix: improve error handling for invalid URL submission

This commit is contained in:
Amit Ranjan 2024-09-24 02:21:02 +05:30
parent 37f20f7d79
commit 2da2552c3b
2 changed files with 6 additions and 1 deletions

View File

@ -25,6 +25,7 @@ import { ContentContainer } from "@/app-components/dialogs/layouts/ContentContai
import { ContentItem } from "@/app-components/dialogs/layouts/ContentItem"; import { ContentItem } from "@/app-components/dialogs/layouts/ContentItem";
import { Input } from "@/app-components/inputs/Input"; import { Input } from "@/app-components/inputs/Input";
import { ToggleableInput } from "@/app-components/inputs/ToggleableInput"; import { ToggleableInput } from "@/app-components/inputs/ToggleableInput";
import { URL_REGEX } from "@/constants";
import { IMenuItem, IMenuItemAttributes, MenuType } from "@/types/menu.types"; import { IMenuItem, IMenuItemAttributes, MenuType } from "@/types/menu.types";
export type MenuDialogProps = DialogProps & { export type MenuDialogProps = DialogProps & {
@ -66,7 +67,8 @@ export const MenuDialog: FC<MenuDialogProps> = ({
url: { url: {
required: t("message.url_is_invalid"), required: t("message.url_is_invalid"),
validate: (value: string = "") => validate: (value: string = "") =>
isAbsoluteUrl(value) || t("message.url_is_invalid"), (isAbsoluteUrl(value) && URL_REGEX.test(value)) ||
t("message.url_is_invalid"),
}, },
payload: {}, payload: {},
}; };

View File

@ -21,3 +21,6 @@ export const DATE_TIME_FORMAT = {
export const USER_DEFAULT_PICTURE = export const USER_DEFAULT_PICTURE =
"https://avatars.dicebear.com/v2/identicon/6659e07058af581e68e33d05.svg"; "https://avatars.dicebear.com/v2/identicon/6659e07058af581e68e33d05.svg";
export const URL_REGEX =
/^(https?:\/\/)?((([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(:[0-9]{1,5})?(\/[^\s]*)?)$/i;