This commit is contained in:
@@ -13,9 +13,86 @@ type Option = TerritoryOption;
|
||||
const levels = ["province", "district", "admin_post", "locality"];
|
||||
const labels = ["Província", "Distrito", "Posto administrativo", "Localidade"];
|
||||
const control = "w-full rounded border bg-background p-2 text-foreground";
|
||||
const emptyTerritoryPath: TerritoryOption[] = [];
|
||||
|
||||
export function ProvinceSelect({
|
||||
value,
|
||||
onChange,
|
||||
endpoint = "/api/v1/investment/territory-options",
|
||||
placeholder = "Seleccione uma província",
|
||||
className = control,
|
||||
label = "Província",
|
||||
required = false,
|
||||
}: {
|
||||
value: string;
|
||||
onChange: (value: string) => void;
|
||||
endpoint?: string;
|
||||
placeholder?: string;
|
||||
className?: string;
|
||||
label?: string;
|
||||
required?: boolean;
|
||||
}) {
|
||||
const id = useId();
|
||||
const [options, setOptions] = useState<Option[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [retry, setRetry] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
fetch(`${endpoint}?type=province&page=1`, {
|
||||
signal: controller.signal,
|
||||
headers: { Accept: "application/json" },
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (!response.ok) throw new Error("Não foi possível carregar as províncias.");
|
||||
return response.json();
|
||||
})
|
||||
.then((data) => setOptions(data.data))
|
||||
.catch((cause) => {
|
||||
if (!controller.signal.aborted)
|
||||
setError(cause instanceof Error ? cause.message : "Erro de ligação.");
|
||||
})
|
||||
.finally(() => {
|
||||
if (!controller.signal.aborted) setLoading(false);
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [endpoint, retry]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<select
|
||||
id={id}
|
||||
aria-label={label}
|
||||
className={className}
|
||||
required={required}
|
||||
value={options.some((option) => option.name === value) ? value : ""}
|
||||
disabled={loading || Boolean(error)}
|
||||
onChange={(event) => onChange(event.target.value)}
|
||||
>
|
||||
<option value="">{loading ? "A carregar províncias…" : placeholder}</option>
|
||||
{options.map((option) => (
|
||||
<option key={option.id} value={option.name}>
|
||||
{option.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{error && (
|
||||
<span role="alert" className="block text-sm">
|
||||
{error}{" "}
|
||||
<button type="button" onClick={() => setRetry((current) => current + 1)}>
|
||||
Tentar novamente
|
||||
</button>
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export function TerritoryFields({
|
||||
initial = [],
|
||||
initial = emptyTerritoryPath,
|
||||
onChange,
|
||||
endpoint = "/api/v1/investment/territory-options",
|
||||
}: {
|
||||
@@ -24,6 +101,7 @@ export function TerritoryFields({
|
||||
endpoint?: string;
|
||||
}) {
|
||||
const [path, setPath] = useState(initial);
|
||||
useEffect(() => setPath(initial), [initial]);
|
||||
return (
|
||||
<div className="grid gap-4 md:col-span-full md:grid-cols-2">
|
||||
{(["province_id", "district_id", "admin_post_id", "locality_id"] as const).map(
|
||||
@@ -64,7 +142,6 @@ export function TerritoryLevel({
|
||||
fieldError?: string;
|
||||
}) {
|
||||
const id = useId();
|
||||
const [q, setQ] = useState("");
|
||||
const [page, setPage] = useState(1);
|
||||
const [options, setOptions] = useState<Option[]>([]);
|
||||
const [more, setMore] = useState(false);
|
||||
@@ -85,7 +162,6 @@ export function TerritoryLevel({
|
||||
const params = new URLSearchParams({
|
||||
type: levels[index],
|
||||
parent_id: parent,
|
||||
q,
|
||||
page: String(page),
|
||||
});
|
||||
const response = await fetch(`${endpoint}?${params}`, {
|
||||
@@ -108,23 +184,12 @@ export function TerritoryLevel({
|
||||
clearTimeout(timer);
|
||||
controller.abort();
|
||||
};
|
||||
}, [index, parent, q, page, enabled, endpoint, retry]);
|
||||
}, [index, parent, page, enabled, endpoint, retry]);
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<label htmlFor={id} className="font-medium">
|
||||
{labels[index]}
|
||||
</label>
|
||||
<input
|
||||
className={control}
|
||||
aria-label={`Pesquisar ${labels[index]}`}
|
||||
disabled={!enabled}
|
||||
value={q}
|
||||
onChange={(e) => {
|
||||
setQ(e.target.value);
|
||||
setPage(1);
|
||||
}}
|
||||
placeholder="Pesquisar por código ou nome"
|
||||
/>
|
||||
<select
|
||||
id={id}
|
||||
aria-invalid={Boolean(fieldError)}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { createContext, useContext, useRef, useState } from "react";
|
||||
import { router } from "@inertiajs/react";
|
||||
import { PortalMenu } from "@/layouts/portal-navigation";
|
||||
import { ProvinceSelect } from "@/components/investment-territory";
|
||||
import { MATURITY_LEVELS } from "@/lib/investment-maturity";
|
||||
import type { Dispatch, FormEvent, ReactNode, SetStateAction } from "react";
|
||||
import type { LucideIcon } from "lucide-react";
|
||||
@@ -81,21 +82,6 @@ function QueryStatus({
|
||||
);
|
||||
}
|
||||
|
||||
const PROVINCES = [
|
||||
"Maputo Cidade",
|
||||
"Maputo Província",
|
||||
"Gaza",
|
||||
"Inhambane",
|
||||
"Sofala",
|
||||
"Manica",
|
||||
"Tete",
|
||||
"Zambézia",
|
||||
"Nampula",
|
||||
"Cabo Delgado",
|
||||
"Niassa",
|
||||
];
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Componentes */
|
||||
/* ------------------------------------------------------------------ */
|
||||
@@ -386,18 +372,12 @@ function OpportunitiesView({
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<select
|
||||
<ProvinceSelect
|
||||
value={filters.province}
|
||||
onChange={(e) => changeFilters({ ...filters, province: e.target.value })}
|
||||
onChange={(province) => changeFilters({ ...filters, province })}
|
||||
placeholder="Todas as províncias"
|
||||
className="rounded-lg border border-slate-200 px-3 py-2 text-sm"
|
||||
>
|
||||
<option value="">Todas as províncias</option>
|
||||
{PROVINCES.map((p) => (
|
||||
<option key={p} value={p}>
|
||||
{p}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
/>
|
||||
<select
|
||||
value={filters.maturity}
|
||||
onChange={(e) => changeFilters({ ...filters, maturity: e.target.value })}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Link, router, useForm } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { Management, Field, control, button } from "../management/shared";
|
||||
import { capabilities, purposes, states } from "./labels";
|
||||
import { ProvinceSelect } from "@/components/investment-territory";
|
||||
|
||||
type Source = {
|
||||
id: string;
|
||||
@@ -157,10 +158,12 @@ export default function Index({ controls, sources, documents, runs, today }: Pro
|
||||
{query.data.capability === "recommend" && (
|
||||
<>
|
||||
<Field label={t("Província declarada", "Declared province")}>
|
||||
<input
|
||||
className={control}
|
||||
<ProvinceSelect
|
||||
value={query.data.province}
|
||||
onChange={(e) => query.setData("province", e.target.value)}
|
||||
onChange={(province) => query.setData("province", province)}
|
||||
className={control}
|
||||
placeholder={t("Seleccione uma província", "Select a province")}
|
||||
label={t("Província declarada", "Declared province")}
|
||||
/>
|
||||
</Field>
|
||||
<Field label={t("Maturidade pretendida", "Desired maturity")}>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { Link, useForm } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { Management, Field, control, button } from "../management/shared";
|
||||
import { TerritoryFields, type TerritoryOption } from "@/components/investment-territory";
|
||||
export default function Analysis({
|
||||
demand,
|
||||
candidates,
|
||||
@@ -7,8 +9,15 @@ export default function Analysis({
|
||||
gap,
|
||||
proposal,
|
||||
sectors,
|
||||
territoryPath,
|
||||
}: {
|
||||
demand: { id: string; version_no: number; quantity: number; qualification: string };
|
||||
demand: {
|
||||
id: string;
|
||||
version_no: number;
|
||||
quantity: number;
|
||||
qualification: string;
|
||||
geo_location_id: string;
|
||||
};
|
||||
candidates: {
|
||||
id: string;
|
||||
quantity: number;
|
||||
@@ -29,7 +38,9 @@ export default function Analysis({
|
||||
source: string;
|
||||
} | null;
|
||||
sectors: { id: number; name: string }[];
|
||||
territoryPath: TerritoryOption[];
|
||||
}) {
|
||||
const [selectedTerritory, setSelectedTerritory] = useState(territoryPath);
|
||||
const form = useForm({
|
||||
demand_version: demand.version_no,
|
||||
sector_id: "",
|
||||
@@ -41,12 +52,19 @@ export default function Analysis({
|
||||
risks: "",
|
||||
source: "",
|
||||
currency: "MZN",
|
||||
province_id: territoryPath[0]?.id ?? "",
|
||||
district_id: territoryPath[1]?.id ?? "",
|
||||
admin_post_id: territoryPath[2]?.id ?? "",
|
||||
locality_id: territoryPath[3]?.id ?? "",
|
||||
});
|
||||
return (
|
||||
<Management title="Análise assistida de competências">
|
||||
<p>
|
||||
Procura: {demand.quantity} trabalhadores · {demand.qualification}
|
||||
</p>
|
||||
<p>
|
||||
Localização da procura: {territoryPath.map((territory) => territory.name).join(" · ") || "Não indicada"}
|
||||
</p>
|
||||
<p className="rounded border p-4">
|
||||
{gap.state === "expired"
|
||||
? "Fonte expirada. Actualize a declaração antes de analisar."
|
||||
@@ -120,6 +138,33 @@ export default function Analysis({
|
||||
form.post(`/management/education/demands/${demand.id}/investment`);
|
||||
}}
|
||||
>
|
||||
<div className="space-y-2 md:col-span-2">
|
||||
<p className="font-medium">Localização da oportunidade educativa</p>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Inicialmente preenchida com a localização da procura. Confirme ou ajuste cada nível territorial.
|
||||
</p>
|
||||
<TerritoryFields
|
||||
initial={selectedTerritory}
|
||||
endpoint="/management/territory-options"
|
||||
onChange={(path) => {
|
||||
setSelectedTerritory(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 ?? "",
|
||||
}));
|
||||
}}
|
||||
/>
|
||||
{Object.entries(form.errors)
|
||||
.filter(([key]) => key.endsWith("_id"))
|
||||
.map(([key, error]) => (
|
||||
<p role="alert" key={key}>
|
||||
{error}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
<Field label="Sector">
|
||||
<select
|
||||
required
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { Link, useForm } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { Management, Field, control, button, Pagination } from "../management/shared";
|
||||
import type { Paginated } from "../management/shared";
|
||||
import { TerritoryFields, type TerritoryOption } from "@/components/investment-territory";
|
||||
type Option = { id: string; name?: string; title?: string; code?: string };
|
||||
type RecordRow = {
|
||||
id: string;
|
||||
@@ -21,7 +23,7 @@ type Props = {
|
||||
providers: Option[];
|
||||
courses: Option[];
|
||||
projects: Option[];
|
||||
territories: Option[];
|
||||
territories: TerritoryOption[];
|
||||
today: string;
|
||||
filters: { q?: string; status?: string; geo_location_id?: string };
|
||||
indicators: {
|
||||
@@ -31,6 +33,19 @@ type Props = {
|
||||
pending_demands: number;
|
||||
};
|
||||
};
|
||||
const territoryLevels = ["province", "district", "admin_post", "locality"];
|
||||
|
||||
function territoryPath(id: string, territories: TerritoryOption[]): TerritoryOption[] {
|
||||
const byId = new Map(territories.map((territory) => [territory.id, territory]));
|
||||
const path: TerritoryOption[] = [];
|
||||
let current = byId.get(id);
|
||||
while (current && path.length < territoryLevels.length) {
|
||||
if (territoryLevels.includes(current.location_type)) path.unshift(current);
|
||||
current = current.parent_id ? byId.get(current.parent_id) : undefined;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
function Errors({ errors }: { errors: Record<string, string> }) {
|
||||
return (
|
||||
<>
|
||||
@@ -124,6 +139,7 @@ function Catalog({ kind, title, providers }: { kind: string; title: string; prov
|
||||
}
|
||||
function Intake({ kind, props }: { kind: "demands" | "capacities"; props: Props }) {
|
||||
const demand = kind === "demands";
|
||||
const [territoryResetKey, setTerritoryResetKey] = useState(0);
|
||||
const form = useForm({
|
||||
project_id: "",
|
||||
course_id: "",
|
||||
@@ -149,7 +165,10 @@ function Intake({ kind, props }: { kind: "demands" | "capacities"; props: Props
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post(`/management/education/${kind}`, {
|
||||
onSuccess: () => form.reset(),
|
||||
onSuccess: () => {
|
||||
form.reset();
|
||||
setTerritoryResetKey((key) => key + 1);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
@@ -171,12 +190,15 @@ function Intake({ kind, props }: { kind: "demands" | "capacities"; props: Props
|
||||
value={form.data.skill_id}
|
||||
onChange={(v) => form.setData("skill_id", v)}
|
||||
/>
|
||||
<Select
|
||||
label="Território"
|
||||
options={props.territories}
|
||||
value={form.data.geo_location_id}
|
||||
onChange={(v) => form.setData("geo_location_id", v)}
|
||||
/>
|
||||
<div className="md:col-span-2">
|
||||
<TerritoryFields
|
||||
key={territoryResetKey}
|
||||
endpoint="/management/territory-options"
|
||||
onChange={(path) =>
|
||||
form.setData("geo_location_id", path[path.length - 1]?.id ?? "")
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
{demand && (
|
||||
<Field label="Empregador declarante">
|
||||
<input
|
||||
@@ -389,20 +411,15 @@ export default function Index(props: Props) {
|
||||
<option value="expired">Fonte expirada</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Território">
|
||||
<select
|
||||
className={control}
|
||||
value={search.data.geo_location_id}
|
||||
onChange={(e) => search.setData("geo_location_id", e.target.value)}
|
||||
>
|
||||
<option value="">Todos</option>
|
||||
{props.territories.map((t) => (
|
||||
<option key={t.id} value={t.id}>
|
||||
{t.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
<div className="md:col-span-2">
|
||||
<TerritoryFields
|
||||
initial={territoryPath(search.data.geo_location_id, props.territories)}
|
||||
endpoint="/management/territory-options"
|
||||
onChange={(path) =>
|
||||
search.setData("geo_location_id", path[path.length - 1]?.id ?? "")
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<button className={button} disabled={search.processing}>
|
||||
Filtrar
|
||||
|
||||
@@ -17,6 +17,7 @@ export default function Catalogue({
|
||||
favourites,
|
||||
territorial,
|
||||
territorySelection,
|
||||
catalogueUrl,
|
||||
}: {
|
||||
filters: Record<string, string | string[] | boolean>;
|
||||
references: References;
|
||||
@@ -28,6 +29,7 @@ export default function Catalogue({
|
||||
};
|
||||
favourites: number[];
|
||||
territorySelection: TerritoryOption[];
|
||||
catalogueUrl: string;
|
||||
territorial: {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -87,7 +89,7 @@ export default function Catalogue({
|
||||
const data = JSON.parse(draftFilterKey);
|
||||
lastRequest.current = draftFilterKey;
|
||||
router.get(
|
||||
"/oportunidades",
|
||||
catalogueUrl,
|
||||
{ ...data, education: data.education ? 1 : 0 },
|
||||
{
|
||||
preserveState: true,
|
||||
@@ -103,7 +105,7 @@ export default function Catalogue({
|
||||
clearTimeout(timer);
|
||||
cancel?.();
|
||||
};
|
||||
}, [draftFilterKey]);
|
||||
}, [draftFilterKey, catalogueUrl]);
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
const values = JSON.parse(filterKey) as Record<string, string | string[] | boolean>;
|
||||
@@ -180,7 +182,7 @@ export default function Catalogue({
|
||||
const params = new URLSearchParams(query());
|
||||
params.set("dimension", dimension);
|
||||
params.delete("page");
|
||||
return `/oportunidades?${params}`;
|
||||
return `${catalogueUrl}?${params}`;
|
||||
};
|
||||
return (
|
||||
<Frame
|
||||
@@ -212,7 +214,7 @@ export default function Catalogue({
|
||||
setComparison([]);
|
||||
setSelected([]);
|
||||
form.transform((data) => ({ ...data, education: data.education ? 1 : 0 }));
|
||||
form.get("/oportunidades", { preserveState: true });
|
||||
form.get(catalogueUrl, { preserveState: true });
|
||||
}}
|
||||
>
|
||||
<Field label="Pesquisar oportunidades">
|
||||
@@ -455,7 +457,7 @@ export default function Catalogue({
|
||||
<button className={button} disabled={form.processing}>
|
||||
Aplicar filtros
|
||||
</button>
|
||||
<Link href="/oportunidades" className="underline">
|
||||
<Link href={catalogueUrl} className="underline">
|
||||
Limpar filtros
|
||||
</Link>
|
||||
</div>
|
||||
@@ -475,7 +477,7 @@ export default function Catalogue({
|
||||
onClick={() => {
|
||||
const params = new URLSearchParams(query());
|
||||
params.set("view", value);
|
||||
router.get(`/oportunidades?${params}`, {}, { preserveScroll: true });
|
||||
router.get(`${catalogueUrl}?${params}`, {}, { preserveScroll: true });
|
||||
}}
|
||||
>
|
||||
{["Grelha", "Lista", "Mapa", "Lista e mapa"][i]}
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Head, Link, useForm, usePage } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { PortalMenu } from "@/layouts/portal-navigation";
|
||||
import { newSubmissionKey } from "@/lib/portal-api";
|
||||
import { ProvinceSelect } from "@/components/investment-territory";
|
||||
|
||||
const input = "w-full rounded-lg border border-slate-300 bg-white p-3 text-slate-900";
|
||||
const button =
|
||||
@@ -249,14 +250,25 @@ function PartnershipForm() {
|
||||
seeking: "Parceiro ou capacidade que procura",
|
||||
}[key]
|
||||
}
|
||||
<textarea
|
||||
className={input}
|
||||
required
|
||||
minLength={key === "offer" || key === "seeking" ? 20 : 1}
|
||||
maxLength={key === "offer" || key === "seeking" ? 2000 : 100}
|
||||
value={form.data[key]}
|
||||
onChange={(e) => form.setData(key, e.target.value)}
|
||||
/>
|
||||
{key === "province" ? (
|
||||
<ProvinceSelect
|
||||
value={form.data.province}
|
||||
onChange={(province) => form.setData("province", province)}
|
||||
className={input}
|
||||
required
|
||||
placeholder="Seleccione uma província"
|
||||
label="Província"
|
||||
/>
|
||||
) : (
|
||||
<textarea
|
||||
className={input}
|
||||
required
|
||||
minLength={key === "offer" || key === "seeking" ? 20 : 1}
|
||||
maxLength={key === "offer" || key === "seeking" ? 2000 : 100}
|
||||
value={form.data[key]}
|
||||
onChange={(e) => form.setData(key, e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
<label className="flex gap-2">
|
||||
@@ -680,11 +692,23 @@ export default function Services(p: Props) {
|
||||
key
|
||||
]
|
||||
}
|
||||
<input
|
||||
className={input}
|
||||
value={filter.data[key]}
|
||||
onChange={(e) => filter.setData(key, e.target.value)}
|
||||
/>
|
||||
{key === "province" ? (
|
||||
<ProvinceSelect
|
||||
value={filter.data.province}
|
||||
onChange={(province) =>
|
||||
filter.setData("province", province)
|
||||
}
|
||||
className={input}
|
||||
placeholder="Todas as províncias"
|
||||
label="Filtrar por província"
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className={input}
|
||||
value={filter.data[key]}
|
||||
onChange={(e) => filter.setData(key, e.target.value)}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
<button className={button}>Filtrar</button>
|
||||
|
||||
Reference in New Issue
Block a user