diff --git a/src/components/molecules/RegisterForm/RegisterForm.tsx b/src/components/molecules/RegisterForm/RegisterForm.tsx index 2f456118..7a9f8f91 100644 --- a/src/components/molecules/RegisterForm/RegisterForm.tsx +++ b/src/components/molecules/RegisterForm/RegisterForm.tsx @@ -15,6 +15,7 @@ import { useState } from "react" import { Container } from "@medusajs/ui" import Link from "next/link" import { PasswordValidator } from "@/components/cells/PasswordValidator/PasswordValidator" +import { toast } from "@/lib/helpers/toast" export const RegisterForm = () => { const methods = useForm({ @@ -43,15 +44,18 @@ const Form = () => { "8chars": false, symbolOrDigit: false, }) - const [error, setError] = useState() const { handleSubmit, register, watch, formState: { errors, isSubmitting }, - } = useFormContext() + } = useFormContext() + + const submit = async (data: RegisterFormData) => { + if (!passwordError.isValid) { + return + } - const submit = async (data: FieldValues) => { const formData = new FormData() formData.append("email", data.email) formData.append("password", data.password) @@ -59,9 +63,11 @@ const Form = () => { formData.append("last_name", data.lastName) formData.append("phone", data.phone) - const res = passwordError.isValid && (await signup(formData)) + const res = await signup(formData) - if (res && !res?.id) setError(res) + if (res && !res?.id) { + toast.error({ title: res }) + } } return ( @@ -118,7 +124,6 @@ const Form = () => { /> - {error &&

{error}

}