11import React , { Component } from 'react' ;
22import { Link as RouterLink } from 'react-router-dom' ;
3- import { Formik , Form , withFormik } from 'formik' ;
3+ import { Formik , Form } from 'formik' ;
44import * as Yup from 'yup' ;
55
66import {
@@ -26,6 +26,7 @@ class PasswordReset extends Component {
2626 state = {
2727 loading : false ,
2828 message : { } ,
29+ email : '' ,
2930 showPassword : false ,
3031 showPasswordConfirmation : false ,
3132 } ;
@@ -52,21 +53,59 @@ class PasswordReset extends Component {
5253 *
5354 * @return {undefined }
5455 */
55- handleSubmit = async ( values , { setSubmitting } ) => {
56+ handleSubmit = async ( values , { setSubmitting, setErrors } ) => {
5657 setSubmitting ( false ) ;
58+
59+ this . setState ( { loading : true } ) ;
60+
61+ try {
62+ const { match, pageProps } = this . props ;
63+ const { token } = match . params ;
64+
65+ const response = await axios . patch (
66+ `api/v1/auth/password/reset/${ token } ` ,
67+ values ,
68+ ) ;
69+
70+ await pageProps . authenticate ( JSON . stringify ( response . data ) ) ;
71+
72+ this . setState ( { loading : false } ) ;
73+ } catch ( error ) {
74+ if ( ! error . response ) {
75+ throw new Error ( 'Unknown error' ) ;
76+ }
77+
78+ const { errors } = error . response . data ;
79+
80+ if ( errors ) {
81+ setErrors ( errors ) ;
82+ }
83+
84+ this . setState ( { loading : false } ) ;
85+ }
5786 } ;
5887
88+ componentDidMount ( ) {
89+ const { location } = this . props ;
90+
91+ const queryParams = UrlUtils . _queryParams ( location . search ) ;
92+
93+ if ( ! queryParams . hasOwnProperty ( 'email' ) ) {
94+ return ;
95+ }
96+
97+ this . setState ( {
98+ email : queryParams . email ,
99+ } ) ;
100+ }
101+
59102 render ( ) {
60- const { classes, location } = this . props ;
61- const email = UrlUtils . _queryParams ( location . search ) . hasOwnProperty (
62- 'email' ,
63- )
64- ? UrlUtils . _queryParams ( location . search ) . email
65- : '' ;
103+ const { classes } = this . props ;
66104
67105 const {
68106 loading,
69107 message,
108+ email,
70109 showPassword,
71110 showPasswordConfirmation,
72111 } = this . state ;
@@ -265,4 +304,4 @@ const styles = theme => ({
265304 } ,
266305} ) ;
267306
268- export default withStyles ( styles ) ( withFormik ( { } ) ( PasswordReset ) ) ;
307+ export default withStyles ( styles ) ( PasswordReset ) ;
0 commit comments