42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import axios from "axios";
|
|
import { all, call, put, select, takeLatest } from "redux-saga/effects";
|
|
import { selectBodyshop } from "../user/user.selectors";
|
|
import { techLoginFailure, techLoginSuccess } from "./tech.actions";
|
|
import TechActionTypes from "./tech.types";
|
|
|
|
export function* onSignInStart() {
|
|
yield takeLatest(TechActionTypes.TECH_LOGIN_START, signInStart);
|
|
}
|
|
export function* signInStart({ payload: { employeeid, pin } }) {
|
|
try {
|
|
const bodyshop = yield select(selectBodyshop);
|
|
const response = yield call(axios.post, "/tech/login", {
|
|
shopid: bodyshop.id,
|
|
employeeid: employeeid,
|
|
pin: pin,
|
|
});
|
|
console.log("response", response);
|
|
const { valid, technician, error } = response.data;
|
|
|
|
console.log(
|
|
"function*signInStart -> valid, technician, erro",
|
|
valid,
|
|
technician,
|
|
error
|
|
);
|
|
|
|
if (valid) {
|
|
console.log("Valid in else");
|
|
yield put(techLoginSuccess(technician));
|
|
} else {
|
|
yield put(techLoginFailure(error));
|
|
}
|
|
} catch (error) {
|
|
yield put(techLoginFailure(error));
|
|
}
|
|
}
|
|
|
|
export function* techSagas() {
|
|
yield all([call(onSignInStart)]);
|
|
}
|