withFormik({ mapPropsToValues: props => ({ username: '', password: '' }), validationSchema: Yup.object().shape({ username: Yup.string().required(), password: Yup.string().required() }), handleSubmit: async (values, { props, setSubmitting, setStatus }) => { const action = await props.loginUser(values); setSubmitting(false); if (action.type === LOGIN_FAILURE) { setStatus({ error: 'Unable to login with the provided credentials.'}); } else if (action.type === LOGIN_SUCCESS) { props.history.push('/dashboard/statements'); } }, })(LoginForm)
withFormik({ // Transform outer props into form values mapPropsToValues: props => ({ email: props.userEmail, password: '' }), validationSchema: Yup.object().shape({ email: Yup.string().email('This is not a valid email'), password: Yup.string().min(6, 'Your password has to be at least 6 characters') }), // Submission handler handleSubmit: (values, { props, setStatus }) => { const { email, password } = values; if (!password) { setStatus('No details changed'); return; } setStatus('Sending...'); props .changeUserDetails(email, password) .then(() => setStatus('Details successfully changed!')) .catch(error => setStatus('Problems... please log out and try again')); } })(InnerForm)
return setStatus({ error: action.error});
withFormik({ mapPropsToValues: props => ({ username: '', password1: '', password2: '', firstName: '', lastName: '', email: '' }), validationSchema: Yup.object().shape({ email: Yup.string().required().email('Invalid email'), username: Yup.string().required(), firstName: Yup.string().required('First name is a required field'), password1: Yup.string().required(), password2: Yup.string().required(), }), handleSubmit: async (values, { props, setSubmitting, setStatus }) => { const action = await props.registerUser(values); setSubmitting(false); if (action.type === REGISTER_FAILURE) { setStatus({ error: 'Unable to register with the provided data.'}); } else if (action.type === REGISTER_SUCCESS) { props.history.push('/dashboard/statements'); } }, })(RegisterForm)
resetForm({}) } catch (error) { setStatus(error.response.data.message)
resetForm({}) } catch (error) { setStatus(error.response.data.message)