import { useState } from 'react'; import * as Yup from 'yup'; import { useNavigate, useLocation } from 'react-router-dom'; import { Formik, Form } from 'formik'; import { AuthWrapper } from '@/components/auth-wrapper/authWrapper.tsx'; import { AuthLogo } from '@/components/auth-logo/authLogo.tsx'; import { AuthButton } from '@/components/buttons/authButton.tsx'; import { AuthInputs } from '@/components/inputs/authInputs.tsx'; import { useAuth } from '@/providers/authProvider.tsx'; import '@/styles/cards.css'; interface FormValues { username: string; password: string; } export const SignInPage = () => { const [respError, setRespError] = useState(''); const { login } = useAuth(); const navigate = useNavigate(); const location = useLocation(); const initialValues: FormValues = { username: '', password: '', }; const validationSchema = Yup.object().shape({ username: Yup.string() .min(3, 'Minimum 3 symbol') .required('Required field'), password: Yup.string() .min(6, 'Minimum 6 symbol') .required('Required field'), }); const handleSubmit = async (e: FormValues) => { if (respError) { setRespError(''); } try { await login({ username: e.username, password: e.password }); // Use the 'from' state if available, otherwise default to '/applications' const from = location.state?.from || '/applications'; navigate(from); } catch (e) { setRespError(typeof e === 'string' ? e : ''); } }; return (
{/*
*/}

Sign In

{ handleSubmit(values); }}> {() => (
{respError && respError}
{}} /> { navigate('/signup'); }} />
)}
); };