Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as actions from "./actions";
- const initialState = {
- workSchedules: {
- isFetched: undefined
- },
- workScheduleMore: undefined,
- workScheduleApproveUpdate: undefined,
- workScheduleCalendar: {
- isFetched: undefined
- }
- };
- const documents = (state = initialState, action) => {
- switch (action.type) {
- // work schedule
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL: {
- return {
- ...state,
- workSchedules: {
- ...state.workSchedules,
- isFetched: undefined
- },
- workScheduleUpdate: undefined,
- workScheduleApproveUpdate: undefined
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL_SUCCESS: {
- return {
- ...state,
- workSchedules: {
- data: action.workSchedule,
- isFetched: true
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL_FAILED: {
- return {
- ...state,
- workSchedules: {
- ...state.workSchedules,
- data: {
- ...state.workSchedules.data,
- list: []
- },
- isFetched: false
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID: {
- return {
- ...state,
- workScheduleMore: {
- ...state.workScheduleMore,
- isFetched: undefined
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID_SUCCESS: {
- return {
- ...state,
- workScheduleMore: {
- ...state.workScheduleMore,
- isFetched: true,
- [action.workSchedule.id]: { ...action.workSchedule, isFetched: true }
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID_FAILED: {
- return {
- ...state,
- workScheduleMore: {
- ...state.workScheduleMore,
- isFetched: false
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_EMPTY_SUCCESS: {
- return {
- ...state,
- workSchedules: {
- data: {
- ...state.workSchedules.data,
- list: []
- },
- isFetched: true
- }
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE: {
- return {
- ...state,
- workScheduleUpdate: undefined,
- workScheduleApproveUpdate: undefined
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE_SUCCESS: {
- return {
- ...state,
- workScheduleUpdate: true,
- workScheduleApproveUpdate: true
- };
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE_FAILED: {
- return {
- ...state,
- workScheduleUpdate: false,
- workScheduleApproveUpdate: false
- };
- }
- // work schedule calendar
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_INIT: {
- return {
- ...state,
- workScheduleCalendar: {
- ...state.workScheduleCalendar,
- isFetched: undefined
- }
- }
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_SUCCESS: {
- return {
- ...state,
- workScheduleCalendar: {
- data: action.workScheduleCalendar,
- isFetched: true
- }
- }
- }
- case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_FAILED: {
- return {
- ...state,
- workScheduleCalendar: {
- data: [],
- isFetched: false
- }
- }
- }
- default:
- return state;
- }
- };
- export default documents;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement