refactor: Improve i18n for recover 2fa

This commit is contained in:
Myzel394 2023-03-04 21:37:47 +01:00
parent 8fbca78772
commit 1e6bf650b5
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
3 changed files with 26 additions and 10 deletions

View File

@ -7,6 +7,9 @@
"2faCode": { "2faCode": {
"label": "Code", "label": "Code",
"placeholder": "123456" "placeholder": "123456"
},
"recoveryCode": {
"label": "Recovery Code"
} }
} }
} }

View File

@ -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."
}
}

View File

@ -20,7 +20,7 @@ interface Form {
} }
export default function Recover2FARoute(): ReactElement { export default function Recover2FARoute(): ReactElement {
const {t} = useTranslation() const {t} = useTranslation(["recover-2fa", "common"])
const {showError, showSuccess} = useErrorSuccessSnacks() const {showError, showSuccess} = useErrorSuccessSnacks()
const {login} = useContext(AuthContext) const {login} = useContext(AuthContext)
const navigate = useNavigate() const navigate = useNavigate()
@ -29,17 +29,17 @@ export default function Recover2FARoute(): ReactElement {
try { try {
const user = await getMe() const user = await getMe()
showSuccess(t("routes.Recover2FARoute.loggedIn").toString()) showSuccess(t("events.loggedIn").toString())
login(user) login(user)
navigate("/aliases") navigate("/aliases")
} catch (error) { } catch (error) {
showSuccess(t("routes.Recover2FARoute.canLoginNow").toString()) showSuccess(t("events.canLogInNow").toString())
navigate("/auth/login") navigate("/auth/login")
} }
}, },
onError: error => { onError: error => {
if (error.response?.status == 401) { if (error.response?.status == 401) {
showError(t("routes.Recover2FARoute.unauthorized").toString()) showError(t("events.unauthorized").toString())
navigate("/auth/login") navigate("/auth/login")
} else { } else {
showError(error) showError(error)
@ -48,7 +48,10 @@ export default function Recover2FARoute(): ReactElement {
}) })
const schema = yup.object().shape({ 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<Form>({ const formik = useFormik<Form>({
@ -76,7 +79,7 @@ export default function Recover2FARoute(): ReactElement {
> >
<Grid item> <Grid item>
<Typography variant="h5" component="h1" align="center"> <Typography variant="h5" component="h1" align="center">
{t("routes.Recover2FARoute.title")} {t("title")}
</Typography> </Typography>
</Grid> </Grid>
<Grid item> <Grid item>
@ -86,17 +89,17 @@ export default function Recover2FARoute(): ReactElement {
</Grid> </Grid>
<Grid item> <Grid item>
<Typography variant="body1" align="center"> <Typography variant="body1" align="center">
{t("routes.Recover2FARoute.description")} {t("description")}
</Typography> </Typography>
</Grid> </Grid>
<Grid item> <Grid item xs={12} width="100%">
<TextField <TextField
autoFocus autoFocus
key="recoveryCode" key="recoveryCode"
fullWidth fullWidth
name="recoveryCode" name="recoveryCode"
id="recoveryCode" id="recoveryCode"
label={t("routes.Recover2FARoute.forms.recoveryCode.label")} label={t("fields.recoveryCode.label", {ns: "common"})}
value={formik.values.recoveryCode} value={formik.values.recoveryCode}
onChange={formik.handleChange} onChange={formik.handleChange}
error={Boolean( error={Boolean(
@ -112,7 +115,7 @@ export default function Recover2FARoute(): ReactElement {
loading={formik.isSubmitting} loading={formik.isSubmitting}
startIcon={<BsShieldLockFill />} startIcon={<BsShieldLockFill />}
> >
{t("routes.Recover2FARoute.forms.submit")} {t("continueActionLabel")}
</LoadingButton> </LoadingButton>
</Grid> </Grid>
</Grid> </Grid>