2
2
import InputError from ' @/components/InputError.vue' ;
3
3
import AppLayout from ' @/layouts/AppLayout.vue' ;
4
4
import SettingsLayout from ' @/layouts/settings/Layout.vue' ;
5
- import { Head , useForm } from ' @inertiajs/vue3' ;
5
+ import { Form , Head } from ' @inertiajs/vue3' ;
6
6
import { ref } from ' vue' ;
7
7
8
8
import HeadingSmall from ' @/components/HeadingSmall.vue' ;
@@ -20,34 +20,6 @@ const breadcrumbItems: BreadcrumbItem[] = [
20
20
21
21
const passwordInput = ref <HTMLInputElement | null >(null );
22
22
const currentPasswordInput = ref <HTMLInputElement | null >(null );
23
-
24
- const form = useForm ({
25
- current_password: ' ' ,
26
- password: ' ' ,
27
- password_confirmation: ' ' ,
28
- });
29
-
30
- const updatePassword = () => {
31
- form .put (route (' password.update' ), {
32
- preserveScroll: true ,
33
- onSuccess : () => form .reset (),
34
- onError : (errors : any ) => {
35
- if (errors .password ) {
36
- form .reset (' password' , ' password_confirmation' );
37
- if (passwordInput .value instanceof HTMLInputElement ) {
38
- passwordInput .value .focus ();
39
- }
40
- }
41
-
42
- if (errors .current_password ) {
43
- form .reset (' current_password' );
44
- if (currentPasswordInput .value instanceof HTMLInputElement ) {
45
- currentPasswordInput .value .focus ();
46
- }
47
- }
48
- },
49
- });
50
- };
51
23
</script >
52
24
53
25
<template >
@@ -58,61 +30,82 @@ const updatePassword = () => {
58
30
<div class =" space-y-6" >
59
31
<HeadingSmall title =" Update password" description =" Ensure your account is using a long, random password to stay secure" />
60
32
61
- <form method =" POST" @submit.prevent =" updatePassword" class =" space-y-6" >
33
+ <Form
34
+ method =" put"
35
+ :action =" route('password.update')"
36
+ :options =" {
37
+ preserveScroll: true,
38
+ }"
39
+ @error ="
40
+ (errors) => {
41
+ if (errors.password && passwordInput) {
42
+ passwordInput.focus();
43
+ }
44
+
45
+ if (errors.current_password && currentPasswordInput) {
46
+ currentPasswordInput.focus();
47
+ }
48
+ }
49
+ "
50
+ reset-on-success
51
+ :reset-on-error =" ['password', 'password_confirmation', 'current_password']"
52
+ class =" space-y-6"
53
+ v-slot =" { errors, processing, recentlySuccessful }"
54
+ >
62
55
<div class =" grid gap-2" >
63
56
<Label for =" current_password" >Current password</Label >
64
57
<Input
65
58
id =" current_password"
66
59
ref =" currentPasswordInput"
67
- v-model = " form. current_password"
60
+ name = " current_password"
68
61
type =" password"
69
- class =" mt-1 block w-full"
62
+ class =" block w-full mt-1 "
70
63
autocomplete =" current-password"
71
64
placeholder =" Current password"
72
65
/>
73
- <InputError :message =" form. errors.current_password" />
66
+ <InputError :message =" errors.current_password" />
74
67
</div >
75
68
76
69
<div class =" grid gap-2" >
77
70
<Label for =" password" >New password</Label >
78
71
<Input
79
72
id =" password"
80
73
ref =" passwordInput"
81
- v-model = " form. password"
74
+ name = " password"
82
75
type =" password"
83
- class =" mt-1 block w-full"
76
+ class =" block w-full mt-1 "
84
77
autocomplete =" new-password"
85
78
placeholder =" New password"
86
79
/>
87
- <InputError :message =" form. errors.password" />
80
+ <InputError :message =" errors.password" />
88
81
</div >
89
82
90
83
<div class =" grid gap-2" >
91
84
<Label for =" password_confirmation" >Confirm password</Label >
92
85
<Input
93
86
id =" password_confirmation"
94
- v-model = " form. password_confirmation"
87
+ name = " password_confirmation"
95
88
type =" password"
96
- class =" mt-1 block w-full"
89
+ class =" block w-full mt-1 "
97
90
autocomplete =" new-password"
98
91
placeholder =" Confirm password"
99
92
/>
100
- <InputError :message =" form. errors.password_confirmation" />
93
+ <InputError :message =" errors.password_confirmation" />
101
94
</div >
102
95
103
96
<div class =" flex items-center gap-4" >
104
- <Button :disabled =" form. processing" >Save password</Button >
97
+ <Button :disabled =" processing" >Save password</Button >
105
98
106
99
<Transition
107
100
enter-active-class =" transition ease-in-out"
108
101
enter-from-class =" opacity-0"
109
102
leave-active-class =" transition ease-in-out"
110
103
leave-to-class =" opacity-0"
111
104
>
112
- <p v-show =" form. recentlySuccessful" class =" text-sm text-neutral-600" >Saved.</p >
105
+ <p v-show =" recentlySuccessful" class =" text-sm text-neutral-600" >Saved.</p >
113
106
</Transition >
114
107
</div >
115
- </form >
108
+ </Form >
116
109
</div >
117
110
</SettingsLayout >
118
111
</AppLayout >
0 commit comments