100 lines
3.0 KiB
JavaScript
100 lines
3.0 KiB
JavaScript
import { Formik } from "formik";
|
|
import React from "react";
|
|
import { View, StyleSheet, Text } from "react-native";
|
|
import { Button, TextInput } from "react-native-paper";
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import { connect } from "react-redux";
|
|
import { employeeSignInStart } from "../../redux/employee/employee.actions";
|
|
import { createStructuredSelector } from "reselect";
|
|
import {
|
|
selectCurrentEmployee,
|
|
selectSigningIn,
|
|
selectSignInError
|
|
} from "../../redux/employee/employee.selectors";
|
|
|
|
import ErrorDisplay from "../error-display/error-display.component";
|
|
// import Timer from "../../util/timer";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
currentEmployee: selectCurrentEmployee,
|
|
signingIn: selectSigningIn,
|
|
signingError: selectSignInError,
|
|
});
|
|
|
|
// JF add prop functions to call dispatch with actions
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
employeeSignInStart: (employeeId, pin) => dispatch(employeeSignInStart({ employeeId, pin })),
|
|
});
|
|
|
|
export function EmployeeSignIn({currentEmployee,signingError, signingIn, employeeSignInStart }) {
|
|
const { t } = useTranslation();
|
|
|
|
//TODO add call to dispatch action
|
|
const formSubmit = (values) => {
|
|
const { employeeId, pin } = values;
|
|
employeeSignInStart(employeeId, pin);
|
|
};
|
|
|
|
return (
|
|
<View style={localStyles.content}>
|
|
{/* {currentEmployee ? <Redirect to={`/timeticketbrowser/landing`} /> : null} */}
|
|
<View style={localStyles.signInContainer}>
|
|
<Formik
|
|
initialValues={{ employeeId: "", pin: "" }}
|
|
onSubmit={formSubmit}
|
|
>
|
|
{({ handleChange, handleBlur, handleSubmit, values }) => (
|
|
<View>
|
|
<TextInput
|
|
label={t("employeesignin.fields.employeeid")}
|
|
mode="outlined"
|
|
autoCapitalize="none"
|
|
keyboardType="default"
|
|
onChangeText={handleChange("employeeId")}
|
|
onBlur={handleBlur("employeeId")}
|
|
value={values.employeeId}
|
|
style={[localStyles.input]}
|
|
/>
|
|
<TextInput
|
|
label={t("employeesignin.fields.pin")}
|
|
mode="outlined"
|
|
secureTextEntry={true}
|
|
onChangeText={handleChange("pin")}
|
|
onBlur={handleBlur("pin")}
|
|
value={values.pin}
|
|
style={[localStyles.input]}
|
|
/>
|
|
{signingError && (
|
|
<ErrorDisplay errorMessage={signingError} />
|
|
)}
|
|
<Button
|
|
mode="outlined"
|
|
loading={signingIn}
|
|
onPress={handleSubmit}
|
|
>
|
|
<Text>{t("employeesignin.actions.employeesignin")}</Text>
|
|
</Button>
|
|
</View>
|
|
)}
|
|
</Formik>
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
const localStyles = StyleSheet.create({
|
|
content: {
|
|
display: "flex",
|
|
flex: 1,
|
|
},
|
|
signInContainer: {
|
|
flex: 1,
|
|
},
|
|
input: {
|
|
margin: 12,
|
|
},
|
|
});
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(EmployeeSignIn);
|