@@ -1,14 +1,15 @@
|
||||
import { useForm } from "@inertiajs/react";
|
||||
import { Management } from "../management/shared";
|
||||
import { Field, input, button, card, groupLabels } from "./shared";
|
||||
import type { Option } from "./shared";
|
||||
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 (
|
||||
<Management title="Opções dos formulários e filtros">
|
||||
<p>
|
||||
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.
|
||||
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.
|
||||
</p>
|
||||
<OptionForm groups={groups} />
|
||||
<div className="space-y-4">
|
||||
@@ -21,7 +22,11 @@ export default function References({ options }: { options: Option[] }) {
|
||||
{options
|
||||
.filter((o) => o.group === group)
|
||||
.map((o) => (
|
||||
<OptionForm key={o.id} option={o} groups={groups} />
|
||||
<OptionForm
|
||||
key={o.id}
|
||||
option={o}
|
||||
groups={groups}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
@@ -33,8 +38,8 @@ export default function References({ options }: { options: Option[] }) {
|
||||
function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
const form = useForm({
|
||||
group: option?.group ?? groups[0],
|
||||
code: option?.code ?? "",
|
||||
label: option?.label ?? "",
|
||||
code: option?.code ?? '',
|
||||
label: option?.label ?? '',
|
||||
active: option?.active ?? true,
|
||||
requires_description: option?.requires_description ?? false,
|
||||
sort_order: option?.sort_order ?? 0,
|
||||
@@ -44,19 +49,25 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
className="space-y-3 rounded border p-4"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post("/management/investment/references" + (option ? "/" + option.id : ""), {
|
||||
preserveScroll: true,
|
||||
});
|
||||
form.post(
|
||||
'/management/investment/references' +
|
||||
(option ? '/' + option.id : ''),
|
||||
{
|
||||
preserveScroll: true,
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<h2 className="font-semibold">{option ? "Editar opção" : "Criar opção"}</h2>
|
||||
<h2 className="font-semibold">
|
||||
{option ? 'Editar opção' : 'Criar opção'}
|
||||
</h2>
|
||||
<div className="grid gap-3 md:grid-cols-3">
|
||||
<Field label="Grupo">
|
||||
<select
|
||||
disabled={!!option}
|
||||
className={input}
|
||||
value={form.data.group}
|
||||
onChange={(e) => form.setData("group", e.target.value)}
|
||||
onChange={(e) => form.setData('group', e.target.value)}
|
||||
>
|
||||
{groups.map((g) => (
|
||||
<option key={g} value={g}>
|
||||
@@ -71,7 +82,7 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
required
|
||||
readOnly={!!option}
|
||||
value={form.data.code}
|
||||
onChange={(e) => form.setData("code", e.target.value)}
|
||||
onChange={(e) => form.setData('code', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
<Field label="Etiqueta">
|
||||
@@ -79,7 +90,7 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
className={input}
|
||||
required
|
||||
value={form.data.label}
|
||||
onChange={(e) => form.setData("label", e.target.value)}
|
||||
onChange={(e) => form.setData('label', e.target.value)}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
@@ -87,7 +98,7 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.active}
|
||||
onChange={(e) => form.setData("active", e.target.checked)}
|
||||
onChange={(e) => form.setData('active', e.target.checked)}
|
||||
/>
|
||||
Activa
|
||||
</label>
|
||||
@@ -95,7 +106,9 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.requires_description}
|
||||
onChange={(e) => form.setData("requires_description", e.target.checked)}
|
||||
onChange={(e) =>
|
||||
form.setData('requires_description', e.target.checked)
|
||||
}
|
||||
/>
|
||||
Exige especificação
|
||||
</label>
|
||||
@@ -106,7 +119,9 @@ function OptionForm({ option, groups }: { option?: Option; groups: string[] }) {
|
||||
max="10000"
|
||||
className={input}
|
||||
value={form.data.sort_order}
|
||||
onChange={(e) => form.setData("sort_order", Number(e.target.value))}
|
||||
onChange={(e) =>
|
||||
form.setData('sort_order', Number(e.target.value))
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
{Object.entries(form.errors).map(([key, value]) => (
|
||||
|
||||
Reference in New Issue
Block a user