138 lines
5.9 KiB
TypeScript
138 lines
5.9 KiB
TypeScript
import { Head, Link, useForm } from '@inertiajs/react';
|
|
import {
|
|
FormErrors,
|
|
PageTitle,
|
|
Panel,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { conflictScope } from '@/types/conflict';
|
|
import type { ConflictDeclaration } from '@/types/conflict';
|
|
import { date } from '@/types/procurement';
|
|
|
|
export default function DeclarationHistory({
|
|
history,
|
|
canCorrect,
|
|
}: {
|
|
history: ConflictDeclaration[];
|
|
canCorrect: boolean;
|
|
}) {
|
|
const current = history[history.length - 1];
|
|
const form = useForm({
|
|
reason: current.reason,
|
|
known_since: current.known_since.slice(0, 10),
|
|
});
|
|
return (
|
|
<>
|
|
<Head title="Histórico da declaração" />
|
|
<div className="mx-auto flex w-full max-w-4xl flex-col gap-7 p-5 lg:p-8">
|
|
<PageTitle
|
|
eyebrow="Conflitos de interesses"
|
|
title="Histórico da declaração"
|
|
description={`${current.author.name} · ${conflictScope(current)}`}
|
|
action={
|
|
<Button asChild variant="outline">
|
|
<Link href="/conflitos">Voltar às declarações</Link>
|
|
</Button>
|
|
}
|
|
/>
|
|
<Panel
|
|
title={
|
|
current.has_conflict
|
|
? 'Conflito registado com impedimento'
|
|
: 'Ausência de conflito declarada'
|
|
}
|
|
description="Uma ausência declarada não retira outros conflitos registados. Não há caducidade ou levantamento automático."
|
|
>
|
|
<ol className="space-y-5">
|
|
{history.map((d) => (
|
|
<li
|
|
className="border-l-2 border-teal-600/40 pl-4"
|
|
key={d.id}
|
|
>
|
|
<p className="text-sm font-semibold">
|
|
Registo #{d.id}
|
|
{d.previous_id
|
|
? ` · Correcção de #${d.previous_id}`
|
|
: ' · Declaração inicial'}
|
|
</p>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
{d.author.name} · Registado em{' '}
|
|
{date(d.declared_at)} às{' '}
|
|
{d.declared_at.slice(11, 19)} UTC ·
|
|
Conhecimento em {date(d.known_since)}
|
|
</p>
|
|
<p className="mt-3 text-sm whitespace-pre-wrap">
|
|
{d.reason}
|
|
</p>
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</Panel>
|
|
{canCorrect && (
|
|
<Panel
|
|
title="Corrigir fundamento ou data de conhecimento"
|
|
description="A correcção cria um novo registo e mantém os anteriores. O autor, âmbito e situação declarada permanecem iguais."
|
|
>
|
|
<form
|
|
className="space-y-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.put(`/conflitos/${current.id}`, {
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<div className="space-y-2">
|
|
<Label htmlFor="correct-date">
|
|
Data de conhecimento
|
|
</Label>
|
|
<Input
|
|
id="correct-date"
|
|
type="date"
|
|
required
|
|
value={form.data.known_since}
|
|
onChange={(e) =>
|
|
form.setData(
|
|
'known_since',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</div>
|
|
<div className="space-y-2">
|
|
<Label htmlFor="correct-reason">
|
|
Fundamento corrigido
|
|
</Label>
|
|
<textarea
|
|
id="correct-reason"
|
|
className={`${controlClass} h-28 py-3`}
|
|
required
|
|
minLength={10}
|
|
maxLength={5000}
|
|
value={form.data.reason}
|
|
onChange={(e) =>
|
|
form.setData('reason', e.target.value)
|
|
}
|
|
/>
|
|
</div>
|
|
<Button disabled={form.processing}>
|
|
Registar correcção no histórico
|
|
</Button>
|
|
</form>
|
|
</Panel>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|
|
DeclarationHistory.layout = {
|
|
breadcrumbs: [
|
|
{ title: 'Conflitos de interesses', href: '/conflitos' },
|
|
{ title: 'Histórico', href: '#' },
|
|
],
|
|
};
|