Send Confirmation
diff --git a/app/routes/settings+/profile.index.tsx b/app/routes/settings+/profile.index.tsx
index 03c4467..1d3b2af 100644
--- a/app/routes/settings+/profile.index.tsx
+++ b/app/routes/settings+/profile.index.tsx
@@ -1,5 +1,5 @@
-import { conform, useForm } from '@conform-to/react'
-import { getFieldsetConstraint, parse } from '@conform-to/zod'
+import { getFormProps, getInputProps, useForm } from '@conform-to/react'
+import { getZodConstraint, parseWithZod } from '@conform-to/zod'
import { invariantResponse } from '@epic-web/invariant'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
@@ -177,7 +177,7 @@ export default function EditUserProfile() {
}
async function profileUpdateAction({ userId, formData }: ProfileActionArgs) {
- const submission = await parse(formData, {
+ const submission = await parseWithZod(formData, {
async: true,
schema: ProfileFormSchema.superRefine(async ({ username }, ctx) => {
const existingUsername = await prisma.user.findUnique({
@@ -193,11 +193,11 @@ async function profileUpdateAction({ userId, formData }: ProfileActionArgs) {
}
}),
})
- if (submission.intent !== 'submit') {
- return json({ status: 'idle', submission } as const)
- }
- if (!submission.value) {
- return json({ status: 'error', submission } as const, { status: 400 })
+ if (submission.status !== 'success') {
+ return json(
+ { result: submission.reply() },
+ { status: submission.status === 'error' ? 400 : 200 },
+ )
}
const data = submission.value
@@ -211,7 +211,9 @@ async function profileUpdateAction({ userId, formData }: ProfileActionArgs) {
},
})
- return json({ status: 'success', submission } as const)
+ return json({
+ result: submission.reply(),
+ })
}
function UpdateProfile() {
@@ -221,20 +223,19 @@ function UpdateProfile() {
const [form, fields] = useForm({
id: 'edit-profile',
- constraint: getFieldsetConstraint(ProfileFormSchema),
- lastSubmission: fetcher.data?.submission,
+ constraint: getZodConstraint(ProfileFormSchema),
+ lastResult: fetcher.data?.result,
onValidate({ formData }) {
- return parse(formData, { schema: ProfileFormSchema })
+ return parseWithZod(formData, { schema: ProfileFormSchema })
},
defaultValue: {
username: data.user.username,
- name: data.user.name ?? '',
- email: data.user.email,
+ name: data.user.name,
},
})
return (
-
+
@@ -261,11 +262,7 @@ function UpdateProfile() {
size="wide"
name="intent"
value={profileUpdateActionIntent}
- status={
- fetcher.state !== 'idle'
- ? 'pending'
- : fetcher.data?.status ?? 'idle'
- }
+ status={fetcher.state !== 'idle' ? 'pending' : form.status ?? 'idle'}
>
Save changes
diff --git a/app/routes/settings+/profile.password.tsx b/app/routes/settings+/profile.password.tsx
index 097a472..50f3f44 100644
--- a/app/routes/settings+/profile.password.tsx
+++ b/app/routes/settings+/profile.password.tsx
@@ -1,5 +1,5 @@
-import { conform, useForm } from '@conform-to/react'
-import { getFieldsetConstraint, parse } from '@conform-to/zod'
+import { getFormProps, getInputProps, useForm } from '@conform-to/react'
+import { getZodConstraint, parseWithZod } from '@conform-to/zod'
import { type SEOHandle } from '@nasa-gcn/remix-seo'
import {
json,
@@ -65,7 +65,7 @@ export async function action({ request }: ActionFunctionArgs) {
const userId = await requireUserId(request)
await requirePassword(userId)
const formData = await request.formData()
- const submission = await parse(formData, {
+ const submission = await parseWithZod(formData, {
async: true,
schema: ChangePasswordForm.superRefine(
async ({ currentPassword, newPassword }, ctx) => {
@@ -82,15 +82,15 @@ export async function action({ request }: ActionFunctionArgs) {
},
),
})
- // clear the payload so we don't send the password back to the client
- submission.payload = {}
- if (submission.intent !== 'submit') {
- // clear the value so we don't send the password back to the client
- submission.value = undefined
- return json({ status: 'idle', submission } as const)
- }
- if (!submission.value) {
- return json({ status: 'error', submission } as const, { status: 400 })
+ if (submission.status !== 'success') {
+ return json(
+ {
+ result: submission.reply({
+ hideFields: ['currentPassword', 'newPassword', 'confirmNewPassword'],
+ }),
+ },
+ { status: submission.status === 'error' ? 400 : 200 },
+ )
}
const { newPassword } = submission.value
@@ -124,20 +124,20 @@ export default function ChangePasswordRoute() {
const [form, fields] = useForm({
id: 'password-change-form',
- constraint: getFieldsetConstraint(ChangePasswordForm),
- lastSubmission: actionData?.submission,
+ constraint: getZodConstraint(ChangePasswordForm),
+ lastResult: actionData?.result,
onValidate({ formData }) {
- return parse(formData, { schema: ChangePasswordForm })
+ return parseWithZod(formData, { schema: ChangePasswordForm })
},
shouldRevalidate: 'onBlur',
})
return (
-