Skip to content

Commit

Permalink
fix(ui): i18next API change
Browse files Browse the repository at this point in the history
  • Loading branch information
skamril committed Oct 3, 2023
1 parent ff8e635 commit e8a8503
Show file tree
Hide file tree
Showing 23 changed files with 78 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ function CreateGroupDialog(props: Props) {

try {
newGroup = await mounted(createGroup(name));
enqueueSnackbar(t("settings.success.groupCreation", [newGroup.name]), {
variant: "success",
});
enqueueSnackbar(
t("settings.success.groupCreation", { 0: newGroup.name }),
{
variant: "success",
},
);
} catch (e) {
enqueueErrorSnackbar(t("settings.error.groupSave", [name]), e as Error);
enqueueErrorSnackbar(
t("settings.error.groupSave", { 0: name }),
e as Error,
);
throw e;
}

Expand Down Expand Up @@ -82,7 +88,7 @@ function CreateGroupDialog(props: Props) {
reloadFetchGroups();

enqueueErrorSnackbar(
t("settings.error.userRolesSave", [newGroup.name]),
t("settings.error.userRolesSave", { 0: newGroup.name }),
e as Error,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function UpdateGroupDialog(props: Props) {
const groupName = name || group.name;

const notifySuccess = R.once(() =>
enqueueSnackbar(t("settings.success.groupUpdate", [groupName]), {
enqueueSnackbar(t("settings.success.groupUpdate", { 0: groupName }), {
variant: "success",
}),
);
Expand All @@ -79,7 +79,7 @@ function UpdateGroupDialog(props: Props) {
notifySuccess();
} catch (e) {
enqueueErrorSnackbar(
t("settings.error.groupSave", [groupName]),
t("settings.error.groupSave", { 0: groupName }),
e as Error,
);
throw e;
Expand Down Expand Up @@ -139,7 +139,7 @@ function UpdateGroupDialog(props: Props) {
reloadFetchUsers();

enqueueErrorSnackbar(
t("settings.error.groupRolesSave", [groupName]),
t("settings.error.groupRolesSave", { 0: groupName }),
e as Error,
);
}
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/App/Settings/Groups/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ function Groups() {
mounted(deleteGroup(group.id))
.then(() => {
dispatch({ type: GroupActionKind.DELETE, payload: group.id });
enqueueSnackbar(t("settings.success.groupDelete", [group.name]), {
enqueueSnackbar(t("settings.success.groupDelete", { 0: group.name }), {
variant: "success",
});
})
.catch((err) => {
enqueueErrorSnackbar(
t("settings.error.groupDelete", [group.name]),
t("settings.error.groupDelete", { 0: group.name }),
err,
);
})
Expand Down Expand Up @@ -264,7 +264,7 @@ function Groups() {
alert="warning"
open
>
{t("settings.question.deleteGroup", [groupToDelete.name])}
{t("settings.question.deleteGroup", { 0: groupToDelete.name })}
</ConfirmationDialog>
)}
{groupToEdit && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ function CreateTokenDialog(props: Props) {

setTokenValueToDisplay(tokenValue);

enqueueSnackbar(t("settings.success.tokenCreation", [name]), {
enqueueSnackbar(t("settings.success.tokenCreation", { 0: name }), {
variant: "success",
});
} catch (e) {
enqueueErrorSnackbar(t("settings.error.tokenSave", [name]), e as Error);
enqueueErrorSnackbar(
t("settings.error.tokenSave", { 0: name }),
e as Error,
);
closeDialog();
} finally {
reloadFetchTokens();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function TokenInfoDialog(props: Props) {
titleIcon={InfoIcon}
>
<DialogContentText>
{t("settings.currentToken", [token.name])}
{t("settings.currentToken", { 0: token.name })}
</DialogContentText>
<Form config={{ defaultValues }} hideSubmitButton>
{(formObj) => <TokenForm onlyPermissions readOnly {...formObj} />}
Expand Down
6 changes: 3 additions & 3 deletions webapp/src/components/App/Settings/Tokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,13 @@ function Tokens() {
mounted(deleteBot(token.id))
.then(() => {
dispatch({ type: TokenActionKind.DELETE, payload: token.id });
enqueueSnackbar(t("settings.success.tokenDelete", [token.name]), {
enqueueSnackbar(t("settings.success.tokenDelete", { 0: token.name }), {
variant: "success",
});
})
.catch((err) => {
enqueueErrorSnackbar(
t("settings.error.tokenDelete", [token.name]),
t("settings.error.tokenDelete", { 0: token.name }),
err,
);
})
Expand Down Expand Up @@ -281,7 +281,7 @@ function Tokens() {
alert="warning"
open
>
{t("settings.question.deleteToken", [tokenToDelete.name])}
{t("settings.question.deleteToken", { 0: tokenToDelete.name })}
</ConfirmationDialog>
)}
{tokenToDisplayInfo && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ function CreateUserDialog(props: Props) {

try {
newUser = await mounted(createUser(username, password));
enqueueSnackbar(t("settings.success.userCreation", [newUser.name]), {
enqueueSnackbar(t("settings.success.userCreation", { 0: newUser.name }), {
variant: "success",
});
} catch (e) {
enqueueErrorSnackbar(
t("settings.error.userSave", [username]),
t("settings.error.userSave", { 0: username }),
e as Error,
);
throw e;
Expand Down Expand Up @@ -79,7 +79,7 @@ function CreateUserDialog(props: Props) {
reloadFetchUsers();

enqueueErrorSnackbar(
t("settings.error.userRolesSave", [newUser.name]),
t("settings.error.userRolesSave", { 0: newUser.name }),
e as Error,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ function UpdateUserDialog(props: Props) {

editUser({ id: user.id, roles });

enqueueSnackbar(t("settings.success.userUpdate", [user.name]), {
enqueueSnackbar(t("settings.success.userUpdate", { 0: user.name }), {
variant: "success",
});
} catch (e) {
// Because we cannot recover roles eventually deleted/created
reloadFetchUsers();

enqueueErrorSnackbar(
t("settings.error.userRolesSave", [user.name]),
t("settings.error.userRolesSave", { 0: user.name }),
e as Error,
);
}
Expand All @@ -104,7 +104,7 @@ function UpdateUserDialog(props: Props) {
return (
<UserFormDialog
title={t("settings.updateUser")}
subtitle={t("settings.currentUser", [user.name])}
subtitle={t("settings.currentUser", { 0: user.name })}
titleIcon={EditIcon}
defaultValues={defaultValues}
onSubmit={handleSubmit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function UserForm(props: Props) {
required: t("form.field.required") as string,
minLength: {
value: PASSWORD_MIN_LENGTH,
message: t("form.field.minLength", [PASSWORD_MIN_LENGTH]),
message: t("form.field.minLength", { 0: PASSWORD_MIN_LENGTH }),
},
})}
/>
Expand Down
9 changes: 6 additions & 3 deletions webapp/src/components/App/Settings/Users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,15 @@ function Users() {
mounted(deleteUser(user.id))
.then(() => {
dispatch({ type: UserActionKind.DELETE, payload: user.id });
enqueueSnackbar(t("settings.success.userDelete", [user.name]), {
enqueueSnackbar(t("settings.success.userDelete", { 0: user.name }), {
variant: "success",
});
})
.catch((err) => {
enqueueErrorSnackbar(t("settings.error.userDelete", [user.name]), err);
enqueueErrorSnackbar(
t("settings.error.userDelete", { 0: user.name }),
err,
);
})
.finally(() => {
setUsersInLoading((prev) => prev.filter((u) => u !== user));
Expand Down Expand Up @@ -244,7 +247,7 @@ function Users() {
alert="warning"
open
>
{t("settings.question.deleteUser", [userToDelete.name])}
{t("settings.question.deleteUser", { 0: userToDelete.name })}
</ConfirmationDialog>
)}
{userToEdit && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Fields() {
rules={{
min: {
value: 0,
message: t("form.field.minValue", [0]),
message: t("form.field.minValue", { 0: 0 }),
},
}}
/>
Expand All @@ -94,7 +94,7 @@ function Fields() {
rules={{
min: {
value: 0,
message: t("form.field.minValue", [0]),
message: t("form.field.minValue", { 0: 0 }),
},
}}
/>
Expand All @@ -107,7 +107,7 @@ function Fields() {
rules={{
min: {
value: 0,
message: t("form.field.minValue", [0]),
message: t("form.field.minValue", { 0: 0 }),
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function Fields(props: Props) {
formValues,
) => {
if (value < 1 || Number.isNaN(value)) {
return t("form.field.minValue", [1]);
return t("form.field.minValue", { 0: 1 });
}
if (formValues.firstDay > formValues.lastDay) {
return false;
Expand All @@ -110,9 +110,9 @@ function Fields(props: Props) {
: t("study.configuration.general.nbYears.error.derated");
}
if (value < 1) {
return t("form.field.minValue", [1]);
return t("form.field.minValue", { 0: 1 });
}
return value <= 50000 ? true : t("form.field.maxValue", [50000]);
return value <= 50000 ? true : t("form.field.maxValue", { 0: 50000 });
};

////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Rulesets() {
throw new Error(
t(
"study.configuration.general.mcScenarioBuilder.error.ruleset.rename",
[activeRuleset],
{ 0: activeRuleset },
),
{ cause: err },
);
Expand All @@ -71,9 +71,9 @@ function Rulesets() {
reloadConfig();

throw new Error(
t("study.configuration.general.mcScenarioBuilder.error.ruleset.add", [
name,
]),
t("study.configuration.general.mcScenarioBuilder.error.ruleset.add", {
0: name,
}),
{ cause: err },
);
});
Expand All @@ -93,7 +93,7 @@ function Rulesets() {
enqueueErrorSnackbar(
t(
"study.configuration.general.mcScenarioBuilder.error.ruleset.delete",
[activeRuleset],
{ 0: activeRuleset },
),
err,
);
Expand All @@ -113,7 +113,7 @@ function Rulesets() {
enqueueErrorSnackbar(
t(
"study.configuration.general.mcScenarioBuilder.error.ruleset.duplicate",
[activeRuleset],
{ 0: activeRuleset },
),
err,
);
Expand Down Expand Up @@ -221,7 +221,7 @@ function Rulesets() {
>
{t(
"study.configuration.general.mcScenarioBuilder.dialog.delete.text",
[activeRuleset],
{ 0: activeRuleset },
)}
</ConfirmationDialog>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ function Table(props: Props) {
reloadConfig();

throw new Error(
t("study.configuration.general.mcScenarioBuilder.error.table", [
`${activeRuleset}.${symbol}`,
]),
t("study.configuration.general.mcScenarioBuilder.error.table", {
0: `${activeRuleset}.${symbol}`,
}),
{ cause: err },
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function AllocationField({ field, index, label }: Props) {
rules={{
min: {
value: 0,
message: t("form.field.minValue", [0]),
message: t("form.field.minValue", { 0: 0 }),
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ function CorrelationField({ field, index, label }: Props) {
rules={{
min: {
value: -100,
message: t("form.field.minValue", [-100]),
message: t("form.field.minValue", { 0: -100 }),
},
max: {
value: 100,
message: t("form.field.maxValue", [100]),
message: t("form.field.maxValue", { 0: 100 }),
},
}}
disabled={field.areaId === currentArea?.id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function Fields() {
rules={{
min: {
value: 0,
message: t("form.field.minValue", [0]),
message: t("form.field.minValue", { 0: 0 }),
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ function AddConstraintTermDialog(props: Props) {
data = tmpValues.data as LinkCreationInfoDTO;
if (!isOptionExist(options.links, data.area1, data.area2)) {
enqueueSnackbar(
t("study.error.missingData", [t("study.area1"), t("study.area2")]),
t("study.error.missingData", {
0: t("study.area1"),
1: t("study.area2"),
}),
{ variant: "error" },
);
onCancel();
Expand All @@ -88,7 +91,10 @@ function AddConstraintTermDialog(props: Props) {
data = tmpValues.data as ClusterElement;
if (!isOptionExist(options.clusters, data.area, data.cluster)) {
enqueueSnackbar(
t("study.error.missingData", [t("study.area"), t("study.cluster")]),
t("study.error.missingData", {
0: t("study.area"),
1: t("study.cluster"),
}),
{ variant: "error" },
);
onCancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ function UpdateDistrictDialog(props: Props) {
open
>
<Typography sx={{ p: 3 }}>
{t("study.modelization.map.districts.delete.confirm", [
districtsById[getValues("districtId")].name,
])}
{t("study.modelization.map.districts.delete.confirm", {
0: districtsById[getValues("districtId")].name,
})}
</Typography>
</ConfirmationDialog>
)}
Expand Down
Loading

0 comments on commit e8a8503

Please sign in to comment.