1- import { type BreadcrumbItem , type SharedData } from '@/types' ;
2- import { Transition } from '@headlessui/react' ;
3- import { Head , useForm , usePage } from '@inertiajs/react' ;
4- import { FormEventHandler } from 'react' ;
5-
61import DeleteUser from '@/components/delete-user' ;
72import HeadingSmall from '@/components/heading-small' ;
83import InputError from '@/components/input-error' ;
@@ -11,6 +6,9 @@ import { Input } from '@/components/ui/input';
116import { Label } from '@/components/ui/label' ;
127import AppLayout from '@/layouts/app-layout' ;
138import SettingsLayout from '@/layouts/settings/layout' ;
9+ import { type BreadcrumbItem , type SharedData } from '@/types' ;
10+ import { Transition } from '@headlessui/react' ;
11+ import { Form , Head , usePage } from '@inertiajs/react' ;
1412
1513const breadcrumbs : BreadcrumbItem [ ] = [
1614 {
@@ -19,27 +17,9 @@ const breadcrumbs: BreadcrumbItem[] = [
1917 } ,
2018] ;
2119
22- type ProfileForm = {
23- name : string ;
24- email : string ;
25- } ;
26-
2720export default function Profile ( ) {
2821 const { auth } = usePage < SharedData > ( ) . props ;
2922
30- const { data, setData, patch, errors, processing, recentlySuccessful } = useForm < Required < ProfileForm > > ( {
31- name : auth . user . name ,
32- email : auth . user . email ,
33- } ) ;
34-
35- const submit : FormEventHandler = ( e ) => {
36- e . preventDefault ( ) ;
37-
38- patch ( route ( 'profile.update' ) , {
39- preserveScroll : true ,
40- } ) ;
41- } ;
42-
4323 return (
4424 < AppLayout breadcrumbs = { breadcrumbs } >
4525 < Head title = "Profile settings" />
@@ -48,53 +28,65 @@ export default function Profile() {
4828 < div className = "space-y-6" >
4929 < HeadingSmall title = "Profile information" description = "Update your name and email address" />
5030
51- < form onSubmit = { submit } className = "space-y-6" >
52- < div className = "grid gap-2" >
53- < Label htmlFor = "name" > Name</ Label >
54-
55- < Input
56- id = "name"
57- className = "mt-1 block w-full"
58- value = { data . name }
59- onChange = { ( e ) => setData ( 'name' , e . target . value ) }
60- required
61- autoComplete = "name"
62- placeholder = "Full name"
63- />
64-
65- < InputError className = "mt-2" message = { errors . name } />
66- </ div >
67-
68- < div className = "grid gap-2" >
69- < Label htmlFor = "email" > Email address</ Label >
70-
71- < Input
72- id = "email"
73- type = "email"
74- className = "mt-1 block w-full"
75- value = { data . email }
76- required
77- autoComplete = "username"
78- disabled
79- />
80-
81- < InputError className = "mt-2" message = { errors . email } />
82- </ div >
83-
84- < div className = "flex items-center gap-4" >
85- < Button disabled = { processing } > Save</ Button >
86-
87- < Transition
88- show = { recentlySuccessful }
89- enter = "transition ease-in-out"
90- enterFrom = "opacity-0"
91- leave = "transition ease-in-out"
92- leaveTo = "opacity-0"
93- >
94- < p className = "text-sm text-neutral-600" > Saved</ p >
95- </ Transition >
96- </ div >
97- </ form >
31+ < Form
32+ method = "patch"
33+ action = { route ( 'profile.update' ) }
34+ options = { {
35+ preserveScroll : true ,
36+ } }
37+ className = "space-y-6"
38+ >
39+ { ( { processing, recentlySuccessful, errors } ) => (
40+ < >
41+ < div className = "grid gap-2" >
42+ < Label htmlFor = "name" > Name</ Label >
43+
44+ < Input
45+ id = "name"
46+ className = "mt-1 block w-full"
47+ defaultValue = { auth . user . name }
48+ name = "name"
49+ required
50+ autoComplete = "name"
51+ placeholder = "Full name"
52+ />
53+
54+ < InputError className = "mt-2" message = { errors . name } />
55+ </ div >
56+
57+ < div className = "grid gap-2" >
58+ < Label htmlFor = "email" > Email address</ Label >
59+
60+ < Input
61+ id = "email"
62+ type = "email"
63+ className = "mt-1 block w-full"
64+ defaultValue = { auth . user . email }
65+ name = "email"
66+ required
67+ autoComplete = "username"
68+ disabled
69+ />
70+
71+ < InputError className = "mt-2" message = { errors . email } />
72+ </ div >
73+
74+ < div className = "flex items-center gap-4" >
75+ < Button disabled = { processing } > Save</ Button >
76+
77+ < Transition
78+ show = { recentlySuccessful }
79+ enter = "transition ease-in-out"
80+ enterFrom = "opacity-0"
81+ leave = "transition ease-in-out"
82+ leaveTo = "opacity-0"
83+ >
84+ < p className = "text-sm text-neutral-600" > Saved</ p >
85+ </ Transition >
86+ </ div >
87+ </ >
88+ ) }
89+ </ Form >
9890 </ div >
9991
10092 < DeleteUser />
0 commit comments