// * Packages import { usePage } from "@inertiajs/react"; import { CornerDownRightIcon } from "lucide-react"; import { ReactNode } from "react"; // * Components shadcn import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; // * Other import str from "@/hooks/use-string"; import useTrans from "@/hooks/use-translations"; import { ConfigField, DynamicFieldTypes } from "@/back/types/global"; type ConfigTableProps = { config: ConfigField[]; }; export default function ConfigTable({ config }: ConfigTableProps) { // Enums. const enumDynamicFieldTypes = usePage().props .enumDynamicFieldTypes as DynamicFieldTypes; const getEnumDynamicFieldType = (value: number) => { return Object.values(enumDynamicFieldTypes).find((def) => def.value === value); }; // Translations. const transType = str(useTrans("validation.custom.type")).ucFirst().value(); const transLabel = str(useTrans("validation.custom.label")).ucFirst().value() const transValidation = str(useTrans("validation.custom.validation")).ucFirst().value(); // Recursive component. const GetChildrenRow = (fields: ConfigField[], depth: number = 0): ReactNode => { return Object.entries(fields).map( ([id, field]) => ( <>
{depth > 0 && } {depth > 0 && #{depth}} {getEnumDynamicFieldType(field.type)?.label}
{field.label} ({field.key}) {field.validation}
{field.children && GetChildrenRow(field.children, depth + 1)} ) ) } return ( {transType} {transLabel} {transValidation} {GetChildrenRow(config)}
); }