@@ -1,3 +1,8 @@
|
||||
import {
|
||||
ClassificationEditor,
|
||||
type ClassificationOptions,
|
||||
type ClassificationRelation,
|
||||
} from './opportunity-classification';
|
||||
import { valueText } from '@/lib/value-text';
|
||||
import OpportunityParcelGeometry from './opportunity-parcel-geometry';
|
||||
import TerritoryGeometryPreview from './territory-geometry-preview';
|
||||
@@ -27,11 +32,15 @@ function resourceTerritory(resource?: Resource) {
|
||||
return typeof id === 'string' ? id : undefined;
|
||||
}
|
||||
export type CanonicalOptions = {
|
||||
classification?: ClassificationOptions;
|
||||
version: string;
|
||||
modularProfiles?: Record<string, string>;
|
||||
historyVersion?: string | null;
|
||||
schema: Schema;
|
||||
submissionTextLimits?: Record<string, { minLength?: number; maxLength?: number }>;
|
||||
submissionTextLimits?: Record<
|
||||
string,
|
||||
{ minLength?: number; maxLength?: number }
|
||||
>;
|
||||
definitions: Record<string, Schema>;
|
||||
contacts: { id: string; full_name: string }[];
|
||||
contactInvestors?: { id: string; legal_name: string }[];
|
||||
@@ -205,6 +214,7 @@ const labels: Record<string, string> = {
|
||||
environmental_social: 'Aspetos ambientais e sociais',
|
||||
risks: 'Riscos',
|
||||
relations: 'Relações',
|
||||
enterprise_size: 'Dimensão empresarial declarada (separada do setor)',
|
||||
amount: 'Montante',
|
||||
name: 'Nome',
|
||||
label: 'Designação',
|
||||
@@ -316,11 +326,19 @@ function Editor({
|
||||
schema = options.definitions[schema.$ref.split('/').pop()!] ?? schema;
|
||||
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
||||
const label = labels[name] ?? name.replaceAll('_', ' ');
|
||||
const parcelUnit = name === 'area_unit' && path.includes('land_rights.parcels.');
|
||||
const textLimits = path === 'canonical.demand_statement'
|
||||
? options.submissionTextLimits?.demand_statement
|
||||
: undefined;
|
||||
const descriptions = [errors[path] ? path + '-error' : '', parcelUnit ? path + '-help' : '', textLimits ? path + '-length-help' : ''].filter(Boolean).join(' ');
|
||||
const parcelUnit =
|
||||
name === 'area_unit' && path.includes('land_rights.parcels.');
|
||||
const textLimits =
|
||||
path === 'canonical.demand_statement'
|
||||
? options.submissionTextLimits?.demand_statement
|
||||
: undefined;
|
||||
const descriptions = [
|
||||
errors[path] ? path + '-error' : '',
|
||||
parcelUnit ? path + '-help' : '',
|
||||
textLimits ? path + '-length-help' : '',
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
const props = {
|
||||
id: path,
|
||||
'aria-invalid': !!errors[path],
|
||||
@@ -416,7 +434,12 @@ function Editor({
|
||||
.map((v) => (
|
||||
<option key={valueText(v)} value={valueText(v)}>
|
||||
{name === 'area_unit'
|
||||
? ({ sqm: 'Metros quadrados (m²)', ha: 'Hectares (ha)', sqkm: 'Quilómetros quadrados (km²)' }[valueText(v) as 'sqm' | 'ha' | 'sqkm'] ?? valueText(v))
|
||||
? ({
|
||||
sqm: 'Metros quadrados (m²)',
|
||||
ha: 'Hectares (ha)',
|
||||
sqkm: 'Quilómetros quadrados (km²)',
|
||||
}[valueText(v) as 'sqm' | 'ha' | 'sqkm'] ??
|
||||
valueText(v))
|
||||
: valueText(v).replaceAll('_', ' ')}
|
||||
</option>
|
||||
))}
|
||||
@@ -563,10 +586,11 @@ function Editor({
|
||||
{input}
|
||||
{textLimits && (
|
||||
<p id={path + '-length-help'} className="text-sm text-gray-600">
|
||||
Descreva a necessidade e a finalidade da oportunidade.
|
||||
Para submeter: {textLimits.minLength} a {textLimits.maxLength} caracteres.
|
||||
Texto atual: {Array.from(valueText(value ?? '').trim()).length} caracteres.
|
||||
Pode guardar o rascunho incompleto.
|
||||
Descreva a necessidade e a finalidade da oportunidade. Para
|
||||
submeter: {textLimits.minLength} a {textLimits.maxLength}{' '}
|
||||
caracteres. Texto atual:{' '}
|
||||
{Array.from(valueText(value ?? '').trim()).length}{' '}
|
||||
caracteres. Pode guardar o rascunho incompleto.
|
||||
</p>
|
||||
)}
|
||||
{parcelUnit && (
|
||||
@@ -636,6 +660,8 @@ export default function OpportunityCanonicalFields({
|
||||
'review_due_date',
|
||||
'images',
|
||||
'truth_declaration',
|
||||
'enterprise_size',
|
||||
'relations',
|
||||
];
|
||||
const specialized =
|
||||
category === 'real_estate'
|
||||
@@ -788,6 +814,55 @@ export default function OpportunityCanonicalFields({
|
||||
</p>
|
||||
)}
|
||||
{Array.from(new Set([...common, ...specialized])).map((key) => {
|
||||
if (key === 'relations' && options.classification) {
|
||||
const rows = (value.relations ??
|
||||
[]) as ClassificationRelation[];
|
||||
const legacySchema = options.definitions.relationCreate;
|
||||
return (
|
||||
<div key={key} className="space-y-4">
|
||||
<ClassificationEditor
|
||||
rows={rows}
|
||||
onChange={(rows) => set('relations', rows)}
|
||||
options={options.classification}
|
||||
documents={options.resources.documents ?? []}
|
||||
authorities={options.authorities}
|
||||
errors={errors}
|
||||
/>
|
||||
{rows.map((row, i) =>
|
||||
!row.classification ? (
|
||||
<Editor
|
||||
key={i}
|
||||
name={`Relação anterior ${i + 1}`}
|
||||
path={`canonical.relations.${i}`}
|
||||
schema={{
|
||||
...legacySchema,
|
||||
properties: Object.fromEntries(
|
||||
Object.entries(
|
||||
legacySchema.properties ??
|
||||
{},
|
||||
).filter(
|
||||
([k]) =>
|
||||
k !== 'classification',
|
||||
),
|
||||
),
|
||||
}}
|
||||
value={row}
|
||||
options={options}
|
||||
errors={errors}
|
||||
onChange={(v) =>
|
||||
set(
|
||||
'relations',
|
||||
rows.map((r, j) =>
|
||||
j === i ? v : r,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : null,
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (key === 'module_profile_version') {
|
||||
const current = valueText(value[key] ?? '');
|
||||
const version =
|
||||
|
||||
Reference in New Issue
Block a user