import { Form, Formik, Field } from "formik"; import FormGroup from "../components/FormGroup"; import type { NPEDErrorValues, NPEDFieldType } from "../../../types/types"; import { useNPEDAuth } from "../../../hooks/useNPEDAuth"; import { toast } from "sonner"; const NPEDFields = () => { const { signIn, user, signOut } = useNPEDAuth(); const initialValues = user ? { username: user.propUsername.value, password: "", clientId: user.propClientID.value, frontId: "NPED", rearId: "NPED", } : { username: "", password: "", clientId: "", frontId: "NPED", rearId: "NPED", }; const handleSubmit = (values: NPEDFieldType) => { const valuesToSend = { ...values, }; signIn(valuesToSend); toast.success("Signed in successfully"); }; const validateValues = (values: NPEDFieldType) => { const errors: NPEDErrorValues = {}; if (!values.username) errors.username = "Required"; if (!values.password) errors.password = "Required"; if (!values.clientId) errors.clientId = "Required"; return errors; }; const handleLogoutClick = () => { signOut(); }; return ( {({ errors, touched }) => (
{touched.username && errors.username && ( {errors.username} )} {touched.password && errors.password && ( {errors.password} )} {touched.clientId && errors.clientId && ( {errors.clientId} )} {!user?.propClientID?.value ? ( ) : ( )}
)}
); }; export default NPEDFields;