Skip to content

Commit 2eeb21b

Browse files
[Human App] feat: rewrite UI notification system (#2983)
1 parent 61b6d91 commit 2eeb21b

24 files changed

+350
-365
lines changed

packages/apps/human-app/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"lodash": "^4.17.21",
3535
"material-react-table": "^3.0.1",
3636
"mui-image": "^1.0.7",
37+
"notistack": "^3.0.1",
3738
"query-string": "^9.0.0",
3839
"react": "^18.2.0",
3940
"react-dom": "^18.2.0",

packages/apps/human-app/frontend/src/main.tsx

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { JWTExpirationCheck } from '@/shared/contexts/jwt-expiration-check';
1919
import { ColorModeProvider } from '@/shared/contexts/color-mode-context';
2020
import { HomePageStateProvider } from '@/shared/contexts/homepage-state';
2121
import { RegisteredOraclesProvider } from '@/shared/contexts/registered-oracles';
22+
import { NotificationProvider } from '@/shared/providers/notifications-provider';
2223

2324
const root = document.getElementById('root');
2425
if (!root) throw Error('root element is undefined');
@@ -35,23 +36,25 @@ createRoot(root).render(
3536
<ColorModeProvider>
3637
<CssBaseline />
3738
<QueryClientProvider client={queryClient}>
38-
<BrowserRouter>
39-
<WalletConnectProvider>
40-
<HomePageStateProvider>
41-
<Web3AuthProvider>
42-
<AuthProvider>
43-
<DisplayModal />
44-
<JWTExpirationCheck>
45-
<RegisteredOraclesProvider>
46-
<Router />
47-
</RegisteredOraclesProvider>
48-
</JWTExpirationCheck>
49-
</AuthProvider>
50-
</Web3AuthProvider>
51-
</HomePageStateProvider>
52-
<ReactQueryDevtools client={queryClient} initialIsOpen={false} />
53-
</WalletConnectProvider>
54-
</BrowserRouter>
39+
<NotificationProvider>
40+
<BrowserRouter>
41+
<WalletConnectProvider>
42+
<HomePageStateProvider>
43+
<Web3AuthProvider>
44+
<AuthProvider>
45+
<DisplayModal />
46+
<JWTExpirationCheck>
47+
<RegisteredOraclesProvider>
48+
<Router />
49+
</RegisteredOraclesProvider>
50+
</JWTExpirationCheck>
51+
</AuthProvider>
52+
</Web3AuthProvider>
53+
</HomePageStateProvider>
54+
<ReactQueryDevtools client={queryClient} initialIsOpen={false} />
55+
</WalletConnectProvider>
56+
</BrowserRouter>
57+
</NotificationProvider>
5558
</QueryClientProvider>
5659
</ColorModeProvider>
5760
</StrictMode>

packages/apps/human-app/frontend/src/modules/worker/components/hcaptcha-labeling/user-stats-accordion.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import { useEffect } from 'react';
88
import { t } from 'i18next';
99
import { UserStatsDetails } from '@/modules/worker/components/hcaptcha-labeling/user-stats-details';
1010
import { useHCaptchaUserStats } from '@/modules/worker/services/hcaptcha-user-stats';
11-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
11+
import {
12+
TopNotificationType,
13+
useNotification,
14+
} from '@/shared/hooks/use-notification';
1215
import { getErrorMessageForError } from '@/shared/errors';
1316
import { useColorMode } from '@/shared/hooks/use-color-mode';
1417

@@ -23,13 +26,13 @@ export function UserStatsAccordion() {
2326
error: hcaptchaUserStatsError,
2427
refetch: refetchUserStats,
2528
} = useHCaptchaUserStats();
26-
const { setTopNotification } = useProtectedLayoutNotification();
29+
const { showNotification } = useNotification();
2730

2831
useEffect(() => {
2932
if (isHcaptchaUserStatsError) {
30-
setTopNotification({
31-
type: 'warning',
32-
content: getErrorMessageForError(hcaptchaUserStatsError),
33+
showNotification({
34+
type: TopNotificationType.WARNING,
35+
message: getErrorMessageForError(hcaptchaUserStatsError),
3336
});
3437
}
3538
// eslint-disable-next-line react-hooks/exhaustive-deps -- ...

packages/apps/human-app/frontend/src/modules/worker/components/profile/profile.page.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { useEffect } from 'react';
33
import { t } from 'i18next';
44
import { ProfileData } from '@/modules/worker/components/profile/profile-data';
55
import { ProfileActions } from '@/modules/worker/components/profile/profile-actions';
6-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
6+
import {
7+
TopNotificationType,
8+
useNotification,
9+
} from '@/shared/hooks/use-notification';
710
import { useWalletConnect } from '@/shared/hooks/use-wallet-connect';
811
import { useIsMobile } from '@/shared/hooks/use-is-mobile';
912
import { useAuthenticatedUser } from '@/modules/auth/hooks/use-authenticated-user';
@@ -12,16 +15,15 @@ export function WorkerProfilePage() {
1215
const { user } = useAuthenticatedUser();
1316
const isMobile = useIsMobile();
1417
const { isConnected } = useWalletConnect();
15-
const { setTopNotification: setTopNotificationInLayout } =
16-
useProtectedLayoutNotification();
18+
const { showNotification } = useNotification();
1719

1820
const setNotifications = () => {
1921
if (user.wallet_address) {
2022
return;
2123
}
22-
setTopNotificationInLayout({
23-
type: 'warning',
24-
content: t('worker.profile.topNotifications.completeSteps'),
24+
showNotification({
25+
type: TopNotificationType.WARNING,
26+
message: t('worker.profile.topNotifications.completeSteps'),
2527
});
2628
};
2729

packages/apps/human-app/frontend/src/modules/worker/hooks/use-get-oracles-notifications.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
1+
import {
2+
TopNotificationType,
3+
useNotification,
4+
} from '@/shared/hooks/use-notification';
25
import { getErrorMessageForError } from '@/shared/errors';
3-
import { delay } from '@/shared/helpers/time';
46
import type { ResponseError } from '@/shared/types/global.type';
57

68
export function useGetOraclesNotifications() {
7-
const { setTopNotification, closeNotification } =
8-
useProtectedLayoutNotification();
9+
const { showNotification } = useNotification();
910

10-
const onError = async (error: ResponseError) => {
11-
setTopNotification({
12-
type: 'warning',
13-
content: getErrorMessageForError(error),
11+
const onError = (error: ResponseError) => {
12+
showNotification({
13+
type: TopNotificationType.WARNING,
14+
message: getErrorMessageForError(error),
15+
durationMs: 5000,
1416
});
15-
await delay(5000);
16-
closeNotification();
1717
};
1818

1919
return { onError };

packages/apps/human-app/frontend/src/modules/worker/hooks/use-hcaptcha-labeling-notifications.tsx

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
import { t } from 'i18next';
2-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
2+
import {
3+
TopNotificationType,
4+
useNotification,
5+
} from '@/shared/hooks/use-notification';
36
import { getErrorMessageForError } from '@/shared/errors';
4-
import { delay } from '@/shared/helpers/time';
57
import type { ResponseError } from '@/shared/types/global.type';
68

79
export function useHCaptchaLabelingNotifications() {
8-
const { setTopNotification, closeNotification } =
9-
useProtectedLayoutNotification();
10+
const { showNotification } = useNotification();
1011

11-
const onSuccess = async () => {
12-
setTopNotification({
13-
type: 'success',
14-
content: t('worker.hcaptchaLabelingStats.solvedSuccess'),
12+
const onSuccess = () => {
13+
showNotification({
14+
type: TopNotificationType.SUCCESS,
15+
message: t('worker.hcaptchaLabelingStats.solvedSuccess'),
16+
durationMs: 2000,
1517
});
16-
17-
await delay(2000);
18-
closeNotification();
1918
};
20-
const onError = async (error: ResponseError) => {
21-
setTopNotification({
22-
type: 'warning',
23-
content: getErrorMessageForError(error),
19+
const onError = (error: ResponseError) => {
20+
showNotification({
21+
type: TopNotificationType.WARNING,
22+
message: getErrorMessageForError(error),
23+
durationMs: 5000,
2424
});
25-
26-
await delay(2000);
27-
closeNotification();
2825
};
2926

3027
return { onSuccess, onError };

packages/apps/human-app/frontend/src/modules/worker/hooks/use-jobs-notifications.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import { t } from 'i18next';
2-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
2+
import {
3+
TopNotificationType,
4+
useNotification,
5+
} from '@/shared/hooks/use-notification';
36
import { getErrorMessageForError } from '@/shared/errors';
4-
import { delay } from '@/shared/helpers/time';
57

68
export const useJobsNotifications = () => {
7-
const { setTopNotification, closeNotification } =
8-
useProtectedLayoutNotification();
9+
const { showNotification } = useNotification();
910

10-
const onJobAssignmentSuccess = async () => {
11-
setTopNotification({
12-
content: t('worker.jobs.successFullyAssignedJob'),
13-
type: 'success',
11+
const onJobAssignmentSuccess = () => {
12+
showNotification({
13+
message: t('worker.jobs.successFullyAssignedJob'),
14+
type: TopNotificationType.SUCCESS,
15+
durationMs: 5000,
1416
});
15-
await delay(5000);
16-
closeNotification();
1717
};
1818

19-
const onJobAssignmentError = async (error: unknown) => {
20-
setTopNotification({
21-
content: getErrorMessageForError(error),
22-
type: 'warning',
19+
const onJobAssignmentError = (error: unknown) => {
20+
showNotification({
21+
message: getErrorMessageForError(error),
22+
type: TopNotificationType.WARNING,
23+
durationMs: 5000,
2324
});
24-
await delay(5000);
25-
closeNotification();
2625
};
2726

2827
return { onJobAssignmentSuccess, onJobAssignmentError };
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
1+
import {
2+
TopNotificationType,
3+
useNotification,
4+
} from '@/shared/hooks/use-notification';
25
import { getErrorMessageForError } from '@/shared/errors';
36
import type { ResponseError } from '@/shared/types/global.type';
47

58
export function useKycErrorNotifications() {
6-
const { setTopNotification } = useProtectedLayoutNotification();
9+
const { showNotification } = useNotification();
710

811
return (error: ResponseError) => {
9-
setTopNotification({
10-
type: 'warning',
11-
content: getErrorMessageForError(error),
12+
showNotification({
13+
type: TopNotificationType.WARNING,
14+
message: getErrorMessageForError(error),
15+
durationMs: 5000,
1216
});
1317
};
1418
}

packages/apps/human-app/frontend/src/modules/worker/hooks/use-protected-layout-notifications.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

packages/apps/human-app/frontend/src/modules/worker/hooks/use-register-address-notifications.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import { useProtectedLayoutNotification } from '@/modules/worker/hooks/use-protected-layout-notifications';
1+
import { t } from 'i18next';
2+
import {
3+
TopNotificationType,
4+
useNotification,
5+
} from '@/shared/hooks/use-notification';
26
import { getErrorMessageForError } from '@/shared/errors';
37
import type { ResponseError } from '@/shared/types/global.type';
48

59
export function useRegisterAddressNotifications() {
6-
const { setTopNotification, closeNotification } =
7-
useProtectedLayoutNotification();
10+
const { showNotification } = useNotification();
811

912
const onSuccess = () => {
10-
closeNotification();
13+
showNotification({
14+
type: TopNotificationType.SUCCESS,
15+
message: t('worker.registerAddress.success'),
16+
});
1117
};
1218
const onError = (error: ResponseError) => {
13-
setTopNotification({
14-
type: 'warning',
15-
content: getErrorMessageForError(error),
19+
showNotification({
20+
type: TopNotificationType.WARNING,
21+
message: getErrorMessageForError(error),
22+
durationMs: 5000,
1623
});
1724
};
1825

0 commit comments

Comments
 (0)