Skip to content

Commit 522d773

Browse files
committed
migrate to react 19, react-router 7
1 parent ac72e30 commit 522d773

File tree

6 files changed

+117
-90
lines changed

6 files changed

+117
-90
lines changed

client/package-lock.json

Lines changed: 86 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
"i18next-http-backend": "^2.6.2",
3030
"jwt-decode": "^4.0.0",
3131
"moment": "^2.30.1",
32-
"react": "^18.3.1",
33-
"react-dom": "^18.3.1",
34-
"react-error-boundary": "^4.1.2",
32+
"react": "^19.0.0",
33+
"react-dom": "^19.0.0",
34+
"react-error-boundary": "^5.0.0",
3535
"react-i18next": "^15.1.2",
3636
"react-icons": "^5.3.0",
37-
"react-router-dom": "^6.27.0",
37+
"react-router-dom": "^7.1.1",
3838
"zustand": "^5.0.1"
3939
},
4040
"devDependencies": {
@@ -43,8 +43,8 @@
4343
"@testing-library/jest-dom": "^5.17.0",
4444
"@testing-library/react": "^16.1.0",
4545
"@testing-library/user-event": "^13.5.0",
46-
"@types/react": "^18.3.12",
47-
"@types/react-dom": "^18.3.1",
46+
"@types/react": "^19.0.7",
47+
"@types/react-dom": "^19.0.3",
4848
"@vitejs/plugin-react-swc": "^3.5.0",
4949
"eslint": "^9.14.0",
5050
"eslint-config-prettier": "^9.1.0",

client/src/_foundation/net/fetch-json.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ interface FetchJsonResponse<T> {
88
error?: {
99
status: number;
1010
message: string;
11+
original?: string;
1112
};
1213
}
1314

1415
/**
1516
* Fetches JSON data from the specified endpoint.
1617
* Cacthes any errors that may occur during the fetch request and returns an error in the response object as FetchJsonResponse.
17-
* It expects the server to return a JSON object like `{"error": "User not found"}` in case of an error, "error" field could be also named "message" or "reason" or "detail".
18+
* It expects the server to return a JSON object like `{"error": "User not found"}` in case of an error, "error" field could be also named "message" or "reason" or "title".
1819
*
1920
* @template T - The expected type of the response data.
2021
* @param {string} endpoint - The URL endpoint to fetch data from.
@@ -32,7 +33,7 @@ interface FetchJsonResponse<T> {
3233
* if (response.success) {
3334
* console.log(response.data);
3435
* } else {
35-
* console.error(response.error?.status, response.error?.message);
36+
* console.error(response.error?.status, response.error?.message, response.error?.original);
3637
* }
3738
* ```
3839
*/
@@ -65,17 +66,20 @@ const fetchJson = async <T>(
6566
status: UNKNOWN_ERROR_STATUS,
6667
};
6768
let errorMessage = knownError.message;
69+
const errorResponseText = await errorResponse.text();
6870
try {
69-
const errorJson = await errorResponse.json();
70-
// expects that the server returns a JSON object with a ('message' | 'error' | 'detail' | 'reason') field
71+
const errorJson = JSON.parse(errorResponseText) as Record<
72+
string,
73+
string
74+
>;
75+
// expects that the server returns a JSON object with a ('message' | 'error' | 'title' | 'reason') field
7176
errorMessage =
7277
errorJson.message ||
7378
errorJson.error ||
74-
errorJson.detail ||
75-
errorJson.reason ||
76-
(errorJson as string);
79+
errorJson.title ||
80+
errorJson.reason;
7781
} catch {
78-
errorMessage = await errorResponse.text();
82+
errorMessage = errorResponseText;
7983
}
8084
if (errorMessage?.length === 0) errorMessage = UNKNOWN_ERROR_MESSAGE;
8185
return {
@@ -84,6 +88,7 @@ const fetchJson = async <T>(
8488
error: {
8589
status: errorResponse.status,
8690
message: errorMessage,
91+
original: errorResponseText,
8792
},
8893
};
8994
}

client/src/app/pages/users.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SimpleSuspense } from '@/_foundation/components/simple-suspense';
21
import { User } from '@/features/users/types/user';
32
import { Heading, Text, VStack } from '@chakra-ui/react';
43
import { ReactElement, useEffect, useState } from 'react';
@@ -19,16 +18,11 @@ export const UsersPage = (): ReactElement => {
1918
<Heading as="h2" size="md">
2019
{t('Users.Title')}
2120
</Heading>
22-
<SimpleSuspense
23-
fallback={<Text>{t('Loading')}</Text>}
24-
emptyText={t('Users.Empty')}
25-
>
26-
{users?.map((user) => (
27-
<Text key={user.Username}>
28-
{user.Username} ({user.Status})
29-
</Text>
30-
))}
31-
</SimpleSuspense>
21+
{users?.map((user) => (
22+
<Text key={user.Username}>
23+
{user.Username} ({user.Status})
24+
</Text>
25+
))}
3226
</VStack>
3327
);
3428
};

0 commit comments

Comments
 (0)