forked from ToolJet/ToolJet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrentSessionStore.js
More file actions
33 lines (30 loc) · 1.08 KB
/
currentSessionStore.js
File metadata and controls
33 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import create from 'zustand';
import { zustandDevTools } from './utils';
import { organizationService } from '@/_services';
const initialState = {
organizations: [],
isGettingOrganizations: false,
};
//TODO: migrate all rxjs functions to zustand in future
export const useCurrentSessionStore = create(
zustandDevTools(
(set, get) => ({
...initialState,
actions: {
fetchOrganizations: async () => {
if (get().isGettingOrganizations || get().organizations.length) return;
try {
set({ isGettingOrganizations: true });
const response = await organizationService.getOrganizations();
set({ organizations: response.organizations, isGettingOrganizations: false });
} catch (error) {
console.error('Error while fetching organizations', error);
}
},
setOrganizations: (organizations) => set({ organizations }),
},
}),
{ name: 'Current Session Store' }
)
);
export const useCurrentSessionStoreActions = () => useCurrentSessionStore((state) => state.actions);