import { Head, Link, useForm, router } from '@inertiajs/react'; import { Ban, CalendarDays, MessageSquareText, Plus, Repeat, Filter, X, } from 'lucide-react'; import { useState } from 'react'; import InputError from '@/components/input-error'; import { PageHeading } from '@/components/page-heading'; import { ReservationStatus } from '@/components/reservation-status'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Label } from '@/components/ui/label'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select'; import type { Paginated, Reservation } from '@/types'; const statusOptions = [ { value: '', label: 'Todos os estados' }, { value: 'pending_approval', label: 'Pendente de aprovação' }, { value: 'awaiting_information', label: 'A aguardar esclarecimentos' }, { value: 'approved', label: 'Aprovada' }, { value: 'ready', label: 'Pronta para entrega' }, { value: 'delivered', label: 'Entregue' }, { value: 'in_use', label: 'Em utilização' }, { value: 'returned', label: 'Devolvida' }, { value: 'completed', label: 'Concluída' }, { value: 'rejected', label: 'Rejeitada' }, { value: 'cancelled', label: 'Cancelada' }, { value: 'expired', label: 'Expirada' }, { value: 'no_show', label: 'Falta' }, { value: 'overdue', label: 'Atrasada' }, { value: 'incident', label: 'Incidente' }, ]; export default function ReservationsIndex({ reservations, status = '', }: { reservations: Paginated; status?: string; }) { const [selected, setSelected] = useState(null); const [clarification, setClarification] = useState( null, ); const cancelForm = useForm({ reason: '' }); const clarificationForm = useForm({ response: '' }); const format = new Intl.DateTimeFormat('pt-PT', { dateStyle: 'medium', timeStyle: 'short', }); const cancellableStatuses = [ 'draft', 'pending_approval', 'awaiting_information', 'approved', 'ready', ]; function handleStatusChange(value: string) { router.get('/requisicoes', { status: value || undefined }, { preserveState: true, preserveScroll: true, }); } function openCancellation(reservation: Reservation) { cancelForm.reset(); cancelForm.clearErrors(); setSelected(reservation); } function submitCancellation(event: React.FormEvent) { event.preventDefault(); if (!selected) { return; } cancelForm.post(`/requisicoes/${selected.uuid}/cancelar`, { preserveScroll: true, onSuccess: () => setSelected(null), }); } function openClarification(reservation: Reservation) { clarificationForm.reset(); clarificationForm.clearErrors(); setClarification(reservation); } function submitClarification(event: React.FormEvent) { event.preventDefault(); if (!clarification) { return; } clarificationForm.post(`/requisicoes/${clarification.uuid}/responder`, { preserveScroll: true, onSuccess: () => setClarification(null), }); } return ( <>
Nova requisição } />
{status && ( )}
{reservations.data.length ? (
Referência Equipamentos Período Estado Ações
{reservations.data.map((reservation) => (
{reservation.reference} {reservation.recurring_group_id && ( {' '} Série semanal )}
{reservation.status === 'awaiting_information' && ( )}

{reservation.items .map((item) => item.asset.name) .join(', ')}

{reservation.purpose}

{format.format( new Date(reservation.starts_at), )}

{format.format( new Date(reservation.ends_at), )}

{cancellableStatuses.includes( reservation.status, ) && ( )}
))}
) : (

Ainda não criou requisições

)} {reservations.last_page > 1 && ( )} !open && setSelected(null)} >
Cancelar requisição {selected?.reference}: indique o motivo. O cancelamento liberta imediatamente os equipamentos reservados.