525 lines
23 KiB
TypeScript
525 lines
23 KiB
TypeScript
import { createOperationKey } from '@/lib/operation-key';
|
|
import { useForm, usePage, Link, router } from '@inertiajs/react';
|
|
import {
|
|
Frame,
|
|
Field,
|
|
Errors,
|
|
control,
|
|
button,
|
|
labels,
|
|
type Partnership,
|
|
} from './shared';
|
|
type Room = {
|
|
id: number;
|
|
status: string;
|
|
version: number;
|
|
agreement: {
|
|
title: string;
|
|
terms: string;
|
|
confirmations: Record<string, { actor_id: number; date: string }>;
|
|
legal_signature_status: string;
|
|
} | null;
|
|
};
|
|
type Milestone = {
|
|
id: number;
|
|
title: string;
|
|
responsible_id: number;
|
|
due_date: string | null;
|
|
status: string;
|
|
evidence: string | null;
|
|
version: number;
|
|
};
|
|
type Props = {
|
|
room: Room;
|
|
partnership: Partnership & { user_id: number };
|
|
interest: { id: number; user_id: number };
|
|
canWrite: boolean;
|
|
messages: {
|
|
id: number;
|
|
name: string;
|
|
author_id: number;
|
|
body: string;
|
|
created_at: string;
|
|
}[];
|
|
documents: {
|
|
id: number;
|
|
owner_id: number;
|
|
file_name: string;
|
|
shared: boolean;
|
|
status: string;
|
|
malware_scan_status: string;
|
|
}[];
|
|
milestones: Milestone[];
|
|
};
|
|
function MilestoneForm({ p, item }: { p: Props; item?: Milestone }) {
|
|
const form = useForm({
|
|
title: item?.title ?? '',
|
|
responsible_id: item?.responsible_id ?? p.partnership.user_id,
|
|
due_date: item?.due_date ?? '',
|
|
status: item?.status ?? 'pending',
|
|
evidence: item?.evidence ?? '',
|
|
version: item?.version ?? null,
|
|
});
|
|
return (
|
|
<form
|
|
className="space-y-3 rounded border p-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
if (item)
|
|
form.put(
|
|
`/parcerias/salas/${p.room.id}/marcos/${item.id}`,
|
|
{ preserveScroll: true },
|
|
);
|
|
else
|
|
form.post(`/parcerias/salas/${p.room.id}/marcos`, {
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
>
|
|
<h3 className="font-bold">
|
|
{item ? 'Atualizar marco' : 'Acrescentar marco'}
|
|
</h3>
|
|
<Field label="Entregável">
|
|
<input
|
|
className={control}
|
|
value={form.data.title}
|
|
onChange={(e) => form.setData('title', e.target.value)}
|
|
/>
|
|
</Field>
|
|
<Field label="Responsável">
|
|
<select
|
|
className={control}
|
|
value={form.data.responsible_id}
|
|
onChange={(e) =>
|
|
form.setData('responsible_id', Number(e.target.value))
|
|
}
|
|
>
|
|
<option value={p.partnership.user_id}>Proponente</option>
|
|
<option value={p.interest.user_id}>Candidato</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Data prevista">
|
|
<input
|
|
className={control}
|
|
type="date"
|
|
value={form.data.due_date}
|
|
onChange={(e) => form.setData('due_date', e.target.value)}
|
|
/>
|
|
</Field>
|
|
<Field label="Estado">
|
|
<select
|
|
className={control}
|
|
value={form.data.status}
|
|
onChange={(e) => form.setData('status', e.target.value)}
|
|
>
|
|
{['pending', 'progress', 'completed'].map((x) => (
|
|
<option key={x} value={x}>
|
|
{x === 'pending' ? 'Pendente' : labels[x]}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
<Field label="Evidência ou referência do resultado">
|
|
<textarea
|
|
className={control}
|
|
value={form.data.evidence}
|
|
onChange={(e) => form.setData('evidence', e.target.value)}
|
|
/>
|
|
</Field>
|
|
<Errors errors={form.errors} />
|
|
<button className={button} disabled={form.processing}>
|
|
Guardar marco
|
|
</button>
|
|
</form>
|
|
);
|
|
}
|
|
export default function Page(p: Props) {
|
|
return <RoomPage key={p.room.id + ':' + p.room.version} {...p} />;
|
|
}
|
|
function RoomPage(p: Props) {
|
|
const { auth } = usePage<{ auth: { user: { id: number } } }>().props;
|
|
const message = useForm({ body: '', client_key: createOperationKey() });
|
|
const agreement = useForm({
|
|
version: p.room.version,
|
|
action: 'record',
|
|
title: p.room.agreement?.title ?? '',
|
|
terms: p.room.agreement?.terms ?? '',
|
|
reason: '',
|
|
});
|
|
const upload = useForm<{ file: File | null; shared: boolean }>({
|
|
file: null,
|
|
shared: false,
|
|
});
|
|
const act = (action: string) => {
|
|
agreement.transform((data) => ({ ...data, action }));
|
|
agreement.post(`/parcerias/salas/${p.room.id}/acordo`, {
|
|
preserveScroll: true,
|
|
});
|
|
};
|
|
const mutable =
|
|
p.canWrite && !['closed', 'cancelled'].includes(p.room.status);
|
|
return (
|
|
<Frame title={'Conexão privada — ' + p.partnership.title}>
|
|
<div className="space-y-6">
|
|
<Link
|
|
className="underline"
|
|
href={'/parcerias/' + p.partnership.id}
|
|
>
|
|
Regressar à parceria
|
|
</Link>
|
|
<p>
|
|
Estado da conexão: {labels[p.room.status]}. Esta sala
|
|
pertence apenas às partes autorizadas; não encerra outras
|
|
candidaturas.
|
|
</p>
|
|
<section className="space-y-4 rounded border p-5">
|
|
<h2 className="text-xl font-bold">
|
|
Mensagens e esclarecimentos
|
|
</h2>
|
|
{p.messages.map((m) => (
|
|
<article className="bg-muted rounded p-4" key={m.id}>
|
|
<p className="font-semibold">
|
|
{m.name} · {m.created_at}
|
|
</p>
|
|
<p className="whitespace-pre-wrap">{m.body}</p>
|
|
</article>
|
|
))}
|
|
{mutable && (
|
|
<form
|
|
className="space-y-3"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
message.post(
|
|
`/parcerias/salas/${p.room.id}/mensagens`,
|
|
{
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
message.setData({
|
|
body: '',
|
|
client_key: createOperationKey(),
|
|
});
|
|
},
|
|
},
|
|
);
|
|
}}
|
|
>
|
|
<Field label="Mensagem privada">
|
|
<textarea
|
|
className={control}
|
|
disabled={message.processing}
|
|
value={message.data.body}
|
|
onChange={(e) =>
|
|
message.setData('body', e.target.value)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Errors errors={message.errors} />
|
|
<button
|
|
className={button}
|
|
disabled={message.processing}
|
|
>
|
|
Enviar mensagem
|
|
</button>
|
|
</form>
|
|
)}
|
|
</section>
|
|
<section className="space-y-4 rounded border p-5">
|
|
<h2 className="text-xl font-bold">
|
|
Documentos autorizados
|
|
</h2>
|
|
<p>
|
|
O original fica no repositório privado. A partilha exige
|
|
autorização explícita; o download exige análise
|
|
antimalware limpa e hash correspondente. Anexar não
|
|
confirma autenticidade nem vigência.
|
|
</p>
|
|
<p
|
|
role="status"
|
|
aria-live="polite"
|
|
aria-label="Documentos disponíveis nesta sala"
|
|
>
|
|
{p.documents.length
|
|
? `${p.documents.length} documento(s) disponível(is) para esta conta.`
|
|
: 'Nenhum documento está autorizado para consulta por esta conta nesta sala.'}
|
|
</p>
|
|
{!mutable && p.documents.some((d) => d.shared && d.owner_id === auth.user.id) && (
|
|
<p role="status" aria-live="polite">
|
|
A sala está encerrada. O autor pode retirar uma autorização de partilha existente; novas partilhas permanecem indisponíveis.
|
|
</p>
|
|
)}
|
|
{p.documents.map((d) => (
|
|
<article key={d.id}>
|
|
<p>
|
|
{d.file_name} ·{' '}
|
|
{d.shared
|
|
? 'Partilhado com a contraparte'
|
|
: 'Privado do autor'}{' '}
|
|
· Análise: {d.malware_scan_status}
|
|
</p>
|
|
{d.owner_id === auth.user.id && (mutable || d.shared) && (
|
|
<button
|
|
className="underline"
|
|
onClick={() =>
|
|
router.post(
|
|
`/parcerias/salas/${p.room.id}/documentos/${d.id}/partilha`,
|
|
{ shared: !d.shared },
|
|
{ preserveScroll: true },
|
|
)
|
|
}
|
|
>
|
|
{d.shared
|
|
? 'Retirar autorização de partilha'
|
|
: 'Autorizar partilha com a contraparte'}
|
|
</button>
|
|
)}
|
|
{d.status === 'active' &&
|
|
d.malware_scan_status === 'clean' && (
|
|
<a
|
|
className="underline"
|
|
href={`/parcerias/salas/${p.room.id}/documentos/${d.id}`}
|
|
>
|
|
Descarregar documento
|
|
</a>
|
|
)}
|
|
</article>
|
|
))}
|
|
{mutable && (
|
|
<form
|
|
className="space-y-3"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
upload.post(
|
|
`/parcerias/salas/${p.room.id}/documentos`,
|
|
{
|
|
forceFormData: true,
|
|
preserveScroll: true,
|
|
},
|
|
);
|
|
}}
|
|
>
|
|
<Field label="Anexar PDF ou imagem">
|
|
<input
|
|
type="file"
|
|
className="w-full max-w-full min-w-0"
|
|
accept=".pdf,.jpg,.jpeg,.png"
|
|
onChange={(e) =>
|
|
upload.setData(
|
|
'file',
|
|
e.target.files?.[0] ?? null,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<label className="block">
|
|
<input
|
|
type="checkbox"
|
|
checked={upload.data.shared}
|
|
onChange={(e) =>
|
|
upload.setData(
|
|
'shared',
|
|
e.target.checked,
|
|
)
|
|
}
|
|
/>{' '}
|
|
Autorizo a consulta pela contraparte desta sala.
|
|
</label>
|
|
<Errors errors={upload.errors} />
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
upload.processing || !upload.data.file
|
|
}
|
|
>
|
|
Guardar documento privado
|
|
</button>
|
|
</form>
|
|
)}
|
|
</section>
|
|
<section className="space-y-4 rounded border p-5">
|
|
<h2 className="text-xl font-bold">
|
|
Acordo e plano conjunto
|
|
</h2>
|
|
<p>
|
|
Registe o instrumento, objetivos, contribuições,
|
|
responsabilidades, indicadores, riscos, dependências e
|
|
condições de saída. A confirmação no portal regista a
|
|
concordância comunicada pelas partes; não certifica
|
|
assinatura jurídica ou due diligence.
|
|
</p>
|
|
{p.room.agreement && (
|
|
<>
|
|
<h3 className="font-bold">
|
|
{p.room.agreement.title}
|
|
</h3>
|
|
<p className="whitespace-pre-wrap">
|
|
{p.room.agreement.terms}
|
|
</p>
|
|
<p>
|
|
Confirmações:{' '}
|
|
{Object.entries(p.room.agreement.confirmations)
|
|
.map(
|
|
([party, c]) =>
|
|
`${party}: autor ${c.actor_id}, ${c.date}`,
|
|
)
|
|
.join('; ') || 'Pendentes'}
|
|
</p>
|
|
</>
|
|
)}
|
|
{mutable && (
|
|
<>
|
|
<Field label="Motivo da ação">
|
|
<textarea
|
|
className={control}
|
|
value={agreement.data.reason}
|
|
onChange={(e) =>
|
|
agreement.setData(
|
|
'reason',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
{['negotiation', 'agreement_recorded'].includes(
|
|
p.room.status,
|
|
) && (
|
|
<>
|
|
<Field label="Título do instrumento">
|
|
<input
|
|
className={control}
|
|
value={agreement.data.title}
|
|
onChange={(e) =>
|
|
agreement.setData(
|
|
'title',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Condições e plano de valor">
|
|
<textarea
|
|
className={control}
|
|
rows={6}
|
|
value={agreement.data.terms}
|
|
onChange={(e) =>
|
|
agreement.setData(
|
|
'terms',
|
|
e.target.value,
|
|
)
|
|
}
|
|
/>
|
|
</Field>
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('record')}
|
|
>
|
|
Registar versão do acordo
|
|
</button>
|
|
</>
|
|
)}
|
|
<div className="flex flex-wrap gap-3">
|
|
{p.room.status === 'agreement_recorded' && (
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('confirm')}
|
|
>
|
|
Confirmar pela minha parte
|
|
</button>
|
|
)}
|
|
{p.room.status === 'agreed' && (
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('start')}
|
|
>
|
|
Iniciar acompanhamento
|
|
</button>
|
|
)}
|
|
{p.room.status === 'execution' && (
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('complete')}
|
|
>
|
|
Concluir após os marcos
|
|
</button>
|
|
)}
|
|
{['agreed', 'execution'].includes(
|
|
p.room.status,
|
|
) && (
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('renew')}
|
|
>
|
|
Registar renovação
|
|
</button>
|
|
)}
|
|
<button
|
|
className={button}
|
|
disabled={
|
|
agreement.processing ||
|
|
!agreement.data.reason
|
|
}
|
|
onClick={() => act('cancel')}
|
|
>
|
|
Cancelar conexão com motivo
|
|
</button>
|
|
</div>
|
|
<Errors errors={agreement.errors} />
|
|
</>
|
|
)}
|
|
</section>
|
|
<section className="space-y-4">
|
|
<h2 className="text-xl font-bold">Marcos e responsáveis</h2>
|
|
<p>
|
|
Participação atual:{' '}
|
|
{auth.user.id === p.partnership.user_id
|
|
? 'Proponente'
|
|
: auth.user.id === p.interest.user_id
|
|
? 'Candidato'
|
|
: 'Representante autorizado'}
|
|
.
|
|
</p>
|
|
{p.milestones.map((m) => (
|
|
<article
|
|
key={m.id + ':' + m.version}
|
|
className="space-y-3"
|
|
>
|
|
<p>
|
|
{m.title} ·{' '}
|
|
{m.status === 'pending'
|
|
? 'Pendente'
|
|
: labels[m.status]}{' '}
|
|
· Prazo: {m.due_date ?? 'Pendente'} ·
|
|
Responsável ID {m.responsible_id}
|
|
</p>
|
|
{mutable && <MilestoneForm p={p} item={m} />}
|
|
</article>
|
|
))}
|
|
{mutable &&
|
|
['agreement_recorded', 'agreed', 'execution'].includes(
|
|
p.room.status,
|
|
) && <MilestoneForm p={p} />}
|
|
</section>
|
|
</div>
|
|
</Frame>
|
|
);
|
|
}
|