@@ -18,6 +18,13 @@ import { date } from '@/types/procurement';
|
||||
export default function DeclarationHistory(props: {
|
||||
history: ConflictDeclaration[];
|
||||
canCorrect: boolean;
|
||||
canAuthoriseRelease?: boolean;
|
||||
release?: {
|
||||
id: number;
|
||||
authorised_by: number;
|
||||
authorised_at: string;
|
||||
reason: string;
|
||||
} | null;
|
||||
}) {
|
||||
const current = props.history[props.history.length - 1];
|
||||
const identity = `${useConflictPreparationIdentity()}:correction:${current.id}:${current.declared_at}:${props.canCorrect}`;
|
||||
@@ -27,10 +34,19 @@ function HistoryFields({
|
||||
history,
|
||||
canCorrect,
|
||||
identity,
|
||||
canAuthoriseRelease,
|
||||
release,
|
||||
}: {
|
||||
identity: string;
|
||||
history: ConflictDeclaration[];
|
||||
canCorrect: boolean;
|
||||
canAuthoriseRelease?: boolean;
|
||||
release?: {
|
||||
id: number;
|
||||
authorised_by: number;
|
||||
authorised_at: string;
|
||||
reason: string;
|
||||
} | null;
|
||||
}) {
|
||||
const current = history[history.length - 1];
|
||||
const initial = {
|
||||
@@ -56,9 +72,11 @@ function HistoryFields({
|
||||
/>
|
||||
<Panel
|
||||
title={
|
||||
current.has_conflict
|
||||
? 'Conflito registado com impedimento'
|
||||
: 'Ausência de conflito declarada'
|
||||
release
|
||||
? 'Impedimento levantado pela direcção'
|
||||
: 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."
|
||||
>
|
||||
@@ -87,6 +105,22 @@ function HistoryFields({
|
||||
))}
|
||||
</ol>
|
||||
</Panel>
|
||||
{release && (
|
||||
<Panel
|
||||
title="Autorização da direcção"
|
||||
description={`Autorizada por #${release.authorised_by} em ${date(release.authorised_at)}. Aplica-se apenas a esta declaração e às suas correcções.`}
|
||||
>
|
||||
<p className="text-sm whitespace-pre-wrap">
|
||||
{release.reason}
|
||||
</p>
|
||||
</Panel>
|
||||
)}
|
||||
{canAuthoriseRelease && (
|
||||
<ReleaseForm
|
||||
identity={identity}
|
||||
declarationId={current.id}
|
||||
/>
|
||||
)}
|
||||
{canCorrect && (
|
||||
<Panel
|
||||
title="Corrigir fundamento ou data de conhecimento"
|
||||
@@ -159,6 +193,70 @@ function HistoryFields({
|
||||
</>
|
||||
);
|
||||
}
|
||||
function ReleaseForm({
|
||||
identity,
|
||||
declarationId,
|
||||
}: {
|
||||
identity: string;
|
||||
declarationId: number;
|
||||
}) {
|
||||
const form = useForm(`${identity}:release`, {
|
||||
reason: '',
|
||||
operation_key: crypto.randomUUID(),
|
||||
});
|
||||
const dirty = form.data.reason.trim() !== '';
|
||||
const ref = usePreparationDirty(dirty, true);
|
||||
return (
|
||||
<Panel
|
||||
title="Autorizar levantamento do impedimento"
|
||||
description="Decisão expressa da direcção. A declaração original permanece no histórico; outros conflitos continuam a impedir a participação."
|
||||
>
|
||||
<form
|
||||
ref={ref}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post(`/conflitos/${declarationId}/levantamento`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () => {
|
||||
const initial = {
|
||||
reason: '',
|
||||
operation_key: crypto.randomUUID(),
|
||||
};
|
||||
form.setData(initial);
|
||||
form.clearErrors();
|
||||
router.remember(
|
||||
initial,
|
||||
`${identity}:release:data`,
|
||||
);
|
||||
router.remember({}, `${identity}:release:errors`);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
<FormErrors errors={form.errors} />
|
||||
<Label htmlFor="release-reason">
|
||||
Fundamento da autorização
|
||||
</Label>
|
||||
<textarea
|
||||
id="release-reason"
|
||||
required
|
||||
minLength={10}
|
||||
maxLength={5000}
|
||||
className={`${controlClass} h-28 py-3`}
|
||||
value={form.data.reason}
|
||||
onChange={(event) =>
|
||||
form.setData('reason', event.target.value)
|
||||
}
|
||||
/>
|
||||
<Button disabled={form.processing}>
|
||||
Autorizar levantamento
|
||||
</Button>
|
||||
</form>
|
||||
</Panel>
|
||||
);
|
||||
}
|
||||
DeclarationHistory.layout = {
|
||||
breadcrumbs: [
|
||||
{ title: 'Conflitos de interesses', href: '/conflitos' },
|
||||
|
||||
Reference in New Issue
Block a user