refactor recovery and set new password
This commit is contained in:
1 parent
69db716f0b
commit
5916d0ca33
2 files changed
+19
-34
No files matched your search
@@ -1,12 +1,13 @@
|
|||||||
import { Button, TextField } from "@/Components/inputs";
|
import { Button } from "@/Components/inputs";
|
||||||
import { BaseAuthPage, TextLink } from "@/Components/design-elements";
|
import { BaseAuthPage, TextLink } from "@/Components/design-elements";
|
||||||
|
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, FormProvider } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
||||||
import { useRecoveryForm } from "@/Hooks/useRecoveryForm";
|
import { useRecoveryForm } from "@/Hooks/useRecoveryForm";
|
||||||
import type { RecoveryFormData } from "@/Validation/recovery";
|
import type { RecoveryFormData } from "@/Validation/recovery";
|
||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { FormTextField } from "@/Components/inputs/forms/FormTextField";
|
||||||
|
|
||||||
const ForgotPasswordPage = () => {
|
const ForgotPasswordPage = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -14,10 +15,11 @@ const ForgotPasswordPage = () => {
|
|||||||
|
|
||||||
const { schema, defaults } = useRecoveryForm();
|
const { schema, defaults } = useRecoveryForm();
|
||||||
|
|
||||||
const { control, handleSubmit } = useForm<RecoveryFormData>({
|
const form = useForm<RecoveryFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
const { handleSubmit } = form;
|
||||||
|
|
||||||
const onSubmit = async (data: RecoveryFormData) => {
|
const onSubmit = async (data: RecoveryFormData) => {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
@@ -30,24 +32,18 @@ const ForgotPasswordPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<FormProvider {...form}>
|
||||||
<BaseAuthPage
|
<BaseAuthPage
|
||||||
component="form"
|
component="form"
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
title={t("pages.auth.forgotPassword.title")}
|
title={t("pages.auth.forgotPassword.title")}
|
||||||
subtitle={t("pages.auth.forgotPassword.subtitle")}
|
subtitle={t("pages.auth.forgotPassword.subtitle")}
|
||||||
>
|
>
|
||||||
<Controller
|
<FormTextField
|
||||||
name="email"
|
name="email"
|
||||||
control={control}
|
type="email"
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
fieldLabel={t("pages.auth.common.form.option.email.label")}
|
fieldLabel={t("pages.auth.common.form.option.email.label")}
|
||||||
placeholder={t("pages.auth.common.form.option.email.placeholder")}
|
placeholder={t("pages.auth.common.form.option.email.placeholder")}
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error ? t(fieldState.error.message ?? "") : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
@@ -63,6 +59,7 @@ const ForgotPasswordPage = () => {
|
|||||||
href="/login"
|
href="/login"
|
||||||
/>
|
/>
|
||||||
</BaseAuthPage>
|
</BaseAuthPage>
|
||||||
|
</FormProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { BaseAuthPage, BulletPointCheck, TextLink } from "@/Components/design-elements";
|
import { BaseAuthPage, BulletPointCheck, TextLink } from "@/Components/design-elements";
|
||||||
import { Button, TextField } from "@/Components/inputs";
|
import { Button } from "@/Components/inputs";
|
||||||
import Stack from "@mui/material/Stack";
|
import Stack from "@mui/material/Stack";
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useForm, Controller } from "react-hook-form";
|
import { useForm, FormProvider } from "react-hook-form";
|
||||||
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
import { zodResolver } from "@hookform/resolvers/zod/dist/zod.js";
|
||||||
import { useSetNewPasswordForm } from "@/Hooks/useSetNewPasswordForm";
|
import { useSetNewPasswordForm } from "@/Hooks/useSetNewPasswordForm";
|
||||||
import type { SetNewPasswordFormData } from "@/Validation/setNewPassword";
|
import type { SetNewPasswordFormData } from "@/Validation/setNewPassword";
|
||||||
@@ -12,6 +12,7 @@ import { useParams, useNavigate } from "react-router-dom";
|
|||||||
import { usePost } from "@/Hooks/UseApi";
|
import { usePost } from "@/Hooks/UseApi";
|
||||||
import { useDispatch } from "react-redux";
|
import { useDispatch } from "react-redux";
|
||||||
import { setAuthState } from "@/Features/Auth/authSlice";
|
import { setAuthState } from "@/Features/Auth/authSlice";
|
||||||
|
import { FormTextField } from "@/Components/inputs/forms/FormTextField";
|
||||||
|
|
||||||
const SetNewPasswordPage = () => {
|
const SetNewPasswordPage = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -23,11 +24,11 @@ const SetNewPasswordPage = () => {
|
|||||||
|
|
||||||
const { schema, defaults } = useSetNewPasswordForm();
|
const { schema, defaults } = useSetNewPasswordForm();
|
||||||
|
|
||||||
const { control, handleSubmit, watch } = useForm<SetNewPasswordFormData>({
|
const form = useForm<SetNewPasswordFormData>({
|
||||||
resolver: zodResolver(schema),
|
resolver: zodResolver(schema),
|
||||||
defaultValues: defaults,
|
defaultValues: defaults,
|
||||||
});
|
});
|
||||||
|
const { handleSubmit, watch } = form;
|
||||||
const password = watch("password");
|
const password = watch("password");
|
||||||
const confirm = watch("confirm");
|
const confirm = watch("confirm");
|
||||||
|
|
||||||
@@ -57,40 +58,26 @@ const SetNewPasswordPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<FormProvider {...form}>
|
||||||
<BaseAuthPage
|
<BaseAuthPage
|
||||||
component="form"
|
component="form"
|
||||||
onSubmit={handleSubmit(onSubmit)}
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
title={t("pages.auth.setNewPassword.title")}
|
title={t("pages.auth.setNewPassword.title")}
|
||||||
subtitle={t("pages.auth.setNewPassword.subtitle")}
|
subtitle={t("pages.auth.setNewPassword.subtitle")}
|
||||||
>
|
>
|
||||||
<Controller
|
<FormTextField
|
||||||
name="password"
|
name="password"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="password"
|
type="password"
|
||||||
fieldLabel={t("pages.auth.common.form.option.password.label")}
|
fieldLabel={t("pages.auth.common.form.option.password.label")}
|
||||||
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
/>
|
||||||
)}
|
<FormTextField
|
||||||
/>
|
|
||||||
<Controller
|
|
||||||
name="confirm"
|
name="confirm"
|
||||||
control={control}
|
|
||||||
render={({ field, fieldState }) => (
|
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
type="password"
|
type="password"
|
||||||
fieldLabel={t("pages.auth.common.form.option.confirmPassword.label")}
|
fieldLabel={t("pages.auth.common.form.option.confirmPassword.label")}
|
||||||
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
placeholder={t("pages.auth.common.form.option.password.placeholder")}
|
||||||
error={!!fieldState.error}
|
|
||||||
helperText={fieldState.error?.message ?? ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Stack gap={theme.spacing(4)}>
|
<Stack gap={theme.spacing(4)}>
|
||||||
<BulletPointCheck
|
<BulletPointCheck
|
||||||
text={t("pages.auth.common.passwordRules.length")}
|
text={t("pages.auth.common.passwordRules.length")}
|
||||||
@@ -132,6 +119,7 @@ const SetNewPasswordPage = () => {
|
|||||||
href="/login"
|
href="/login"
|
||||||
/>
|
/>
|
||||||
</BaseAuthPage>
|
</BaseAuthPage>
|
||||||
|
</FormProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user