import { Head, Link, router, useForm, usePage } from '@inertiajs/react'; import { FormErrors, PageTitle, Panel } from '@/components/procurement'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { date, roleLabels } from '@/types/procurement'; type Criterion = { id: number; label: string; category: string; required: boolean; }; type Answer = { criterion_id: number; result: 'pending' | 'met' | 'not_met' | 'not_applicable'; evidence: string; reason: string; }; type Proposal = { id: number; reference: string; supplier: { name: string } | null; }; type Set = { id: number; revision: number; reason: string; created_at: string; criteria: Criterion[]; snapshot: { author: { name: string }; proposals: Proposal[] }; }; type Assessment = { id: number; quotation_id: number; analyst_id: number; revision: number; answers: Answer[]; reason: string; created_at: string; snapshot: { analyst: { name: string; purchasing_role: string } }; }; type Props = { requisition: { id: number; number: string; justification: string }; sets: Pick[]; selected: Set | null; latestId: number; latestCriteria: Criterion[]; basisHash: string; isCurrent: boolean; proposals: Proposal[]; records: Assessment[]; history: { data: Assessment[]; prev_page_url: string | null; next_page_url: string | null; }; actorId: number; canDefine: boolean; canAssess: boolean; closedForChanges: boolean; }; const categories: Record = { legal: 'Jurídica', financial: 'Económico-financeira', fiscal: 'Fiscal', technical: 'Técnica', administrative: 'Administrativa', }; const results: Record = { pending: 'Por analisar', met: 'Cumprido', not_met: 'Não cumprido', not_applicable: 'Não aplicável', }; const selectClass = 'h-10 w-full rounded-md border bg-background px-3 text-sm'; function DefineForm({ requisition, latestId, latestCriteria, basisHash, proposals, }: Pick< Props, 'requisition' | 'latestId' | 'latestCriteria' | 'basisHash' | 'proposals' >) { const form = useForm({ previous_id: latestId, basis_hash: basisHash, reason: '', criteria: latestCriteria.length ? latestCriteria.map(({ label, category, required }) => ({ label, category, required, })) : [{ label: '', category: 'administrative', required: false }], }); const change = ( index: number, values: Partial>, ) => form.setData( 'criteria', form.data.criteria.map((criterion, position) => position === index ? { ...criterion, ...values } : criterion, ), ); return (
{ event.preventDefault(); form.post(`/requisicoes/${requisition.id}/qualificacao`, { preserveScroll: true, onSuccess: () => form.setData('reason', ''), }); }} className="space-y-4" > {(form.data.previous_id !== latestId || form.data.basis_hash !== basisHash) && (

Os requisitos ou as propostas mudaram. O texto introduzido foi mantido; confira a base actual antes de criar uma nova versão.

)}

Esta versão ficará ligada às {proposals.length} propostas actualmente registadas:{' '} {proposals.map((proposal) => proposal.reference).join(', ')}.

{form.data.criteria.map((criterion, index) => (
{form.data.criteria.length > 1 && ( )}
))}