SHARE
TWEET

Untitled

a guest Jun 25th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as actions from "./actions";
  2.  
  3. const initialState = {
  4.   workSchedules: {
  5.     isFetched: undefined
  6.   },
  7.   workScheduleMore: undefined,
  8.   workScheduleApproveUpdate: undefined,
  9.   workScheduleCalendar: {
  10.     isFetched: undefined
  11.   }
  12. };
  13.  
  14. const documents = (state = initialState, action) => {
  15.   switch (action.type) {
  16.     // work schedule
  17.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL: {
  18.       return {
  19.         ...state,
  20.         workSchedules: {
  21.           ...state.workSchedules,
  22.           isFetched: undefined
  23.         },
  24.         workScheduleUpdate: undefined,
  25.         workScheduleApproveUpdate: undefined
  26.       };
  27.     }
  28.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL_SUCCESS: {
  29.       return {
  30.         ...state,
  31.         workSchedules: {
  32.           data: action.workSchedule,
  33.           isFetched: true
  34.         }
  35.       };
  36.     }
  37.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_ALL_FAILED: {
  38.       return {
  39.         ...state,
  40.         workSchedules: {
  41.           ...state.workSchedules,
  42.           data: {
  43.             ...state.workSchedules.data,
  44.             list: []
  45.           },
  46.           isFetched: false
  47.         }
  48.       };
  49.     }
  50.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID: {
  51.       return {
  52.         ...state,
  53.         workScheduleMore: {
  54.           ...state.workScheduleMore,
  55.           isFetched: undefined
  56.         }
  57.       };
  58.     }
  59.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID_SUCCESS: {
  60.       return {
  61.         ...state,
  62.         workScheduleMore: {
  63.           ...state.workScheduleMore,
  64.           isFetched: true,
  65.           [action.workSchedule.id]: { ...action.workSchedule, isFetched: true }
  66.         }
  67.       };
  68.     }
  69.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_BY_ID_FAILED: {
  70.       return {
  71.         ...state,
  72.         workScheduleMore: {
  73.           ...state.workScheduleMore,
  74.           isFetched: false
  75.         }
  76.       };
  77.     }
  78.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_EMPTY_SUCCESS: {
  79.       return {
  80.         ...state,
  81.         workSchedules: {
  82.           data: {
  83.             ...state.workSchedules.data,
  84.             list: []
  85.           },
  86.           isFetched: true
  87.         }
  88.       };
  89.     }
  90.     case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE: {
  91.       return {
  92.         ...state,
  93.         workScheduleUpdate: undefined,
  94.         workScheduleApproveUpdate: undefined
  95.       };
  96.     }
  97.     case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE_SUCCESS: {
  98.       return {
  99.         ...state,
  100.         workScheduleUpdate: true,
  101.         workScheduleApproveUpdate: true
  102.       };
  103.     }
  104.     case actions.DOCUMENTS_WORK_SCHEDULE_UPDATE_FAILED: {
  105.       return {
  106.         ...state,
  107.         workScheduleUpdate: false,
  108.         workScheduleApproveUpdate: false
  109.       };
  110.     }
  111.     // work schedule calendar
  112.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_INIT: {
  113.       return {
  114.         ...state,
  115.         workScheduleCalendar: {
  116.           ...state.workScheduleCalendar,
  117.           isFetched: undefined
  118.         }
  119.       }
  120.     }
  121.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_SUCCESS: {
  122.       return {
  123.         ...state,
  124.         workScheduleCalendar: {
  125.           data: action.workScheduleCalendar,
  126.           isFetched: true
  127.         }
  128.       }
  129.     }
  130.     case actions.DOCUMENTS_WORK_SCHEDULE_FETCH_CALENDAR_FAILED: {
  131.       return {
  132.         ...state,
  133.         workScheduleCalendar: {
  134.           data: [],
  135.           isFetched: false
  136.         }
  137.       }
  138.     }
  139.     default:
  140.       return state;
  141.   }
  142. };
  143.  
  144. export default documents;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top