|
| 1 | +import { AlertCircle, CheckCircle } from 'lucide-react'; |
| 2 | +import DateSelection from './DateSelection'; |
| 3 | +import TimeSlotSelection from './TimeSlotSelection'; |
| 4 | +import BookingSummary from './BookingSummary'; |
| 5 | + |
| 6 | +const BookingForm = ({ |
| 7 | + schedule, |
| 8 | + selectedDate, |
| 9 | + setSelectedDate, |
| 10 | + availableSlots, |
| 11 | + selectedSlot, |
| 12 | + setSelectedSlot, |
| 13 | + reason, |
| 14 | + setReason, |
| 15 | + isTeleconsultation, |
| 16 | + setIsTeleconsultation, |
| 17 | + loading, |
| 18 | + error, |
| 19 | + success, |
| 20 | + dateAvailability, |
| 21 | + doctor, |
| 22 | + onBooking, |
| 23 | +}) => { |
| 24 | + return ( |
| 25 | + <div className="lg:col-span-2"> |
| 26 | + <div className="bg-white rounded-lg shadow-md p-6"> |
| 27 | + <h3 className="text-lg font-semibold text-gray-900 mb-6">Select Date & Time</h3> |
| 28 | + |
| 29 | + {/* Success/Error Messages */} |
| 30 | + {error && ( |
| 31 | + <div className="mb-6 p-4 bg-red-50 border border-red-200 rounded-lg"> |
| 32 | + <div className="flex items-center"> |
| 33 | + <AlertCircle className="h-5 w-5 text-red-500 mr-2" /> |
| 34 | + <p className="text-red-700">{error}</p> |
| 35 | + </div> |
| 36 | + </div> |
| 37 | + )} |
| 38 | + |
| 39 | + {success && ( |
| 40 | + <div className="mb-6 p-4 bg-green-50 border border-green-200 rounded-lg"> |
| 41 | + <div className="flex items-center"> |
| 42 | + <CheckCircle className="h-5 w-5 text-green-500 mr-2" /> |
| 43 | + <p className="text-green-700">{success}</p> |
| 44 | + </div> |
| 45 | + </div> |
| 46 | + )} |
| 47 | + |
| 48 | + <form onSubmit={onBooking} className="space-y-6"> |
| 49 | + {/* Date Selection */} |
| 50 | + <DateSelection |
| 51 | + selectedDate={selectedDate} |
| 52 | + setSelectedDate={setSelectedDate} |
| 53 | + schedule={schedule} |
| 54 | + dateAvailability={dateAvailability} |
| 55 | + /> |
| 56 | + |
| 57 | + {/* Time Slot Selection */} |
| 58 | + {selectedDate && availableSlots.length > 0 && ( |
| 59 | + <TimeSlotSelection |
| 60 | + availableSlots={availableSlots} |
| 61 | + selectedSlot={selectedSlot} |
| 62 | + setSelectedSlot={setSelectedSlot} |
| 63 | + /> |
| 64 | + )} |
| 65 | + |
| 66 | + {/* Reason for Visit */} |
| 67 | + <div> |
| 68 | + <label htmlFor="reason" className="block text-sm font-medium text-gray-700 mb-2"> |
| 69 | + Reason for Visit * |
| 70 | + </label> |
| 71 | + <textarea |
| 72 | + id="reason" |
| 73 | + value={reason} |
| 74 | + onChange={(e) => setReason(e.target.value)} |
| 75 | + rows={3} |
| 76 | + className="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-blue-500 focus:border-blue-500" |
| 77 | + placeholder="Please describe your symptoms or reason for consultation..." |
| 78 | + required |
| 79 | + /> |
| 80 | + </div> |
| 81 | + |
| 82 | + {/* Teleconsultation Option */} |
| 83 | + {doctor?.availableForTeleconsultation && ( |
| 84 | + <div className="flex items-center"> |
| 85 | + <input |
| 86 | + id="teleconsultation" |
| 87 | + type="checkbox" |
| 88 | + checked={isTeleconsultation} |
| 89 | + onChange={(e) => setIsTeleconsultation(e.target.checked)} |
| 90 | + className="h-4 w-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500" |
| 91 | + /> |
| 92 | + <label htmlFor="teleconsultation" className="ml-2 text-sm text-gray-700"> |
| 93 | + Request Teleconsultation (Video Call) |
| 94 | + </label> |
| 95 | + </div> |
| 96 | + )} |
| 97 | + |
| 98 | + {/* Booking Summary */} |
| 99 | + {selectedDate && selectedSlot && ( |
| 100 | + <BookingSummary |
| 101 | + selectedDate={selectedDate} |
| 102 | + selectedSlot={selectedSlot} |
| 103 | + isTeleconsultation={isTeleconsultation} |
| 104 | + consultationFee={doctor?.consultationFee} |
| 105 | + /> |
| 106 | + )} |
| 107 | + |
| 108 | + {/* Submit Button */} |
| 109 | + <button |
| 110 | + type="submit" |
| 111 | + disabled={loading || !selectedDate || !selectedSlot || !reason.trim()} |
| 112 | + className="w-full bg-blue-600 text-white py-3 px-4 rounded-lg font-medium hover:bg-blue-700 focus:ring-4 focus:ring-blue-200 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors" |
| 113 | + > |
| 114 | + {loading ? ( |
| 115 | + <div className="flex items-center justify-center"> |
| 116 | + <div className="animate-spin rounded-full h-5 w-5 border-b-2 border-white mr-2"></div> |
| 117 | + Booking Appointment... |
| 118 | + </div> |
| 119 | + ) : ( |
| 120 | + 'Book Appointment' |
| 121 | + )} |
| 122 | + </button> |
| 123 | + </form> |
| 124 | + </div> |
| 125 | + </div> |
| 126 | + ); |
| 127 | +}; |
| 128 | + |
| 129 | +export default BookingForm; |
0 commit comments