Skip to content

Commit 013bda7

Browse files
committed
chore: Destructure form on profile page
https://harperdb.atlassian.net/browse/STUDIO-489
1 parent f78a3c5 commit 013bda7

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/features/profile/index.tsx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function ProfileIndex() {
2424
const navigate = useNavigate();
2525
const { user } = useCloudAuth();
2626

27-
const form = useForm({
27+
const methods = useForm({
2828
resolver: zodResolver(UpdateUserSchema),
2929
defaultValues: {
3030
confirmNewPassword: '',
@@ -34,15 +34,16 @@ export function ProfileIndex() {
3434
newPassword: '',
3535
},
3636
});
37+
const { control, handleSubmit, reset, formState: { defaultValues, isDirty, isValid } } = methods;
3738
const { mutate: updateUser, isPending: isUpdatePending } = useUpdateUserMutation();
3839

3940
const onSubmitClick = useCallback(
4041
async (formData: z.infer<typeof UpdateUserSchema>) => {
4142
if (formData) {
4243
updateUser(formData, {
4344
onSuccess: (data) => {
44-
form.reset({
45-
...form.formState.defaultValues,
45+
reset({
46+
...defaultValues,
4647
...data,
4748
});
4849
authStore.updateUserForEntity(OverallAppSignIn, data);
@@ -60,16 +61,16 @@ export function ProfileIndex() {
6061
});
6162
}
6263
},
63-
[form, navigate, router, updateUser],
64+
[defaultValues, navigate, reset, router, updateUser],
6465
);
6566

6667
return (
6768
<div className="mt-20 px-4 pt-4 md:px-12">
6869
<h2 className="text-2xl font-light">Profile</h2>
69-
<Form {...form}>
70-
<form onSubmit={form.handleSubmit(onSubmitClick)} className="grid gap-4 my-4">
70+
<Form {...methods}>
71+
<form onSubmit={handleSubmit(onSubmitClick)} className="grid gap-4 my-4">
7172
<FormField
72-
control={form.control}
73+
control={control}
7374
name="firstname"
7475
render={({ field }) => (
7576
<FormItem>
@@ -88,7 +89,7 @@ export function ProfileIndex() {
8889
/>
8990

9091
<FormField
91-
control={form.control}
92+
control={control}
9293
name="lastname"
9394
render={({ field }) => (
9495
<FormItem>
@@ -120,7 +121,7 @@ export function ProfileIndex() {
120121
</FormControl>
121122

122123
<FormField
123-
control={form.control}
124+
control={control}
124125
name="newPassword"
125126
render={({ field }) => (
126127
<FormItem>
@@ -141,7 +142,7 @@ export function ProfileIndex() {
141142
/>
142143

143144
<FormField
144-
control={form.control}
145+
control={control}
145146
name="confirmNewPassword"
146147
render={({ field }) => (
147148
<FormItem>
@@ -165,7 +166,7 @@ export function ProfileIndex() {
165166
type="submit"
166167
variant="submit"
167168
className="rounded-full"
168-
disabled={isUpdatePending || !form.formState.isDirty || !form.formState.isValid}
169+
disabled={isUpdatePending || !isDirty || !isValid}
169170
>
170171
<Save /> Update Profile
171172
</Button>

0 commit comments

Comments
 (0)