i18n: Refactor, fix and clean up auth forms

This commit is contained in:
Michal Šmahel committed 2025-06-09 21:54:47 +02:00
1 parent 74915f6840
commit 00f3941ca6
24 files changed
+1899 -717

No files matched your search

+56 -40
View File
@@ -5,7 +5,7 @@ import { useDispatch } from "react-redux";
import { useNavigate } from "react-router";
import { createToast } from "../../Utils/toastUtils";
import { forgotPassword } from "../../Features/Auth/authSlice";
import { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
import Background from "../../assets/Images/background-grid.svg?react";
import EmailIcon from "../../assets/icons/email.svg?react";
import Logo from "../../assets/icons/checkmate-icon.svg?react";
@@ -31,16 +31,16 @@ const CheckEmail = () => {
const toastFail = [
{
body: "Email not found.",
body: t("auth.forgotPassword.toasts.emailNotFound"),
},
{
body: "Redirecting in 3...",
body: t("auth.forgotPassword.toasts.redirect").replace("<seconds/>", "3"),
},
{
body: "Redirecting in 2...",
body: t("auth.forgotPassword.toasts.redirect").replace("<seconds/>", "2"),
},
{
body: "Redirecting in 1...",
body: t("auth.forgotPassword.toasts.redirect").replace("<seconds/>", "1"),
},
];
@@ -62,19 +62,19 @@ const CheckEmail = () => {
const action = await dispatch(forgotPassword(form));
if (action.payload.success) {
createToast({
body: `Instructions sent to ${form.email}.`,
body: t("auth.forgotPassword.toasts.sent").replace("<email/>", form.email),
});
setDisabled(false);
} else {
if (action.payload) {
// dispatch errors
createToast({
body: action.payload.msg,
body: action.payload.msg, // FIXME: Potential untranslated string
});
} else {
// unknown errors
createToast({
body: "Unknown error.",
body: t("common.toasts.unknownError"),
});
}
}
@@ -160,18 +160,24 @@ const CheckEmail = () => {
svgHeight={24}
mb={theme.spacing(4)}
>
<EmailIcon alt="email icon" />
<EmailIcon alt={t("auth.forgotPassword.imageAlts.email")} />
</IconBox>
</Stack>
<Typography component="h1">{t("authCheckEmailTitle")}</Typography>
<Typography component="h1">{t("auth.forgotPassword.heading")}</Typography>
<Typography>
{t("authCheckEmailDescription")}{" "}
<Typography
className="email-sent-to"
component="span"
>
{email || "username@email.com"}
</Typography>
<Trans
i18nKey="auth.forgotPassword.subheadings.stepTwo"
components={{
email: (
<Typography
className="email-sent-to"
component="span"
>
{email || "username@email.com"}
</Typography>
),
}}
/>
</Typography>
</Box>
<Button
@@ -183,23 +189,27 @@ const CheckEmail = () => {
maxWidth: 400,
}}
>
{t("authCheckEmailOpenEmailButton")}
{t("auth.forgotPassword.buttons.openEmail")}
</Button>
<Typography sx={{ alignSelf: "center", mt: theme.spacing(6) }}>
{t("authCheckEmailDidntReceiveEmail")}{" "}
<Typography
component="span"
onClick={resendToken}
sx={{
color: theme.palette.accent.main,
userSelect: "none",
pointerEvents: disabled ? "none" : "auto",
cursor: disabled ? "default" : "pointer",
opacity: disabled ? 0.5 : 1,
<Trans
i18nKey="auth.forgotPassword.links.resend"
components={{
a: (
<Typography
component="span"
onClick={resendToken}
sx={{
color: theme.palette.accent.main,
userSelect: "none",
pointerEvents: disabled ? "none" : "auto",
cursor: disabled ? "default" : "pointer",
opacity: disabled ? 0.5 : 1,
}}
/>
),
}}
>
{t("authCheckEmailClickToResend")}
</Typography>
/>
</Typography>
</Stack>
</Stack>
@@ -207,15 +217,21 @@ const CheckEmail = () => {
textAlign="center"
p={theme.spacing(12)}
>
<Typography display="inline-block">{t("goBackTo")}</Typography>
<Typography
component="span"
ml={theme.spacing(2)}
color={theme.palette.accent.main}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
>
{t("authLoginTitle")}
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
components={{
a: (
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
/>
),
}}
/>
</Typography>
</Box>
</Stack>
+28 -22
View File
@@ -11,7 +11,7 @@ import Logo from "../../assets/icons/checkmate-icon.svg?react";
import Key from "../../assets/icons/key.svg?react";
import Background from "../../assets/Images/background-grid.svg?react";
import IconBox from "../../Components/IconBox";
import { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
import "./index.css";
const ForgotPassword = () => {
@@ -41,8 +41,8 @@ const ForgotPassword = () => {
// validation errors
const err =
error.details && error.details.length > 0
? error.details[0].message
: "Error validating data.";
? error.details[0].message // FIXME: Possibly untranslated string
: t("auth.common.errors.validation");
setErrors({ email: err });
createToast({
body: err,
@@ -53,18 +53,18 @@ const ForgotPassword = () => {
sessionStorage.setItem("email", form.email);
navigate("/check-email");
createToast({
body: `Instructions sent to ${form.email}.`,
body: t("auth.forgotPassword.toasts.sent").replace("<email/>", form.email),
});
} else {
if (action.payload) {
// dispatch errors
createToast({
body: action.payload.msg,
body: action.payload.msg, // FIXME: Potentially untranslated string
});
} else {
// unknown errors
createToast({
body: "Unknown error.",
body: t("common.toasts.unknownError"),
});
}
}
@@ -162,11 +162,11 @@ const ForgotPassword = () => {
svgHeight={24}
mb={theme.spacing(4)}
>
<Key alt="password key icon" />
<Key alt={t("auth.forgotPassword.imageAlts.passwordKey")} />
</IconBox>
</Stack>
<Typography component="h1">{t("authForgotPasswordTitle")}</Typography>
<Typography>{t("authForgotPasswordInstructions")}</Typography>
<Typography component="h1">{t("auth.forgotPassword.heading")}</Typography>
<Typography>{t("auth.forgotPassword.subheadings.stepOne")}</Typography>
</Box>
<Box
component="form"
@@ -179,13 +179,13 @@ const ForgotPassword = () => {
<TextInput
type="email"
id="forgot-password-email-input"
label={t("email")}
label={t("auth.common.inputs.email.label")}
isRequired={true}
placeholder={t("enterEmail")}
placeholder={t("auth.common.inputs.email.placeholder")}
value={form.email}
onChange={handleChange}
error={errors.email ? true : false}
helperText={t(errors.email)}
helperText={t(errors.email)} // Localization keys are in validation.js
/>
<Button
variant="contained"
@@ -198,7 +198,7 @@ const ForgotPassword = () => {
mt: theme.spacing(15),
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Box>
</Stack>
@@ -207,15 +207,21 @@ const ForgotPassword = () => {
textAlign="center"
p={theme.spacing(12)}
>
<Typography display="inline-block">{t("goBackTo")}</Typography>
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
>
{t("authLoginTitle")}
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
components={{
a: (
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
/>
),
}}
/>
</Typography>
</Box>
</Stack>
@@ -35,8 +35,8 @@ const EmailStep = ({ form, errors, onSubmit, onChange }) => {
position="relative"
>
<Box>
<Typography component="h1">{t("authLoginTitle")}</Typography>
<Typography>{t("authLoginEnterEmail")}</Typography>
<Typography component="h1">{t("auth.login.heading")}</Typography>
<Typography>{t("auth.login.subheadings.stepOne")}</Typography>
</Box>
<Box
textAlign="left"
@@ -50,14 +50,14 @@ const EmailStep = ({ form, errors, onSubmit, onChange }) => {
<TextInput
type="email"
id="login-email-input"
label={t("email")}
label={t("auth.common.inputs.email.label")}
isRequired={true}
placeholder="jordan.ellis@domain.com"
placeholder={t("auth.common.inputs.email.placeholder")}
autoComplete="email"
value={form.email}
onChange={onChange}
error={errors.email ? true : false}
helperText={errors.email ? t(errors.email) : ""}
helperText={errors.email ? t(errors.email) : ""} // Localization keys are in validation.js
ref={inputRef}
/>
<Stack
@@ -87,7 +87,7 @@ const EmailStep = ({ form, errors, onSubmit, onChange }) => {
},
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Box>
@@ -1,7 +1,7 @@
import { Box, Typography, useTheme } from "@mui/material";
import PropTypes from "prop-types";
import { useNavigate } from "react-router";
import { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
const ForgotPasswordLabel = ({ email, errorEmail }) => {
const theme = useTheme();
@@ -22,16 +22,20 @@ const ForgotPasswordLabel = ({ email, errorEmail }) => {
display="inline-block"
color={theme.palette.primary.main}
>
{t("authForgotPasswordTitle")}
</Typography>
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
sx={{ userSelect: "none" }}
onClick={handleNavigate}
>
{t("authForgotPasswordResetPassword")}
<Trans
i18nKey="auth.login.links.forgotPassword"
components={{
a: (
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
sx={{ userSelect: "none" }}
onClick={handleNavigate}
/>
),
}}
/>
</Typography>
</Box>
);
@@ -38,8 +38,8 @@ const PasswordStep = ({ form, errors, onSubmit, onChange, onBack }) => {
textAlign="center"
>
<Box>
<Typography component="h1">{t("authLoginTitle")}</Typography>
<Typography>{t("authLoginEnterPassword")}</Typography>
<Typography component="h1">{t("auth.login.heading")}</Typography>
<Typography>{t("auth.login.subheadings.stepTwo")}</Typography>
</Box>
<Box
component="form"
@@ -56,14 +56,14 @@ const PasswordStep = ({ form, errors, onSubmit, onChange, onBack }) => {
<TextInput
type="password"
id="login-password-input"
label={t("password")}
label={t("auth.common.inputs.password.label")}
isRequired={true}
placeholder="••••••••••"
autoComplete="current-password"
value={form.password}
onChange={onChange}
error={errors.password ? true : false}
helperText={errors.password}
helperText={errors.password ? t(errors.password) : ""} // Localization keys are in validation.js
ref={inputRef}
endAdornment={<PasswordEndAdornment />}
/>
@@ -95,7 +95,7 @@ const PasswordStep = ({ form, errors, onSubmit, onChange, onBack }) => {
}}
>
<ArrowBackRoundedIcon />
{t("commonBack")}{" "}
{t("auth.common.navigation.back")}{" "}
</Button>
<Button
variant="contained"
@@ -121,7 +121,7 @@ const PasswordStep = ({ form, errors, onSubmit, onChange, onBack }) => {
boxShadow: `none`,
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Box>
+29 -25
View File
@@ -15,7 +15,7 @@ import PasswordStep from "./Components/PasswordStep";
import ThemeSwitch from "../../../Components/ThemeSwitch";
import ForgotPasswordLabel from "./Components/ForgotPasswordLabel";
import LanguageSelector from "../../../Components/LanguageSelector";
import { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
const DEMO = import.meta.env.VITE_APP_DEMO;
@@ -83,8 +83,8 @@ const Login = () => {
if (error) {
const errorMessage = error.details[0].message;
const translatedMessage = errorMessage.startsWith("auth")
? t(errorMessage)
: errorMessage;
? t(errorMessage) // Localization keys are in validation.js
: errorMessage; // FIXME: Potential untranslated string
setErrors((prev) => ({ ...prev, email: translatedMessage }));
createToast({ body: translatedMessage });
} else {
@@ -104,31 +104,31 @@ const Login = () => {
body:
error.details && error.details.length > 0
? error.details[0].message.startsWith("auth")
? t(error.details[0].message)
: error.details[0].message
: t("Error validating data."),
? t(error.details[0].message) // Localization keys are in validation.js
: error.details[0].message // FIXME: Potential untranslated string
: t("auth.common.errors.validation"),
});
} else {
const action = await dispatch(login(form));
if (action.payload.success) {
navigate("/uptime");
createToast({
body: t("welcomeBack"),
body: t("auth.login.toasts.success"),
});
} else {
if (action.payload) {
if (action.payload.msg === "Incorrect password")
setErrors({
password: "The password you provided does not match our records",
password: t("auth.common.fields.password.errors.incorrect"),
});
// dispatch errors
createToast({
body: action.payload.msg,
body: t("auth.login.toasts.incorrectPassword"),
});
} else {
// unknown errors
createToast({
body: "Unknown error.",
body: t("common.toasts.unknownError"),
});
}
}
@@ -237,21 +237,25 @@ const Login = () => {
display="inline-block"
color={theme.palette.primary.main}
>
{t("doNotHaveAccount")}
</Typography>
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
sx={{
cursor: "pointer",
"&:hover": {
color: theme.palette.accent.darker,
},
}}
onClick={() => navigate("/register")}
>
{t("registerHere")}
<Trans
i18nKey="auth.login.links.register"
components={{
a: (
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
sx={{
cursor: "pointer",
"&:hover": {
color: theme.palette.accent.darker,
},
}}
onClick={() => navigate("/register")}
/>
),
}}
/>
</Typography>
</Box>
</Stack>
+20 -14
View File
@@ -8,7 +8,7 @@ import Background from "../../assets/Images/background-grid.svg?react";
import ConfirmIcon from "../../assets/icons/check-outlined.svg?react";
import Logo from "../../assets/icons/checkmate-icon.svg?react";
import IconBox from "../../Components/IconBox";
import { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
import "./index.css";
const NewPasswordConfirmed = () => {
@@ -96,11 +96,11 @@ const NewPasswordConfirmed = () => {
svgHeight={24}
mb={theme.spacing(4)}
>
<ConfirmIcon alt="password confirm icon" />
<ConfirmIcon alt={t("auth.forgotPassword.imageAlts.passwordConfirm")} />
</IconBox>
</Stack>
<Typography component="h1">{t("passwordreset")}</Typography>
<Typography mb={theme.spacing(2)}>{t("authNewPasswordConfirmed")}</Typography>
<Typography component="h1">{t("auth.forgotPassword.heading")}</Typography>
<Typography mb={theme.spacing(2)}>{t("auth.forgotPassword.subheadings.stepFour")}</Typography>
</Box>
<Button
variant="contained"
@@ -110,7 +110,7 @@ const NewPasswordConfirmed = () => {
maxWidth: 400,
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Stack>
@@ -118,15 +118,21 @@ const NewPasswordConfirmed = () => {
textAlign="center"
p={theme.spacing(12)}
>
<Typography display="inline-block">{t("goBackTo")}</Typography>
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
>
{t("authLoginTitle")}
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
components={{
a: (
<Typography
component="span"
color={theme.palette.accent.main}
ml={theme.spacing(2)}
onClick={handleNavigate}
sx={{ userSelect: "none" }}
/>
),
}}
/>
</Typography>
</Box>
</Stack>
+33 -19
View File
@@ -35,11 +35,15 @@ const LandingPage = ({ isSuperAdmin, onSignup }) => {
textAlign="center"
>
<Box>
<Typography component="h1">{t("signUp")}</Typography>
<Typography component="h1">
{isSuperAdmin
? t("auth.registration.heading.superAdmin")
: t("auth.registration.heading.user")}
</Typography>
<Typography>
{isSuperAdmin
? t("authRegisterCreateSuperAdminAccount")
: t("authRegisterCreateAccount")}
? t("auth.registration.description.superAdmin")
: t("auth.registration.description.user")}
</Typography>
</Box>
<Box width="100%">
@@ -62,13 +66,15 @@ const LandingPage = ({ isSuperAdmin, onSignup }) => {
}}
>
<Mail />
{t("authRegisterSignUpWithEmail")}
{isSuperAdmin
? t("auth.registration.gettingStartedButton.superAdmin")
: t("auth.registration.gettingStartedButton.user")}
</Button>
</Box>
<Box maxWidth={400}>
<Typography className="tos-p">
<Trans
i18nKey="authRegisterBySigningUp"
i18nKey="auth.registration.termsAndPolicies"
components={{
a1: (
<Typography
@@ -189,7 +195,8 @@ const Register = ({ isSuperAdmin }) => {
newErrors[err.path[0]] = err.message;
});
setErrors(newErrors);
createToast({ body: error.details[0].message || "Error validating data." });
// Localization keys are in validation.js
createToast({ body: t(error.details[0].message || "auth.common.errors.validation") });
};
const handleStepOne = async (e) => {
@@ -246,7 +253,7 @@ const Register = ({ isSuperAdmin }) => {
const authToken = action.payload.data;
navigate("/uptime");
createToast({
body: "Welcome! Your account was created successfully.",
body: t("auth.registration.toasts.success"),
});
} else {
if (action.payload) {
@@ -255,7 +262,7 @@ const Register = ({ isSuperAdmin }) => {
});
} else {
createToast({
body: "Unknown error.",
body: t("common.toasts.unknownError"),
});
}
}
@@ -346,6 +353,7 @@ const Register = ({ isSuperAdmin }) => {
/>
) : step === 1 ? (
<StepOne
isSuperAdmin={isSuperAdmin}
form={form}
errors={errors}
onSubmit={handleStepOne}
@@ -354,6 +362,7 @@ const Register = ({ isSuperAdmin }) => {
/>
) : step === 2 ? (
<StepTwo
isSuperAdmin={isSuperAdmin}
form={form}
errors={errors}
onSubmit={handleStepTwo}
@@ -362,6 +371,7 @@ const Register = ({ isSuperAdmin }) => {
/>
) : step === 3 ? (
<StepThree
isSuperAdmin={isSuperAdmin}
/* form={form}
errors={errors} */
onSubmit={handleStepThree}
@@ -377,17 +387,21 @@ const Register = ({ isSuperAdmin }) => {
p={theme.spacing(12)}
>
<Typography display="inline-block">
{t("authRegisterAlreadyHaveAccount")}
</Typography>
<Typography
component="span"
ml={theme.spacing(2)}
onClick={() => {
navigate("/login");
}}
sx={{ userSelect: "none", color: theme.palette.accent.main }}
>
{t("authRegisterLoginLink")}
<Trans
i18nKey="auth.registration.links.login"
components={{
a: (
<Typography
component="span"
ml={theme.spacing(2)}
onClick={() => {
navigate("/login");
}}
sx={{ userSelect: "none", color: theme.palette.accent.main }}
/>
),
}}
/>
</Typography>
</Box>
</Stack>
@@ -7,6 +7,7 @@ import TextInput from "../../../../Components/Inputs/TextInput";
import { useTranslation } from "react-i18next";
StepOne.propTypes = {
isSuperAdmin: PropTypes.bool,
form: PropTypes.object,
errors: PropTypes.object,
onSubmit: PropTypes.func,
@@ -18,6 +19,7 @@ StepOne.propTypes = {
* Renders the first step of the sign up process.
*
* @param {Object} props
* @param {boolean} props.isSuperAdmin - Whether the user is creating and admin account
* @param {Object} props.form - Form state object.
* @param {Object} props.errors - Object containing form validation errors.
* @param {Function} props.onSubmit - Callback function to handle form submission.
@@ -26,7 +28,7 @@ StepOne.propTypes = {
* @returns {JSX.Element}
*/
function StepOne({ form, errors, onSubmit, onChange, onBack }) {
function StepOne({ isSuperAdmin, form, errors, onSubmit, onChange, onBack }) {
const theme = useTheme();
const inputRef = useRef(null);
const { t } = useTranslation();
@@ -45,8 +47,12 @@ function StepOne({ form, errors, onSubmit, onChange, onBack }) {
textAlign="center"
>
<Box>
<Typography component="h1">{t("signUp")}</Typography>
<Typography>{t("authRegisterStepOnePersonalDetails")}</Typography>
<Typography component="h1">
{isSuperAdmin
? t("auth.registration.heading.superAdmin")
: t("auth.registration.heading.user")}
</Typography>
<Typography>{t("auth.registration.subheadings.stepOne")}</Typography>
</Box>
<Box
@@ -64,26 +70,26 @@ function StepOne({ form, errors, onSubmit, onChange, onBack }) {
>
<TextInput
id="register-firstname-input"
label={t("authRegisterFirstName")}
label={t("auth.common.inputs.firstName.label")}
isRequired={true}
placeholder="Jordan"
placeholder={t("auth.common.inputs.firstName.placeholder")}
autoComplete="given-name"
value={form.firstName}
onChange={onChange}
error={errors.firstName ? true : false}
helperText={errors.firstName}
helperText={t(errors.firstName)} // Localization keys are in validation.js
ref={inputRef}
/>
<TextInput
id="register-lastname-input"
label={t("authRegisterLastName")}
label={t("auth.common.inputs.lastName.label")}
isRequired={true}
placeholder="Ellis"
placeholder={t("auth.common.inputs.lastName.placeholder")}
autoComplete="family-name"
value={form.lastName}
onChange={onChange}
error={errors.lastName ? true : false}
helperText={errors.lastName}
helperText={t(errors.lastName)} // Localization keys are in validation.js
/>
</Box>
<Stack
@@ -108,7 +114,7 @@ function StepOne({ form, errors, onSubmit, onChange, onBack }) {
}}
>
<ArrowBackRoundedIcon />
{t("commonBack")}
{t("auth.common.navigation.back")}
</Button>
<Button
variant="contained"
@@ -124,7 +130,7 @@ function StepOne({ form, errors, onSubmit, onChange, onBack }) {
},
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Box>
@@ -8,6 +8,7 @@ import Check from "../../../../Components/Check/Check";
import { useValidatePassword } from "../../hooks/useValidatePassword";
import { useTranslation } from "react-i18next";
StepThree.propTypes = {
isSuperAdmin: PropTypes.bool,
onSubmit: PropTypes.func,
onBack: PropTypes.func,
};
@@ -16,11 +17,12 @@ StepThree.propTypes = {
* Renders the third step of the sign up process.
*
* @param {Object} props
* @param {boolean} props.isSuperAdmin - Whether the user is creating and admin account
* @param {Function} props.onSubmit - Callback function to handle form submission.
* @param {Function} props.onBack - Callback function to handle "Back" button click.
* @returns {JSX.Element}
*/
function StepThree({ onSubmit, onBack }) {
function StepThree({ isSuperAdmin, onSubmit, onBack }) {
const theme = useTheme();
const inputRef = useRef(null);
const { t } = useTranslation();
@@ -39,8 +41,12 @@ function StepThree({ onSubmit, onBack }) {
textAlign="center"
>
<Box>
<Typography component="h1">{t("signUp")}</Typography>
<Typography>{t("createPassword")}</Typography>
<Typography component="h1">
{isSuperAdmin
? t("auth.registration.heading.superAdmin")
: t("auth.registration.heading.user")}
</Typography>
<Typography>{t("auth.registration.subheadings.stepThree")}</Typography>
</Box>
<Box
component="form"
@@ -64,26 +70,30 @@ function StepThree({ onSubmit, onBack }) {
type="password"
id="register-password-input"
name="password"
label={t("authLoginEnterPassword")}
label={t("auth.common.inputs.password.label")}
isRequired={true}
placeholder={t("createAPassword")}
placeholder="••••••••••"
autoComplete="current-password"
value={form.password}
onChange={handleChange}
error={errors.password && errors.password[0] ? true : false}
helperText={errors.password === "auth.common.inputs.password.errors.empty"
? t(errors.password)
: ""} // Other errors are related to required password conditions and are visualized below the input
ref={inputRef}
/>
<TextInput
type="password"
id="register-confirm-input"
name="confirm"
label={t("authSetNewPasswordConfirmPassword")}
label={t("auth.common.inputs.passwordConfirm.label")}
isRequired={true}
placeholder={t("confirmPassword")}
placeholder={t("auth.common.inputs.passwordConfirm.placeholder")}
autoComplete="current-password"
value={form.confirm}
onChange={handleChange}
error={errors.confirm && errors.confirm[0] ? true : false}
helperText={t(errors.confirm)} // Localization keys are in validation.js
/>
</Box>
<Stack
@@ -91,33 +101,33 @@ function StepThree({ onSubmit, onBack }) {
mb={{ xs: theme.spacing(6), sm: theme.spacing(8) }}
>
<Check
noHighlightText={t("authPasswordMustBeAtLeast")}
text={t("authPasswordCharactersLong")}
noHighlightText={t("auth.common.inputs.password.rules.length.beginning")}
text={t("auth.common.inputs.password.rules.length.highlighted")}
variant={feedbacks.length}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordSpecialCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.special.beginning")}
text={t("auth.common.inputs.password.rules.special.highlighted")}
variant={feedbacks.special}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordOneNumber")}
noHighlightText={t("auth.common.inputs.password.rules.number.beginning")}
text={t("auth.common.inputs.password.rules.number.highlighted")}
variant={feedbacks.number}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordUpperCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.uppercase.beginning")}
text={t("auth.common.inputs.password.rules.uppercase.highlighted")}
variant={feedbacks.uppercase}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordLowerCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.lowercase.beginning")}
text={t("auth.common.inputs.password.rules.lowercase.highlighted")}
variant={feedbacks.lowercase}
/>
<Check
noHighlightText={t("authPasswordConfirmAndPassword")}
text={t("authPasswordMustMatch")}
noHighlightText={t("auth.common.inputs.password.rules.match.beginning")}
text={t("auth.common.inputs.password.rules.match.highlighted")}
variant={feedbacks.confirm}
/>
</Stack>
@@ -141,7 +151,7 @@ function StepThree({ onSubmit, onBack }) {
}}
>
<ArrowBackRoundedIcon />
{t("commonBack")}
{t("auth.common.navigation.back")}
</Button>
<Button
type="submit"
@@ -161,7 +171,7 @@ function StepThree({ onSubmit, onBack }) {
},
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Box>
@@ -7,6 +7,7 @@ import TextInput from "../../../../Components/Inputs/TextInput";
import { useTranslation } from "react-i18next";
StepTwo.propTypes = {
isSuperAdmin: PropTypes.bool,
form: PropTypes.object,
errors: PropTypes.object,
onSubmit: PropTypes.func,
@@ -18,6 +19,7 @@ StepTwo.propTypes = {
* Renders the second step of the sign up process.
*
* @param {Object} props
* @param {boolean} props.isSuperAdmin - Whether the user is creating and admin account
* @param {Object} props.form - Form state object.
* @param {Object} props.errors - Object containing form validation errors.
* @param {Function} props.onSubmit - Callback function to handle form submission.
@@ -25,7 +27,7 @@ StepTwo.propTypes = {
* @param {Function} props.onBack - Callback function to handle "Back" button click.
* @returns {JSX.Element}
*/
function StepTwo({ form, errors, onSubmit, onChange, onBack }) {
function StepTwo({ isSuperAdmin, form, errors, onSubmit, onChange, onBack }) {
const theme = useTheme();
const inputRef = useRef(null);
const { t } = useTranslation();
@@ -43,8 +45,12 @@ function StepTwo({ form, errors, onSubmit, onChange, onBack }) {
textAlign="center"
>
<Box>
<Typography component="h1">{t("signUp")}</Typography>
<Typography>{t("enterEmail")}</Typography>
<Typography component="h1">
{isSuperAdmin
? t("auth.registration.heading.superAdmin")
: t("auth.registration.heading.user")}
</Typography>
<Typography>{t("auth.registration.subheadings.stepTwo")}</Typography>
</Box>
<Box
@@ -60,22 +66,15 @@ function StepTwo({ form, errors, onSubmit, onChange, onBack }) {
<TextInput
type="email"
id="register-email-input"
label={t("authRegisterEmail")}
label={t("auth.common.inputs.email.label")}
isRequired={true}
placeholder="jordan.ellis@domain.com"
placeholder={t("auth.common.inputs.email.placeholder")}
autoComplete="email"
value={form.email}
onInput={(e) => (e.target.value = e.target.value.toLowerCase())}
onChange={onChange}
error={errors.email ? true : false}
helperText={
errors.email &&
(errors.email.includes("required")
? t("authRegisterEmailRequired")
: errors.email.includes("valid email")
? t("authRegisterEmailInvalid")
: t(errors.email))
}
helperText={t(errors.email)} // Localization keys are in validation.js
ref={inputRef}
/>
<Stack
@@ -98,7 +97,7 @@ function StepTwo({ form, errors, onSubmit, onChange, onBack }) {
}}
>
<ArrowBackRoundedIcon />
{t("commonBack")}
{t("auth.common.navigation.back")}
</Button>
<Button
variant="contained"
@@ -114,7 +113,7 @@ function StepTwo({ form, errors, onSubmit, onChange, onBack }) {
},
}}
>
{t("continue")}
{t("auth.common.navigation.continue")}
</Button>
</Stack>
</Box>
+44 -36
View File
@@ -16,7 +16,7 @@ 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 { useTranslation } from "react-i18next";
import { Trans, useTranslation } from "react-i18next";
const SetNewPassword = () => {
const navigate = useNavigate();
@@ -43,20 +43,20 @@ const SetNewPassword = () => {
createToast({
body:
error.details && error.details.length > 0
? error.details[0].message
: "Error validating data.",
? 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: "Your password was reset successfully.",
body: t("auth.forgotPassword.toasts.success"),
});
} else {
const errorMessage = action.payload
? action.payload.msg
: "Unable to reset password. Please try again later or contact support.";
? action.payload.msg // FIXME: Potential untranslated string
: t("auth.forgotPassword.toasts.error");
createToast({
body: errorMessage,
});
@@ -140,11 +140,11 @@ const SetNewPassword = () => {
svgHeight={24}
mb={theme.spacing(4)}
>
<LockIcon alt="lock icon" />
<LockIcon alt={t("auth.forgotPassword.imageAlts.lock")} />
</IconBox>
</Stack>
<Typography component="h1">{t("authSetNewPasswordTitle")}</Typography>
<Typography>{t("authSetNewPasswordDescription")}</Typography>
<Typography component="h1">{t("auth.forgotPassword.heading")}</Typography>
<Typography>{t("auth.forgotPassword.subheadings.stepThree")}</Typography>
</Box>
<Box
width="100%"
@@ -165,13 +165,15 @@ const SetNewPassword = () => {
id={passwordId}
type="password"
name="password"
label={t("commonPassword")}
label={t("auth.common.inputs.password.label")}
isRequired={true}
placeholder="••••••••"
value={form.password}
onChange={handleChange}
error={errors.password ? true : false}
helperText={errors.password}
helperText={errors.password === "auth.common.inputs.password.errors.empty"
? t(errors.password)
: ""} // Other errors are related to required password conditions and are visualized below the input
endAdornment={<PasswordEndAdornment />}
/>
</Box>
@@ -185,13 +187,13 @@ const SetNewPassword = () => {
id={confirmPasswordId}
type="password"
name="confirm"
label={t("authSetNewPasswordConfirmPassword")}
label={t("auth.common.inputs.passwordConfirm.label")}
isRequired={true}
placeholder="••••••••"
placeholder={t("auth.common.inputs.passwordConfirm.placeholder")}
value={form.confirm}
onChange={handleChange}
error={errors.confirm ? true : false}
helperText={errors.confirm}
helperText={t(errors.confirm)} // Localization keys are in validation.js
endAdornment={<PasswordEndAdornment />}
/>
</Box>
@@ -200,33 +202,33 @@ const SetNewPassword = () => {
mb={theme.spacing(12)}
>
<Check
noHighlightText={t("authPasswordMustBeAtLeast")}
text={t("authPasswordCharactersLong")}
noHighlightText={t("auth.common.inputs.password.rules.length.beginning")}
text={t("auth.common.inputs.password.rules.length.highlighted")}
variant={feedbacks.length}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordSpecialCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.special.beginning")}
text={t("auth.common.inputs.password.rules.special.highlighted")}
variant={feedbacks.special}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordOneNumber")}
noHighlightText={t("auth.common.inputs.password.rules.number.beginning")}
text={t("auth.common.inputs.password.rules.number.highlighted")}
variant={feedbacks.number}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordUpperCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.uppercase.beginning")}
text={t("auth.common.inputs.password.rules.uppercase.highlighted")}
variant={feedbacks.uppercase}
/>
<Check
noHighlightText={t("authPasswordMustContainAtLeast")}
text={t("authPasswordLowerCharacter")}
noHighlightText={t("auth.common.inputs.password.rules.lowercase.beginning")}
text={t("auth.common.inputs.password.rules.lowercase.highlighted")}
variant={feedbacks.lowercase}
/>
<Check
noHighlightText={t("authPasswordConfirmAndPassword")}
text={t("authPasswordMustMatch")}
noHighlightText={t("auth.common.inputs.password.rules.match.beginning")}
text={t("auth.common.inputs.password.rules.match.highlighted")}
variant={feedbacks.confirm}
/>
</Stack>
@@ -243,7 +245,7 @@ const SetNewPassword = () => {
}
sx={{ width: "100%", maxWidth: 400 }}
>
{t("authSetNewPasswordResetPassword")}
{t("auth.forgotPassword.buttons.resetPassword")}
</Button>
</Stack>
</Stack>
@@ -251,15 +253,21 @@ const SetNewPassword = () => {
textAlign="center"
p={theme.spacing(12)}
>
<Typography display="inline-block">{t("goBackTo")} —</Typography>
<Typography
component="span"
color={theme.palette.primary.main}
ml={theme.spacing(2)}
onClick={() => navigate("/login")}
sx={{ userSelect: "none" }}
>
{t("authLoginTitle")}
<Typography display="inline-block">
<Trans
i18nKey="auth.forgotPassword.links.login"
components={{
a: (
<Typography
component="span"
color={theme.palette.primary.main}
ml={theme.spacing(2)}
onClick={() => navigate("/login")}
sx={{ userSelect: "none" }}
/>
),
}}
/>
</Typography>
</Box>
</Stack>