@@ -12,6 +12,7 @@ import FormImageInput from '../Form/FormImageInput';
12
12
import FormInput from '../Form/FormInput' ;
13
13
import FormSubmitButton from '../Form/FormSubmitButton' ;
14
14
import Alert from '../Helpers/Alert' ;
15
+ import { useNavigate } from 'react-router-dom' ;
15
16
16
17
type Inputs = {
17
18
username : string ;
@@ -25,11 +26,13 @@ function UserDetailsForm() {
25
26
const { register, handleSubmit, control } = useForm < Inputs > ( {
26
27
defaultValues : { username : user . username , email : user . email , image : user . image } ,
27
28
} ) ;
28
- const queryClient = useQueryClient ( ) ;
29
29
30
30
const [ loading , setLoading ] = useState ( false ) ;
31
31
const [ error , setError ] = useState < string | null > ( null ) ;
32
32
33
+ const queryClient = useQueryClient ( ) ;
34
+ const navigate = useNavigate ( ) ;
35
+
33
36
function onSubmit ( inputs : Inputs ) {
34
37
setLoading ( true ) ;
35
38
setError ( null ) ;
@@ -47,6 +50,7 @@ function UserDetailsForm() {
47
50
. put < UserDto > ( `/api/users` , dto )
48
51
. then ( ( ) => {
49
52
queryClient . invalidateQueries ( [ 'users' , 'me' ] ) ;
53
+ navigate ( '..' ) ;
50
54
toast . success ( `Successfully updated user details!` ) ;
51
55
} )
52
56
. catch ( ( err ) => setError ( Utils . requestErrorToString ( err ) ) )
@@ -88,7 +92,7 @@ function UserDetailsForm() {
88
92
/>
89
93
</ FormField >
90
94
91
- < FormSubmitButton > Update details </ FormSubmitButton >
95
+ < FormSubmitButton > Update profile </ FormSubmitButton >
92
96
</ Form >
93
97
) ;
94
98
}
0 commit comments