64 lines
No EOL
2.1 KiB
TypeScript
64 lines
No EOL
2.1 KiB
TypeScript
// * Packages
|
|
import { usePage } from "@inertiajs/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 { DynamicField, DynamicFieldTypes } from "@/back//types/global";
|
|
|
|
type ConfigTableProps = {
|
|
config: DynamicField[];
|
|
};
|
|
|
|
export default function ConfigTable({ config }: ConfigTableProps) {
|
|
const enumDynamicFieldTypes = usePage().props .enumDynamicFieldTypes as DynamicFieldTypes;
|
|
const getEnumDynamicFieldType = (value: number) => {
|
|
return Object.values(enumDynamicFieldTypes).find((def) => def.value === value);
|
|
};
|
|
|
|
return (
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>
|
|
{str(useTrans("validation.custom.type")).ucFirst().value()}
|
|
</TableHead>
|
|
<TableHead>
|
|
{str(useTrans("validation.custom.label")).ucFirst().value()}
|
|
</TableHead>
|
|
<TableHead>
|
|
{str(useTrans("validation.custom.validation")).ucFirst().value()}
|
|
</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{Object.entries(config).map(
|
|
([id, field]) => (
|
|
<TableRow key={id}>
|
|
<TableCell>
|
|
{getEnumDynamicFieldType(field.type)?.label}
|
|
</TableCell>
|
|
<TableCell>
|
|
{field.label}
|
|
<code className="text-xs ms-1">
|
|
({field.key})
|
|
</code>
|
|
</TableCell>
|
|
<TableCell>
|
|
{field.validation}
|
|
</TableCell>
|
|
</TableRow>
|
|
),
|
|
)}
|
|
</TableBody>
|
|
</Table>
|
|
);
|
|
} |