-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
89 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,44 +10,65 @@ import SubmitButton from "@/components/utils/SubmitButton"; | |
import { signinFormValidation } from "@/lib/validators/userValidation"; | ||
import Link from "next/link"; | ||
import { FormFieldType } from "@/types/fromTypes"; | ||
import { useSignInMutation } from "@/lib/features/api/authApi"; | ||
import { useToast } from "../ui/use-toast"; | ||
import { useRouter } from "next/navigation"; | ||
|
||
const LoginForm = () => { | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
const [signIn, { isLoading: isPosting, data, error: signinError }] = useSignInMutation(); | ||
const [error, setError] = useState(""); | ||
const { toast } = useToast(); | ||
const router = useRouter(); | ||
|
||
const form = useForm<z.infer<typeof signinFormValidation>>({ | ||
resolver: zodResolver(signinFormValidation), | ||
defaultValues: { | ||
phone: "", | ||
email: "", | ||
password: "", | ||
}, | ||
}); | ||
|
||
const onSubmit = async (values: z.infer<typeof signinFormValidation>) => { | ||
setIsLoading(true); | ||
console.log("clicked"); | ||
setIsLoading(false); | ||
try { | ||
const result = await signIn(values).unwrap(); | ||
router.push("/signin/otp-verification"); | ||
toast({ | ||
title: "OTP Verification", | ||
description: "Please check your email for the OTP.", | ||
variant: "default", | ||
}); | ||
} catch (error: any) { | ||
setError(error.data?.message || "An error occurred during sign-in."); | ||
console.log(error); | ||
|
||
toast({ | ||
title: "Sign-In Failed", | ||
description: error.data?.message || "Please try again.", | ||
variant: "destructive", | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Form {...form}> | ||
<form | ||
onSubmit={form.handleSubmit(onSubmit)} | ||
className="space-y-6 flex-1" | ||
> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6 flex-1"> | ||
<section className="mb-12 space-y-4"> | ||
<h1 className="header">Welcome Back 👋</h1> | ||
<p className="text-dark-700"> | ||
Schedule your first appointment{" "} | ||
<Link href={"/signup"} className="text-blue-400"> | ||
<Link href="/signup" className="text-blue-400"> | ||
Sign Up | ||
</Link> | ||
</p> | ||
</section> | ||
|
||
<CustomFormField | ||
control={form.control} | ||
fieldType={FormFieldType.PHONE_INPUT} | ||
name="phone" | ||
label="Phone Number" | ||
fieldType={FormFieldType.INPUT} | ||
name="email" | ||
label="Email Address" | ||
placeholder="[email protected]" | ||
iconSrc="/assets/icons/email.svg" | ||
/> | ||
|
||
<CustomFormField | ||
|
@@ -58,7 +79,9 @@ const LoginForm = () => { | |
placeholder="Enter your password" | ||
/> | ||
|
||
<SubmitButton isLoading={isLoading}>Sign In</SubmitButton> | ||
{error && <p className="text-red-500 text-sm mt-2">{error}</p>} | ||
|
||
<SubmitButton isLoading={isPosting}>Sign In</SubmitButton> | ||
</form> | ||
</Form> | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c657750
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
avm-care – ./
avm-care-git-main-sinans-projects-8d312afe.vercel.app
avm-care-sinans-projects-8d312afe.vercel.app
avm-care.vercel.app