varias alteracoes

This commit is contained in:
2026-09-29 08:41:57 +02:00
parent b77714b156
commit 2e0217b486
51 changed files with 2605 additions and 270 deletions
+84 -135
View File
@@ -1,15 +1,16 @@
import { Link, useForm } from '@inertiajs/react';
import { Management, Field, button, control } from '../management/shared';
import { titles, statuses, stages, roles } from './types';
import type { Structure, StructureRecord, Chain } from './types';
import ValueNetwork from './value-network';
import type { ChainLink, Gap } from './value-network';
import { Link, useForm } from "@inertiajs/react";
import InvestmentTerritory, { TerritoryFields } from "@/components/investment-territory";
import { Management, Field, button, control } from "../management/shared";
import { titles, statuses, stages, roles } from "./types";
import type { Structure, StructureRecord, Chain } from "./types";
import ValueNetwork from "./value-network";
import type { ChainLink, Gap } from "./value-network";
function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) {
const form = useForm({
code: chain?.code ?? '',
name: chain?.name ?? '',
stage: chain?.stage ?? 'input',
code: chain?.code ?? "",
name: chain?.name ?? "",
stage: chain?.stage ?? "input",
});
return (
<form
@@ -17,8 +18,7 @@ function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) {
onSubmit={(e) => {
e.preventDefault();
const url = `/management/clusters/${clusterId}/chains`;
if (chain)
form.put(`${url}/${chain.id}`, { preserveScroll: true });
if (chain) form.put(`${url}/${chain.id}`, { preserveScroll: true });
else
form.post(url, {
preserveScroll: true,
@@ -26,28 +26,26 @@ function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) {
});
}}
>
<h3 className="font-semibold">
{chain ? chain.name : 'Nova etapa'}
</h3>
<h3 className="font-semibold">{chain ? chain.name : "Nova etapa"}</h3>
<Field label="Código da etapa" error={form.errors.code}>
<input
className={control}
value={form.data.code}
onChange={(e) => form.setData('code', e.target.value)}
onChange={(e) => form.setData("code", e.target.value)}
/>
</Field>
<Field label="Nome da etapa" error={form.errors.name}>
<input
className={control}
value={form.data.name}
onChange={(e) => form.setData('name', e.target.value)}
onChange={(e) => form.setData("name", e.target.value)}
/>
</Field>
<Field label="Fase da cadeia" error={form.errors.stage}>
<select
className={control}
value={form.data.stage}
onChange={(e) => form.setData('stage', e.target.value)}
onChange={(e) => form.setData("stage", e.target.value)}
>
{Object.entries(stages).map(([value, label]) => (
<option key={value} value={value}>
@@ -85,36 +83,47 @@ export default function Editor({
role: string;
}[];
}) {
const isProject = structure === 'projects';
const isProject = structure === "projects";
const form = useForm({
code: record?.code ?? '',
name: record?.name ?? '',
status: record?.status ?? (isProject ? 'draft' : 'planned'),
sector: record?.sector ?? '',
description: record?.description ?? '',
budget_amount: record?.budget_amount ?? '',
budget_currency: record?.budget_currency ?? '',
start_date: record?.start_date?.slice(0, 10) ?? '',
end_date: record?.end_date?.slice(0, 10) ?? '',
code: record?.code ?? "",
name: record?.name ?? "",
status: record?.status ?? (isProject ? "draft" : "planned"),
sector: record?.sector ?? "",
description: record?.description ?? "",
budget_amount: record?.budget_amount ?? "",
budget_currency: record?.budget_currency ?? "",
start_date: record?.start_date?.slice(0, 10) ?? "",
end_date: record?.end_date?.slice(0, 10) ?? "",
province_id: "",
district_id: "",
admin_post_id: "",
locality_id: "",
});
const association = useForm({ project_id: '', role: 'complementary' });
const association = useForm({ project_id: "", role: "complementary" });
return (
<Management
title={`${record ? 'Editar' : 'Criar'} ${isProject ? 'projecto' : 'cluster'}`}
>
<Management title={`${record ? "Editar" : "Criar"} ${isProject ? "projecto" : "cluster"}`}>
<Link className="underline" href={`/management/${structure}`}>
Voltar a {titles[structure].toLowerCase()}
</Link>
<p>
Registo interno de gestão. O estado activo não publica este
conteúdo no portal.
</p>
<p>Registo interno de gestão. O estado activo não publica este conteúdo no portal.</p>
{!record && (
<TerritoryFields
onChange={(path) =>
form.setData((data) => ({
...data,
province_id: path[0]?.id ?? "",
district_id: path[1]?.id ?? "",
admin_post_id: path[2]?.id ?? "",
locality_id: path[3]?.id ?? "",
}))
}
/>
)}
<form
className="max-w-3xl space-y-4"
onSubmit={(e) => {
e.preventDefault();
if (record)
form.put(`/management/${structure}/${record.id}`);
if (record) form.put(`/management/${structure}/${record.id}`);
else form.post(`/management/${structure}`);
}}
>
@@ -122,29 +131,27 @@ export default function Editor({
<input
className={control}
value={form.data.code}
onChange={(e) => form.setData('code', e.target.value)}
onChange={(e) => form.setData("code", e.target.value)}
/>
</Field>
<Field label="Nome" error={form.errors.name}>
<input
className={control}
value={form.data.name}
onChange={(e) => form.setData('name', e.target.value)}
onChange={(e) => form.setData("name", e.target.value)}
/>
</Field>
<Field label="Estado" error={form.errors.status}>
<select
className={control}
value={form.data.status}
onChange={(e) => form.setData('status', e.target.value)}
onChange={(e) => form.setData("status", e.target.value)}
>
{Object.entries(statuses[structure]).map(
([value, label]) => (
<option key={value} value={value}>
{label}
</option>
),
)}
{Object.entries(statuses[structure]).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</Field>
{!isProject && (
@@ -152,25 +159,18 @@ export default function Editor({
<input
className={control}
value={form.data.sector}
onChange={(e) =>
form.setData('sector', e.target.value)
}
onChange={(e) => form.setData("sector", e.target.value)}
/>
</Field>
)}
{isProject && (
<>
<Field
label="Descrição"
error={form.errors.description}
>
<Field label="Descrição" error={form.errors.description}>
<textarea
className={control}
rows={5}
value={form.data.description}
onChange={(e) =>
form.setData('description', e.target.value)
}
onChange={(e) => form.setData("description", e.target.value)}
/>
</Field>
<Field
@@ -181,12 +181,7 @@ export default function Editor({
inputMode="decimal"
className={control}
value={form.data.budget_amount}
onChange={(e) =>
form.setData(
'budget_amount',
e.target.value,
)
}
onChange={(e) => form.setData("budget_amount", e.target.value)}
/>
</Field>
<Field
@@ -198,37 +193,24 @@ export default function Editor({
className={control}
value={form.data.budget_currency}
onChange={(e) =>
form.setData(
'budget_currency',
e.target.value.toUpperCase(),
)
form.setData("budget_currency", e.target.value.toUpperCase())
}
/>
</Field>
<Field
label="Data de início"
error={form.errors.start_date}
>
<Field label="Data de início" error={form.errors.start_date}>
<input
type="date"
className={control}
value={form.data.start_date}
onChange={(e) =>
form.setData('start_date', e.target.value)
}
onChange={(e) => form.setData("start_date", e.target.value)}
/>
</Field>
<Field
label="Data de conclusão"
error={form.errors.end_date}
>
<Field label="Data de conclusão" error={form.errors.end_date}>
<input
type="date"
className={control}
value={form.data.end_date}
onChange={(e) =>
form.setData('end_date', e.target.value)
}
onChange={(e) => form.setData("end_date", e.target.value)}
/>
</Field>
</>
@@ -240,9 +222,7 @@ export default function Editor({
{!isProject && record && (
<>
<section className="max-w-3xl space-y-4">
<h2 className="text-xl font-semibold">
Projectos associados
</h2>
<h2 className="text-xl font-semibold">Projectos associados</h2>
{memberships.map((member) => (
<p key={member.id}>
<Link
@@ -250,93 +230,61 @@ export default function Editor({
href={`/management/projects/${member.project_id}/edit`}
>
{member.name}
</Link>{' '}
</Link>{" "}
· {roles[member.role]}
</p>
))}
{!memberships.length && (
<p>Ainda não existem projectos associados.</p>
)}
{!memberships.length && <p>Ainda não existem projectos associados.</p>}
<form
className="space-y-3"
onSubmit={(e) => {
e.preventDefault();
association.post(
`/management/clusters/${record.id}/projects`,
{ preserveScroll: true },
);
association.post(`/management/clusters/${record.id}/projects`, {
preserveScroll: true,
});
}}
>
<Field
label="Projecto"
error={association.errors.project_id}
>
<Field label="Projecto" error={association.errors.project_id}>
<select
className={control}
value={association.data.project_id}
onChange={(e) =>
association.setData(
'project_id',
e.target.value,
)
association.setData("project_id", e.target.value)
}
>
<option value="">Seleccione</option>
{projects.map((project) => (
<option
key={project.id}
value={project.id}
>
<option key={project.id} value={project.id}>
{project.code} — {project.name}
</option>
))}
</select>
</Field>
<Field
label="Papel no cluster"
error={association.errors.role}
>
<Field label="Papel no cluster" error={association.errors.role}>
<select
className={control}
value={association.data.role}
onChange={(e) =>
association.setData(
'role',
e.target.value,
)
}
onChange={(e) => association.setData("role", e.target.value)}
>
{Object.entries(roles).map(
([value, label]) => (
<option key={value} value={value}>
{label}
</option>
),
)}
{Object.entries(roles).map(([value, label]) => (
<option key={value} value={value}>
{label}
</option>
))}
</select>
</Field>
<button
className={button}
disabled={association.processing}
>
<button className={button} disabled={association.processing}>
Guardar associação
</button>
<p className="text-sm">
Seleccionar um projecto já associado permite
actualizar o seu papel.
Seleccionar um projecto já associado permite actualizar o seu papel.
</p>
</form>
</section>
<section className="max-w-3xl space-y-4">
<h2 className="text-xl font-semibold">
Etapas da cadeia de valor
</h2>
<h2 className="text-xl font-semibold">Etapas da cadeia de valor</h2>
{chains.map((chain) => (
<ChainForm
key={chain.id}
clusterId={record.id}
chain={chain}
/>
<ChainForm key={chain.id} clusterId={record.id} chain={chain} />
))}
<ChainForm clusterId={record.id} />
</section>
@@ -348,6 +296,7 @@ export default function Editor({
/>
</>
)}
{record && <InvestmentTerritory kind={structure} id={record.id} />}
</Management>
);
}