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,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)]);
}