99 lines
2.8 KiB
JavaScript
99 lines
2.8 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";
|
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
currentEmployee: selectCurrentEmployee,
|
|
signingIn: selectSigningIn,
|
|
signingError: selectSignInError,
|
|
});
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
employeeSignInStart: (employeeId, pin) =>
|
|
dispatch(employeeSignInStart({ employeeId, pin })),
|
|
});
|
|
|
|
export function EmployeeSignIn({
|
|
signingError,
|
|
signingIn,
|
|
employeeSignInStart,
|
|
}) {
|
|
const { t } = useTranslation();
|
|
|
|
const formSubmit = (values) => {
|
|
const { employeeId, pin } = values;
|
|
employeeSignInStart(employeeId, pin);
|
|
};
|
|
|
|
return (
|
|
<View style={localStyles.content}>
|
|
<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);
|