Skip to content

Commit 98acf99

Browse files
committed
Migrate to Form component
1 parent dde7912 commit 98acf99

File tree

10 files changed

+235
-322
lines changed

10 files changed

+235
-322
lines changed

Gemfile.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ GEM
225225
date
226226
stringio
227227
public_suffix (6.0.2)
228-
puma (7.0.1)
228+
puma (7.0.2)
229229
nio4r (~> 2.0)
230230
raabro (1.4.0)
231231
racc (1.8.1)
@@ -348,7 +348,7 @@ GEM
348348
fugit (~> 1.11.0)
349349
railties (>= 7.1)
350350
thor (>= 1.3.1)
351-
sorbet-runtime (0.6.12495)
351+
sorbet-runtime (0.6.12507)
352352
sqlite3 (2.7.3-aarch64-linux-gnu)
353353
sqlite3 (2.7.3-aarch64-linux-musl)
354354
sqlite3 (2.7.3-arm-linux-gnu)
@@ -372,9 +372,9 @@ GEM
372372
timeout (0.4.3)
373373
tzinfo (2.0.6)
374374
concurrent-ruby (~> 1.0)
375-
unicode-display_width (3.1.5)
376-
unicode-emoji (~> 4.0, >= 4.0.4)
377-
unicode-emoji (4.0.4)
375+
unicode-display_width (3.2.0)
376+
unicode-emoji (~> 4.1)
377+
unicode-emoji (4.1.0)
378378
uri (1.0.3)
379379
useragent (0.16.11)
380380
vite_rails (3.0.19)

app/frontend/components/DeleteUser.vue

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { useForm } from "@inertiajs/vue3"
2+
import { Form } from "@inertiajs/vue3"
33
import { ref } from "vue"
44
55
import HeadingSmall from "@/components/HeadingSmall.vue"
@@ -20,26 +20,6 @@ import { Label } from "@/components/ui/label"
2020
import { usersPath } from "@/routes"
2121
2222
const passwordInput = ref<HTMLInputElement | null>(null)
23-
24-
const form = useForm({
25-
password_challenge: "",
26-
})
27-
28-
const deleteUser = (e: Event) => {
29-
e.preventDefault()
30-
31-
form.delete(usersPath(), {
32-
preserveScroll: true,
33-
onSuccess: () => closeModal(),
34-
onError: () => passwordInput.value?.focus(),
35-
onFinish: () => form.reset(),
36-
})
37-
}
38-
39-
const closeModal = () => {
40-
form.clearErrors()
41-
form.reset()
42-
}
4323
</script>
4424

4525
<template>
@@ -62,7 +42,15 @@ const closeModal = () => {
6242
<Button variant="destructive">Delete account</Button>
6343
</DialogTrigger>
6444
<DialogContent>
65-
<form class="space-y-6" @submit="deleteUser">
45+
<Form
46+
method="delete"
47+
:action="usersPath()"
48+
:options="{ preserveScroll: true }"
49+
:onError="() => passwordInput?.focus()"
50+
resetOnSuccess
51+
className="space-y-6"
52+
#default="{ resetAndClearErrors, processing, errors }"
53+
>
6654
<DialogHeader class="space-y-3">
6755
<DialogTitle
6856
>Are you sure you want to delete your account?</DialogTitle
@@ -81,28 +69,27 @@ const closeModal = () => {
8169
type="password"
8270
name="password_challenge"
8371
ref="passwordInput"
84-
v-model="form.password_challenge"
8572
placeholder="Password"
8673
/>
87-
<InputError :message="form.errors.password_challenge" />
74+
<InputError :message="errors.password_challenge" />
8875
</div>
8976

9077
<DialogFooter class="gap-2">
9178
<DialogClose as-child>
92-
<Button variant="secondary" @click="closeModal">
79+
<Button variant="secondary" @click="resetAndClearErrors">
9380
Cancel
9481
</Button>
9582
</DialogClose>
9683

9784
<Button
9885
type="submit"
9986
variant="destructive"
100-
:disabled="form.processing"
87+
:disabled="processing"
10188
>
10289
Delete account
10390
</Button>
10491
</DialogFooter>
105-
</form>
92+
</Form>
10693
</DialogContent>
10794
</Dialog>
10895
</div>
Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { Head, useForm } from "@inertiajs/vue3"
2+
import { Form, Head } from "@inertiajs/vue3"
33
import { LoaderCircle } from "lucide-vue-next"
44
55
import InputError from "@/components/InputError.vue"
@@ -15,21 +15,6 @@ interface Props {
1515
}
1616
1717
const props = defineProps<Props>()
18-
19-
const form = useForm({
20-
sid: props.sid,
21-
email: props.email,
22-
password: "",
23-
password_confirmation: "",
24-
})
25-
26-
const submit = () => {
27-
form.put(identityPasswordResetPath(), {
28-
onFinish: () => {
29-
form.reset("password", "password_confirmation")
30-
},
31-
})
32-
}
3318
</script>
3419

3520
<template>
@@ -39,56 +24,60 @@ const submit = () => {
3924
>
4025
<Head title="Reset password" />
4126

42-
<form @submit.prevent="submit">
27+
<Form
28+
method="put"
29+
:action="identityPasswordResetPath()"
30+
:transform="(data) => ({ ...data, sid, email })"
31+
:resetOnSuccess="['password', 'password_confirmation']"
32+
#default="{ errors, processing }"
33+
>
4334
<div class="grid gap-6">
4435
<div class="grid gap-2">
4536
<Label for="email">Email</Label>
4637
<Input
4738
id="email"
48-
type="email"
4939
name="email"
40+
type="email"
5041
autocomplete="email"
51-
v-model="form.email"
42+
:defaultValue="props.email"
5243
class="mt-1 block w-full"
5344
readonly
5445
/>
55-
<InputError :message="form.errors.email" class="mt-2" />
46+
<InputError :message="errors.email" class="mt-2" />
5647
</div>
5748

5849
<div class="grid gap-2">
5950
<Label for="password">Password</Label>
6051
<Input
6152
id="password"
62-
type="password"
6353
name="password"
54+
type="password"
6455
autocomplete="new-password"
65-
v-model="form.password"
6656
class="mt-1 block w-full"
6757
autofocus
6858
placeholder="Password"
6959
/>
70-
<InputError :message="form.errors.password" />
60+
<InputError :message="errors.password" />
7161
</div>
7262

7363
<div class="grid gap-2">
7464
<Label for="password_confirmation"> Confirm Password </Label>
7565
<Input
7666
id="password_confirmation"
77-
type="password"
7867
name="password_confirmation"
68+
type="password"
7969
autocomplete="new-password"
80-
v-model="form.password_confirmation"
8170
class="mt-1 block w-full"
8271
placeholder="Confirm password"
8372
/>
84-
<InputError :message="form.errors.password_confirmation" />
73+
<InputError :message="errors.password_confirmation" />
8574
</div>
8675

87-
<Button type="submit" class="mt-4 w-full" :disabled="form.processing">
88-
<LoaderCircle v-if="form.processing" class="h-4 w-4 animate-spin" />
76+
<Button type="submit" class="mt-4 w-full" :disabled="processing">
77+
<LoaderCircle v-if="processing" class="h-4 w-4 animate-spin" />
8978
Reset password
9079
</Button>
9180
</div>
92-
</form>
81+
</Form>
9382
</AuthLayout>
9483
</template>

app/frontend/pages/identity/password_resets/new.vue

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { Head, useForm } from "@inertiajs/vue3"
2+
import { Form, Head } from "@inertiajs/vue3"
33
import { LoaderCircle } from "lucide-vue-next"
44
55
import InputError from "@/components/InputError.vue"
@@ -9,14 +9,6 @@ import { Input } from "@/components/ui/input"
99
import { Label } from "@/components/ui/label"
1010
import AuthLayout from "@/layouts/AuthLayout.vue"
1111
import { identityPasswordResetPath, signInPath } from "@/routes"
12-
13-
const form = useForm({
14-
email: "",
15-
})
16-
17-
const submit = () => {
18-
form.post(identityPasswordResetPath())
19-
}
2012
</script>
2113

2214
<template>
@@ -27,28 +19,31 @@ const submit = () => {
2719
<Head title="Forgot password" />
2820

2921
<div class="space-y-6">
30-
<form @submit.prevent="submit">
22+
<Form
23+
method="post"
24+
:action="identityPasswordResetPath()"
25+
#default="{ errors, processing }"
26+
>
3127
<div class="grid gap-2">
3228
<Label for="email">Email address</Label>
3329
<Input
3430
id="email"
35-
type="email"
3631
name="email"
32+
type="email"
3733
autocomplete="off"
38-
v-model="form.email"
3934
autofocus
4035
placeholder="[email protected]"
4136
/>
42-
<InputError :message="form.errors.email" />
37+
<InputError :message="errors.email" />
4338
</div>
4439

4540
<div class="my-6 flex items-center justify-start">
46-
<Button class="w-full" :disabled="form.processing">
47-
<LoaderCircle v-if="form.processing" class="h-4 w-4 animate-spin" />
41+
<Button class="w-full" :disabled="processing">
42+
<LoaderCircle v-if="processing" class="h-4 w-4 animate-spin" />
4843
Email password reset link
4944
</Button>
5045
</div>
51-
</form>
46+
</Form>
5247

5348
<div class="text-muted-foreground space-x-1 text-center text-sm">
5449
<span>Or, return to</span>
Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { Head, useForm } from "@inertiajs/vue3"
2+
import { Form, Head } from "@inertiajs/vue3"
33
import { LoaderCircle } from "lucide-vue-next"
44
55
import InputError from "@/components/InputError.vue"
@@ -9,18 +9,6 @@ import { Input } from "@/components/ui/input"
99
import { Label } from "@/components/ui/label"
1010
import AuthBase from "@/layouts/AuthLayout.vue"
1111
import { newIdentityPasswordResetPath, signInPath, signUpPath } from "@/routes"
12-
13-
const form = useForm({
14-
email: "",
15-
password: "",
16-
remember: false,
17-
})
18-
19-
const submit = () => {
20-
form.post(signInPath(), {
21-
onFinish: () => form.reset("password"),
22-
})
23-
}
2412
</script>
2513

2614
<template>
@@ -30,21 +18,27 @@ const submit = () => {
3018
>
3119
<Head title="Log in" />
3220

33-
<form @submit.prevent="submit" class="flex flex-col gap-6">
21+
<Form
22+
method="post"
23+
:action="signInPath()"
24+
:resetOnSuccess="['password']"
25+
class="flex flex-col gap-6"
26+
#default="{ errors, processing }"
27+
>
3428
<div class="grid gap-6">
3529
<div class="grid gap-2">
3630
<Label for="email">Email address</Label>
3731
<Input
3832
id="email"
33+
name="email"
3934
type="email"
4035
required
4136
autofocus
4237
:tabindex="1"
4338
autocomplete="email"
44-
v-model="form.email"
4539
placeholder="[email protected]"
4640
/>
47-
<InputError :message="form.errors.email" />
41+
<InputError :message="errors.email" />
4842
</div>
4943

5044
<div class="grid gap-2">
@@ -60,23 +54,23 @@ const submit = () => {
6054
</div>
6155
<Input
6256
id="password"
57+
name="password"
6358
type="password"
6459
required
6560
:tabindex="2"
6661
autocomplete="current-password"
67-
v-model="form.password"
6862
placeholder="Password"
6963
/>
70-
<InputError :message="form.errors.password" />
64+
<InputError :message="errors.password" />
7165
</div>
7266

7367
<Button
7468
type="submit"
7569
class="mt-4 w-full"
7670
:tabindex="4"
77-
:disabled="form.processing"
71+
:disabled="processing"
7872
>
79-
<LoaderCircle v-if="form.processing" class="h-4 w-4 animate-spin" />
73+
<LoaderCircle v-if="processing" class="h-4 w-4 animate-spin" />
8074
Log in
8175
</Button>
8276
</div>
@@ -85,6 +79,6 @@ const submit = () => {
8579
Don't have an account?
8680
<TextLink :href="signUpPath()" :tabindex="5">Sign up</TextLink>
8781
</div>
88-
</form>
82+
</Form>
8983
</AuthBase>
9084
</template>

0 commit comments

Comments
 (0)