Skip to content

Commit

Permalink
refactor: useForm
Browse files Browse the repository at this point in the history
  • Loading branch information
rharkor committed Sep 16, 2023
1 parent 00c0e29 commit ff24cfa
Show file tree
Hide file tree
Showing 6 changed files with 4 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/app/[lang]/(sys-auth)/forgot-password/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export default function ForgotPasswordForm({ dictionary }: { dictionary: TDictio
autoComplete="email"
autoCorrect="off"
disabled={isDisabled}
form={form}
name="email"
/>
</div>
Expand Down
2 changes: 0 additions & 2 deletions src/app/[lang]/(sys-auth)/reset-password/[token]/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default function ResetPasswordForm({ dictionary, token }: { dictionary: T
type="password-eye-slash"
placeholder={dictionary.password}
autoComplete="new-password"
form={form}
/>
</div>
<div className="grid gap-1">
Expand All @@ -71,7 +70,6 @@ export default function ResetPasswordForm({ dictionary, token }: { dictionary: T
type="password"
placeholder={dictionary.passwordConfirmation}
autoComplete="new-password"
form={form}
/>
</div>
<Button type="submit" isLoading={isLoading}>
Expand Down
2 changes: 0 additions & 2 deletions src/components/auth/login-user-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export function LoginUserAuthForm({ dictionary, searchParams, ...props }: UserAu
autoComplete="email"
autoCorrect="off"
disabled={isLoading}
form={form}
name="email"
/>
</div>
Expand All @@ -130,7 +129,6 @@ export function LoginUserAuthForm({ dictionary, searchParams, ...props }: UserAu
autoComplete="new-password"
autoCorrect="off"
disabled={isLoading}
form={form}
name="password"
/>
</div>
Expand Down
4 changes: 0 additions & 4 deletions src/components/auth/register-user-auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ export function RegisterUserAuthForm({ dictionary, isMinimized, searchParams, ..
autoComplete="email"
autoCorrect="off"
disabled={isLoading || !isMinimized}
form={form}
name="email"
className={cn({
"pointer-events-none": !isMinimized,
Expand Down Expand Up @@ -189,7 +188,6 @@ export function RegisterUserAuthForm({ dictionary, isMinimized, searchParams, ..
autoComplete="username"
autoCorrect="off"
disabled={isLoading}
form={form}
name="username"
/>
</div>
Expand All @@ -203,7 +201,6 @@ export function RegisterUserAuthForm({ dictionary, isMinimized, searchParams, ..
autoComplete="new-password"
autoCorrect="off"
disabled={isLoading}
form={form}
name="password"
/>
</div>
Expand All @@ -217,7 +214,6 @@ export function RegisterUserAuthForm({ dictionary, isMinimized, searchParams, ..
autoComplete="new-password"
autoCorrect="off"
disabled={isLoading}
form={form}
name="confirmPassword"
/>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/components/profile/update-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export default function UpdateAccount({
placeholder={dictionary.profilePage.profileDetails.username.placeholder}
type="text"
disabled={updateUserMutation.isLoading || account.isInitialLoading}
form={form}
name="username"
/>
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/components/ui/form-field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { HTMLInputTypeAttribute } from "react"
import { ControllerRenderProps, FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
import { ControllerRenderProps, FieldPath, FieldValues, useFormContext, UseFormReturn } from "react-hook-form"
import {
FormControl,
FormDescription,
Expand All @@ -21,7 +21,7 @@ export interface FormFieldProps<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> extends InputWithOmittedProps {
form: UseFormReturn<TFieldValues>
form?: UseFormReturn<TFieldValues>
name: TName
label?: string
placeholder?: string
Expand Down Expand Up @@ -65,6 +65,8 @@ export default function FormField<
className,
...props
}: FormFieldProps<TFieldValues, TName>) {
const formContext = useFormContext<TFieldValues>()
form ??= formContext
return (
<FormFieldComponent
control={form.control}
Expand Down

0 comments on commit ff24cfa

Please sign in to comment.