fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,15 +1,160 @@
|
||||
import { Head, router, usePage } from '@inertiajs/react';
|
||||
import { useRef, useState } from 'react';
|
||||
type Row={id:string;protocol:string;status:string;version:number;analyst_id:number|null;due_at:string|null;etag?:string};
|
||||
export default function DeskAssignments(){
|
||||
const {requests,analysts,kind,flash}=usePage<{requests:Row[];analysts:{id:number;name:string}[];kind?:'interest';flash?:{success?:string}}>().props;
|
||||
const alertRef=useRef<HTMLDivElement>(null);
|
||||
const stateNames:Record<string,string>={received:'Recebido',submitted:'Submetido',in_review:'Em revisão',reviewed:'Revisto',qualification:'Em qualificação',qualified:'Qualificado',contacted:'Contactado',contact_accepted:'Contacto aceite',referred:'Encaminhado',due_diligence:'Em diligência',negotiation:'Em negociação',pending:'Pendente',accepted:'Aceite',rejected:'Recusado',returned:'Devolvido',processing:'Em tratamento',draft:'Rascunho'};
|
||||
const title=kind==='interest'?'Atribuições de interesses':'Atribuições do Balcão';
|
||||
const [selected,setSelected]=useState<Record<string,string>>({});
|
||||
const [reason,setReason]=useState<Record<string,string>>({});
|
||||
const [errors,setErrors]=useState<Record<string,string>>({});
|
||||
const [busy,setBusy]=useState<string|null>(null);
|
||||
function assign(row:Row){setBusy(row.id);setErrors({});router.post(kind==='interest'?`/management/interests/${row.id}/responsavel`:`/balcao-virtual/pedidos/${row.id}/responsavel`,{...(kind==='interest'?{etag:row.etag}:{version:row.version}),analyst_id:selected[row.id]??String(row.analyst_id??''),reason:reason[row.id]??''},{preserveScroll:true,onError:e=>{setErrors(e);queueMicrotask(()=>alertRef.current?.focus());},onFinish:()=>setBusy(null)});}
|
||||
return <main className="mx-auto max-w-5xl space-y-6 p-6"><Head title={title}/><h1 className="text-2xl font-semibold">{title}</h1><p>Atribua o acompanhamento de um pedido. Esta lista não dá acesso ao conteúdo privado do dossier. O proponente não pode ser designado como analista do seu pedido.</p><a href={kind==='interest'?'/management/interests':'/balcao-virtual/painel'} className="underline">{kind==='interest'?'Interesses atribuídos':'Voltar ao Balcão'}</a><div ref={alertRef} role="alert" tabIndex={-1}>{Object.values(errors).join(' ')}</div>{flash?.success&&<p role="status">{flash.success}</p>}{requests.length===0?<p>Não há pedidos para atribuir.</p>:requests.map(row=><section key={row.id} className="space-y-3 rounded border p-4"><h2 className="font-semibold">{row.protocol||row.id}</h2><p>Estado: {stateNames[row.status]??'Por esclarecer'}</p><label className="block">Responsável<select className="ml-2 border p-2" value={selected[row.id]??String(row.analyst_id??'')} onChange={e=>setSelected({...selected,[row.id]:e.target.value})}><option value="">Seleccione</option>{analysts.map(a=><option key={a.id} value={a.id}>{a.name}</option>)}</select></label><label className="block">Fundamento<textarea className="block w-full border p-2" value={reason[row.id]??''} onChange={e=>setReason({...reason,[row.id]:e.target.value})}/></label><button className="rounded bg-emerald-900 px-4 py-2 text-white" disabled={busy!==null} onClick={()=>assign(row)}>{busy===row.id?'A guardar…':'Guardar atribuição'}</button></section>)}</main>;
|
||||
type Row = {
|
||||
id: string;
|
||||
protocol: string;
|
||||
status: string;
|
||||
version: number;
|
||||
analyst_id: number | null;
|
||||
due_at: string | null;
|
||||
etag?: string;
|
||||
};
|
||||
export default function DeskAssignments() {
|
||||
const { requests, analysts, kind, flash } = usePage<{
|
||||
requests: Row[];
|
||||
analysts: { id: number; name: string }[];
|
||||
kind?: 'interest';
|
||||
flash?: { success?: string };
|
||||
}>().props;
|
||||
const alertRef = useRef<HTMLDivElement>(null);
|
||||
const stateNames: Record<string, string> = {
|
||||
received: 'Recebido',
|
||||
submitted: 'Submetido',
|
||||
in_review: 'Em revisão',
|
||||
reviewed: 'Revisto',
|
||||
qualification: 'Em qualificação',
|
||||
qualified: 'Qualificado',
|
||||
contacted: 'Contactado',
|
||||
contact_accepted: 'Contacto aceite',
|
||||
referred: 'Encaminhado',
|
||||
due_diligence: 'Em diligência',
|
||||
negotiation: 'Em negociação',
|
||||
pending: 'Pendente',
|
||||
accepted: 'Aceite',
|
||||
rejected: 'Recusado',
|
||||
returned: 'Devolvido',
|
||||
processing: 'Em tratamento',
|
||||
draft: 'Rascunho',
|
||||
};
|
||||
const title =
|
||||
kind === 'interest'
|
||||
? 'Atribuições de interesses'
|
||||
: 'Atribuições do Balcão';
|
||||
const [selected, setSelected] = useState<Record<string, string>>({});
|
||||
const [reason, setReason] = useState<Record<string, string>>({});
|
||||
const [errors, setErrors] = useState<Record<string, string>>({});
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
function assign(row: Row) {
|
||||
setBusy(row.id);
|
||||
setErrors({});
|
||||
router.post(
|
||||
kind === 'interest'
|
||||
? `/management/interests/${row.id}/responsavel`
|
||||
: `/balcao-virtual/pedidos/${row.id}/responsavel`,
|
||||
{
|
||||
...(kind === 'interest'
|
||||
? { etag: row.etag }
|
||||
: { version: row.version }),
|
||||
analyst_id: selected[row.id] ?? String(row.analyst_id ?? ''),
|
||||
reason: reason[row.id] ?? '',
|
||||
},
|
||||
{
|
||||
preserveScroll: true,
|
||||
onError: (e) => {
|
||||
setErrors(e);
|
||||
queueMicrotask(() => alertRef.current?.focus());
|
||||
},
|
||||
onFinish: () => setBusy(null),
|
||||
},
|
||||
);
|
||||
}
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl space-y-6 p-6">
|
||||
<Head title={title} />
|
||||
<h1 className="text-2xl font-semibold">{title}</h1>
|
||||
<p>
|
||||
Atribua o acompanhamento de um pedido. Esta lista não dá acesso
|
||||
ao conteúdo privado do dossier. O proponente não pode ser
|
||||
designado como analista do seu pedido.
|
||||
</p>
|
||||
<a
|
||||
href={
|
||||
kind === 'interest'
|
||||
? '/management/interests'
|
||||
: '/balcao-virtual/painel'
|
||||
}
|
||||
className="underline"
|
||||
>
|
||||
{kind === 'interest'
|
||||
? 'Interesses atribuídos'
|
||||
: 'Voltar ao Balcão'}
|
||||
</a>
|
||||
<div ref={alertRef} role="alert" tabIndex={-1}>
|
||||
{Object.values(errors).join(' ')}
|
||||
</div>
|
||||
{flash?.success && <p role="status">{flash.success}</p>}
|
||||
{requests.length === 0 ? (
|
||||
<p>Não há pedidos para atribuir.</p>
|
||||
) : (
|
||||
requests.map((row) => (
|
||||
<section
|
||||
key={row.id}
|
||||
className="space-y-3 rounded border p-4"
|
||||
>
|
||||
<h2 className="font-semibold">
|
||||
{row.protocol || row.id}
|
||||
</h2>
|
||||
<p>
|
||||
Estado: {stateNames[row.status] ?? 'Por esclarecer'}
|
||||
</p>
|
||||
<label className="block">
|
||||
Responsável
|
||||
<select
|
||||
className="ml-2 border p-2"
|
||||
value={
|
||||
selected[row.id] ??
|
||||
String(row.analyst_id ?? '')
|
||||
}
|
||||
onChange={(e) =>
|
||||
setSelected({
|
||||
...selected,
|
||||
[row.id]: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{analysts.map((a) => (
|
||||
<option key={a.id} value={a.id}>
|
||||
{a.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="block">
|
||||
Fundamento
|
||||
<textarea
|
||||
className="block w-full border p-2"
|
||||
value={reason[row.id] ?? ''}
|
||||
onChange={(e) =>
|
||||
setReason({
|
||||
...reason,
|
||||
[row.id]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className="rounded bg-emerald-900 px-4 py-2 text-white"
|
||||
disabled={busy !== null}
|
||||
onClick={() => assign(row)}
|
||||
>
|
||||
{busy === row.id
|
||||
? 'A guardar…'
|
||||
: 'Guardar atribuição'}
|
||||
</button>
|
||||
</section>
|
||||
))
|
||||
)}
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user