11import React , { useState } from 'react' ;
22import { Link , RouteComponentProps } from 'react-router-dom' ;
33import loginCheckpoint from '@/api/auth/loginCheckpoint' ;
4- import { httpErrorToHuman } from '@/api/http' ;
54import LoginFormContainer from '@/components/auth/LoginFormContainer' ;
65import { ActionCreator } from 'easy-peasy' ;
76import { StaticContext } from 'react-router' ;
@@ -20,8 +19,7 @@ interface Values {
2019type OwnProps = RouteComponentProps < Record < string , string | undefined > , StaticContext , { token ?: string } >
2120
2221type Props = OwnProps & {
23- addError : ActionCreator < FlashStore [ 'addError' ] [ 'payload' ] > ;
24- clearFlashes : ActionCreator < FlashStore [ 'clearFlashes' ] [ 'payload' ] > ;
22+ clearAndAddHttpError : ActionCreator < FlashStore [ 'clearAndAddHttpError' ] [ 'payload' ] > ;
2523}
2624
2725const LoginCheckpointContainer = ( ) => {
@@ -79,9 +77,7 @@ const LoginCheckpointContainer = () => {
7977} ;
8078
8179const EnhancedForm = withFormik < Props , Values > ( {
82- handleSubmit : ( { code, recoveryCode } , { setSubmitting, props : { addError, clearFlashes, location } } ) => {
83- clearFlashes ( ) ;
84-
80+ handleSubmit : ( { code, recoveryCode } , { setSubmitting, props : { clearAndAddHttpError, location } } ) => {
8581 loginCheckpoint ( location . state ?. token || '' , code , recoveryCode )
8682 . then ( response => {
8783 if ( response . complete ) {
@@ -95,7 +91,7 @@ const EnhancedForm = withFormik<Props, Values>({
9591 . catch ( error => {
9692 console . error ( error ) ;
9793 setSubmitting ( false ) ;
98- addError ( { message : httpErrorToHuman ( error ) } ) ;
94+ clearAndAddHttpError ( { error : error } ) ;
9995 } ) ;
10096 } ,
10197
@@ -106,7 +102,7 @@ const EnhancedForm = withFormik<Props, Values>({
106102} ) ( LoginCheckpointContainer ) ;
107103
108104export default ( { history, location, ...props } : OwnProps ) => {
109- const { addError , clearFlashes } = useFlash ( ) ;
105+ const { clearAndAddHttpError } = useFlash ( ) ;
110106
111107 if ( ! location . state ?. token ) {
112108 history . replace ( '/auth/login' ) ;
@@ -115,8 +111,7 @@ export default ({ history, location, ...props }: OwnProps) => {
115111 }
116112
117113 return < EnhancedForm
118- addError = { addError }
119- clearFlashes = { clearFlashes }
114+ clearAndAddHttpError = { clearAndAddHttpError }
120115 history = { history }
121116 location = { location }
122117 { ...props }
0 commit comments