|
1 | | -import { CoachingSession, defaultCoachingSession } from '@/types/coaching-session'; |
2 | | -import { CoachingRelationshipWithUserNames, defaultCoachingRelationshipWithUserNames } from '@/types/coaching_relationship_with_user_names'; |
3 | | -import { Id } from '@/types/general'; |
4 | | -import { create } from 'zustand'; |
5 | | -import { createJSONStorage, devtools, persist } from 'zustand/middleware'; |
| 1 | +import { |
| 2 | + CoachingSession, |
| 3 | + defaultCoachingSession, |
| 4 | +} from "@/types/coaching-session"; |
| 5 | +import { |
| 6 | + CoachingRelationshipWithUserNames, |
| 7 | + defaultCoachingRelationshipWithUserNames, |
| 8 | +} from "@/types/coaching_relationship_with_user_names"; |
| 9 | +import { Id } from "@/types/general"; |
| 10 | +import { defaultOrganization, Organization } from "@/types/organization"; |
| 11 | +import { create } from "zustand"; |
| 12 | +import { createJSONStorage, devtools, persist } from "zustand/middleware"; |
6 | 13 |
|
7 | 14 | interface AppState { |
8 | | - organizationId: Id; |
9 | | - relationshipId: Id; |
10 | | - coachingSessionId: Id; |
11 | | - coachingSession: CoachingSession; |
12 | | - coachingRelationship: CoachingRelationshipWithUserNames; |
| 15 | + organizationId: Id; |
| 16 | + relationshipId: Id; |
| 17 | + coachingSessionId: Id; |
| 18 | + organization: Organization; |
| 19 | + coachingSession: CoachingSession; |
| 20 | + coachingRelationship: CoachingRelationshipWithUserNames; |
13 | 21 | } |
14 | 22 |
|
15 | 23 | interface AppStateActions { |
16 | | - setOrganizationId: (organizationId: Id) => void; |
17 | | - setRelationshipId: (relationshipId: Id) => void; |
18 | | - setCoachingSessionId: (coachingSessionId: Id) => void; |
19 | | - setCoachingSession: (coachingSession: CoachingSession) => void; |
20 | | - setCoachingRelationship: (coachingRelationship: CoachingRelationshipWithUserNames) => void; |
21 | | - reset (): void; |
| 24 | + setOrganizationId: (organizationId: Id) => void; |
| 25 | + setRelationshipId: (relationshipId: Id) => void; |
| 26 | + setCoachingSessionId: (coachingSessionId: Id) => void; |
| 27 | + setOrganization: (organization: Organization) => void; |
| 28 | + setCoachingSession: (coachingSession: CoachingSession) => void; |
| 29 | + setCoachingRelationship: ( |
| 30 | + coachingRelationship: CoachingRelationshipWithUserNames |
| 31 | + ) => void; |
| 32 | + reset(): void; |
22 | 33 | } |
23 | 34 |
|
24 | 35 | export type AppStateStore = AppState & AppStateActions; |
25 | 36 |
|
26 | 37 | export const defaultInitState: AppState = { |
27 | | - organizationId: "", |
28 | | - relationshipId: "", |
29 | | - coachingSessionId: "", |
30 | | - coachingSession: defaultCoachingSession(), |
31 | | - coachingRelationship: defaultCoachingRelationshipWithUserNames(), |
32 | | -} |
| 38 | + organizationId: "", |
| 39 | + relationshipId: "", |
| 40 | + coachingSessionId: "", |
| 41 | + organization: defaultOrganization(), |
| 42 | + coachingSession: defaultCoachingSession(), |
| 43 | + coachingRelationship: defaultCoachingRelationshipWithUserNames(), |
| 44 | +}; |
33 | 45 |
|
34 | | -export const createAppStateStore = ( |
35 | | - initState: AppState = defaultInitState, |
36 | | -) => { |
37 | | - const appStateStore = create<AppStateStore>()( |
38 | | - devtools( |
39 | | - persist( |
40 | | - (set) => ({ |
41 | | - ... initState, |
| 46 | +export const createAppStateStore = (initState: AppState = defaultInitState) => { |
| 47 | + const appStateStore = create<AppStateStore>()( |
| 48 | + devtools( |
| 49 | + persist( |
| 50 | + (set) => ({ |
| 51 | + ...initState, |
42 | 52 |
|
43 | | - setOrganizationId: (organizationId) => { |
44 | | - set({ organizationId }); |
45 | | - }, |
46 | | - setRelationshipId: (relationshipId) => { |
47 | | - set({ relationshipId }); |
48 | | - }, |
49 | | - setCoachingSessionId: (coachingSessionId) => { |
50 | | - set({ coachingSessionId }); |
51 | | - }, |
52 | | - setCoachingSession: (coachingSession) => { |
53 | | - set({ coachingSession }); |
54 | | - }, |
55 | | - setCoachingRelationship: (coachingRelationship) => { |
56 | | - set({ coachingRelationship }); |
57 | | - }, |
58 | | - reset (): void { |
59 | | - set(defaultInitState); |
60 | | - } |
61 | | - }), |
62 | | - { |
63 | | - name: 'app-state-store', |
64 | | - storage: createJSONStorage(() => sessionStorage), |
65 | | - } |
66 | | - ) |
67 | | - ) |
| 53 | + setOrganizationId: (organizationId) => { |
| 54 | + set({ organizationId }); |
| 55 | + }, |
| 56 | + setRelationshipId: (relationshipId) => { |
| 57 | + set({ relationshipId }); |
| 58 | + }, |
| 59 | + setCoachingSessionId: (coachingSessionId) => { |
| 60 | + set({ coachingSessionId }); |
| 61 | + }, |
| 62 | + setOrganization: (organization) => { |
| 63 | + set({ organization }); |
| 64 | + }, |
| 65 | + setCoachingSession: (coachingSession) => { |
| 66 | + set({ coachingSession }); |
| 67 | + }, |
| 68 | + setCoachingRelationship: (coachingRelationship) => { |
| 69 | + set({ coachingRelationship }); |
| 70 | + }, |
| 71 | + reset(): void { |
| 72 | + set(defaultInitState); |
| 73 | + }, |
| 74 | + }), |
| 75 | + { |
| 76 | + name: "app-state-store", |
| 77 | + storage: createJSONStorage(() => sessionStorage), |
| 78 | + } |
| 79 | + ) |
68 | 80 | ) |
69 | | - return appStateStore; |
70 | | -} |
| 81 | + ); |
| 82 | + return appStateStore; |
| 83 | +}; |
0 commit comments