1234567891011121314151617181920212223242526272829303132 |
- import { createSlice, PayloadAction } from '@reduxjs/toolkit';
- import { Organization, OrganizationState, UserOrg } from 'app/types';
- export const initialState: OrganizationState = {
- organization: {} as Organization,
- userOrgs: [] as UserOrg[],
- };
- const organizationSlice = createSlice({
- name: 'organization',
- initialState,
- reducers: {
- organizationLoaded: (state, action: PayloadAction<Organization>): OrganizationState => {
- return { ...state, organization: action.payload };
- },
- setOrganizationName: (state, action: PayloadAction<string>): OrganizationState => {
- return { ...state, organization: { ...state.organization, name: action.payload } };
- },
- userOrganizationsLoaded: (state, action: PayloadAction<UserOrg[]>): OrganizationState => {
- return { ...state, userOrgs: action.payload };
- },
- },
- });
- export const { setOrganizationName, organizationLoaded, userOrganizationsLoaded } = organizationSlice.actions;
- export const organizationReducer = organizationSlice.reducer;
- export default {
- organization: organizationReducer,
- };
|