From f0ca3fc17c654052f90eccb9e120cb4d074dbc61 Mon Sep 17 00:00:00 2001 From: Vijesh Shetty Date: Mon, 3 Jun 2024 18:21:43 +0530 Subject: [PATCH] some fixes --- app/app/login/page.tsx | 6 +++ app/app/register/page.tsx | 40 ++++++++++++++++--- components/CardComponents/LinkCard.tsx | 6 +-- .../CardComponents/QRCodeCardComponent.tsx | 4 +- components/NavigationBars/SideNavBar.tsx | 2 +- lib/actions/register.ts | 28 +++++++++---- lib/services/pgConnect.ts | 5 +++ package-lock.json | 35 ++++++++++++++++ package.json | 1 + 9 files changed, 107 insertions(+), 20 deletions(-) diff --git a/app/app/login/page.tsx b/app/app/login/page.tsx index 9afdaae..837afd8 100644 --- a/app/app/login/page.tsx +++ b/app/app/login/page.tsx @@ -19,6 +19,7 @@ import { useRouter } from "next/navigation"; import { SkeletonCard } from "@/components/CardComponents/SkeletonCard"; import { Turnstile } from '@marsidev/react-turnstile' import { captchaVerify } from "@/lib/actions/captchaVerify"; +import { LoadingSpinner } from "@/components/LoadingComponents/LoadingSpinner"; const LoginPage = () => { const [email, setEmail] = useState(""); @@ -28,6 +29,8 @@ const LoginPage = () => { const [loading, setLoading] = useState(true); const [token,setToken] = useState("") const site_id = process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY || "" + + const [confirmLoading,setConfirmLoading] = useState(false) const { data } = useSession(); useEffect(() => { @@ -81,6 +84,7 @@ const LoginPage = () => { + {confirmLoading?:
} diff --git a/app/app/register/page.tsx b/app/app/register/page.tsx index 4b0233a..7e7a4a7 100644 --- a/app/app/register/page.tsx +++ b/app/app/register/page.tsx @@ -19,6 +19,8 @@ import { useSession } from "next-auth/react"; import { SkeletonCard } from "@/components/CardComponents/SkeletonCard"; import { Turnstile } from "@marsidev/react-turnstile"; import { captchaVerify } from "@/lib/actions/captchaVerify"; +import { LoadingSpinner } from "@/components/LoadingComponents/LoadingSpinner"; +import { HTTP_STATUS } from "@/lib/constants"; @@ -27,9 +29,13 @@ const RegisterPage = () => { const [token,setToken] = useState("") const site_id = process.env.NEXT_PUBLIC_CAPTCHA_SITE_KEY || "" + const [confirmLoading,setConfirmLoading] = useState(false) + const registerUser = async (formData: FormData) => { - const verify = await captchaVerify(token); + // Issue :- Component is not rendering after the below setState + setConfirmLoading(true) + const verify = await captchaVerify(token); if(verify == 403){ toast({ title:"Invalid Captcha", @@ -39,15 +45,28 @@ const RegisterPage = () => { return; } - const status = await register(formData); - - if (status == 200) { + const status:number = await register(formData); + + if (status == HTTP_STATUS.OK) { toast({ title: "User registered successfully !!", description: "Please login to continue", }); redirect("/app/login"); - } else if (status == 403) { + } else if ( status == HTTP_STATUS.BAD_REQUEST){ + toast({ + title: "Invalid Inputs !!", + description: "Enter valid email / Password should contains atleast 6 characters", + variant:"destructive" + }); + } + else if ( status == HTTP_STATUS.NOT_FOUND){ + toast({ + title: "Please enter all fields", + variant:"destructive" + }); + } + else if (status == HTTP_STATUS.UNAUTHORIZED) { toast({ title: "User already exists !!", variant: "destructive", @@ -58,6 +77,8 @@ const RegisterPage = () => { variant: "destructive", }); } + + setConfirmLoading(false) }; const { data } = useSession(); @@ -75,7 +96,7 @@ const RegisterPage = () => { ); - + return (
@@ -87,6 +108,12 @@ const RegisterPage = () => {
+ + { setToken(token) }} siteKey={site_id} /> + {confirmLoading?:
}
diff --git a/components/CardComponents/LinkCard.tsx b/components/CardComponents/LinkCard.tsx index 86ae790..d448523 100644 --- a/components/CardComponents/LinkCard.tsx +++ b/components/CardComponents/LinkCard.tsx @@ -41,8 +41,8 @@ export function LinkCard({
-
-

+
+

{title}

@@ -57,7 +57,7 @@ export function LinkCard({ - diff --git a/components/CardComponents/QRCodeCardComponent.tsx b/components/CardComponents/QRCodeCardComponent.tsx index 2dfd8e4..2b1a4e2 100644 --- a/components/CardComponents/QRCodeCardComponent.tsx +++ b/components/CardComponents/QRCodeCardComponent.tsx @@ -50,7 +50,7 @@ export function QRCodeCardComponent({ qrcode }: { qrcode: any }) { } return ( -
+
@@ -60,7 +60,7 @@ export function QRCodeCardComponent({ qrcode }: { qrcode: any }) {
-