feat(offers): implement phase four private details and confidentiality in QA
This commit is contained in:
@@ -0,0 +1,279 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { profileJson } from '@/lib/profile-json';
|
||||
type Acceptance = { id: string; actor_id: number; version_hash: string };
|
||||
type Grant = { interested_user_id: number; version_hash: string };
|
||||
type Overview = {
|
||||
seller: boolean;
|
||||
nda_pending: boolean;
|
||||
can_accept: boolean;
|
||||
can_authorize: boolean;
|
||||
version_hash: string | null;
|
||||
nda: { sha256: string; version: number; fingerprint: string } | null;
|
||||
requests: Acceptance[];
|
||||
grants: Grant[];
|
||||
acceptance: Acceptance | null;
|
||||
etag: string | null;
|
||||
history: { id: string; action: string; at: string; version_hash: string }[];
|
||||
};
|
||||
export default function OfferConfidentialAccess({
|
||||
id,
|
||||
onChanged,
|
||||
}: {
|
||||
id: number;
|
||||
onChanged?: (etag: string) => void;
|
||||
}) {
|
||||
const [overview, setOverview] = useState<Overview | null>(null);
|
||||
const [confirm, setConfirm] = useState(false);
|
||||
const [reason, setReason] = useState('');
|
||||
const [message, setMessage] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [business, setBusiness] = useState<Record<
|
||||
string,
|
||||
string | number | null
|
||||
> | null>(null);
|
||||
const base = `/minhas-oportunidades/ofertas/${id}`;
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
profileJson(`${base}/confidencialidade`, {}, 'GET')
|
||||
.then((result) => {
|
||||
if (active) setOverview(result);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (active) setMessage(error.message);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [base]);
|
||||
async function act(action: string, target?: Acceptance | Grant) {
|
||||
if (!overview || !confirm || busy) return;
|
||||
setBusy(true);
|
||||
setBusiness(null);
|
||||
try {
|
||||
await profileJson(`${base}/confidencialidade`, {
|
||||
action,
|
||||
confirm,
|
||||
reason,
|
||||
version_hash: target?.version_hash ?? overview.version_hash,
|
||||
nda_sha256: overview.nda?.sha256,
|
||||
nda_fingerprint: overview.nda?.fingerprint,
|
||||
interested_user_id:
|
||||
target &&
|
||||
('actor_id' in target
|
||||
? target.actor_id
|
||||
: target.interested_user_id),
|
||||
acceptance_id: target && 'id' in target ? target.id : undefined,
|
||||
});
|
||||
const next = await profileJson(
|
||||
`${base}/confidencialidade`,
|
||||
{},
|
||||
'GET',
|
||||
);
|
||||
setOverview(next);
|
||||
if (typeof next.etag === 'string') onChanged?.(next.etag);
|
||||
setConfirm(false);
|
||||
setMessage('Decisão registada para a versão indicada.');
|
||||
} catch (error) {
|
||||
setMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Não foi possível registar.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
async function read() {
|
||||
setBusy(true);
|
||||
setBusiness(null);
|
||||
try {
|
||||
const result = await profileJson(`${base}/confidencial`, {}, 'GET');
|
||||
setBusiness(result.business);
|
||||
setMessage('Acesso autorizado e registado para esta versão.');
|
||||
} catch (error) {
|
||||
setMessage(
|
||||
error instanceof Error ? error.message : 'Acesso indisponível.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
const labels: Record<string, string> = {
|
||||
sector: 'Sector principal',
|
||||
secondary_sector: 'Sector secundário',
|
||||
revenue: 'Receita',
|
||||
cash_flow: 'Lucro / fluxo de caixa',
|
||||
currency: 'Moeda',
|
||||
reason: 'Motivo da venda',
|
||||
availability: 'Disponibilidade declarada',
|
||||
};
|
||||
return (
|
||||
<section className="space-y-3 rounded-lg border p-4">
|
||||
<h2 className="font-semibold">Acesso confidencial à empresa</h2>
|
||||
<p>
|
||||
O acesso depende da aceitação do NDA e da autorização expressa
|
||||
do vendedor para a mesma versão.
|
||||
</p>
|
||||
{overview?.nda_pending && (
|
||||
<p>
|
||||
O exemplar aprovado do NDA ainda não foi disponibilizado. O
|
||||
acesso confidencial mantém-se fechado.
|
||||
</p>
|
||||
)}
|
||||
{overview?.nda && (
|
||||
<a className="underline" href={`${base}/nda`}>
|
||||
Consultar NDA — versão {overview.nda.version}
|
||||
</a>
|
||||
)}
|
||||
{overview && (
|
||||
<fieldset disabled={busy} className="space-y-3">
|
||||
<label className="block">
|
||||
{overview.seller
|
||||
? 'Fundamento da decisão'
|
||||
: 'Observação (opcional)'}
|
||||
<textarea
|
||||
className="block w-full rounded border p-2"
|
||||
minLength={overview.seller ? 20 : undefined}
|
||||
maxLength={1000}
|
||||
value={reason}
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={confirm}
|
||||
onChange={(e) => setConfirm(e.target.checked)}
|
||||
/>
|
||||
{overview.seller
|
||||
? 'Confirmo a decisão expressa para o interessado e versão indicados.'
|
||||
: 'Confirmo a operação para o exemplar e a versão indicados.'}
|
||||
</label>
|
||||
{!overview.seller && (
|
||||
<div className="flex flex-wrap gap-3">
|
||||
<button
|
||||
type="button"
|
||||
className="rounded border p-2"
|
||||
disabled={!confirm || !overview.can_accept}
|
||||
onClick={() => void act('accept')}
|
||||
>
|
||||
Li e aceito — registar aceitação
|
||||
</button>
|
||||
{overview.acceptance && (
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={!confirm}
|
||||
onClick={() =>
|
||||
void act(
|
||||
'withdraw',
|
||||
overview.acceptance!,
|
||||
)
|
||||
}
|
||||
>
|
||||
Retirar aceitação
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={overview.nda_pending}
|
||||
onClick={() => void read()}
|
||||
>
|
||||
Consultar dados autorizados
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{overview.seller && (
|
||||
<>
|
||||
<ul className="space-y-2">
|
||||
{overview.requests.map((item) => (
|
||||
<li
|
||||
key={item.id}
|
||||
className="flex flex-wrap gap-3"
|
||||
>
|
||||
Interessado #{item.actor_id} · versão{' '}
|
||||
{item.version_hash.slice(0, 12)}
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={
|
||||
!confirm ||
|
||||
reason.trim().length < 20 ||
|
||||
!overview.can_authorize ||
|
||||
overview.version_hash !==
|
||||
item.version_hash
|
||||
}
|
||||
onClick={() =>
|
||||
void act('authorize', item)
|
||||
}
|
||||
>
|
||||
Autorizar esta aceitação
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<ul>
|
||||
{overview.grants.map((item) => (
|
||||
<li key={item.interested_user_id}>
|
||||
Autorização ao interessado #
|
||||
{item.interested_user_id}
|
||||
<button
|
||||
type="button"
|
||||
className="ml-3 underline"
|
||||
disabled={
|
||||
!confirm ||
|
||||
reason.trim().length < 20
|
||||
}
|
||||
onClick={() =>
|
||||
void act('revoke', item)
|
||||
}
|
||||
>
|
||||
Revogar
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</>
|
||||
)}
|
||||
</fieldset>
|
||||
)}
|
||||
{overview && overview.history.length > 0 && (
|
||||
<details>
|
||||
<summary>Histórico de acesso e decisões</summary>
|
||||
<ul className="mt-3 space-y-2">
|
||||
{overview.history.map((event) => (
|
||||
<li key={event.id}>
|
||||
{(
|
||||
{
|
||||
accept: 'Aceitação do NDA',
|
||||
authorize: 'Autorização do vendedor',
|
||||
revoke: 'Autorização revogada',
|
||||
withdraw: 'Aceitação retirada',
|
||||
} as Record<string, string>
|
||||
)[event.action] ?? 'Decisão registada'}{' '}
|
||||
· {new Date(event.at).toLocaleString('pt-MZ')} ·
|
||||
versão {event.version_hash.slice(0, 12)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
{business && (
|
||||
<dl className="grid gap-2 sm:grid-cols-2">
|
||||
{Object.entries(business).map(([key, value]) => (
|
||||
<div key={key}>
|
||||
<dt className="font-semibold">
|
||||
{labels[key] ?? key}
|
||||
</dt>
|
||||
<dd className="break-words">
|
||||
{value ?? 'Não indicado'}
|
||||
</dd>
|
||||
</div>
|
||||
))}
|
||||
</dl>
|
||||
)}
|
||||
<p role="status">{message}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
export type OfferParticulars = {
|
||||
business?: Record<string, string | number | null> | null;
|
||||
property?: Record<string, string | number | string[] | null> | null;
|
||||
};
|
||||
const control = 'w-full min-w-0 rounded-md border p-2';
|
||||
const propertyLabels: Record<string, string> = {
|
||||
house: 'Casa',
|
||||
apartment: 'Apartamento',
|
||||
office: 'Escritório',
|
||||
retail: 'Espaço comercial',
|
||||
warehouse: 'Armazém',
|
||||
hospitality: 'Hotelaria',
|
||||
industrial: 'Industrial',
|
||||
mixed_use: 'Uso misto',
|
||||
development: 'Empreendimento',
|
||||
other: 'Outro',
|
||||
};
|
||||
|
||||
export default function OfferParticularsFields({
|
||||
value,
|
||||
category,
|
||||
sectors,
|
||||
propertyTypes,
|
||||
disabled,
|
||||
onChange,
|
||||
}: {
|
||||
value: OfferParticulars;
|
||||
category: string;
|
||||
sectors: { id: number; name: string }[];
|
||||
propertyTypes: string[];
|
||||
disabled: boolean;
|
||||
onChange: (next: OfferParticulars) => void;
|
||||
}) {
|
||||
if (!['business_sale', 'real_estate'].includes(category)) return null;
|
||||
const business = category === 'business_sale';
|
||||
const group = business ? 'business' : 'property';
|
||||
const data = value[group] ?? {};
|
||||
const update = (key: string, next: string | string[] | null) =>
|
||||
onChange({ ...value, [group]: { ...data, [key]: next } });
|
||||
const text = (key: string, label: string, numeric = false) => (
|
||||
<label key={key} className="space-y-1">
|
||||
{label}
|
||||
<input
|
||||
className={control}
|
||||
value={String(data[key] ?? '')}
|
||||
inputMode={numeric ? 'decimal' : 'text'}
|
||||
maxLength={numeric ? 30 : 1000}
|
||||
onChange={(e) => update(key, e.target.value || null)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
const select = (
|
||||
key: string,
|
||||
label: string,
|
||||
options: { value: string; label: string }[],
|
||||
) => (
|
||||
<label key={key} className="space-y-1">
|
||||
{label}
|
||||
<select
|
||||
className={control}
|
||||
value={String(data[key] ?? '')}
|
||||
onChange={(e) => update(key, e.target.value || null)}
|
||||
>
|
||||
<option value="">Por indicar</option>
|
||||
{options.map((item) => (
|
||||
<option key={item.value} value={item.value}>
|
||||
{item.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<fieldset
|
||||
disabled={disabled}
|
||||
className="space-y-4 rounded-lg border p-4"
|
||||
>
|
||||
<legend className="px-2 font-semibold">
|
||||
{business
|
||||
? 'Dados da empresa — acesso reservado'
|
||||
: 'Características do imóvel'}
|
||||
</legend>
|
||||
<p className="text-sm">
|
||||
Campos opcionais durante a preparação. A gravação não publica
|
||||
estes dados.
|
||||
</p>
|
||||
<div className="grid min-w-0 gap-4 sm:grid-cols-2">
|
||||
{business ? (
|
||||
<>
|
||||
{['sector_id', 'secondary_sector_id'].map(
|
||||
(key, index) =>
|
||||
select(
|
||||
key,
|
||||
index
|
||||
? 'Sector secundário'
|
||||
: 'Sector principal',
|
||||
sectors.map((sector) => ({
|
||||
value: String(sector.id),
|
||||
label: sector.name,
|
||||
})),
|
||||
),
|
||||
)}
|
||||
{text('revenue', 'Receita resumida', true)}
|
||||
{text(
|
||||
'cash_flow',
|
||||
'Lucro ou fluxo de caixa resumido',
|
||||
true,
|
||||
)}
|
||||
{select('currency', 'Moeda dos valores da empresa', [
|
||||
{ value: 'MZN', label: 'MZN' },
|
||||
{ value: 'USD', label: 'USD' },
|
||||
])}
|
||||
{text('reason', 'Motivo da venda')}
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{select('transaction_type', 'Tipo de negócio', [
|
||||
{ value: 'sale', label: 'Venda' },
|
||||
{ value: 'lease', label: 'Arrendamento' },
|
||||
])}
|
||||
{select(
|
||||
'property_type',
|
||||
'Tipo de imóvel',
|
||||
propertyTypes.map((type) => ({
|
||||
value: type,
|
||||
label: propertyLabels[type] ?? type,
|
||||
})),
|
||||
)}
|
||||
{text('land_area', 'Área do terreno', true)}
|
||||
{text('built_area', 'Área construída', true)}
|
||||
{select('area_unit', 'Unidade da área', [
|
||||
{ value: 'sqm', label: 'm²' },
|
||||
{ value: 'ha', label: 'ha' },
|
||||
{ value: 'sqkm', label: 'km²' },
|
||||
])}
|
||||
{[
|
||||
'house',
|
||||
'apartment',
|
||||
'hospitality',
|
||||
'mixed_use',
|
||||
].includes(String(data.property_type)) && (
|
||||
<>
|
||||
{text('bedrooms', 'Quartos', true)}
|
||||
{text('bathrooms', 'Casas de banho', true)}
|
||||
</>
|
||||
)}
|
||||
<label>
|
||||
Características e comodidades (uma por linha)
|
||||
<textarea
|
||||
className={control}
|
||||
value={
|
||||
Array.isArray(data.amenities)
|
||||
? data.amenities.join('\n')
|
||||
: ''
|
||||
}
|
||||
onChange={(e) =>
|
||||
update(
|
||||
'amenities',
|
||||
e.target.value
|
||||
.split('\n')
|
||||
.filter(Boolean),
|
||||
)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
</>
|
||||
)}
|
||||
{select('availability', 'Disponibilidade declarada', [
|
||||
{ value: 'available', label: 'Disponível' },
|
||||
{ value: 'sold', label: 'Vendido' },
|
||||
...(!business
|
||||
? [{ value: 'leased', label: 'Arrendado' }]
|
||||
: []),
|
||||
])}
|
||||
</div>
|
||||
{value[business ? 'property' : 'business'] && (
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
onClick={() =>
|
||||
onChange({
|
||||
...value,
|
||||
[business ? 'property' : 'business']: null,
|
||||
})
|
||||
}
|
||||
>
|
||||
Retirar os dados do tipo anterior antes de guardar esta
|
||||
categoria
|
||||
</button>
|
||||
)}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { profileJson } from '@/lib/profile-json';
|
||||
import { createOperationKey } from '@/lib/operation-key';
|
||||
type Resource = {
|
||||
id: string;
|
||||
version: number;
|
||||
deleted: boolean;
|
||||
caption: string | null;
|
||||
digitally_edited: boolean | null;
|
||||
edit_description: string | null;
|
||||
scan: string;
|
||||
};
|
||||
export default function OfferPrivateResources({
|
||||
id,
|
||||
etag,
|
||||
editable,
|
||||
property,
|
||||
disabled,
|
||||
onChanged,
|
||||
}: {
|
||||
id: number;
|
||||
etag: string;
|
||||
editable: boolean;
|
||||
property: boolean;
|
||||
disabled: boolean;
|
||||
onChanged: (etag: string) => void;
|
||||
}) {
|
||||
const [resources, setResources] = useState<{
|
||||
images: Resource[];
|
||||
documents: Resource[];
|
||||
}>({ images: [], documents: [] });
|
||||
const [internal, setInternal] = useState(false);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [kind, setKind] = useState('images');
|
||||
const [caption, setCaption] = useState('');
|
||||
const [edited, setEdited] = useState(false);
|
||||
const [editDescription, setEditDescription] = useState('');
|
||||
const [message, setMessage] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [editing, setEditing] = useState<Resource | null>(null);
|
||||
const base = `/minhas-oportunidades/ofertas/${id}/recursos`;
|
||||
async function refresh() {
|
||||
const result = await profileJson(base, {}, 'GET');
|
||||
setResources(result.resources);
|
||||
setInternal(result.internalProofAccess);
|
||||
onChanged(result.etag);
|
||||
}
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
profileJson(base, {}, 'GET')
|
||||
.then((result) => {
|
||||
if (active) {
|
||||
setResources(result.resources);
|
||||
setInternal(result.internalProofAccess);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
if (active) setMessage(error.message);
|
||||
});
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [base]);
|
||||
async function upload() {
|
||||
if ((!file && !editing) || busy || disabled) return;
|
||||
setBusy(true);
|
||||
setMessage('');
|
||||
const form = new FormData();
|
||||
if (file) form.append('file', file);
|
||||
form.append('etag', etag);
|
||||
if (editing) form.append('version', String(editing.version));
|
||||
else form.append('creation_key', createOperationKey());
|
||||
form.append(
|
||||
'reason',
|
||||
'Envio privado de suporte da oferta pelo promotor.',
|
||||
);
|
||||
form.append(
|
||||
'payload',
|
||||
JSON.stringify(
|
||||
kind === 'images'
|
||||
? {
|
||||
visibility: 'internal',
|
||||
caption,
|
||||
alt_text: caption,
|
||||
digitally_edited: edited,
|
||||
edit_description: edited ? editDescription : null,
|
||||
}
|
||||
: {
|
||||
visibility: 'internal',
|
||||
classification: 'restricted',
|
||||
category: 'real_estate_proof',
|
||||
},
|
||||
),
|
||||
);
|
||||
try {
|
||||
await profileJson(
|
||||
editing
|
||||
? `${base}/images/${editing.id}/guardar`
|
||||
: `${base}/${kind}`,
|
||||
form,
|
||||
);
|
||||
await refresh();
|
||||
setFile(null);
|
||||
setEditing(null);
|
||||
setMessage(
|
||||
'Original guardado em privado. A análise de segurança pode ainda estar pendente.',
|
||||
);
|
||||
} catch (error) {
|
||||
setMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Não foi possível guardar.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
async function lifecycle(resource: Resource, resourceKind: string) {
|
||||
setBusy(true);
|
||||
try {
|
||||
await profileJson(`${base}/${resourceKind}/${resource.id}`, {
|
||||
etag,
|
||||
version: resource.version,
|
||||
action: resource.deleted ? 'restore' : 'delete',
|
||||
confirm: true,
|
||||
reason: 'Alteração explícita dos suportes privados da oferta.',
|
||||
});
|
||||
await refresh();
|
||||
} catch (error) {
|
||||
setMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Não foi possível alterar.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<section className="space-y-4 rounded-lg border p-4">
|
||||
<h2 className="font-semibold">Fotografias e suportes privados</h2>
|
||||
<p>
|
||||
Até seis fotografias. JPEG, PNG ou WebP, até 10 MB e pelo menos
|
||||
400 × 400 píxeis. Os comprovativos são reservados à validação
|
||||
interna; o envio não certifica titularidade.
|
||||
</p>
|
||||
{disabled && <p>Guarde os dados antes de alterar os ficheiros.</p>}
|
||||
{editable && (
|
||||
<fieldset
|
||||
disabled={busy || disabled}
|
||||
className="grid gap-3 sm:grid-cols-2"
|
||||
>
|
||||
<label>
|
||||
Tipo
|
||||
<select
|
||||
className="w-full rounded border p-2"
|
||||
value={kind}
|
||||
disabled={editing !== null}
|
||||
onChange={(e) => setKind(e.target.value)}
|
||||
>
|
||||
<option value="images">Fotografia</option>
|
||||
{property && (
|
||||
<option value="documents">
|
||||
Comprovativo imobiliário
|
||||
</option>
|
||||
)}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Ficheiro
|
||||
<input
|
||||
type="file"
|
||||
className="block w-full min-w-0"
|
||||
accept={
|
||||
kind === 'images'
|
||||
? 'image/jpeg,image/png,image/webp'
|
||||
: '.pdf,.docx,.xlsx,.png,.jpg,.jpeg'
|
||||
}
|
||||
onChange={(e) =>
|
||||
setFile(e.target.files?.[0] ?? null)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{kind === 'images' && (
|
||||
<>
|
||||
<label>
|
||||
Legenda / divisão
|
||||
<input
|
||||
className="w-full rounded border p-2"
|
||||
maxLength={250}
|
||||
value={caption}
|
||||
onChange={(e) => setCaption(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={edited}
|
||||
onChange={(e) =>
|
||||
setEdited(e.target.checked)
|
||||
}
|
||||
/>{' '}
|
||||
Imagem editada digitalmente
|
||||
</label>
|
||||
{edited && (
|
||||
<label>
|
||||
Alterações efectuadas
|
||||
<textarea
|
||||
className="w-full rounded border p-2"
|
||||
maxLength={1000}
|
||||
value={editDescription}
|
||||
onChange={(e) =>
|
||||
setEditDescription(e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<button
|
||||
type="button"
|
||||
className="rounded border p-2"
|
||||
disabled={
|
||||
(!file && !editing) ||
|
||||
(!editing &&
|
||||
kind === 'images' &&
|
||||
resources.images.filter((item) => !item.deleted)
|
||||
.length >= 6)
|
||||
}
|
||||
onClick={() => void upload()}
|
||||
>
|
||||
{editing
|
||||
? 'Guardar alterações da fotografia'
|
||||
: 'Guardar ficheiro privado'}
|
||||
</button>
|
||||
</fieldset>
|
||||
)}
|
||||
{editing && (
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
setEditing(null);
|
||||
setFile(null);
|
||||
}}
|
||||
>
|
||||
Cancelar alteração da fotografia
|
||||
</button>
|
||||
)}
|
||||
{(['images', 'documents'] as const).map((resourceKind) => (
|
||||
<ul key={resourceKind} className="space-y-2">
|
||||
{resources[resourceKind].map((resource) => (
|
||||
<li
|
||||
key={resource.id}
|
||||
className="flex flex-wrap gap-3 break-words"
|
||||
>
|
||||
<span>
|
||||
{resource.caption ||
|
||||
(resourceKind === 'images'
|
||||
? 'Fotografia'
|
||||
: 'Comprovativo')}{' '}
|
||||
· versão {resource.version} ·{' '}
|
||||
{resource.deleted
|
||||
? 'Retirado'
|
||||
: resource.scan === 'clean'
|
||||
? 'Análise concluída'
|
||||
: 'Análise de segurança pendente'}
|
||||
</span>
|
||||
{!resource.deleted &&
|
||||
resource.scan === 'clean' &&
|
||||
(resourceKind === 'images' || internal) && (
|
||||
<a
|
||||
className="underline"
|
||||
href={`${base}/${resourceKind}/${resource.id}`}
|
||||
>
|
||||
Consultar original
|
||||
</a>
|
||||
)}
|
||||
{editable &&
|
||||
resourceKind === 'images' &&
|
||||
!resource.deleted && (
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={busy || disabled}
|
||||
onClick={() => {
|
||||
setEditing(resource);
|
||||
setKind('images');
|
||||
setCaption(resource.caption ?? '');
|
||||
setEdited(
|
||||
resource.digitally_edited ??
|
||||
false,
|
||||
);
|
||||
setEditDescription(
|
||||
resource.edit_description ?? '',
|
||||
);
|
||||
setFile(null);
|
||||
}}
|
||||
>
|
||||
Alterar fotografia
|
||||
</button>
|
||||
)}
|
||||
{editable && (
|
||||
<button
|
||||
className="underline"
|
||||
disabled={busy || disabled}
|
||||
onClick={() =>
|
||||
void lifecycle(resource, resourceKind)
|
||||
}
|
||||
>
|
||||
{resource.deleted ? 'Restaurar' : 'Retirar'}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="underline"
|
||||
disabled={busy || disabled}
|
||||
onClick={() =>
|
||||
void refresh().catch((error) => setMessage(error.message))
|
||||
}
|
||||
>
|
||||
Actualizar estado dos ficheiros
|
||||
</button>
|
||||
<p role="status">{message}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user