1
1
import axios from 'axios' ;
2
- import { Alert , Button , Label , TextInput } from 'flowbite-react' ;
2
+ import { Alert , Button , TextInput } from 'flowbite-react' ;
3
3
import { Field , Form , Formik , FormikValues } from 'formik' ;
4
4
import { GetServerSideProps , NextPage } from 'next' ;
5
5
import { useRouter } from 'next/router' ;
6
6
import React , { useState } from 'react' ;
7
+ import { useToasts } from '../src/components/contexts/ToastContext' ;
7
8
import { API_URL } from '../src/config' ;
8
9
import { showErrors } from '../src/utils/viewHelpers' ;
9
10
@@ -27,6 +28,7 @@ export const getServerSideProps: GetServerSideProps = async ({ query }) => {
27
28
const Reset : NextPage < { token : string } > = ( { token } ) => {
28
29
const [ errors , setErrors ] = useState ( ) ;
29
30
const router = useRouter ( ) ;
31
+ const { addToast } = useToasts ( ) ;
30
32
31
33
return (
32
34
< section className = "bg-gray-50 dark:bg-gray-900" >
@@ -38,10 +40,15 @@ const Reset: NextPage<{ token: string }> = ({ token }) => {
38
40
onSubmit = { ( values ) => {
39
41
axios
40
42
. put ( `${ API_URL } /users/password` , { user : { ...values } } )
41
- . then ( ( res ) => {
43
+ . then ( ( ) => {
42
44
router . push ( '/login' ) ;
43
45
} )
44
46
. catch ( ( error ) => {
47
+ addToast (
48
+ error ?. response ?. data ?. toString ( ) ||
49
+ 'Something went wrong'
50
+ ) ;
51
+
45
52
setErrors ( error ?. response ?. data ) ;
46
53
} ) ;
47
54
} }
0 commit comments