189 lines
8.4 KiB
TypeScript
189 lines
8.4 KiB
TypeScript
import { Head, Link, useForm } from '@inertiajs/react';
|
|
import {
|
|
Panel,
|
|
PageTitle,
|
|
FormErrors,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { Button } from '@/components/ui/button';
|
|
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
|
|
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
|
|
|
type Props = {
|
|
families: { key: string; label: string }[];
|
|
exports: {
|
|
data: {
|
|
id: number;
|
|
families: string[];
|
|
created_at: string;
|
|
size: number;
|
|
sha256: string;
|
|
download_url: string;
|
|
}[];
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
};
|
|
};
|
|
|
|
export default function PrivateAudit(props: Props) {
|
|
const identity = useProcurementPreparationIdentity(
|
|
`private-audit:${props.families.map((family) => family.key).join(',')}`,
|
|
);
|
|
const form = useForm(identity, {
|
|
operation_key: crypto.randomUUID(),
|
|
families: [] as string[],
|
|
purpose: '',
|
|
});
|
|
const formRef = usePreparationDirty(form.isDirty);
|
|
return (
|
|
<>
|
|
<Head title="Exportação privada de auditoria" />
|
|
<div className="mx-auto flex w-full max-w-5xl flex-col gap-6 p-5 lg:p-8">
|
|
<PageTitle
|
|
eyebrow="Auditoria"
|
|
title="Exportação privada de auditoria"
|
|
description="Seleccione os dados abrangidos pela sua autoridade. O pacote inclui um manifesto com fontes, contagens e hashes e os originais verificáveis aplicáveis."
|
|
/>
|
|
<Panel title="Preparar pacote">
|
|
<p className="mb-4 text-sm">
|
|
Bancos completos, documentos bancários específicos,
|
|
conteúdo privado de Pessoas e credenciais ficam fora
|
|
deste pacote. Os dados representam os registos
|
|
existentes; não recalculam saldos nem certificam os
|
|
documentos.
|
|
</p>
|
|
<form
|
|
ref={formRef}
|
|
className="space-y-4"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
form.post('/auditoria/privada', {
|
|
onSuccess: () => {
|
|
const clean = {
|
|
operation_key: crypto.randomUUID(),
|
|
families: [] as string[],
|
|
purpose: '',
|
|
};
|
|
form.setDefaults(clean);
|
|
form.setData(clean);
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<fieldset className="space-y-2">
|
|
<legend className="font-medium">Conteúdo</legend>
|
|
{props.families.map((family) => (
|
|
<label
|
|
key={family.key}
|
|
className="flex items-center gap-2"
|
|
>
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.families.includes(
|
|
family.key,
|
|
)}
|
|
onChange={(event) =>
|
|
form.setData(
|
|
'families',
|
|
event.target.checked
|
|
? [
|
|
...form.data.families,
|
|
family.key,
|
|
]
|
|
: form.data.families.filter(
|
|
(key) =>
|
|
key !==
|
|
family.key,
|
|
),
|
|
)
|
|
}
|
|
/>
|
|
{family.label}
|
|
</label>
|
|
))}
|
|
</fieldset>
|
|
<label className="block">
|
|
Finalidade (opcional)
|
|
<textarea
|
|
className={controlClass}
|
|
maxLength={500}
|
|
value={form.data.purpose}
|
|
onChange={(event) =>
|
|
form.setData('purpose', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<Button
|
|
type="submit"
|
|
disabled={
|
|
form.processing ||
|
|
form.data.families.length === 0
|
|
}
|
|
>
|
|
Preparar exportação privada
|
|
</Button>
|
|
</form>
|
|
</Panel>
|
|
<Panel title="Os seus pacotes preparados">
|
|
{props.exports.data.length === 0 && (
|
|
<p>Ainda não preparou um pacote neste contexto.</p>
|
|
)}
|
|
<ul className="space-y-4">
|
|
{props.exports.data.map((item) => (
|
|
<li
|
|
key={item.id}
|
|
className="space-y-1 border-b pb-4"
|
|
>
|
|
<p>
|
|
Pacote {item.id} —{' '}
|
|
{new Date(item.created_at).toLocaleString(
|
|
'pt-MZ',
|
|
)}
|
|
</p>
|
|
<p className="text-sm">
|
|
{item.families
|
|
.map(
|
|
(key) =>
|
|
props.families.find(
|
|
(family) =>
|
|
family.key === key,
|
|
)?.label ?? key,
|
|
)
|
|
.join('; ')}{' '}
|
|
· {item.size.toLocaleString('pt-MZ')} bytes
|
|
</p>
|
|
<p className="font-mono text-xs break-all">
|
|
SHA-256: {item.sha256}
|
|
</p>
|
|
<a
|
|
className="underline"
|
|
href={item.download_url}
|
|
>
|
|
Descarregar ZIP verificado
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
<div className="mt-4 flex gap-4">
|
|
{props.exports.prev_page_url && (
|
|
<Link href={props.exports.prev_page_url}>
|
|
Anterior
|
|
</Link>
|
|
)}
|
|
{props.exports.next_page_url && (
|
|
<Link href={props.exports.next_page_url}>
|
|
Seguinte
|
|
</Link>
|
|
)}
|
|
</div>
|
|
</Panel>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
|
|
PrivateAudit.layout = {
|
|
breadcrumbs: [{ title: 'Auditoria privada', href: '/auditoria/privada' }],
|
|
};
|