added employee folder redux
This commit is contained in:
42
redux/employee/employee.sagas.js
Normal file
42
redux/employee/employee.sagas.js
Normal 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)]);
|
||||
}
|
||||
Reference in New Issue
Block a user