From 2101257e759ea6f43fb2c499eb3e248baf3cd9fc Mon Sep 17 00:00:00 2001 From: marcellinuselbert11 Date: Wed, 20 Oct 2021 00:33:54 +0700 Subject: [PATCH 1/3] Fix incomplete submit --- frontend/modules/Home/index.tsx | 43 ++++++++++++++++++++++++++++++--- frontend/package-lock.json | 30 +++++++++++------------ frontend/package.json | 1 + 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/frontend/modules/Home/index.tsx b/frontend/modules/Home/index.tsx index 87fb6129..664d2826 100644 --- a/frontend/modules/Home/index.tsx +++ b/frontend/modules/Home/index.tsx @@ -39,7 +39,6 @@ const HomePage = () => { const handleAliasType = (text: string) => { setAlias(text.split(" ").length > 1 ? text.split(" ").join("-") : text); }; - const handleSubmit = () => { setIsLoading(true); fetch("/api/shorten", { @@ -72,11 +71,47 @@ const HomePage = () => { } }); }; + const handleEmpty = () => { + if (!isUrlValid) + toast({ + title: "Error occured", + description: "Please enter a valid url", + status: "error", + duration: 5000, + isClosable: true, + }); + else if (url === "" && alias === "") { + toast({ + title: "Error occured", + description: "Please enter long url and short url", + status: "error", + duration: 5000, + isClosable: true, + }); + } else if (alias === "") { + toast({ + title: "Error occured", + description: "Please enter short url", + status: "error", + duration: 5000, + isClosable: true, + }); + } else if (url === "") { + toast({ + title: "Error occured", + description: "Please enter long url", + status: "error", + duration: 5000, + isClosable: true, + }); + } + }; useEffect(() => { - if (!!alias && isUrlValid) { + if (!!alias && isUrlValid && url !== "") { return setIsAllowed(true); } + setIsAllowed(false); }, [url, alias]); @@ -134,7 +169,9 @@ const HomePage = () => {