Updated employee login
This commit is contained in:
@@ -5,34 +5,40 @@ import { Button, TextInput } from "react-native-paper";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { signInEmployeeStart } from "../../redux/employee/employee.actions";
|
import { employeeSignInStart } from "../../redux/employee/employee.actions";
|
||||||
import { createStructuredSelector } from "reselect";
|
import { createStructuredSelector } from "reselect";
|
||||||
import {
|
import {
|
||||||
selectCurrentEmployee, selectSigningIn
|
selectCurrentEmployee,
|
||||||
|
selectSigningIn,
|
||||||
|
selectSignInError
|
||||||
} from "../../redux/employee/employee.selectors";
|
} from "../../redux/employee/employee.selectors";
|
||||||
//TODO JF add props
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
import ErrorDisplay from "../error-display/error-display.component";
|
||||||
|
// import Timer from "../../util/timer";
|
||||||
|
|
||||||
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentEmployee: selectCurrentEmployee,
|
currentEmployee: selectCurrentEmployee,
|
||||||
signingIn: selectSigningIn,
|
signingIn: selectSigningIn,
|
||||||
|
signingError: selectSignInError,
|
||||||
});
|
});
|
||||||
|
|
||||||
//TODO JF add prop functions to call dispatch with actions
|
// JF add prop functions to call dispatch with actions
|
||||||
const mapDispatchToProps = (dispatch) => ({
|
const mapDispatchToProps = (dispatch) => ({
|
||||||
signInEmployeeStart: (employeeId, pin) =>
|
employeeSignInStart: (employeeId, pin) => dispatch(employeeSignInStart({ employeeId, pin })),
|
||||||
dispatch(signInEmployeeStart({ employeeId, pin })),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export function EmployeeSignIn({ signInEmployeeStart, employeeSigningIn }) {
|
export function EmployeeSignIn({currentEmployee,signingError, signingIn, employeeSignInStart }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
//TODO add call to dispatch action
|
//TODO add call to dispatch action
|
||||||
const formSubmit = (values) => {
|
const formSubmit = (values) => {
|
||||||
const { employeeId, pin } = values;
|
const { employeeId, pin } = values;
|
||||||
signInEmployeeStart(employeeId, pin);
|
employeeSignInStart(employeeId, pin);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={localStyles.content}>
|
<View style={localStyles.content}>
|
||||||
|
{/* {currentEmployee ? <Redirect to={`/timeticketbrowser/landing`} /> : null} */}
|
||||||
<View style={localStyles.signInContainer}>
|
<View style={localStyles.signInContainer}>
|
||||||
<Formik
|
<Formik
|
||||||
initialValues={{ employeeId: "", pin: "" }}
|
initialValues={{ employeeId: "", pin: "" }}
|
||||||
@@ -59,9 +65,12 @@ export function EmployeeSignIn({ signInEmployeeStart, employeeSigningIn }) {
|
|||||||
value={values.pin}
|
value={values.pin}
|
||||||
style={[localStyles.input]}
|
style={[localStyles.input]}
|
||||||
/>
|
/>
|
||||||
|
{signingError && (
|
||||||
|
<ErrorDisplay errorMessage={signingError} />
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
mode="outlined"
|
mode="outlined"
|
||||||
loading={employeeSigningIn}
|
loading={signingIn}
|
||||||
onPress={handleSubmit}
|
onPress={handleSubmit}
|
||||||
>
|
>
|
||||||
<Text>{t("employeesignin.actions.employeesignin")}</Text>
|
<Text>{t("employeesignin.actions.employeesignin")}</Text>
|
||||||
|
|||||||
@@ -1,35 +1,21 @@
|
|||||||
import EmployeeActionTypes from "./employee.types";
|
import EmployeeActionTypes from "./employee.types";
|
||||||
|
|
||||||
export const signInEmployeeStart = (employeeIdAndPin) => ({
|
export const employeeSignInStart = (employeeIdAndPin) => ({
|
||||||
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_START,
|
type: EmployeeActionTypes.EMPLOYEE_SIGN_IN_START,
|
||||||
payload: employeeIdAndPin,
|
payload: employeeIdAndPin,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const signInEmployeeSuccess = (technician) => ({
|
export const employeeSignInSuccess = (technician) => ({
|
||||||
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_SUCCESS,
|
type: EmployeeActionTypes.EMPLOYEE_SIGN_IN_SUCCESS,
|
||||||
payload: technician,
|
payload: technician,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const signInEmployeeFailure = (error) => ({
|
export const employeeSignInFailure = (error) => ({
|
||||||
type: EmployeeActionTypes.SIGN_IN_EMPLOYEE_FAILURE,
|
type: EmployeeActionTypes.EMPLOYEE_SIGN_IN_FAILURE,
|
||||||
payload: error,
|
payload: error,
|
||||||
});
|
});
|
||||||
|
|
||||||
export function loginEmployee() {
|
export const employeeSignOut = () => ({
|
||||||
return {
|
type: EmployeeActionTypes.EMPLOYEE_SIGN_OUT,
|
||||||
type: EmployeeActionTypes.AUTHORIZING_EMPLOYEE_REQUEST,
|
payload: error,
|
||||||
payload:"text"
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
export function loginEmployeeSuccess(technician) {
|
|
||||||
return {
|
|
||||||
type: EmployeeActionTypes.AUTHORIZING_EMPLOYEE_SUCCESS,
|
|
||||||
payload: technician
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export function loginEmployeeFal(error) {
|
|
||||||
return {
|
|
||||||
type: EmployeeActionTypes.AUTHORIZING_EMPLOYEE_FALURE,
|
|
||||||
error: error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -3,30 +3,37 @@ import EmployeeActionTypes from "./employee.types";
|
|||||||
const INITIAL_STATE = {
|
const INITIAL_STATE = {
|
||||||
currentEmployee: {
|
currentEmployee: {
|
||||||
authorized: null,
|
authorized: null,
|
||||||
|
technician: null,
|
||||||
},
|
},
|
||||||
employeeSigningIn: false,
|
signingIn: false,
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const employeeReducer = (state = INITIAL_STATE, action) => {
|
const employeeReducer = (state = INITIAL_STATE, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case EmployeeActionTypes.SIGN_IN_EMPLOYEE_START:
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_START:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
employeeSigningIn: true,
|
signingIn: true,
|
||||||
|
};
|
||||||
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_SUCCESS:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
currentEmployee: { authorized: true, technician:action.payload },
|
||||||
|
signingIn: false,
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
case EmployeeActionTypes.SIGN_IN_EMPLOYEE_SUCCESS:
|
case EmployeeActionTypes.EMPLOYEE_SIGN_OUT:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
currentEmployee: action.payload,
|
currentEmployee: { authorized: false, technician:null },
|
||||||
error: null,
|
error: null,
|
||||||
};
|
};
|
||||||
case EmployeeActionTypes.SIGN_OUT_EMPLOYEE_SUCCESS:
|
case EmployeeActionTypes.EMPLOYEE_SIGN_IN_FAILURE:
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
currentEmployee: { authorized: false },
|
signingIn: false,
|
||||||
error: null,
|
error: action.payload,
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import EmployeeActionTypes from "./employee.types";
|
import EmployeeActionTypes from "./employee.types";
|
||||||
import {
|
import {
|
||||||
signInEmployeeStart,
|
employeeSignInStart,
|
||||||
signInEmployeeSuccess,
|
employeeSignInSuccess,
|
||||||
signInEmployeeFailure,
|
employeeSignInFailure,
|
||||||
} from "./employee.actions";
|
} from "./employee.actions";
|
||||||
import { all, call, put, select, takeLatest } from "redux-saga/effects";
|
import { all, call, put, select, takeLatest } from "redux-saga/effects";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
import { logImEXEvent } from "../../firebase/firebase.analytics";
|
||||||
@@ -11,7 +11,7 @@ import axios from "axios";
|
|||||||
|
|
||||||
export function* onSignInEmployeeStart() {
|
export function* onSignInEmployeeStart() {
|
||||||
yield takeLatest(
|
yield takeLatest(
|
||||||
EmployeeActionTypes.SIGN_IN_EMPLOYEE_START,
|
EmployeeActionTypes.EMPLOYEE_SIGN_IN_START,
|
||||||
signInWithEmployeeId
|
signInWithEmployeeId
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -29,12 +29,12 @@ export function* signInWithEmployeeId({ payload: { employeeId, pin } }) {
|
|||||||
const { valid, technician, error } = response.data;
|
const { valid, technician, error } = response.data;
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
yield put(signInEmployeeSuccess(technician));
|
yield put(employeeSignInSuccess(technician));
|
||||||
} else {
|
} else {
|
||||||
yield put(signInEmployeeFailure(error));
|
yield put(employeeSignInFailure(error));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
yield put(signInEmployeeFailure(error));
|
yield put(employeeSignInFailure(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,9 +4,13 @@ const selectEmployee = (state) => state.employee;
|
|||||||
|
|
||||||
export const selectCurrentEmployee = createSelector(
|
export const selectCurrentEmployee = createSelector(
|
||||||
[selectEmployee],
|
[selectEmployee],
|
||||||
(employee) => employee.currentEmployee
|
(employee) => employee.currentEmployee.technician
|
||||||
);
|
);
|
||||||
export const selectSigningIn = createSelector(
|
export const selectSigningIn = createSelector(
|
||||||
[selectEmployee],
|
[selectEmployee],
|
||||||
(employee) => employee.signingIn
|
(employee) => employee.signingIn
|
||||||
|
);
|
||||||
|
export const selectSignInError = createSelector(
|
||||||
|
[selectEmployee],
|
||||||
|
(employee) => employee.error
|
||||||
);
|
);
|
||||||
@@ -1,17 +1,13 @@
|
|||||||
const EmployeeActionTypes = {
|
const EmployeeActionTypes = {
|
||||||
AUTHORIZING_EMPLOYEE_REQUEST:"AUTHORIZING_EMPLOYEE_REQUEST",
|
EMPLOYEE_SIGN_IN_START: "EMPLOYEE_SIGN_IN_START",
|
||||||
AUTHORIZING_EMPLOYEE_SUCCESS:"AUTHORIZING_EMPLOYEE_SUCCESS",
|
EMPLOYEE_SIGN_IN_SUCCESS: "EMPLOYEE_SIGN_IN_SUCCESS",
|
||||||
AUTHORIZING_EMPLOYEE_FAILURE:"AUTHORIZING_EMPLOYEE_FAILURE",
|
EMPLOYEE_SIGN_IN_FAILURE: "EMPLOYEE_SIGN_IN_FAILURE",
|
||||||
SET_CURRENT_EMPLOYEE: "SET_CURRENT_EMPLOYEE",
|
EMPLOYEE_AUTHORIZING_REQUEST: "EMPLOYEE_AUTHORIZING_REQUEST",
|
||||||
SIGN_IN_EMPLOYEE_SUCCESS: "SIGN_IN_EMPLOYEE_SUCCESS",
|
EMPLOYEE_AUTHORIZING_SUCCESS: "EMPLOYEE_AUTHORIZING_SUCCESS",
|
||||||
SIGN_IN_EMPLOYEE_FAILURE: "SIGN_IN_EMPLOYEE_FAILURE",
|
EMPLOYEE_AUTHORIZING_FAILURE: "EMPLOYEE_AUTHORIZING_FAILURE",
|
||||||
SIGN_IN_EMPLOYEE_START: "SIGN_IN_EMPLOYEE_START",
|
EMPLOYEE_SIGN_OUT: "EMPLOYEE_SIGN_OUT",
|
||||||
CHECK_EMPLOYEE_SESSION: "CHECK_EMPLOYEE_SESSION",
|
|
||||||
SIGN_OUT_EMPLOYEE_START: "SIGN_OUT_EMPLOYEE_START",
|
EMPLOYEE_CHECK_SESSION: "EMPLOYEE_CHECK_SESSION",
|
||||||
SIGN_OUT_EMPLOYEE_SUCCESS: "SIGN_OUT_EMPLOYEE_SUCCESS",
|
EMPLOYEE_SET_CURRENT: "EMPLOYEE_SET_CURRENT"
|
||||||
SIGN_OUT_EMPLOYEE_FAILURE: "SIGN_OUT_EMPLOYEE_FAILURE",
|
};
|
||||||
UNAUTHORIZED_EMPLOYEE: "UNAUTHORIZED_EMPLOYEE",
|
export default EmployeeActionTypes;
|
||||||
UPDATE_EMPLOYEE_DETAILS: "UPDATE_EMPLOYEE_DETAILS",
|
|
||||||
UPDATE_EMPLOYEE_DETAILS_SUCCESS: "UPDATE_EMPLOYEE_DETAILS_SUCCESS",
|
|
||||||
};
|
|
||||||
export default EmployeeActionTypes;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user