import { useForm } from "@inertiajs/react"; import { Management } from "../management/shared"; import { Field, input, button, card, groupLabels } from "./shared"; import type { Option } from "./shared"; export default function References({ options }: { options: Option[] }) { const groups = [...new Set(options.map((o) => o.group))]; return (

Os códigos são estáveis; pode corrigir etiquetas ou desactivar opções sem eliminar referências históricas. Cada grupo conserva Outro — especificar.

{groups.map((group) => (
{groupLabels[group] ?? group}
{options .filter((o) => o.group === group) .map((o) => ( ))}
))}
); } function OptionForm({ option, groups }: { option?: Option; groups: string[] }) { const form = useForm({ group: option?.group ?? groups[0], code: option?.code ?? "", label: option?.label ?? "", active: option?.active ?? true, requires_description: option?.requires_description ?? false, sort_order: option?.sort_order ?? 0, }); return (
{ e.preventDefault(); form.post("/management/investment/references" + (option ? "/" + option.id : ""), { preserveScroll: true, }); }} >

{option ? "Editar opção" : "Criar opção"}

form.setData("code", e.target.value)} /> form.setData("label", e.target.value)} />
form.setData("sort_order", Number(e.target.value))} /> {Object.entries(form.errors).map(([key, value]) => (

{value}

))}
); }