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
+41 -2
View File
@@ -1,4 +1,8 @@
import { Link, useForm } from "@inertiajs/react";
import InvestmentTerritory from "@/components/investment-territory";
import InvestmentCoordinates from "@/components/investment-coordinates";
import { TerritoryLevel, type TerritoryOption } from "@/components/investment-territory";
import { useState } from "react";
import { Management, Field, button, control, states } from "./shared";
type Values = Record<string, string | boolean>;
@@ -9,8 +13,6 @@ const opportunityFields = {
slug: "Slug (endereço)",
summary: "Resumo",
description: "Descrição",
province: "Província",
district: "Distrito",
promoter_name: "Promotor",
promoter_type: "Tipo de promotor",
estimated_investment_amount: "Investimento estimado",
@@ -66,6 +68,7 @@ export default function Editor({
initial.is_featured = Boolean(record?.is_featured ?? false);
}
const form = useForm<Values>(initial);
const [creationPath, setCreationPath] = useState<TerritoryOption[]>([]);
return (
<Management
title={`${record ? "Editar" : "Criar"} ${isSector ? "sector" : "oportunidade"}`}
@@ -84,6 +87,40 @@ export default function Editor({
}}
>
<fieldset disabled={form.processing} className="space-y-5">
{!isSector && !record && (
<div className="grid gap-4 md:grid-cols-2">
{(
[
"province_id",
"district_id",
"admin_post_id",
"locality_id",
] as const
).map((key, index) => (
<TerritoryLevel
key={`${key}-${creationPath[index - 1]?.id ?? ""}`}
index={index}
parent={creationPath[index - 1]?.id ?? ""}
selected={creationPath[index]}
endpoint="/api/v1/investment/territory-options"
onChange={(value) => {
const path = [
...creationPath.slice(0, index),
...(value ? [value] : []),
];
setCreationPath(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 ?? "",
}));
}}
/>
))}
</div>
)}
{Object.entries(fields).map(([key, label]) => (
<Field key={key} label={label} error={form.errors[key]}>
{[
@@ -177,6 +214,8 @@ export default function Editor({
</div>
</fieldset>
</form>
{!isSector && record && <InvestmentTerritory kind="opportunities" id={record.id} />}
{!isSector && record && <InvestmentCoordinates id={record.id} />}
</Management>
);
}
+3
View File
@@ -41,6 +41,9 @@ export function Management({ title, children }: { title: string; children: React
<Link href="/management/crm/investors">Investidores</Link>
<Link href="/management/projects">Projectos</Link>
<Link href="/management/clusters">Clusters</Link>
<Link href="/management/territory-associations">
Localizações dos investimentos
</Link>
<Link href="/management/investment/zones">ZEE, ZFI e parques</Link>
{educationEnabled && (
<Link href="/management/education">Competências e formação</Link>
@@ -0,0 +1,108 @@
import { useEffect, useState } from "react";
import InvestmentTerritory from "@/components/investment-territory";
import { Management, Field, control } from "./shared";
export default function TerritoryAssociations() {
const [kind, setKind] = useState("projects");
const [id, setId] = useState("");
const [q, setQ] = useState("");
const [page, setPage] = useState(1);
const [rows, setRows] = useState<{ id: string; name: string }[]>([]);
const [more, setMore] = useState(false);
const [error, setError] = useState("");
useEffect(() => {
const controller = new AbortController();
const timer = setTimeout(async () => {
try {
const params = new URLSearchParams({ kind, q, page: String(page) });
const response = await fetch(`/management/territory-subjects?${params}`, {
signal: controller.signal,
headers: { Accept: "application/json" },
});
if (!response.ok) throw new Error("Não foi possível carregar os investimentos.");
const data = await response.json();
setRows(data.data);
setMore(Boolean(data.next_page_url));
setError("");
} catch (e) {
if (!controller.signal.aborted)
setError(e instanceof Error ? e.message : "Erro de ligação.");
}
}, 250);
return () => {
clearTimeout(timer);
controller.abort();
};
}, [kind, q, page]);
return (
<Management title="Localizações dos investimentos">
<Field label="Tipo de investimento">
<select
className={control}
value={kind}
onChange={(e) => {
setKind(e.target.value);
setId("");
setRows([]);
setQ("");
setPage(1);
}}
>
<option value="projects">Projectos / projectos âncora</option>
<option value="clusters">Clusters</option>
<option value="corridors">Corredores</option>
<option value="zones">ZEE / ZFI / parques industriais</option>
<option value="opportunities">Oportunidades</option>
</select>
</Field>
<Field label="Pesquisar investimento">
<input
className={control}
value={q}
onChange={(e) => {
setQ(e.target.value);
setPage(1);
setId("");
}}
/>
</Field>
<Field label="Investimento">
<select className={control} value={id} onChange={(e) => setId(e.target.value)}>
<option value="">Seleccione</option>
{rows.map((row) => (
<option value={row.id} key={row.id}>
{row.name}
</option>
))}
</select>
</Field>
{error && <p role="alert">{error}</p>}
{!error && rows.length === 0 && <p>Sem registos para esta pesquisa.</p>}
<div className="flex gap-4">
{page > 1 && (
<button
type="button"
onClick={() => {
setId("");
setPage(page - 1);
}}
>
Anterior
</button>
)}
{more && (
<button
type="button"
onClick={() => {
setId("");
setPage(page + 1);
}}
>
Mais investimentos
</button>
)}
</div>
{id && <InvestmentTerritory key={`${kind}-${id}`} kind={kind} id={id} />}
</Management>
);
}