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,20 @@
import TechActionTypes from "./tech.types";
export const loginStart = ({ technician, password }) => ({
type: TechActionTypes.LOGIN_START,
payload: { technician, password },
export const techLoginStart = ({ employeeid, pin }) => ({
type: TechActionTypes.TECH_LOGIN_START,
payload: { employeeid, pin },
});
export const loginSuccess = (tech) => ({
type: TechActionTypes.LOGIN_SUCCESS,
export const techLoginSuccess = (tech) => ({
type: TechActionTypes.TECH_LOGIN_SUCCESS,
payload: tech,
});
export const loginFailure = (error) => ({
type: TechActionTypes.LOGIN_SUCCESS,
export const techLoginFailure = (error) => ({
type: TechActionTypes.TECH_LOGIN_FAILURE,
payload: error,
});
export const techLogout = () => ({
type: TechActionTypes.TECH_LOGOUT,
});

View File

@@ -1,20 +1,33 @@
import TechActionTypes from "./tech.types";
const INITIAL_STATE = {
technician: null,
loginLoading: false,
loginError: null,
};
const applicationReducer = (state = INITIAL_STATE, action) => {
switch (action.type) {
case TechActionTypes.LOGIN_SUCCESS:
case TechActionTypes.TECH_LOGOUT:
return {
...state,
technician: null,
};
case TechActionTypes.TECH_LOGIN_START:
return {
...state,
loginLoading: true,
};
case TechActionTypes.TECH_LOGIN_SUCCESS:
return {
...state,
technician: action.payload,
loginLoading: false,
};
case TechActionTypes.LOGIN_FAILURE:
case TechActionTypes.TECH_LOGIN_FAILURE:
return {
...state,
loginError: action.payload,
loginLoading: false,
};
default:

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

View File

@@ -10,3 +10,7 @@ export const selectLoginError = createSelector(
[selectTechReducer],
(application) => application.loginError
);
export const selectLoginLoading = createSelector(
[selectTechReducer],
(application) => application.loginLoading
);

View File

@@ -1,6 +1,7 @@
const TechActionTypes = {
LOGIN_START: "LOGIN_START",
LOGIN_SUCCESS: "LOGIN_SUCCESS",
LOGIN_FAILURE: "LOGIN_FAILURE",
TECH_LOGIN_START: "TECH_LOGIN_START",
TECH_LOGIN_SUCCESS: "TECH_LOGIN_SUCCESS",
TECH_LOGIN_FAILURE: "TECH_LOGIN_FAILURE",
TECH_LOGOUT: "TECH_LOGOUT",
};
export default TechActionTypes;