Skip to content

Commit

Permalink
chore: better setup error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
geclos committed Oct 1, 2024
1 parent c76fa89 commit 4ab4d71
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions apps/web/src/app/(public)/setup/SetupForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ReactNode } from 'react'

import { Button, FormWrapper, Input, useToast } from '@latitude-data/web-ui'
import { setupAction } from '$/actions/user/setupAction'
import { useServerAction } from 'zsa-react'
import { useFormAction } from '$/hooks/useFormAction'
import useLatitudeAction from '$/hooks/useLatitudeAction'

export default function SetupForm({
email,
Expand All @@ -18,8 +19,9 @@ export default function SetupForm({
footer: ReactNode
}) {
const { toast } = useToast()
const { isPending, error, executeFormAction } = useServerAction(setupAction, {
onError: ({ err }) => {
const { execute, isPending } = useLatitudeAction(setupAction)
const { error, action, data } = useFormAction(execute, {
onError: (err) => {
if (err.code === 'ERROR') {
toast({
title: 'Saving failed',
Expand All @@ -31,31 +33,37 @@ export default function SetupForm({
})
const errors = error?.fieldErrors
return (
<form action={executeFormAction}>
<form action={action}>
<FormWrapper>
<Input
autoFocus
required
name='name'
autoComplete='name'
label='Name'
placeholder='Jon Snow'
// @ts-expect-error
errors={errors?.name}
defaultValue={name}
defaultValue={data?.name || name}
/>
<Input
required
name='email'
autoComplete='email'
label='Email'
placeholder='[email protected]'
// @ts-expect-error
errors={errors?.email}
defaultValue={email}
defaultValue={data?.email || email}
/>
<Input
required
name='companyName'
label='Workspace Name'
placeholder='Acme Inc.'
// @ts-expect-error
errors={errors?.companyName}
defaultValue={companyName}
defaultValue={data?.companyName || companyName}
/>
<Button fullWidth isLoading={isPending} fancy>
Create account
Expand Down

0 comments on commit 4ab4d71

Please sign in to comment.