diff --git a/src/pages/Common/SignUp/SignUpForm.jsx b/src/pages/Common/SignUp/SignUpForm.jsx index c4f64c3..0373049 100644 --- a/src/pages/Common/SignUp/SignUpForm.jsx +++ b/src/pages/Common/SignUp/SignUpForm.jsx @@ -8,6 +8,7 @@ import { useSignUpContext } from "./signUpContext"; import { callCustomAPI, oauthLoginApi } from "@/utils/callCustomAPI"; import { LoadingButton } from "@/components/frontend"; import TLDs from "@/assets/json/email-tlds.json"; +import ReCAPTCHA from "react-google-recaptcha"; const SignUpForm = () => { const navigate = useNavigate(); @@ -15,9 +16,18 @@ const SignUpForm = () => { const role = signUpData.role; const schema = yup.object({ email: yup - .string(), + .string() + .required("Email is required") + .email("Invalid email address") + .test("tld-check", "Invalid email TLD", (value) => { + if (!value) return false; + const tld = value.split(".").pop(); + return TLDs.includes(tld); + }), }); const [loading, setLoading] = useState(false); + const [recaptchaValue, setRecaptchaValue] = useState(null); + const [recaptchaError, setRecaptchaError] = useState(""); const { register, @@ -32,12 +42,20 @@ const SignUpForm = () => { }); const onSubmit = async (data) => { + setRecaptchaError(""); + if (!recaptchaValue) { + setRecaptchaError("Please complete the recaptcha."); + return; + } setLoading(true); try { - const result = await callCustomAPI("email-exist", "post", { email: data.email }, ""); - + const result = await callCustomAPI( + "email-exist", + "post", + { email: data.email }, + "" + ); if (result.error || result.exist) throw new Error("User already exists"); - dispatch({ type: "SET_EMAIL", payload: data.email }); navigate("/signup/details" + "?role=" + role); } catch (err) { @@ -61,77 +79,87 @@ const SignUpForm = () => { window.open(result.data, "_self"); }; - if (!signUpData.role) return ; return ( <> - + - {role == "host" ? "Become a host" : "Sign up"} + + {role == "host" ? "Become a host" : "Sign up"} + {Object.entries(errors).length > 0 ? ( - {Object.values(errors)[0].message} + + {Object.values(errors)[0].message} + ) : ( <>> )} + + { + setRecaptchaValue(val); + setRecaptchaError(""); + }} + /> + + {recaptchaError && ( + + {recaptchaError} + + )} Continue - - OR - + OR + handleGoogleLogin()} - className="flex items-center justify-center gap-2 border-2 py-[10px]" + className='flex items-center justify-center gap-2 border-2 py-[10px]' > - + Sign Up With Google handleFacebookLogin()} - className="flex items-center justify-center gap-2 border-2 py-[10px]" + className='flex items-center justify-center gap-2 border-2 py-[10px]' > - + Sign Up With Facebook handleAppleLogin()} - className="flex items-center justify-center gap-2 border-2 py-[10px]" + className='flex items-center justify-center gap-2 border-2 py-[10px]' > - + Sign Up With Apple - + Already have an account?{" "} Log In {" "} @@ -140,8 +168,15 @@ const SignUpForm = () => { > );
{Object.values(errors)[0].message}
+ {Object.values(errors)[0].message} +
+ {recaptchaError} +