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