This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user