Added login functionality for tech BOD-95

This commit is contained in:
Patrick Fic
2020-06-29 15:24:04 -07:00
parent 2edfadce3a
commit 0e9cc9620b
27 changed files with 552 additions and 115 deletions

View File

@@ -1,16 +1,39 @@
import { all, takeLatest, call, put } from "redux-saga/effects";
import { all, takeLatest, call, put, select } from "redux-saga/effects";
import TechActionTypes from "./tech.types";
import { client } from "../../App/App.container";
import { loginSuccess, loginFailure } from "./tech.actions";
import { techLoginStart,techLoginSuccess, techLoginFailure } from "./tech.actions";
import axios from "axios";
import { selectBodyshop } from "../user/user.selectors";
export function* onSignInStart() {
yield takeLatest(TechActionTypes.LOGIN_START, signInStart);
yield takeLatest(TechActionTypes.TECH_LOGIN_START, signInStart);
}
export function* signInStart({ payload: { technician, password } }) {
export function* signInStart({ payload: { employeeid, pin } }) {
try {
yield put(loginSuccess({ username: "TECHNICIAN" }));
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(loginFailure(error));
yield put(techLoginFailure(error));
}
}