diff --git a/app/property/[id]/page.js b/app/property/[id]/page.js
index 596b1be..ccaa36f 100644
--- a/app/property/[id]/page.js
+++ b/app/property/[id]/page.js
@@ -277,17 +277,20 @@ export default function PropertyDetailsPage() {
return;
}
+ const propId = property?._raw?.id || parseInt(params.id);
+ const startDate = new Date(bookingDates.start).toISOString();
+ const endDate = new Date(bookingDates.end).toISOString();
+
+ console.log('[Booking] Reserving:', { propertyId: propId, startDate, endDate });
+
try {
- await bookReservation({
- propertyId: parseInt(params.id),
- startDate: new Date(bookingDates.start).toISOString(),
- endDate: new Date(bookingDates.end).toISOString(),
- });
+ const res = await bookReservation(propId, startDate, endDate);
+ console.log('[Booking] Success:', res);
setBookingSuccess(true);
+ toast.success('تم إرسال طلب الحجز بنجاح!');
} catch (err) {
- // If API fails, show success anyway for demo purposes
- console.warn('Booking API failed:', err);
- setBookingSuccess(true);
+ console.error('[Booking] Failed:', err);
+ setBookingError(err.message || 'فشل في إرسال طلب الحجز');
}
};
@@ -673,18 +676,28 @@ export default function PropertyDetailsPage() {
-
- السعر لـ {selectedDuration} أيام
- {formatCurrency(property.price * selectedDuration)}
-
-
- سلفة ضمان
- {formatCurrency(500000)}
-
-
- الإجمالي
- {formatCurrency(property.price * selectedDuration + 500000)}
-
+ {(() => {
+ const days = bookingDates.start && bookingDates.end
+ ? Math.ceil((new Date(bookingDates.end) - new Date(bookingDates.start)) / (1000 * 60 * 60 * 24))
+ : 0;
+ const effectiveDays = days > 0 ? days : 1;
+ return (
+ <>
+
+ السعر لـ {effectiveDays} يوم{effectiveDays > 1 ? 'اً' : 'اً'}
+ {formatCurrency(property.price * effectiveDays)}
+
+
+ سلفة ضمان
+ {formatCurrency(property._raw?.deposit || 0)}
+
+
+ الإجمالي
+ {formatCurrency(property.price * effectiveDays + (property._raw?.deposit || 0))}
+
+ >
+ );
+ })()}
{bookingError && (
diff --git a/app/utils/api.js b/app/utils/api.js
index e09737a..20e2ebd 100644
--- a/app/utils/api.js
+++ b/app/utils/api.js
@@ -149,10 +149,11 @@ export async function checkAvailability(propertyId, fromDate = null, toDate = nu
return apiFetch(`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ''}`);
}
-export async function bookReservation(data) {
- return apiFetch('/Reservations/Book', {
+export async function bookReservation(propertyId, startDate, endDate) {
+ console.log('[API] Booking reservation:', { propertyId, startDate, endDate });
+ return apiFetch('/Reservations/BookReservation/book', {
method: 'POST',
- body: JSON.stringify(data),
+ body: JSON.stringify({ propertyId, startDate, endDate }),
});
}