Skip to content

Commit 525529a

Browse files
committed
feat: move status management store to a dedicate file
1 parent 6175fbd commit 525529a

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

src/stores/useStatus.store.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { create } from 'zustand';
2+
3+
type OneStatus = {
4+
title: string;
5+
isDone?: boolean;
6+
isError?: boolean;
7+
payload?: Record<string, string>;
8+
};
9+
10+
type StatusState = {
11+
statuses: Record<
12+
string,
13+
{ isDone?: boolean; isError?: boolean; payload?: Record<string, string> }
14+
>;
15+
addOrUpdateStatusToStore: (status: OneStatus) => void;
16+
resetStatuses: () => void;
17+
};
18+
19+
const useStatusStore = create<StatusState>((set) => ({
20+
statuses: {},
21+
addOrUpdateStatusToStore: (status) =>
22+
set((state) => ({
23+
statuses: {
24+
...state.statuses,
25+
[status.title]: {
26+
isDone: status.isDone,
27+
isError: status.isError ?? false,
28+
payload: status.payload,
29+
},
30+
},
31+
})),
32+
resetStatuses: () => set({ statuses: {} }),
33+
}));
34+
35+
export default useStatusStore;

src/views/profile/addProtectedData.tsx

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
XCircle,
1111
} from 'react-feather';
1212
import { useNavigate } from 'react-router-dom';
13-
import { create } from 'zustand';
1413
import { Alert } from '@/components/Alert';
1514
import { LoadingSpinner } from '@/components/LoadingSpinner';
1615
import { Stepper } from '@/components/Stepper';
1716
import { Button } from '@/components/ui/button';
1817
import { toast } from '@/components/ui/use-toast';
1918
import { getDataProtectorCoreClient } from '@/externals/iexecSdkClient';
19+
import useStatusStore from '@/stores/useStatus.store';
2020
import useUserStore from '@/stores/useUser.store';
2121
import { getUserFriendlyStatues } from '@/utils/getUserFriendlyStatues';
2222
import { cn } from '@/utils/style.utils';
@@ -40,38 +40,6 @@ const COLOR_CLASSES: {
4040
},
4141
};
4242

43-
type OneStatus = {
44-
title: string;
45-
isDone?: boolean;
46-
isError?: boolean;
47-
payload?: Record<string, string>;
48-
};
49-
50-
type StatusState = {
51-
statuses: Record<
52-
string,
53-
{ isDone?: boolean; isError?: boolean; payload?: Record<string, string> }
54-
>;
55-
addOrUpdateStatusToStore: (status: OneStatus) => void;
56-
resetStatuses: () => void;
57-
};
58-
59-
const useStatusStore = create<StatusState>((set) => ({
60-
statuses: {},
61-
addOrUpdateStatusToStore: (status) =>
62-
set((state) => ({
63-
statuses: {
64-
...state.statuses,
65-
[status.title]: {
66-
isDone: status.isDone,
67-
isError: status.isError ?? false,
68-
payload: status.payload,
69-
},
70-
},
71-
})),
72-
resetStatuses: () => set({ statuses: {} }),
73-
}));
74-
7543
export default function AddProtectedData() {
7644
const { address: userAddress } = useUserStore();
7745
const { statuses, addOrUpdateStatusToStore, resetStatuses } =

0 commit comments

Comments
 (0)