22import InputError from ' @/components/InputError.vue' ;
33import AppLayout from ' @/layouts/AppLayout.vue' ;
44import SettingsLayout from ' @/layouts/settings/Layout.vue' ;
5- import { Head , useForm } from ' @inertiajs/vue3' ;
5+ import { Form , Head } from ' @inertiajs/vue3' ;
66import { ref } from ' vue' ;
77
88import HeadingSmall from ' @/components/HeadingSmall.vue' ;
@@ -20,34 +20,6 @@ const breadcrumbItems: BreadcrumbItem[] = [
2020
2121const passwordInput = ref <HTMLInputElement | null >(null );
2222const 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- };
5123 </script >
5224
5325<template >
@@ -58,61 +30,82 @@ const updatePassword = () => {
5830 <div class =" space-y-6" >
5931 <HeadingSmall title =" Update password" description =" Ensure your account is using a long, random password to stay secure" />
6032
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+ >
6255 <div class =" grid gap-2" >
6356 <Label for =" current_password" >Current password</Label >
6457 <Input
6558 id =" current_password"
6659 ref =" currentPasswordInput"
67- v-model = " form. current_password"
60+ name = " current_password"
6861 type =" password"
69- class =" mt-1 block w-full"
62+ class =" block w-full mt-1 "
7063 autocomplete =" current-password"
7164 placeholder =" Current password"
7265 />
73- <InputError :message =" form. errors.current_password" />
66+ <InputError :message =" errors.current_password" />
7467 </div >
7568
7669 <div class =" grid gap-2" >
7770 <Label for =" password" >New password</Label >
7871 <Input
7972 id =" password"
8073 ref =" passwordInput"
81- v-model = " form. password"
74+ name = " password"
8275 type =" password"
83- class =" mt-1 block w-full"
76+ class =" block w-full mt-1 "
8477 autocomplete =" new-password"
8578 placeholder =" New password"
8679 />
87- <InputError :message =" form. errors.password" />
80+ <InputError :message =" errors.password" />
8881 </div >
8982
9083 <div class =" grid gap-2" >
9184 <Label for =" password_confirmation" >Confirm password</Label >
9285 <Input
9386 id =" password_confirmation"
94- v-model = " form. password_confirmation"
87+ name = " password_confirmation"
9588 type =" password"
96- class =" mt-1 block w-full"
89+ class =" block w-full mt-1 "
9790 autocomplete =" new-password"
9891 placeholder =" Confirm password"
9992 />
100- <InputError :message =" form. errors.password_confirmation" />
93+ <InputError :message =" errors.password_confirmation" />
10194 </div >
10295
10396 <div class =" flex items-center gap-4" >
104- <Button :disabled =" form. processing" >Save password</Button >
97+ <Button :disabled =" processing" >Save password</Button >
10598
10699 <Transition
107100 enter-active-class =" transition ease-in-out"
108101 enter-from-class =" opacity-0"
109102 leave-active-class =" transition ease-in-out"
110103 leave-to-class =" opacity-0"
111104 >
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 >
113106 </Transition >
114107 </div >
115- </form >
108+ </Form >
116109 </div >
117110 </SettingsLayout >
118111 </AppLayout >
0 commit comments