feat: update API endpoint for ad creation and enhance InputFile component with category prop
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
import { Field, Label, Input as HeadlessInput } from '@headlessui/react'
|
||||
import { CloudArrowUpIcon } from '@heroicons/react/20/solid'
|
||||
import { useEffect, type ComponentProps, type ReactNode } from 'react'
|
||||
import {
|
||||
get,
|
||||
type FieldError,
|
||||
type FieldValues,
|
||||
type Path,
|
||||
type RegisterOptions,
|
||||
} from 'react-hook-form'
|
||||
import { get, type FieldError, type RegisterOptions } from 'react-hook-form'
|
||||
import { useRemixFormContext } from 'remix-hook-form'
|
||||
import { twMerge } from 'tailwind-merge'
|
||||
|
||||
@@ -15,22 +9,17 @@ import { useAdminContext, type TUpload } from '~/contexts/admin'
|
||||
|
||||
import { Button } from './button'
|
||||
|
||||
type TInputProperties<T extends FieldValues> = Omit<
|
||||
ComponentProps<'input'>,
|
||||
'size'
|
||||
> & {
|
||||
type TInputProperties = Omit<ComponentProps<'input'>, 'size'> & {
|
||||
id: string
|
||||
label?: ReactNode
|
||||
name: Path<T>
|
||||
name: string
|
||||
rules?: RegisterOptions
|
||||
containerClassName?: string
|
||||
labelClassName?: string
|
||||
category?: string
|
||||
category: TUpload
|
||||
}
|
||||
|
||||
export const InputFile = <TFormValues extends Record<string, unknown>>(
|
||||
properties: TInputProperties<TFormValues>,
|
||||
) => {
|
||||
export const InputFile = (properties: TInputProperties) => {
|
||||
const {
|
||||
id,
|
||||
label,
|
||||
@@ -56,8 +45,8 @@ export const InputFile = <TFormValues extends Record<string, unknown>>(
|
||||
const error: FieldError = get(errors, name)
|
||||
|
||||
useEffect(() => {
|
||||
if (uploadedFile && isUploadOpen === name) {
|
||||
setValue(name as string, uploadedFile)
|
||||
if (uploadedFile && isUploadOpen === (category || name)) {
|
||||
setValue(name, uploadedFile)
|
||||
setUploadedFile(undefined)
|
||||
setIsUploadOpen(undefined)
|
||||
}
|
||||
@@ -88,7 +77,7 @@ export const InputFile = <TFormValues extends Record<string, unknown>>(
|
||||
size="fit"
|
||||
className="absolute right-3 h-[42px]"
|
||||
onClick={() => {
|
||||
setIsUploadOpen((category || name) as TUpload)
|
||||
setIsUploadOpen(category)
|
||||
}}
|
||||
>
|
||||
<CloudArrowUpIcon className="h-4 w-4 text-gray-500/50" />
|
||||
|
||||
Reference in New Issue
Block a user