import { useId } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useNavigate } from "react-router-dom"; import { useParams } from "react-router-dom"; import { useTheme } from "@emotion/react"; import { Box, Stack, Typography, Button } from "@mui/material"; import { setNewPassword } from "../../Features/Auth/authSlice"; import { createToast } from "../../Utils/toastUtils"; import { newOrChangedCredentials } from "../../Validation/validation"; import Check from "../../Components/Check/Check"; import TextInput from "../../Components/Inputs/TextInput"; import { PasswordEndAdornment } from "../../Components/Inputs/TextInput/Adornments"; import IconBox from "../../Components/IconBox"; import LockIcon from "../../assets/icons/lock.svg?react"; import Logo from "../../assets/icons/checkmate-icon.svg?react"; import Background from "../../assets/Images/background-grid.svg?react"; import "./index.css"; import { useValidatePassword } from "./hooks/useValidatePassword"; import { Trans, useTranslation } from "react-i18next"; const SetNewPassword = () => { const navigate = useNavigate(); const dispatch = useDispatch(); const theme = useTheme(); const { t } = useTranslation(); const passwordId = useId(); const confirmPasswordId = useId(); const { form, errors, handleChange, feedbacks } = useValidatePassword(); const { isLoading } = useSelector((state) => state.auth); const { token } = useParams(); const handleSubmit = async (e) => { e.preventDefault(); const { error } = newOrChangedCredentials.validate(form, { abortEarly: false, context: { password: form.password }, }); if (error) { createToast({ body: error.details && error.details.length > 0 ? error.details[0].message // FIXME: Potential untranslated string : t("auth.common.errors.validation"), }); } else { const action = await dispatch(setNewPassword({ token, form })); if (action.payload.success) { navigate("/new-password-confirmed"); createToast({ body: t("auth.forgotPassword.toasts.success"), }); } else { const errorMessage = action.payload ? action.payload.msg // FIXME: Potential untranslated string : t("auth.forgotPassword.toasts.error"); createToast({ body: errorMessage, }); } } }; return ( {t("common.appName")} .MuiStack-root": { border: 1, borderRadius: theme.spacing(5), borderColor: theme.palette.primary.lowContrast, backgroundColor: theme.palette.primary.main, padding: { xs: theme.spacing(12), sm: theme.spacing(20), }, }, }} > {t("auth.forgotPassword.heading")} {t("auth.forgotPassword.subheadings.stepThree")} } /> } /> navigate("/login")} sx={{ userSelect: "none" }} /> ), }} /> ); }; export default SetNewPassword;