controllers
This commit is contained in:
1 parent
b6004241e7
commit
021b4e8ae5
1 file changed
+74
-15
@@ -1,24 +1,51 @@
|
|||||||
import { Stack } from "@mui/material";
|
import { Stack } from "@mui/material";
|
||||||
import { ConfigBox } from "@/Components/v2/design-elements";
|
import { ConfigBox } from "@/Components/v2/design-elements";
|
||||||
import { TextField } from "@/Components/v2/inputs";
|
import { TextField, Button } from "@/Components/v2/inputs";
|
||||||
|
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTheme } from "@mui/material";
|
import { useTheme } from "@mui/material";
|
||||||
|
import { useForm, Controller } from "react-hook-form";
|
||||||
|
import { usePasswordForm } from "@/Hooks/usePasswordForm";
|
||||||
|
import type { PasswordFormData } from "@/Validation/password";
|
||||||
|
|
||||||
export const TabPassword = () => {
|
export const TabPassword = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
const { resolver, defaults } = usePasswordForm();
|
||||||
|
|
||||||
|
const { control, handleSubmit } = useForm<PasswordFormData>({
|
||||||
|
resolver,
|
||||||
|
defaultValues: defaults,
|
||||||
|
});
|
||||||
|
|
||||||
|
const onSubmit = (data: PasswordFormData) => {
|
||||||
|
console.log("Password form data:", data);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.spacing(8)}>
|
<Stack
|
||||||
|
gap={theme.spacing(8)}
|
||||||
|
component="form"
|
||||||
|
onSubmit={handleSubmit(onSubmit)}
|
||||||
|
>
|
||||||
<ConfigBox
|
<ConfigBox
|
||||||
title={t("pages.account.form.currentPassword.title")}
|
title={t("pages.account.form.currentPassword.title")}
|
||||||
subtitle={t("pages.account.form.currentPassword.description")}
|
subtitle={t("pages.account.form.currentPassword.description")}
|
||||||
rightContent={
|
rightContent={
|
||||||
<TextField
|
<Controller
|
||||||
type="password"
|
name="currentPassword"
|
||||||
fieldLabel={t("pages.account.form.currentPassword.option.label")}
|
control={control}
|
||||||
placeholder={t("pages.account.form.currentPassword.option.placeholder")}
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
fieldLabel={t("pages.account.form.currentPassword.option.label")}
|
||||||
|
placeholder={t("pages.account.form.currentPassword.option.placeholder")}
|
||||||
|
autoComplete="current-password"
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
@@ -27,21 +54,53 @@ export const TabPassword = () => {
|
|||||||
subtitle={t("pages.account.form.newPassword.description")}
|
subtitle={t("pages.account.form.newPassword.description")}
|
||||||
rightContent={
|
rightContent={
|
||||||
<Stack gap={theme.spacing(8)}>
|
<Stack gap={theme.spacing(8)}>
|
||||||
<TextField
|
<Controller
|
||||||
type="password"
|
name="newPassword"
|
||||||
fieldLabel={t("pages.account.form.newPassword.option.newPassword.label")}
|
control={control}
|
||||||
placeholder={t(
|
render={({ field, fieldState }) => (
|
||||||
"pages.account.form.newPassword.option.newPassword.placeholder"
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
fieldLabel={t(
|
||||||
|
"pages.account.form.newPassword.option.newPassword.label"
|
||||||
|
)}
|
||||||
|
placeholder={t(
|
||||||
|
"pages.account.form.newPassword.option.newPassword.placeholder"
|
||||||
|
)}
|
||||||
|
autoComplete="new-password"
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<Controller
|
||||||
type="password"
|
name="confirm"
|
||||||
fieldLabel={t("pages.account.form.newPassword.option.confirm.label")}
|
control={control}
|
||||||
placeholder={t("pages.account.form.newPassword.option.confirm.placeholder")}
|
render={({ field, fieldState }) => (
|
||||||
|
<TextField
|
||||||
|
{...field}
|
||||||
|
type="password"
|
||||||
|
fieldLabel={t("pages.account.form.newPassword.option.confirm.label")}
|
||||||
|
placeholder={t(
|
||||||
|
"pages.account.form.newPassword.option.confirm.placeholder"
|
||||||
|
)}
|
||||||
|
autoComplete="new-password"
|
||||||
|
error={!!fieldState.error}
|
||||||
|
helperText={fieldState.error?.message ?? ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
sx={{ alignSelf: "flex-end", minWidth: 100 }}
|
||||||
|
>
|
||||||
|
{t("common.buttons.save")}
|
||||||
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
Reference in new issue
Block a user