Files
Checkmate/client/src/Pages/Auth/Recovery/index.tsx
T

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2026-08-07 10:32:01 -07:00
import { Button } from "@/Components/inputs";
2026-02-20 18:13:39 +00:00
import { BaseAuthPage, TextLink } from "@/Components/design-elements";
2026-02-06 21:50:45 +00:00
2026-08-07 10:32:01 -07:00
import { useForm, FormProvider } from "react-hook-form";
2026-02-06 22:14:42 +00:00
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
import { useRecoveryForm } from "@/Hooks/useRecoveryForm";
import type { RecoveryFormData } from "@/Validation/recovery";
import { usePost } from "@/Hooks/UseApi";
2026-02-06 21:50:45 +00:00
import { useTranslation } from "react-i18next";
2026-08-07 10:32:01 -07:00
import { FormTextField } from "@/Components/inputs/forms/FormTextField";
2026-02-06 22:14:42 +00:00
2026-02-06 21:50:45 +00:00
const ForgotPasswordPage = () => {
const { t } = useTranslation();
2026-02-06 22:14:42 +00:00
const { post, loading } = usePost();
const { schema, defaults } = useRecoveryForm();
2026-08-07 10:32:01 -07:00
const form = useForm<RecoveryFormData>({
2026-02-06 22:14:42 +00:00
resolver: zodResolver(schema),
defaultValues: defaults,
});
2026-08-07 10:32:01 -07:00
const { handleSubmit } = form;
2026-02-06 22:14:42 +00:00
const onSubmit = async (data: RecoveryFormData) => {
if (loading) return;
const result = await post("/auth/recovery/request", data);
if (result?.success) {
// Navigate to Check email page
}
};
2026-02-06 21:50:45 +00:00
return (
2026-08-07 10:32:01 -07:00
<FormProvider {...form}>
<BaseAuthPage
component="form"
onSubmit={handleSubmit(onSubmit)}
title={t("pages.auth.forgotPassword.title")}
subtitle={t("pages.auth.forgotPassword.subtitle")}
2026-02-06 21:50:45 +00:00
>
2026-08-07 10:32:01 -07:00
<FormTextField
name="email"
fieldLabel={t("pages.auth.common.form.option.email.label")}
placeholder={t("pages.auth.common.form.option.email.placeholder")}
/>
<Button
variant="contained"
type="submit"
loading={loading}
>
{t("pages.auth.forgotPassword.submit")}
</Button>
<TextLink
alignSelf={"center"}
text={t("pages.auth.forgotPassword.links.login.text")}
linkText={t("pages.auth.forgotPassword.links.login.linkText")}
href="/login"
/>
</BaseAuthPage>
</FormProvider>
2026-02-06 21:50:45 +00:00
);
};
export default ForgotPasswordPage;