2018-09-11 07:14:03 -05:00
|
|
|
import { Team, TeamGroup, TeamMember, TeamsState, TeamState } from 'app/types';
|
|
|
|
import { Action, ActionTypes } from './actions';
|
|
|
|
|
2018-10-11 04:49:34 -05:00
|
|
|
export const initialTeamsState: TeamsState = { teams: [], searchQuery: '', hasFetched: false };
|
2018-09-11 07:14:03 -05:00
|
|
|
export const initialTeamState: TeamState = {
|
|
|
|
team: {} as Team,
|
|
|
|
members: [] as TeamMember[],
|
|
|
|
groups: [] as TeamGroup[],
|
|
|
|
searchMemberQuery: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const teamsReducer = (state = initialTeamsState, action: Action): TeamsState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.LoadTeams:
|
2018-10-11 04:49:34 -05:00
|
|
|
return { ...state, hasFetched: true, teams: action.payload };
|
2018-09-11 07:14:03 -05:00
|
|
|
|
|
|
|
case ActionTypes.SetSearchQuery:
|
|
|
|
return { ...state, searchQuery: action.payload };
|
|
|
|
}
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const teamReducer = (state = initialTeamState, action: Action): TeamState => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ActionTypes.LoadTeam:
|
|
|
|
return { ...state, team: action.payload };
|
|
|
|
|
|
|
|
case ActionTypes.LoadTeamMembers:
|
|
|
|
return { ...state, members: action.payload };
|
|
|
|
|
|
|
|
case ActionTypes.SetSearchMemberQuery:
|
|
|
|
return { ...state, searchMemberQuery: action.payload };
|
|
|
|
|
|
|
|
case ActionTypes.LoadTeamGroups:
|
|
|
|
return { ...state, groups: action.payload };
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
teams: teamsReducer,
|
|
|
|
team: teamReducer,
|
|
|
|
};
|