diff --git a/app/components/ui/combobox.tsx b/app/components/ui/combobox.tsx index d4e662c..d0fb882 100644 --- a/app/components/ui/combobox.tsx +++ b/app/components/ui/combobox.tsx @@ -26,7 +26,7 @@ type TComboboxOption = { id: string } -type TInputProperties = ComponentProps< +type TComboboxProperties = ComponentProps< typeof HeadlessCombobox > & { id: string @@ -40,7 +40,7 @@ type TInputProperties = ComponentProps< } export const Combobox = >( - properties: TInputProperties, + properties: TComboboxProperties, ) => { const { id, diff --git a/app/components/ui/switch.tsx b/app/components/ui/switch.tsx new file mode 100644 index 0000000..a6a6ffc --- /dev/null +++ b/app/components/ui/switch.tsx @@ -0,0 +1,80 @@ +import { Field, Label, Switch as HeadlessSwitch } from '@headlessui/react' +import { type ReactNode } from 'react' +import { + Controller, + get, + type FieldError, + type FieldValues, + type Path, + type RegisterOptions, +} from 'react-hook-form' +import { useRemixFormContext } from 'remix-hook-form' +import { twMerge } from 'tailwind-merge' + +type TSwitchProperties = { + id: string + label?: ReactNode + name: Path + rules?: RegisterOptions + containerClassName?: string + labelClassName?: string + className?: string + inputClassName?: string +} + +export const Switch = >( + properties: TSwitchProperties, +) => { + const { + id, + label, + name, + rules, + containerClassName, + labelClassName, + className, + inputClassName, + } = properties + + const { + control, + formState: { errors }, + } = useRemixFormContext() + + const error: FieldError = get(errors, name) + + return ( + + + ( +
+ { + field.onChange(checked) + }} + className={twMerge( + 'group relative flex h-7 w-14 cursor-pointer rounded-full bg-black/10 p-1 shadow transition-colors duration-200 ease-in-out focus:outline-none data-[checked]:bg-black/10 data-[focus]:outline-1 data-[focus]:outline-white', + className, + )} + > + +
+ )} + /> +
+ ) +} diff --git a/app/pages/contents-create/index.tsx b/app/pages/contents-create/index.tsx index b7a984e..d5c082c 100644 --- a/app/pages/contents-create/index.tsx +++ b/app/pages/contents-create/index.tsx @@ -9,6 +9,7 @@ import { TextEditor } from '~/components/text-editor' import { Button } from '~/components/ui/button' import { Combobox } from '~/components/ui/combobox' import { Input } from '~/components/ui/input' +import { Switch } from '~/components/ui/switch' import { TitleDashboard } from '~/components/ui/title-dashboard' import type { loader } from '~/routes/_admin.lg-admin' @@ -67,6 +68,15 @@ export const CreateContentsPage = () => { mode: 'onSubmit', fetcher, resolver: zodResolver(contentSchema), + defaultValues: { + categories: [], + tags: [], + title: '', + content: '', + featured_image: '', + is_premium: false, + live_at: '', + }, }) const { handleSubmit, control, watch } = formMethods @@ -167,6 +177,13 @@ export const CreateContentsPage = () => { className="border-0 bg-white shadow focus:ring-1 focus:ring-[#2E2F7C] focus:outline-none" labelClassName="text-sm font-medium text-[#363636]" /> +