added employee folder redux

This commit is contained in:
jfrye122
2023-04-13 13:33:12 -04:00
parent d8d8ca0d11
commit 35573417c4
5 changed files with 136 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
import EmployeeActionTypes from "./employee.types";
export const signInEmployeeStart = (employeeIdAndPin) => ({
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_START,
payload: employeeIdAndPin,
});
export const signInEmployeeSuccess = (technician) => ({
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_SUCCESS,
payload: technician,
});
export const signInEmployeeFailure = (error) => ({
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_FAILURE,
payload: error,
});
export function loginEmployee() {
return {
type: EmployeeActionTypes.AUTHORIZING_EMPLOYEE_REQUEST,
payload:"text"
}
}
export function loginEmployeeSuccess(technician) {
return {
type: EmployeeActionTypes.AUTHORIZING_EMPLOYEE_SUCCESS,
payload: technician
}
}

View File

@@ -0,0 +1,36 @@
import EmployeeActionTypes from "./employee.types";
const INITIAL_STATE = {
currentEmployee: {
authorized: null,
},
employeeSigningIn: false,
error: null,
};
const employeeReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case EmployeeActionTypes.SIGN_IN_EMPLOYEE_START:
return {
...state,
employeeSigningIn: true,
error: null,
};
case EmployeeActionTypes.SIGN_IN_EMPLOYEE_SUCCESS:
return {
...state,
currentEmployee: action.payload,
error: null,
};
case EmployeeActionTypes.SIGN_OUT_EMPLOYEE_SUCCESS:
return {
...state,
currentEmployee: { authorized: false },
error: null,
};
default:
return state;
}
};
export default employeeReducer;

View File

@@ -0,0 +1,42 @@
import EmployeeActionTypes from "./employee.types";
import {
signInEmployeeStart,
signInEmployeeSuccess,
signInEmployeeFailure,
} from "./employee.actions";
import { all, call, put, takeLatest } from "redux-saga/effects";
import { logImEXEvent } from "../../firebase/firebase.analytics";
import { selectBodyshop } from "../user/user.selectors";
import axios from "axios";
export function* onSignInEmployeeStart() {
yield takeLatest(
EmployeeActionTypes.SIGN_IN_EMPLOYEE_START,
signInWithEmployeeId
);
}
export function* signInWithEmployeeId({ payload: { employeeid, pin } }) {
try {
logImEXEvent("redux_sign_in_employee_attempt");
//console.loging
const bodyshop = yield select(selectBodyshop);
const response = yield call(axios.post, "/tech/login", {
shopid: bodyshop.id,
employeeid: employeeid,
pin: pin,
});
const { valid, technician, error } = response.data;
if (valid) {
yield put(signInEmployeeSuccess(technician));
} else {
yield put(signInEmployeeFailure(error));
}
} catch (error) {
yield put(signInEmployeeFailure(error));
}
}
export function* employeeSagas() {
yield all([call(onSignInEmployeeStart)]);
}

View File

@@ -0,0 +1,12 @@
import { createSelector } from "reselect";
const selectEmployee = (state) => state.employee;
export const selectCurrentEmployee = createSelector(
[selectEmployee],
(employee) => employee.currentEmployee
);
export const selectSigningIn = createSelector(
[selectEmployee],
(employee) => employee.signingIn
);

View File

@@ -0,0 +1,17 @@
const EmployeeActionTypes = {
AUTHORIZING_EMPLOYEE_REQUEST:"AUTHORIZING_EMPLOYEE_REQUEST",
AUTHORIZING_EMPLOYEE_SUCCESS:"AUTHORIZING_EMPLOYEE_SUCCESS",
AUTHORIZING_EMPLOYEE_SUCCESS:"AUTHORIZING_EMPLOYEE_FAILURE",
SET_CURRENT_EMPLOYEE: "SET_CURRENT_EMPLOYEE",
SIGN_IN_EMPLOYEE_SUCCESS: "SIGN_IN_EMPLOYEE_SUCCESS",
SIGN_IN_EMPLOYEE_FAILURE: "SIGN_IN_EMPLOYEE_FAILURE",
SIGN_IN_EMPLOYEE_START: "SIGN_IN_EMPLOYEE_START",
CHECK_EMPLOYEE_SESSION: "CHECK_EMPLOYEE_SESSION",
SIGN_OUT_EMPLOYEE_START: "SIGN_OUT_EMPLOYEE_START",
SIGN_OUT_EMPLOYEE_SUCCESS: "SIGN_OUT_EMPLOYEE_SUCCESS",
SIGN_OUT_EMPLOYEE_FAILURE: "SIGN_OUT_EMPLOYEE_FAILURE",
UNAUTHORIZED_EMPLOYEE: "UNAUTHORIZED_EMPLOYEE",
UPDATE_EMPLOYEE_DETAILS: "UPDATE_EMPLOYEE_DETAILS",
UPDATE_EMPLOYEE_DETAILS_SUCCESS: "UPDATE_EMPLOYEE_DETAILS_SUCCESS",
};
export default EmployeeActionTypes;