Skip to content

Commit 15cd198

Browse files
authored
Merge pull request #145 from ModusCreateOrg/ADE-215
[ADE-215] Refactor translation hooks and update i18n resources for improved localization support
2 parents 59fc4b1 + c663357 commit 15cd198

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

frontend/src/common/components/Router/TabNavigation.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const TabNavigation = (): JSX.Element => {
4747
const [isUploadModalOpen, setIsUploadModalOpen] = useState(false);
4848
const history = useHistory();
4949
const location = useLocation();
50-
const { t } = useTranslation();
50+
const { t } = useTranslation(['common']);
5151

5252
// Check if the current path starts with the tab path
5353
const isTabActive = (tabPath: string) => {
@@ -120,7 +120,7 @@ const TabNavigation = (): JSX.Element => {
120120
className="ls-tab-navigation__bar-button-icon"
121121
src={homeIcon}
122122
active={isTabActive('/tabs/home')}
123-
alt={t('navigation.home', { ns: 'common', defaultValue: 'Home' })}
123+
alt={t('navigation.home')}
124124
width={24}
125125
height={24}
126126
/>
@@ -134,7 +134,7 @@ const TabNavigation = (): JSX.Element => {
134134
className="ls-tab-navigation__bar-button-icon"
135135
src={reportsIcon}
136136
active={isTabActive('/tabs/reports')}
137-
alt={t('navigation.reports', { ns: 'common', defaultValue: 'Reports' })}
137+
alt={t('navigation.reports')}
138138
width={24}
139139
height={24}
140140
/>
@@ -148,7 +148,7 @@ const TabNavigation = (): JSX.Element => {
148148
<SvgIcon
149149
className="ls-tab-navigation__bar-button-icon"
150150
src={uploadIcon}
151-
alt={t('navigation.upload', { ns: 'common', defaultValue: 'Upload' })}
151+
alt={t('navigation.upload')}
152152
width={24}
153153
height={24}
154154
/>
@@ -159,7 +159,7 @@ const TabNavigation = (): JSX.Element => {
159159
className="ls-tab-navigation__bar-button-icon"
160160
src={chatIcon}
161161
active={isTabActive('/tabs/chat')}
162-
alt={t('navigation.chat', { ns: 'common', defaultValue: 'Chat' })}
162+
alt={t('navigation.chat')}
163163
width={24}
164164
height={24}
165165
/>
@@ -173,7 +173,7 @@ const TabNavigation = (): JSX.Element => {
173173
className="ls-tab-navigation__bar-button-icon"
174174
src={profileIcon}
175175
active={isTabActive('/tabs/account')}
176-
alt={t('navigation.account', { ns: 'common', defaultValue: 'Account' })}
176+
alt={t('navigation.account')}
177177
width={24}
178178
height={24}
179179
/>

frontend/src/common/hooks/useReports.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import {
88
import { MedicalReport } from '../models/medicalReport';
99
import { QueryKey } from 'common/utils/constants';
1010

11+
export const LATEST_REPORTS_LIMIT = 3;
1112
/**
1213
* Hook to fetch the latest reports.
1314
* @param limit - Maximum number of reports to fetch
1415
* @returns Query result with the latest reports
1516
*/
16-
export const useGetLatestReports = (limit = 3) => {
17+
export const useGetLatestReports = (limit = LATEST_REPORTS_LIMIT) => {
1718
return useQuery({
1819
queryKey: [QueryKey.LatestReports, limit],
1920
queryFn: () => fetchLatestReports(limit),
@@ -53,12 +54,15 @@ export const useMarkReportAsRead = () => {
5354
});
5455

5556
// Update the latest reports cache
56-
queryClient.setQueryData<MedicalReport[]>([QueryKey.LatestReports], (oldReports) => {
57-
if (!oldReports) return undefined;
58-
return oldReports.map((report) =>
59-
report.id === updatedReport.id ? updatedReport : report,
60-
);
61-
});
57+
queryClient.setQueryData<MedicalReport[]>(
58+
[QueryKey.LatestReports, LATEST_REPORTS_LIMIT],
59+
(oldReports) => {
60+
if (!oldReports) return undefined;
61+
return oldReports.map((report) =>
62+
report.id === updatedReport.id ? updatedReport : report,
63+
);
64+
},
65+
);
6266
},
6367
});
6468
};
@@ -83,12 +87,15 @@ export const useToggleReportBookmark = () => {
8387
});
8488

8589
// Update the latest reports cache
86-
queryClient.setQueryData<MedicalReport[]>([QueryKey.LatestReports], (oldReports) => {
87-
if (!oldReports) return undefined;
88-
return oldReports.map((report) =>
89-
report.id === updatedReport.id ? updatedReport : report,
90-
);
91-
});
90+
queryClient.setQueryData<MedicalReport[]>(
91+
[QueryKey.LatestReports, LATEST_REPORTS_LIMIT],
92+
(oldReports) => {
93+
if (!oldReports) return undefined;
94+
return oldReports.map((report) =>
95+
report.id === updatedReport.id ? updatedReport : report,
96+
);
97+
},
98+
);
9299

93100
// Update the bookmark status in the report detail page
94101
queryClient.setQueryData<MedicalReport | undefined>(

frontend/src/common/utils/i18n/resources/en/common.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
"menu": "Menu",
3434
"signout": "Sign Out",
3535
"users": "Users",
36-
"chat": "AI Assistant"
36+
"chat": "AI Assistant",
37+
"reports": "Reports",
38+
"upload": "Upload"
3739
},
3840
"reports": {
3941
"uploadDate": "Upload Date"
@@ -91,5 +93,8 @@
9193
"upload": {
9294
"title": "Upload Report"
9395
}
96+
},
97+
"actions": {
98+
"bookmark": "Bookmark"
9499
}
95100
}

frontend/src/common/utils/i18n/resources/en/reportDetail.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@
8585
"discard": "Discard",
8686
"new-upload": "New Upload"
8787
},
88+
"discard": {
89+
"title": "Discard report?",
90+
"message": "{itemName} will be discarded and not be saved to your reports archive. Are you sure?"
91+
},
92+
"new-upload": {
93+
"title": "Upload new report?",
94+
"message": "You've chosen to upload a new report. This will replace your current one. Do you still want to proceed?"
95+
},
8896
"tabs": {
8997
"ai-insights": "AI Insights",
9098
"original-report": "Original Report"

frontend/src/common/utils/i18n/resources/fr/common.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"menu": "Menu",
2424
"signout": "Déconnecter",
2525
"users": "Utilisateurs",
26-
"chat": "Assistant IA"
26+
"chat": "Assistant IA",
27+
"reports": "Rapports",
28+
"upload": "Télécharger"
2729
},
2830
"reports": {
2931
"uploadDate": "Date de téléchargement"

frontend/src/common/utils/i18n/resources/fr/reportDetail.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
"discard": "Annuler",
2828
"new-upload": "Nouveau téléchargement"
2929
},
30+
"discard": {
31+
"title": "Supprimer le rapport?",
32+
"message": "{itemName} sera supprimé et ne sera pas enregistré dans votre archive de rapports. Êtes-vous sûr?"
33+
},
34+
"new-upload": {
35+
"title": "Télécharger un nouveau rapport?",
36+
"message": "Vous avez choisi de télécharger un nouveau rapport. Cela remplacera votre rapport actuel. Voulez-vous toujours continuer?"
37+
},
3038
"tabs": {
3139
"ai-insights": "Analyses IA",
3240
"original-report": "Rapport original"

frontend/src/pages/Home/HomePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const HomePage: React.FC = () => {
9898
report={report}
9999
onClick={() => handleReportClick(report.id)}
100100
onToggleBookmark={() =>
101-
toggleBookmark.mutate({ reportId: report.id, isBookmarked: report.bookmarked })
101+
toggleBookmark.mutate({ reportId: report.id, isBookmarked: !report.bookmarked })
102102
}
103103
showBookmarkButton={true}
104104
/>

frontend/src/pages/Home/components/ReportItem/ReportItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const ReportItem: React.FC<ReportItemProps> = ({
2626
onToggleBookmark,
2727
showBookmarkButton = false,
2828
}) => {
29-
const { t } = useTranslation(['common', 'report']);
29+
const { t } = useTranslation(['common']);
3030
const { title, category, createdAt, status, bookmarked } = report;
3131

3232
// Treat category as string

frontend/src/pages/Reports/ReportsListPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ const ReportsListPage: React.FC = () => {
227227
report={report}
228228
onClick={() => handleReportClick(report.id)}
229229
onToggleBookmark={() =>
230-
toggleBookmark.mutate({ reportId: report.id, isBookmarked: report.bookmarked })
230+
toggleBookmark.mutate({ reportId: report.id, isBookmarked: !report.bookmarked })
231231
}
232232
showBookmarkButton
233233
/>

frontend/src/pages/Reports/components/ActionButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ActionButtonsProps {
1010
}
1111

1212
const ActionButtons: React.FC<ActionButtonsProps> = ({ onDiscard, onNewUpload, reportTitle }) => {
13-
const { t } = useTranslation();
13+
const { t } = useTranslation(['reportDetail', 'common']);
1414
const [showConfirmDiscard, setShowConfirmDiscard] = useState(false);
1515
const [showConfirmNewUpload, setShowConfirmNewUpload] = useState(false);
1616
const [isProcessing, setIsProcessing] = useState(false);

0 commit comments

Comments
 (0)