@@ -2,17 +2,22 @@ import * as React from 'react';
22import OpenInputField from '@/components/forms/OpenInputField' ;
33import { Link } from 'react-router-dom' ;
44import requestPasswordResetEmail from '@/api/auth/requestPasswordResetEmail' ;
5+ import { connect } from 'react-redux' ;
6+ import { ReduxState } from '@/redux/types' ;
7+ import { pushFlashMessage , clearAllFlashMessages } from '@/redux/actions/flash' ;
8+ import { httpErrorToHuman } from '@/api/http' ;
59
610type Props = Readonly < {
7-
11+ pushFlashMessage : typeof pushFlashMessage ;
12+ clearAllFlashMessages : typeof clearAllFlashMessages ;
813} > ;
914
1015type State = Readonly < {
1116 email : string ;
1217 isSubmitting : boolean ;
1318} > ;
1419
15- export default class ForgotPasswordContainer extends React . PureComponent < Props , State > {
20+ class ForgotPasswordContainer extends React . PureComponent < Props , State > {
1621 state : State = {
1722 email : '' ,
1823 isSubmitting : false ,
@@ -22,16 +27,27 @@ export default class ForgotPasswordContainer extends React.PureComponent<Props,
2227 email : e . target . value ,
2328 } ) ;
2429
25- handleSubmission = ( e : React . FormEvent < HTMLFormElement > ) => this . setState ( { isSubmitting : true } , ( ) => {
30+ handleSubmission = ( e : React . FormEvent < HTMLFormElement > ) => {
2631 e . preventDefault ( ) ;
2732
28- requestPasswordResetEmail ( this . state . email )
29- . then ( ( ) => {
30-
31- } )
32- . catch ( console . error )
33- . then ( ( ) => this . setState ( { isSubmitting : false } ) ) ;
34- } ) ;
33+ this . setState ( { isSubmitting : true } , ( ) => {
34+ this . props . clearAllFlashMessages ( ) ;
35+ requestPasswordResetEmail ( this . state . email )
36+ . then ( ( ) => {
37+ // @todo actually handle this.
38+ } )
39+ . catch ( error => {
40+ console . error ( error ) ;
41+ this . props . pushFlashMessage ( {
42+ id : 'auth:forgot-password' ,
43+ type : 'error' ,
44+ title : 'Error' ,
45+ message : httpErrorToHuman ( error ) ,
46+ } ) ;
47+ } )
48+ . then ( ( ) => this . setState ( { isSubmitting : false } ) ) ;
49+ } ) ;
50+ } ;
3551
3652 render ( ) {
3753 return (
@@ -50,11 +66,11 @@ export default class ForgotPasswordContainer extends React.PureComponent<Props,
5066 </ div >
5167 < div className = { 'mt-6' } >
5268 < button
53- className = { 'btn btn-primary btn-jumbo' }
69+ className = { 'btn btn-primary btn-jumbo flex justify-center ' }
5470 disabled = { this . state . isSubmitting || this . state . email . length < 5 }
5571 >
5672 { this . state . isSubmitting ?
57- < span className = { 'spinner white' } > </ span >
73+ < div className = { 'spinner-circle spinner-sm spinner- white' } > </ div >
5874 :
5975 'Send Email'
6076 }
@@ -73,3 +89,14 @@ export default class ForgotPasswordContainer extends React.PureComponent<Props,
7389 ) ;
7490 }
7591}
92+
93+ const mapStateToProps = ( state : ReduxState ) => ( {
94+ flashes : state . flashes ,
95+ } ) ;
96+
97+ const mapDispatchToProps = {
98+ pushFlashMessage,
99+ clearAllFlashMessages,
100+ } ;
101+
102+ export default connect ( mapStateToProps , mapDispatchToProps ) ( ForgotPasswordContainer ) ;
0 commit comments