From 284f84727db99a8683f566170938d438c0c54d78 Mon Sep 17 00:00:00 2001 From: Sinan Date: Wed, 28 Aug 2024 08:42:43 +0530 Subject: [PATCH] sussessfully changed to tanstack-react-query --- client/.env.local | 2 +- client/app/(patient)/new-appointment/page.tsx | 2 +- client/app/(patient)/register/page.tsx | 2 +- .../signin/otp-verification/page.tsx | 45 ++++-- client/app/(patient)/signin/page.tsx | 2 +- client/app/(patient)/signup/page.tsx | 2 +- client/app/layout.tsx | 3 + .../staff/@signin/otp-verification/page.tsx | 2 +- client/app/staff/@signin/page.tsx | 2 +- .../{ => common}/forms/AppointmentForm.tsx | 35 ++--- .../{ => common}/forms/OtpForms.tsx | 2 +- .../{ => common}/forms/RegistrationForm.tsx | 2 +- .../{ => common}/forms/SigninForm.tsx | 45 +++--- client/components/common/forms/SignupForm.tsx | 130 ++++++++++++++++++ .../{ => common}/forms/admin/SigninForm.tsx | 0 client/components/forms/SignupForm.tsx | 126 ----------------- client/lib/hooks/usePatinet.ts | 32 +++++ client/lib/query-provider.tsx | 23 ++++ client/package-lock.json | 127 +++++++++++++++++ client/package.json | 2 + client/services/api/auth/patientAuth.ts | 18 +++ client/services/api/auth/patientInstance.ts | 10 ++ client/tsconfig.json | 2 +- client/types/index.ts | 6 + .../controllers/PatientController.ts | 9 +- 25 files changed, 437 insertions(+), 194 deletions(-) rename client/components/{ => common}/forms/AppointmentForm.tsx (83%) rename client/components/{ => common}/forms/OtpForms.tsx (96%) rename client/components/{ => common}/forms/RegistrationForm.tsx (99%) rename client/components/{ => common}/forms/SigninForm.tsx (66%) create mode 100644 client/components/common/forms/SignupForm.tsx rename client/components/{ => common}/forms/admin/SigninForm.tsx (100%) delete mode 100644 client/components/forms/SignupForm.tsx create mode 100644 client/lib/hooks/usePatinet.ts create mode 100644 client/lib/query-provider.tsx create mode 100644 client/services/api/auth/patientAuth.ts create mode 100644 client/services/api/auth/patientInstance.ts diff --git a/client/.env.local b/client/.env.local index 6f502140..c7d46517 100644 --- a/client/.env.local +++ b/client/.env.local @@ -1,2 +1,2 @@ NEXT_PUBLIC_ENV=development -NEXT_PUBLIC_SERVER_URL=http://localhost:8000 \ No newline at end of file +NEXT_PUBLIC_API_URL=http://localhost:8000/api \ No newline at end of file diff --git a/client/app/(patient)/new-appointment/page.tsx b/client/app/(patient)/new-appointment/page.tsx index edc5050e..8ad65e48 100644 --- a/client/app/(patient)/new-appointment/page.tsx +++ b/client/app/(patient)/new-appointment/page.tsx @@ -1,4 +1,4 @@ -import AppointmentForm from "@/components/forms/AppointmentForm"; +import AppointmentForm from "@/components/common/forms/AppointmentForm"; import Image from "next/image"; import { Metadata } from "next"; diff --git a/client/app/(patient)/register/page.tsx b/client/app/(patient)/register/page.tsx index 2b344ff9..e010d97a 100644 --- a/client/app/(patient)/register/page.tsx +++ b/client/app/(patient)/register/page.tsx @@ -1,5 +1,5 @@ import Image from "next/image"; -import RegistrationForm from "@/components/forms/RegistrationForm"; +import RegistrationForm from "@/components/common/forms/RegistrationForm"; const Register = () => { return (
diff --git a/client/app/(patient)/signin/otp-verification/page.tsx b/client/app/(patient)/signin/otp-verification/page.tsx index 315dfe39..1753931a 100644 --- a/client/app/(patient)/signin/otp-verification/page.tsx +++ b/client/app/(patient)/signin/otp-verification/page.tsx @@ -1,17 +1,46 @@ "use client"; -import OtpVerificationSection from "@/components/forms/OtpForms"; +import OtpVerificationSection from "@/components/common/forms/OtpForms"; import Image from "next/image"; import React, { FormEvent, useState } from "react"; +import { useValidateOtpPatient } from "@/lib/hooks/usePatinet"; +import { useToast } from "@/components/ui/use-toast"; +import { useRouter } from "next/navigation"; +import { Button } from "@/components/ui/button"; +import Link from "next/link"; + const OtpVerificationPage = () => { - const [otp, setOtp] = useState(""); - const [isLoading, setLoading] = useState(false); + const [otp, setOtp] = useState(""); + const { mutate: validateOtp, isPending } = useValidateOtpPatient(); + const { toast } = useToast(); + const navigate = useRouter(); const handleVerify = async (e: FormEvent) => { e.preventDefault(); - try { - } catch (error) { - console.log(error); - } + validateOtp( + { email: "muhammedsinan0549@gmail.com", otp: parseInt(otp) }, + { + onSuccess: (data) => { + toast({ + title: "Otp Verification Success ✅", + description: "Authentication Completed!. let's book your first appointment", + variant: "default", + action: ( + + ), + }); + console.log(data); + }, + onError: (error) => { + toast({ + title: "Otp Verification Failed ❌", + description: error.response?.data.message, + variant: "destructive", + }); + }, + } + ); }; const handleResend = async () => {}; @@ -32,7 +61,7 @@ const OtpVerificationPage = () => { otp={otp} setOtp={setOtp} handleVerify={handleVerify} - isLoading={isLoading} + isLoading={isPending} timer={30} />
diff --git a/client/app/(patient)/signin/page.tsx b/client/app/(patient)/signin/page.tsx index 81b15dcd..f22ee385 100644 --- a/client/app/(patient)/signin/page.tsx +++ b/client/app/(patient)/signin/page.tsx @@ -1,4 +1,4 @@ -import SigninForm from "@/components/forms/SigninForm"; +import SigninForm from "@/components/common/forms/SigninForm"; import Image from "next/image"; import Link from "next/link"; import { Metadata } from "next"; diff --git a/client/app/(patient)/signup/page.tsx b/client/app/(patient)/signup/page.tsx index 6cfccbff..58f9cf0d 100644 --- a/client/app/(patient)/signup/page.tsx +++ b/client/app/(patient)/signup/page.tsx @@ -1,5 +1,5 @@ import Image from "next/image"; -import SignupForm from "@/components/forms/SignupForm"; +import SignupForm from "@/components/common/forms/SignupForm"; import { Metadata } from "next"; export const metadata: Metadata = { diff --git a/client/app/layout.tsx b/client/app/layout.tsx index 00b47523..81ddca61 100644 --- a/client/app/layout.tsx +++ b/client/app/layout.tsx @@ -6,6 +6,7 @@ import { ThemeProvider } from "@/components/layout/ThemeProvider"; import NavBar from "@/components/layout/NavBar"; import Footer from "@/components/layout/Footer"; import { Toaster } from "@/components/ui/toaster"; +import QueryProvider from "@/lib/query-provider" const inter = Plus_Jakarta_Sans({ subsets: ["latin"], @@ -30,12 +31,14 @@ export default function RootLayout({ return ( + {children}