From 1e6bf650b58abb6047a3de13f3f9027d8cb7648f Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 4 Mar 2023 21:37:47 +0100 Subject: [PATCH] refactor: Improve i18n for recover 2fa --- public/locales/en-US/common.json | 3 +++ public/locales/en-US/recover-2fa.json | 10 ++++++++++ src/routes/Recover2FARoute.tsx | 23 +++++++++++++---------- 3 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 public/locales/en-US/recover-2fa.json diff --git a/public/locales/en-US/common.json b/public/locales/en-US/common.json index c8704c6..8f42f06 100644 --- a/public/locales/en-US/common.json +++ b/public/locales/en-US/common.json @@ -7,6 +7,9 @@ "2faCode": { "label": "Code", "placeholder": "123456" + }, + "recoveryCode": { + "label": "Recovery Code" } } } diff --git a/public/locales/en-US/recover-2fa.json b/public/locales/en-US/recover-2fa.json new file mode 100644 index 0000000..66897eb --- /dev/null +++ b/public/locales/en-US/recover-2fa.json @@ -0,0 +1,10 @@ +{ + "title": "Recover Two-Factor Authentication", + "description": "We are very sorry if you lost your codes. Please enter a recovery code to continue. Note that this will disable two-factor authentication for your account. You can enable it again in the settings.", + "continueActionLabel": "Disable 2FA", + "events": { + "unauthorized": "Please make sure to log in first and then reset your two-factor authentication on its screen.", + "canLogInNow": "Two-factor authentication has been disabled. You can log in now.", + "loggedIn": "Two-factor authentication has been disabled. You are logged in now." + } +} diff --git a/src/routes/Recover2FARoute.tsx b/src/routes/Recover2FARoute.tsx index 9f88c16..e0e2a1c 100644 --- a/src/routes/Recover2FARoute.tsx +++ b/src/routes/Recover2FARoute.tsx @@ -20,7 +20,7 @@ interface Form { } export default function Recover2FARoute(): ReactElement { - const {t} = useTranslation() + const {t} = useTranslation(["recover-2fa", "common"]) const {showError, showSuccess} = useErrorSuccessSnacks() const {login} = useContext(AuthContext) const navigate = useNavigate() @@ -29,17 +29,17 @@ export default function Recover2FARoute(): ReactElement { try { const user = await getMe() - showSuccess(t("routes.Recover2FARoute.loggedIn").toString()) + showSuccess(t("events.loggedIn").toString()) login(user) navigate("/aliases") } catch (error) { - showSuccess(t("routes.Recover2FARoute.canLoginNow").toString()) + showSuccess(t("events.canLogInNow").toString()) navigate("/auth/login") } }, onError: error => { if (error.response?.status == 401) { - showError(t("routes.Recover2FARoute.unauthorized").toString()) + showError(t("events.unauthorized").toString()) navigate("/auth/login") } else { showError(error) @@ -48,7 +48,10 @@ export default function Recover2FARoute(): ReactElement { }) const schema = yup.object().shape({ - recoveryCode: yup.string().required().label(t("routes.LoginRoute.forms.otp.code.label")), + recoveryCode: yup + .string() + .required() + .label(t("fields.recoveryCode.label", {ns: "common"})), }) const formik = useFormik
({ @@ -76,7 +79,7 @@ export default function Recover2FARoute(): ReactElement { > - {t("routes.Recover2FARoute.title")} + {t("title")} @@ -86,17 +89,17 @@ export default function Recover2FARoute(): ReactElement { - {t("routes.Recover2FARoute.description")} + {t("description")} - + } > - {t("routes.Recover2FARoute.forms.submit")} + {t("continueActionLabel")}