import { useEffect, useId } from 'react'; import CountrySelect, { type Country } from './country-select'; import OrganizationCountryReuse from './organization-country-reuse'; import { Field, input, button } from '@/pages/investment/shared'; import { useInvestmentProfileEditor, type ProfileRecord, type OrganizationRecord, } from '@/lib/investment-profile-editor'; export default function InvestmentProfileEditor({ record, fields, countries, company = false, actorId, editorId, reportDirty, labels, organizations = [], }: { record: ProfileRecord; fields: string[]; countries: Country[]; company?: boolean; actorId: number; editorId: string; reportDirty: (id: string, dirty: boolean) => void; labels: Record; organizations?: OrganizationRecord[]; }) { const isCompany = company || !!record.id; const editor = useInvestmentProfileEditor( record, fields, isCompany, actorId, editorId, reportDirty, ); const id = useId(), disabled = editor.busy || editor.uncertain || editor.blocked || editor.externalBusy; useEffect(() => { if (Object.keys(editor.errors).length) document .getElementById(id) ?.querySelector('[aria-invalid="true"]') ?.focus(); }, [editor.errors, id]); const fieldErrorKeys = [ ...fields.map((key) => 'payload.' + key), ...(isCompany ? ['payload.country'] : []), ]; return ( <>
{ event.preventDefault(); void editor.save(); }} >
{record.payload.country && (

País anteriormente registado:{' '} {record.payload.country}. Conservado sem atribuir automaticamente residência, constituição ou origem da solicitação.

)} {fields.map((key) => { const fieldId = id + '-' + key, error = editor.errors['payload.' + key] ?? (key === 'incorporation_country_code' ? editor.errors['payload.country'] : undefined), long = [ 'description', 'experience', 'investment_capacity', ].includes(key); return ( {key.endsWith('_country_code') ? ( editor.change(key, value) } /> ) : long ? (