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"; import { faEyeSlash, faEye } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useState } from "react"; import { useIntegrationsContext } from "../../../context/IntegrationsContext"; const NPEDFields = () => { const { state } = useIntegrationsContext(); const [showPwd, setShowPwd] = useState(false); const { signIn, signOut } = useNPEDAuth(); const username = state.npedUser?.propUsername?.value; const password = state.npedUser?.propPassword?.value; const clientId = state.npedUser?.propClientID?.value; const frontId = "NPED"; const rearId = "NPED"; const initialValues = { username: username ?? "", password: password ?? "", clientId: clientId ?? "", frontId: frontId, rearId: rearId, }; const handleSubmit = async (values: NPEDFieldType) => { const valuesToSend = { ...values, }; await signIn(valuesToSend); }; 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(); toast.warning("logged out of NPED"); }; return ( {({ errors, touched, isSubmitting }) => (
{touched.username && errors.username && ( {errors.username} )}
{touched.password && errors.password && ( {errors.password} )} setShowPwd((s) => !s)} icon={showPwd ? faEyeSlash : faEye} />
{touched.clientId && errors.clientId && ( {errors.clientId} )} {!state.npedUser?.propClientID?.value ? ( ) : ( )}
)}
); }; export default NPEDFields;