import CenterLayout from "@/layouts/CenterLayout"; import DashboardLayouts from "@/layouts/dashboardLayouts"; import {Button, Container, Paper, Stack, Typography,} from "@mui/material"; import {Formik} from "formik"; import * as Yup from "yup"; import {useTranslations} from "next-intl"; import PasswordField from "@/core/components/PasswordField"; import StyledForm from "@/core/components/StyledForm"; import {SET_USER_PASSWORD} from "@/core/data/apiRoutes"; import SvgChangePassword from "@/core/components/svgs/SvgChangePassword"; import useRequest from "@/lib/app/hooks/useRequest"; const DashboardChangePasswordComponent = () => { const t = useTranslations(); const requestServer = useRequest({auth: true}) const handleSubmit = (values, {setSubmitting, resetForm}) => { requestServer(SET_USER_PASSWORD, 'post', { data: { current_password: values.current_password, new_password: values.new_password, new_password_confirmation: values.new_password_confirmation, }, }).then((response) => { resetForm(); }).catch(() => { }).finally(() => { setSubmitting(false); }); }; const initialValues = { current_password: "", new_password: "", new_password_confirmation: "", }; const validationSchema = Yup.object().shape({ current_password: Yup.string().required( t("ChangePassword.error_message_current_password") ), new_password: Yup.string() .min(8, t("ChangePassword.error_message_password_length")) .required(t("ChangePassword.error_message_new_password")), new_password_confirmation: Yup.string() .required(t("ChangePassword.error_message_confirm_password")) .test( t("ChangePassword.error_message_password_match"), t("ChangePassword.error_message_password_not_match"), function (value) { return this.parent.new_password === value; } ), }); return ( {(props) => ( { e.preventDefault(); props.handleSubmit(); }} > {t("ChangePassword.typography_change_password")} )} ); }; export default DashboardChangePasswordComponent;