reducers.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. import { createSlice, PayloadAction } from '@reduxjs/toolkit';
  2. import { Organization, OrganizationState, UserOrg } from 'app/types';
  3. export const initialState: OrganizationState = {
  4. organization: {} as Organization,
  5. userOrgs: [] as UserOrg[],
  6. };
  7. const organizationSlice = createSlice({
  8. name: 'organization',
  9. initialState,
  10. reducers: {
  11. organizationLoaded: (state, action: PayloadAction<Organization>): OrganizationState => {
  12. return { ...state, organization: action.payload };
  13. },
  14. setOrganizationName: (state, action: PayloadAction<string>): OrganizationState => {
  15. return { ...state, organization: { ...state.organization, name: action.payload } };
  16. },
  17. userOrganizationsLoaded: (state, action: PayloadAction<UserOrg[]>): OrganizationState => {
  18. return { ...state, userOrgs: action.payload };
  19. },
  20. },
  21. });
  22. export const { setOrganizationName, organizationLoaded, userOrganizationsLoaded } = organizationSlice.actions;
  23. export const organizationReducer = organizationSlice.reducer;
  24. export default {
  25. organization: organizationReducer,
  26. };