import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity'; import { usePreparationDirty } from '@/hooks/use-preparation-dirty'; import { hasPreparationChanges } from '@/lib/requisition-history'; import type { GeographyDescription } from '@/components/administrative-location'; import { Head, Link, router, useForm } from '@inertiajs/react'; import { Download, FileLock2, Pencil, Upload } from 'lucide-react'; import { useRef } from '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 { date } from '@/types/procurement'; import { documentTypes, supplierFields, supplierStatuses, } from '@/types/supplier'; import type { Supplier } from '@/types/supplier'; type Document = { id: number; original_name: string; document_type: string; size: number; created_at: string; sha256: string; }; type Props = { geography?: GeographyDescription; supplier: Supplier; documents: Document[]; canEdit: boolean; canDocuments: boolean; canReview: boolean; }; export default function SupplierShow({ supplier, geography = null, documents, canEdit, canDocuments, canReview, }: Props) { const upload = useForm<{ file: File | null; document_type: string }>({ file: null, document_type: 'license', }); const fileInput = useRef(null); return ( <>
Editar ficha ) : undefined } /> {geography && (

Localização administrativa:{' '} {geography.path .map((node) => node.name) .join(' / ')} {geography.requires_review ? ' (requer revisão)' : ''}

)} {canDocuments && ( Dados bancários e dupla validação → )}
{Object.entries(supplierFields).map(([key, label]) => (
{label}
{key === 'next_review' ? date(supplier.next_review) : supplier[ key as keyof typeof supplierFields ]}
))}
{supplier.review_comment && (

Última validação: {supplier.review_comment}

)}
{canDocuments ? (
{documents.map((document) => (

{document.original_name}

{ documentTypes[ document.document_type ] }{' '} ·{' '} {Math.ceil( document.size / 1024, )}{' '} KB · {date(document.created_at)}

))} {documents.length === 0 && (

Ainda não existem documentos anexados a esta ficha.

)}
{canEdit && (
{ e.preventDefault(); upload.post( `/fornecedores/${supplier.id}/documentos`, { forceFormData: true, preserveScroll: true, onSuccess: () => { upload.reset(); if (fileInput.current) fileInput.current.value = ''; }, }, ); }} >

Anexar documento

upload.setData( 'file', e.target.files?.[0] ?? null, ) } />

O envio de um documento devolve o fornecedor ao estado pendente de validação. Os documentos existentes permanecem no histórico.

{upload.progress && (

Envio: {upload.progress.percentage}%

)} )}
) : (

O acesso aos documentos está reservado a Administração, Procurement e Finanças.

)}
{canReview && ( )}
); } SupplierShow.layout = { breadcrumbs: [ { title: 'Fornecedores', href: '/fornecedores' }, { title: 'Ficha e documentos', href: '#' }, ], }; function SupplierReview({ supplier }: { supplier: Supplier }) { const identity = useProcurementPreparationIdentity( `supplier-review:${supplier.id}:${supplier.version}`, ); return ( ); } function ReviewFields({ supplier, identity, }: { supplier: Supplier; identity: string; }) { const initial = { status: 'active', comment: '' }; const review = useForm(identity, initial); const dirty = hasPreparationChanges(initial, review.data); const ref = usePreparationDirty(dirty); return (
{ e.preventDefault(); review.transform((data) => ({ ...data, version: supplier.version, })); review.post(`/fornecedores/${supplier.id}/validar`, { preserveScroll: true, onSuccess: () => { review.setData(initial); review.clearErrors(); router.remember(initial, `${identity}:data`); router.remember({}, `${identity}:errors`); }, }); }} >