44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
import EmployeeActionTypes from "./employee.types";
|
|
import {
|
|
employeeSignInStart,
|
|
employeeSignInSuccess,
|
|
employeeSignInFailure,
|
|
} from "./employee.actions";
|
|
import { all, call, put, select, 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.EMPLOYEE_SIGN_IN_START,
|
|
signInWithEmployeeId
|
|
);
|
|
}
|
|
export function* signInWithEmployeeId({ payload: { employeeId, pin } }) {
|
|
try {
|
|
logImEXEvent("redux_sign_in_employee_attempt");
|
|
//console.loging
|
|
console.log("Saga", employeeId, pin, pin);
|
|
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(employeeSignInSuccess(technician));
|
|
} else {
|
|
yield put(employeeSignInFailure(error));
|
|
}
|
|
} catch (error) {
|
|
yield put(employeeSignInFailure(error));
|
|
}
|
|
}
|
|
|
|
export function* employeeSagas() {
|
|
yield all([call(onSignInEmployeeStart)]);
|
|
}
|