Skip to content

Commit f7b542f

Browse files
committed
fix: Rework catchError
1 parent 9eea511 commit f7b542f

File tree

17 files changed

+52
-46
lines changed

17 files changed

+52
-46
lines changed

client/public/static/i18n/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"giveAdminRights": "Give admin rights",
55
"cancel": "Cancel",
66
"save": "Save",
7+
"saved": "Saved",
78
"minimize": "Minimize",
89
"maximize": "Maximize",
910

client/public/static/i18n/en/table.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"updateSuccess": "Update Success",
33
"updateError": "Update Error",
4-
"add": "Add new object",
4+
"add": "Add",
5+
"edit": "Edit",
6+
"delete": "Delete",
57
"createdSuccessfully": "Created Successfully",
68
"globalExport": "Download global CSV",
79
"import": "Import",

client/public/static/i18n/en/user.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
"phone": "Phone",
99
"password": "Password",
1010
"passwordConfirm": "Confirm Password",
11-
"giveAdminRights": "Give admin rights"
11+
"giveAdminRights": "Give admin rights",
12+
"newUserAdded": "New user added"
1213
}

client/public/static/i18n/fr/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"giveAdminRights": "Donner les droits admin",
55
"cancel": "Annuler",
66
"save": "Sauvegarder",
7+
"saved": "Sauvegardé",
78
"minimize": "Minimiser",
89
"maximize": "Maximiser",
910

client/public/static/i18n/fr/table.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"updateSuccess": "Mise à jour réussie",
33
"updateError": "Erreur de mise à jour",
4-
"add": "Ajouter un nouvel oubjet",
4+
"add": "Ajouter",
5+
"edit": "Modifier",
6+
"delete": "Supprimer",
57
"createdSuccessfully": "Créé avec succès",
68
"globalExport": "Télécharger le CSV global",
79
"import": "Importer",

client/public/static/i18n/fr/user.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
"phone": "Téléphone",
88
"password": "Mot de passe",
99
"passwordConfirm": "Confirmer le mot de passe",
10-
"giveAdminRights": "Donner les droits d'administrateur"
10+
"giveAdminRights": "Donner les droits d'administrateur",
11+
"newUserAdded": "Nouvel utilisateur ajouté"
1112
}

client/src/components/Datatable.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Box } from '@mui/material';
2-
import { DataGrid, DataGridProps, GridColumns, GridFilterItem, GridLinkOperator } from '@mui/x-data-grid';
3-
import React, { useCallback, useEffect, useState } from 'react';
2+
import { DataGrid, DataGridProps, enUS, frFR, GridColumns, GridFilterItem, GridLinkOperator } from '@mui/x-data-grid';
3+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
44
import { useTranslation } from 'react-i18next';
55
import { useAlert } from '../hooks/useAlert';
6+
import { useLanguage } from '../hooks/useLanguage';
67
import { GlobalCsvExport } from './DatatableGlobalExport';
78
import DatatableToolbar from './DatatableToolbar';
89

@@ -43,6 +44,7 @@ const Datatable = <DataType extends WithId, Model>({
4344
}: DatatableProps<DataType, Model>) => {
4445
const Alert = useAlert();
4546
const { t } = useTranslation('table');
47+
const { language } = useLanguage();
4648

4749
const [isLoading, setLoading] = useState(true);
4850
const [page, setPage] = useState(0);
@@ -53,6 +55,8 @@ const Datatable = <DataType extends WithId, Model>({
5355
const [filtersOperator, setFiltersOperator] = useState<GridLinkOperator>(GridLinkOperator.And);
5456
const [data, setData] = useState<DataType[]>([]);
5557

58+
const localeText = useMemo(() => (language === 'fr' ? frFR : enUS).components.MuiDataGrid.defaultProps.localeText, [language]);
59+
5660
const tableOptions: Omit<DataGridProps, 'columns' | 'rows'> = {
5761
autoHeight: true,
5862
checkboxSelection: true,
@@ -199,6 +203,7 @@ const Datatable = <DataType extends WithId, Model>({
199203
}}
200204
>
201205
<DataGrid
206+
localeText={localeText}
202207
experimentalFeatures={{ newEditingApi: true }}
203208
columns={columns}
204209
components={{

client/src/components/DatatableGlobalExport.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ const DatatableGlobalExport = (props: DatatableGlobalExportProps) => {
2727
Loader.open();
2828
const blob = await globalCsvExport.fetcher(
2929
globalCsvExport.title,
30-
).catch(catchError(Alert, t));
30+
).catch(catchError(Alert));
3131

3232
Loader.close();
3333

3434
if (!blob) {
35-
Alert.open('error', t('InternalServerError'));
35+
Alert.open('error', 'Internal Server Error');
3636
return;
3737
}
3838

@@ -47,7 +47,7 @@ const DatatableGlobalExport = (props: DatatableGlobalExportProps) => {
4747

4848
// Hide the export menu after the export
4949
hideMenu?.();
50-
}, [Alert, globalCsvExport, hideMenu, t, Loader]);
50+
}, [Alert, globalCsvExport, hideMenu, Loader]);
5151

5252
return (
5353
<MenuItem

client/src/components/DatatableToolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const DatatableToolbar = ({
4141

4242
await importMethod(data).then(() => {
4343
Alert.open('success', t('importSuccess'));
44-
}).catch(catchError(Alert, t));
44+
}).catch(catchError(Alert));
4545

4646
reload();
4747
Loader.close();
@@ -60,7 +60,7 @@ const DatatableToolbar = ({
6060
empty().then(() => {
6161
Alert.open('success', t('emptySuccess'));
6262
reload();
63-
}).catch(catchError(Alert, t)).finally(() => {
63+
}).catch(catchError(Alert)).finally(() => {
6464
Loader.close();
6565
});
6666
},

client/src/components/forms/UserForm.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const UserForm = ({ data }: Props) => {
6363
update: personData,
6464
},
6565
}).then(() => {
66-
Alert.open('success', 'Saved');
67-
}).catch(catchError(Alert, t));
66+
Alert.open('success', t('common:saved'));
67+
}).catch(catchError(Alert));
6868
} else { // Addition
6969
processedData.password = formData.password;
7070
await UserRoutes.insert({
@@ -74,10 +74,10 @@ const UserForm = ({ data }: Props) => {
7474
create: personData,
7575
},
7676
}).then(() => {
77-
Alert.open('success', 'New user added');
77+
Alert.open('success', t('newUserAdded'));
7878
navigate('/app/admin/user/list');
7979
reset();
80-
}).catch(catchError(Alert, t));
80+
}).catch(catchError(Alert));
8181
}
8282
Loader.close();
8383
};

0 commit comments

Comments
 (0)