fix(admin-ui): Lint all UI files (#3459)
This commit is contained in:
committed by
GitHub
parent
55febef7f1
commit
ad7d7fcd51
@@ -1,9 +1,10 @@
|
||||
|
||||
import { get } from "lodash"
|
||||
import { FieldPath, FieldValues, UseFormReturn } from "react-hook-form"
|
||||
import { Get } from "type-fest"
|
||||
|
||||
export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__: TValues }> & {
|
||||
export type NestedForm<TValues extends FieldValues> = UseFormReturn<{
|
||||
__nested__: TValues
|
||||
}> & {
|
||||
path(this: void): `__nested__`
|
||||
path<TPath extends FieldPath<TValues>>(
|
||||
this: void,
|
||||
@@ -19,11 +20,11 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
/**
|
||||
* Utility function to create a nested form. This is useful when you want to use a reusable form component within a form.
|
||||
* This is especially useful when you want to use a reusable form component within a form multiple times. For example, an form
|
||||
* that contains both a billing and a shipping address.
|
||||
* that contains both a billing and a shipping address.
|
||||
* @example
|
||||
* const MyForm = () => {
|
||||
* const form = useForm<{ email: string, shipping_address: AddressPayload, billing_address: AddressPayload }>()
|
||||
*
|
||||
*
|
||||
* return (
|
||||
* <div>
|
||||
* <Input {...form.register("email")} label="email" />
|
||||
@@ -32,14 +33,14 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
* </div>
|
||||
* )
|
||||
* }
|
||||
*
|
||||
*
|
||||
* type AddressFormProps = {
|
||||
* form: NestedForm<AddressPayload>
|
||||
* }
|
||||
*
|
||||
*
|
||||
* const AddressForm = ({ form }: AddressFormProps) => {
|
||||
* const { register, path } = form
|
||||
*
|
||||
*
|
||||
* return (
|
||||
* <div>
|
||||
* <Input {...register(path("city"))} label="City" /> // path("city") resolves as "shipping_address.city" or "billing_address.city" depending on the second argument passed to nestedForm
|
||||
@@ -51,7 +52,10 @@ export type NestedForm<TValues extends FieldValues> = UseFormReturn<{ __nested__
|
||||
export function nestedForm<TValues extends FieldValues>(
|
||||
form: UseFormReturn<TValues> | NestedForm<TValues>
|
||||
): NestedForm<TValues>
|
||||
export function nestedForm<TValues extends FieldValues, TPath extends FieldPath<TValues>>(
|
||||
export function nestedForm<
|
||||
TValues extends FieldValues,
|
||||
TPath extends FieldPath<TValues>
|
||||
>(
|
||||
form: UseFormReturn<TValues> | NestedForm<TValues>,
|
||||
path: TPath
|
||||
): NestedForm<Get<TValues, TPath>>
|
||||
@@ -63,7 +67,7 @@ export function nestedForm(
|
||||
...form,
|
||||
path(field?: string | number) {
|
||||
const fullPath = path && field ? `${path}.${field}` : path ? path : field
|
||||
|
||||
|
||||
if ("path" in form) {
|
||||
return form.path(path as any)
|
||||
}
|
||||
@@ -72,12 +76,12 @@ export function nestedForm(
|
||||
},
|
||||
get(obj: any, field?: string | number) {
|
||||
const fullPath = path && field ? `${path}.${field}` : path ? path : field
|
||||
|
||||
if ("get" in form) {
|
||||
return form.get(path)
|
||||
|
||||
if ("get" in form) {
|
||||
return form.get(path)
|
||||
}
|
||||
|
||||
|
||||
return fullPath ? get(obj, fullPath) : obj
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user