diff --git a/web/components/dashboard/crud/dashboard-crud-field-control.tsx b/web/components/dashboard/crud/dashboard-crud-field-control.tsx index 0a9195d..08041a7 100644 --- a/web/components/dashboard/crud/dashboard-crud-field-control.tsx +++ b/web/components/dashboard/crud/dashboard-crud-field-control.tsx @@ -1,9 +1,25 @@ "use client" -import type { FieldError as HookFormFieldError } from "react-hook-form" +import { useState } from "react" +import { CheckIcon, ChevronsUpDownIcon } from "lucide-react" +import type { + FieldError as HookFormFieldError, + UseFormReturn, +} from "react-hook-form" import { Controller, type Control, type UseFormRegister } from "react-hook-form" import { OptionCombobox } from "@/components/option-combobox" +import { Badge } from "@/components/ui/badge" +import { Button } from "@/components/ui/button" +import { Checkbox } from "@/components/ui/checkbox" +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "@/components/ui/command" import { Field, FieldContent, @@ -11,31 +27,73 @@ import { FieldLabel, } from "@/components/ui/field" import { Input } from "@/components/ui/input" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import { Switch } from "@/components/ui/switch" import { Textarea } from "@/components/ui/textarea" +import { useI18n } from "@/i18n/provider" import { cn } from "@/lib/utils" -import type { DashboardCrudFormField } from "./dashboard-crud-utils" +import type { + DashboardCrudFormField, + DashboardCrudFormInputValue, + DashboardCrudFormOption, +} from "./dashboard-crud-utils" export function DashboardCrudFieldControl({ field, control, + form, register, error, }: { field: DashboardCrudFormField - control: Control> - register: UseFormRegister> + control: Control> + form: UseFormReturn< + Record, + undefined, + Record + > + register: UseFormRegister> error?: HookFormFieldError }) { const inputId = `dashboard-crud-field-${field.name}` + if (field.type === "section" || field.type === "group") { + return ( +
+
+
{field.label}
+ {field.description ? ( +
+ {field.description} +
+ ) : null} +
+
+ ) + } + return ( - + {field.label} @@ -45,13 +103,77 @@ export function DashboardCrudFieldControl({ name={field.name} render={({ field: controllerField }) => ( )} /> + ) : field.type === "multiSelect" ? ( + ( + + )} + /> + ) : field.type === "switch" ? ( + ( + + )} + /> + ) : field.type === "checkbox" ? ( + ( + + )} + /> + ) : field.type === "custom" && field.render ? ( + ( + <> + {field.render?.({ + name: field.name, + label: field.label, + value: controllerField.value, + values: form.watch(), + setValue: (name, value) => + form.setValue(name, value, { + shouldDirty: true, + shouldValidate: true, + }), + })} + + )} + /> ) : field.type === "textarea" ? (