Files
imexmobile/redux/employee/employee.sagas.js
2023-04-13 13:33:12 -04:00

43 lines
1.2 KiB
JavaScript

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