import { recoverCustomersPassword } from 'lib/shopify'; import { revalidatePath } from 'next/cache'; import AuthLayout from '../component/AuthLayout'; import FormButton from '../component/FormButton'; import FormFooter from '../component/FormFooter'; import FormHeader from '../component/FormHeader'; let emailError: string | null = null; let isSubmited: boolean = false; const headings = { submited: { title: 'Request Sent.', description: 'If that email address is in our system, you will receive an email with instructions about how to reset your password in a few minutes.', }, default: { title: 'Forgot Password.', description: 'Enter the email address associated with your account to receive a link to reset your password.', }, }; export default function RecoverPassword() { async function handleSubmit(data: FormData) { 'use server'; try { const response = await recoverCustomersPassword({ variables: { email: data.get('email') as string, }, }); if (response.body.data.customerRecover.customerUserErrors.length > 0) { response.body.data.customerRecover.customerUserErrors.filter( (error: any) => { if (error.field && error.field.includes('email')) { emailError = error.message; } } ); } else { isSubmited = true; } } catch (error) { interface ERROR { message: string; } const err = error as { error: ERROR }; emailError = err.error.message; } revalidatePath('/account/recover'); } return (

{headings[isSubmited ? 'submited' : 'default'].description}

{!isSubmited && (
{emailError && (

{emailError}  

)}
)}
); }