import { useAdminSendResetPasswordToken } from "medusa-react" import React, { useState } from "react" import { useForm } from "react-hook-form" import { Trans, useTranslation } from "react-i18next" import useNotification from "../../../hooks/use-notification" import { getErrorMessage } from "../../../utils/error-messages" import FormValidator from "../../../utils/form-validator" import InputError from "../../atoms/input-error" import Button from "../../fundamentals/button" import CheckCircleFillIcon from "../../fundamentals/icons/check-circle-fill-icon" import SigninInput from "../../molecules/input-signin" type ResetTokenCardProps = { goBack: () => void } type FormValues = { email: string } const emailRegex = new RegExp( "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$" ) const ResetTokenCard: React.FC = ({ goBack }) => { const { t } = useTranslation() const [mailSent, setSentMail] = useState(false) const { register, handleSubmit, formState: { errors }, } = useForm() const { mutate, isLoading } = useAdminSendResetPasswordToken() const notification = useNotification() const onSubmit = handleSubmit((values: FormValues) => { mutate( { email: values.email, }, { onSuccess: () => { setSentMail(true) }, onError: (error) => { notification( t("reset-token-card-error", "Error"), getErrorMessage(error), "error" ) }, } ) }) return (

{t("reset-token-card-reset-your-password", "Reset your password")}

Enter your email address below, and we'll
send you instructions on how to reset
your password.
{!mailSent ? ( <>
) : (
{t( "reset-token-card-successfully-sent-you-an-email", "Successfully sent you an email" )}
)} {t("reset-token-card-go-back-to-sign-in", "Go back to sign in")}
) } export default ResetTokenCard