44 lines
1013 B
JavaScript
44 lines
1013 B
JavaScript
import EmployeeActionTypes from "./employee.types";
|
|
|
|
const INITIAL_STATE = {
|
|
currentEmployee: {
|
|
authorized: null,
|
|
technician: null,
|
|
},
|
|
signingIn: false,
|
|
error: null,
|
|
};
|
|
|
|
const employeeReducer = (state = INITIAL_STATE, action) => {
|
|
switch (action.type) {
|
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_START:
|
|
return {
|
|
...state,
|
|
signingIn: true,
|
|
};
|
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_SUCCESS:
|
|
return {
|
|
...state,
|
|
currentEmployee: { authorized: true, technician:action.payload },
|
|
signingIn: false,
|
|
error: null,
|
|
};
|
|
case EmployeeActionTypes.EMPLOYEE_SIGN_OUT:
|
|
return {
|
|
...state,
|
|
currentEmployee: { authorized: false, technician:null },
|
|
error: null,
|
|
};
|
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_FAILURE:
|
|
return {
|
|
...state,
|
|
signingIn: false,
|
|
error: action.payload,
|
|
};
|
|
default:
|
|
return state;
|
|
}
|
|
};
|
|
|
|
export default employeeReducer;
|