diff --git a/src/components/channel-manager/ReservationFormModal.tsx b/src/components/channel-manager/ReservationFormModal.tsx new file mode 100644 index 0000000..eb4781b --- /dev/null +++ b/src/components/channel-manager/ReservationFormModal.tsx @@ -0,0 +1,295 @@ +import React, { useState, useEffect } from 'react'; +import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; +import { Textarea } from '@/components/ui/textarea'; +import { Loader2 } from 'lucide-react'; +import { Reservation, Listing } from '@/hooks/useChannelManager'; + +interface ReservationFormModalProps { + open: boolean; + onClose: () => void; + onSubmit: (data: any) => Promise; + reservation?: Reservation | null; + listings: Listing[]; + mode: 'create' | 'edit'; +} + +export const ReservationFormModal: React.FC = ({ + open, + onClose, + onSubmit, + reservation, + listings, + mode +}) => { + const [loading, setLoading] = useState(false); + const [formData, setFormData] = useState({ + listingId: '', + guestName: '', + guestEmail: '', + guestPhone: '', + checkIn: '', + checkOut: '', + guests: 1, + totalAmount: 0, + status: 'pending' as 'confirmed' | 'pending' | 'cancelled' | 'completed', + paymentStatus: 'pending' as 'paid' | 'pending' | 'refunded', + channel: 'direct', + specialRequests: '', + }); + + useEffect(() => { + if (reservation && mode === 'edit') { + setFormData({ + listingId: reservation.listingId, + guestName: reservation.guestName, + guestEmail: reservation.guestEmail, + guestPhone: reservation.guestPhone, + checkIn: reservation.checkIn, + checkOut: reservation.checkOut || '', + guests: reservation.guests, + totalAmount: reservation.totalAmount, + status: reservation.status, + paymentStatus: reservation.paymentStatus, + channel: reservation.channel, + specialRequests: reservation.specialRequests || '', + }); + } else if (mode === 'create') { + setFormData({ + listingId: '', + guestName: '', + guestEmail: '', + guestPhone: '', + checkIn: '', + checkOut: '', + guests: 1, + totalAmount: 0, + status: 'pending', + paymentStatus: 'pending', + channel: 'direct', + specialRequests: '', + }); + } + }, [reservation, mode, open]); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setLoading(true); + const success = await onSubmit(formData); + if (success) { + onClose(); + } + setLoading(false); + }; + + const handleChange = (field: string, value: any) => { + setFormData(prev => ({ ...prev, [field]: value })); + }; + + return ( + + + + + {mode === 'create' ? 'Crear Nueva Reserva' : 'Editar Reserva'} + + + {mode === 'create' + ? 'Complete los datos para crear una nueva reserva' + : 'Modifique los datos de la reserva'} + + + +
+ {/* Listing Selection */} +
+ + +
+ + {/* Guest Information */} +
+
+ + handleChange('guestName', e.target.value)} + required + /> +
+
+ + handleChange('guestEmail', e.target.value)} + required + /> +
+
+ +
+ + handleChange('guestPhone', e.target.value)} + required + /> +
+ + {/* Dates */} +
+
+ + handleChange('checkIn', e.target.value)} + required + /> +
+
+ + handleChange('checkOut', e.target.value)} + /> +
+
+ + {/* Guests and Amount */} +
+
+ + handleChange('guests', parseInt(e.target.value))} + required + /> +
+
+ + handleChange('totalAmount', parseFloat(e.target.value))} + required + /> +
+
+ + {/* Status */} +
+
+ + +
+
+ + +
+
+ + {/* Channel */} +
+ + +
+ + {/* Special Requests */} +
+ +