import React from 'react'; import { Link, RouteComponentProps } from 'react-router-dom'; import login from '@/api/auth/login'; import LoginFormContainer from '@/components/auth/LoginFormContainer'; import FlashMessageRender from '@/components/FlashMessageRender'; import { Actions, useStoreActions } from 'easy-peasy'; import { ApplicationStore } from '@/state'; import { FormikProps, withFormik } from 'formik'; import { object, string } from 'yup'; import Field from '@/components/elements/Field'; import { httpErrorToHuman } from '@/api/http'; interface Values { username: string; password: string; } type OwnProps = RouteComponentProps & { clearFlashes: any; addFlash: any; } const LoginContainer = ({ isSubmitting }: OwnProps & FormikProps) => (

Login to Continue

Forgot password?
); const EnhancedForm = withFormik({ displayName: 'LoginContainerForm', mapPropsToValues: (props) => ({ username: '', password: '', }), validationSchema: () => object().shape({ username: string().required('A username or email must be provided.'), password: string().required('Please enter your account password.'), }), handleSubmit: ({ username, password }, { props, setSubmitting }) => { props.clearFlashes(); login(username, password) .then(response => { if (response.complete) { // @ts-ignore window.location = response.intended || '/'; return; } props.history.replace('/auth/login/checkpoint', { token: response.confirmationToken }); }) .catch(error => { console.error(error); setSubmitting(false); props.addFlash({ type: 'error', title: 'Error', message: httpErrorToHuman(error) }); }); }, })(LoginContainer); export default (props: RouteComponentProps) => { const { clearFlashes, addFlash } = useStoreActions((actions: Actions) => actions.flashes); return ( ); };