reducers.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { Team, TeamGroup, TeamMember, TeamsState, TeamState } from 'app/types';
  2. import { Action, ActionTypes } from './actions';
  3. export const initialTeamsState: TeamsState = { teams: [], searchQuery: '', hasFetched: false };
  4. export const initialTeamState: TeamState = {
  5. team: {} as Team,
  6. members: [] as TeamMember[],
  7. groups: [] as TeamGroup[],
  8. searchMemberQuery: '',
  9. };
  10. export const teamsReducer = (state = initialTeamsState, action: Action): TeamsState => {
  11. switch (action.type) {
  12. case ActionTypes.LoadTeams:
  13. return { ...state, hasFetched: true, teams: action.payload };
  14. case ActionTypes.SetSearchQuery:
  15. return { ...state, searchQuery: action.payload };
  16. }
  17. return state;
  18. };
  19. export const teamReducer = (state = initialTeamState, action: Action): TeamState => {
  20. switch (action.type) {
  21. case ActionTypes.LoadTeam:
  22. return { ...state, team: action.payload };
  23. case ActionTypes.LoadTeamMembers:
  24. return { ...state, members: action.payload };
  25. case ActionTypes.SetSearchMemberQuery:
  26. return { ...state, searchMemberQuery: action.payload };
  27. case ActionTypes.LoadTeamGroups:
  28. return { ...state, groups: action.payload };
  29. }
  30. return state;
  31. };
  32. export default {
  33. teams: teamsReducer,
  34. team: teamReducer,
  35. };