@@ -119,7 +119,7 @@ export default function Zones({
|
||||
}}
|
||||
>
|
||||
<h2 className="text-xl font-bold">Criar rascunho</h2>
|
||||
<TerritoryFields />
|
||||
<TerritoryFields endpoint="/management/territory-options" />
|
||||
<Field label="Código">
|
||||
<input name="code" className={input} required maxLength={80} />
|
||||
</Field>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
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";
|
||||
@@ -40,10 +39,12 @@ export default function Editor({
|
||||
resource,
|
||||
record,
|
||||
sectors,
|
||||
territoryPath = [],
|
||||
}: {
|
||||
resource: "sectors" | "opportunities";
|
||||
record: Entry | null;
|
||||
sectors: { id: number; name: string }[];
|
||||
territoryPath?: TerritoryOption[];
|
||||
}) {
|
||||
const isSector = resource === "sectors";
|
||||
const fields = isSector ? sectorFields : opportunityFields;
|
||||
@@ -66,9 +67,13 @@ export default function Editor({
|
||||
initial.maturity_level = String(record?.maturity_level ?? "");
|
||||
initial.status = String(record?.status ?? "draft");
|
||||
initial.is_featured = Boolean(record?.is_featured ?? false);
|
||||
initial.territory_version = String(record?.territory_version ?? 0);
|
||||
["province_id", "district_id", "admin_post_id", "locality_id"].forEach((field, index) => {
|
||||
initial[field] = territoryPath[index]?.id ?? "";
|
||||
});
|
||||
}
|
||||
const form = useForm<Values>(initial);
|
||||
const [creationPath, setCreationPath] = useState<TerritoryOption[]>([]);
|
||||
const [creationPath, setCreationPath] = useState<TerritoryOption[]>(territoryPath);
|
||||
return (
|
||||
<Management
|
||||
title={`${record ? "Editar" : "Criar"} ${isSector ? "sector" : "oportunidade"}`}
|
||||
@@ -87,7 +92,7 @@ export default function Editor({
|
||||
}}
|
||||
>
|
||||
<fieldset disabled={form.processing} className="space-y-5">
|
||||
{!isSector && !record && (
|
||||
{!isSector && (
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{(
|
||||
[
|
||||
@@ -102,7 +107,8 @@ export default function Editor({
|
||||
index={index}
|
||||
parent={creationPath[index - 1]?.id ?? ""}
|
||||
selected={creationPath[index]}
|
||||
endpoint="/api/v1/investment/territory-options"
|
||||
endpoint="/management/territory-options"
|
||||
fieldError={form.errors[key]}
|
||||
onChange={(value) => {
|
||||
const path = [
|
||||
...creationPath.slice(0, index),
|
||||
@@ -214,7 +220,6 @@ export default function Editor({
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{!isSector && record && <InvestmentTerritory kind="opportunities" id={record.id} />}
|
||||
{!isSector && record && <InvestmentCoordinates id={record.id} />}
|
||||
</Management>
|
||||
);
|
||||
|
||||
@@ -108,6 +108,7 @@ export default function Editor({
|
||||
<p>Registo interno de gestão. O estado activo não publica este conteúdo no portal.</p>
|
||||
{!record && (
|
||||
<TerritoryFields
|
||||
endpoint="/management/territory-options"
|
||||
onChange={(path) =>
|
||||
form.setData((data) => ({
|
||||
...data,
|
||||
|
||||
Reference in New Issue
Block a user