'use client'; //=========================================== // THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY UNLESS YOU ALSO EDIT THE CORRESPONDING FILE IN packages/template //=========================================== import { yupResolver } from "@hookform/resolvers/yup"; import { strictEmailSchema, yupObject } from "@hexclave/shared/dist/schema-fields"; import { runAsynchronouslyWithAlert } from "@hexclave/shared/dist/utils/promises"; import { Button, Input, Label, Typography, cn } from "@hexclave/ui"; import { useState } from "react"; import { useForm } from "react-hook-form"; import * as yup from "yup"; import { useStackApp, useUser } from ".."; import { FormWarningText } from "../components/elements/form-warning"; import { MaybeFullPage } from "../components/elements/maybe-full-page"; import { StyledLink } from "../components/link"; import { PredefinedMessageCard } from "../components/message-cards/predefined-message-card"; import { useTranslation } from "../lib/translations"; export function ForgotPasswordForm({ onSent }: { onSent?: () => void }) { const { t } = useTranslation(); const schema = yupObject({ email: strictEmailSchema(t("Please enter a valid email")).defined().nonEmpty(t("Please enter your email")) }); const { register, handleSubmit, formState: { errors }, clearErrors } = useForm({ resolver: yupResolver(schema) }); const hexclaveApp = useStackApp(); const [loading, setLoading] = useState(false); const onSubmit = async (data: yup.InferType) => { setLoading(true); try { const { email } = data; await hexclaveApp.sendForgotPasswordEmail(email); onSent?.(); } finally { setLoading(false); } }; return (
runAsynchronouslyWithAlert(handleSubmit(onSubmit)(e))} noValidate > clearErrors('email') })} /> ); } export function ForgotPassword(props: { fullPage?: boolean }) { const { t } = useTranslation(); const hexclaveApp = useStackApp(); const user = useUser(); const [sent, setSent] = useState(false); if (user) { return ; } if (sent) { return ; } return (
{t("Reset Your Password")} {t("Don't need to reset?")}{" "} { e.preventDefault(); runAsynchronouslyWithAlert(hexclaveApp.redirectToSignIn()); }} > {t("Sign in")}
setSent(true)} />
); };