@@ -2,9 +2,25 @@ import { Link, router, useForm } from '@inertiajs/react';
|
||||
import { Frame, Field, input, button, card } from './shared';
|
||||
import PartnershipSourceLinks from '@/components/partnership-source-links';
|
||||
import CountrySelect, { type Country } from '@/components/country-select';
|
||||
import { useEffect, useId } from 'react';
|
||||
|
||||
type RecordData = { version: number; payload: Record<string, string> };
|
||||
type Company = RecordData & { id: string };
|
||||
type Company = RecordData & {
|
||||
id: string;
|
||||
countrySource?: {
|
||||
organization_id: string;
|
||||
organization_version: number;
|
||||
country: string;
|
||||
} | null;
|
||||
};
|
||||
type Organization = {
|
||||
id: string;
|
||||
name: string;
|
||||
version: number;
|
||||
country: string | null;
|
||||
canEdit: boolean;
|
||||
provenance: { reference: string; kind: string } | null;
|
||||
};
|
||||
const labels: Record<string, string> = {
|
||||
phone: 'Telefone',
|
||||
country: 'País anteriormente registado',
|
||||
@@ -23,10 +39,14 @@ export default function Profile({
|
||||
account,
|
||||
companies,
|
||||
countries,
|
||||
organizations = [],
|
||||
organizationCountryAvailable = false,
|
||||
}: {
|
||||
account: RecordData;
|
||||
companies: Company[];
|
||||
countries: Country[];
|
||||
organizations?: Organization[];
|
||||
organizationCountryAvailable?: boolean;
|
||||
}) {
|
||||
return (
|
||||
<Frame title="Perfil de investimento e empresas">
|
||||
@@ -65,6 +85,21 @@ export default function Profile({
|
||||
<h3 className="text-xl font-bold">
|
||||
{company.payload.name}
|
||||
</h3>
|
||||
{company.countrySource && (
|
||||
<p>
|
||||
País reutilizado: {company.countrySource.country};
|
||||
organização{' '}
|
||||
{organizations.find(
|
||||
(o) =>
|
||||
o.id ===
|
||||
company.countrySource?.organization_id,
|
||||
)?.name ?? company.countrySource.organization_id}
|
||||
, versão{' '}
|
||||
{company.countrySource.organization_version}. O
|
||||
valor é uma cópia identificada; não é atualizado
|
||||
automaticamente quando o cadastro mestre muda.
|
||||
</p>
|
||||
)}
|
||||
<Editor
|
||||
key={company.version}
|
||||
record={company}
|
||||
@@ -78,6 +113,35 @@ export default function Profile({
|
||||
'description',
|
||||
]}
|
||||
/>
|
||||
{organizations
|
||||
.filter((o) => o.country)
|
||||
.map((org) => (
|
||||
<div key={org.id} className="mt-3 space-y-2">
|
||||
<p>
|
||||
País mestre de {org.name}: {org.country}. A
|
||||
reutilização altera somente esta declaração;
|
||||
manifestações anteriores conservam o seu
|
||||
valor.
|
||||
</p>
|
||||
<button
|
||||
className={button}
|
||||
onClick={() =>
|
||||
router.post(
|
||||
`/investidor/companies/${company.id}/organization-country`,
|
||||
{
|
||||
version: company.version,
|
||||
organization_id: org.id,
|
||||
organization_version:
|
||||
org.version,
|
||||
},
|
||||
{ preserveScroll: true },
|
||||
)
|
||||
}
|
||||
>
|
||||
Reutilizar país de {org.name}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
className={button + ' mt-4'}
|
||||
onClick={() =>
|
||||
@@ -109,9 +173,129 @@ export default function Profile({
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
<h2 className="text-2xl font-bold">
|
||||
Organizações representadas — cadastro mestre
|
||||
</h2>
|
||||
<p>
|
||||
O país de constituição é independente da residência e da origem
|
||||
da solicitação. Não se associa uma empresa privada a uma
|
||||
organização por semelhança de nome. A declaração do
|
||||
representante não é uma decisão externa nem comprova por si a
|
||||
representação legal.
|
||||
</p>
|
||||
{!organizationCountryAvailable && (
|
||||
<p role="status">
|
||||
Extensão do país de constituição ainda não instalada neste
|
||||
ambiente.
|
||||
</p>
|
||||
)}
|
||||
{organizationCountryAvailable && organizations.length === 0 && (
|
||||
<p>
|
||||
Sem representação organizacional registada para esta conta.
|
||||
</p>
|
||||
)}
|
||||
{organizations.map((org) => (
|
||||
<OrganizationEditor
|
||||
key={org.id + org.version}
|
||||
organization={org}
|
||||
countries={countries}
|
||||
/>
|
||||
))}
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
function OrganizationEditor({
|
||||
organization,
|
||||
countries,
|
||||
}: {
|
||||
organization: Organization;
|
||||
countries: Country[];
|
||||
}) {
|
||||
const form = useForm({
|
||||
version: organization.version,
|
||||
country: organization.country ?? '',
|
||||
source_reference: organization.provenance?.reference ?? '',
|
||||
});
|
||||
const id = useId();
|
||||
useEffect(() => {
|
||||
if (Object.keys(form.errors).length)
|
||||
document
|
||||
.getElementById(id)
|
||||
?.querySelector<HTMLElement>('[aria-invalid="true"]')
|
||||
?.focus();
|
||||
}, [form.errors, id]);
|
||||
return (
|
||||
<section
|
||||
className={card}
|
||||
aria-label={`Cadastro mestre: ${organization.name}`}
|
||||
>
|
||||
<h3 className="text-xl font-bold">{organization.name}</h3>
|
||||
<p>
|
||||
Versão {organization.version}; origem do país:{' '}
|
||||
{organization.provenance?.kind === 'representative_declaration'
|
||||
? 'declaração do representante'
|
||||
: 'não informada'}
|
||||
.
|
||||
</p>
|
||||
<form
|
||||
className="mt-4 space-y-4"
|
||||
id={id}
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.put(
|
||||
`/investidor/organizations/${organization.id}/country`,
|
||||
{ preserveScroll: true },
|
||||
);
|
||||
}}
|
||||
>
|
||||
<Field label="País de constituição da organização">
|
||||
<CountrySelect
|
||||
id={id + '-country'}
|
||||
label="País de constituição da organização"
|
||||
countries={countries}
|
||||
value={form.data.country}
|
||||
disabled={!organization.canEdit}
|
||||
error={form.errors.country}
|
||||
onChange={(country) => form.setData('country', country)}
|
||||
/>
|
||||
</Field>
|
||||
<label className="block" htmlFor={id + '-source'}>
|
||||
Fonte ou referência deste país
|
||||
</label>
|
||||
<textarea
|
||||
id={id + '-source'}
|
||||
className={input}
|
||||
value={form.data.source_reference}
|
||||
disabled={!organization.canEdit}
|
||||
maxLength={2000}
|
||||
aria-invalid={!!form.errors.source_reference}
|
||||
aria-describedby={
|
||||
form.errors.source_reference
|
||||
? id + '-source-error'
|
||||
: undefined
|
||||
}
|
||||
onChange={(event) =>
|
||||
form.setData('source_reference', event.target.value)
|
||||
}
|
||||
/>
|
||||
{form.errors.source_reference && (
|
||||
<p id={id + '-source-error'} role="alert">
|
||||
{form.errors.source_reference}
|
||||
</p>
|
||||
)}
|
||||
{form.errors.version && (
|
||||
<p role="alert">{form.errors.version}</p>
|
||||
)}
|
||||
<button
|
||||
className={button}
|
||||
disabled={!organization.canEdit || form.processing}
|
||||
>
|
||||
Guardar país no cadastro mestre
|
||||
</button>
|
||||
</form>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
function Editor({
|
||||
record,
|
||||
fields,
|
||||
@@ -162,6 +346,8 @@ function Editor({
|
||||
<CountrySelect
|
||||
id={key + (record.id ?? 'account')}
|
||||
countries={countries}
|
||||
label={labels[key]}
|
||||
error={form.errors[`payload.${key}`]}
|
||||
value={form.data.payload[key]}
|
||||
onChange={(value) =>
|
||||
form.setData('payload', {
|
||||
@@ -194,11 +380,12 @@ function Editor({
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{form.errors[`payload.${key}`] && (
|
||||
<p role="alert" className="text-red-700">
|
||||
{form.errors[`payload.${key}`]}
|
||||
</p>
|
||||
)}
|
||||
{!key.endsWith('_country_code') &&
|
||||
form.errors[`payload.${key}`] && (
|
||||
<p role="alert" className="text-red-700">
|
||||
{form.errors[`payload.${key}`]}
|
||||
</p>
|
||||
)}
|
||||
</Field>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user