diff --git a/app/reservations/page.js b/app/reservations/page.js
index a7f4f39..859b31d 100644
--- a/app/reservations/page.js
+++ b/app/reservations/page.js
@@ -68,6 +68,24 @@ function parseTimeSpan(str) {
return ((days * 86400) + (hh * 3600) + (mm * 60) + ss) * 1000;
}
+function formatWindowDuration(str) {
+ if (!str) return '';
+ const clean = str.replace(/-/g, '');
+ const dotIdx = clean.indexOf('.');
+ let totalHours = 0, timePart = clean;
+ if (dotIdx !== -1) {
+ const days = parseInt(clean.substring(0, dotIdx), 10) || 0;
+ totalHours += days * 24;
+ timePart = clean.substring(dotIdx + 1);
+ }
+ const parts = timePart.split(':');
+ if (parts.length >= 2) {
+ totalHours += parseInt(parts[0], 10) || 0;
+ }
+ if (totalHours > 0) return `${String(totalHours).padStart(2, '0')}:00:00`;
+ return timePart.substring(0, 8);
+}
+
function CountdownTimer({ deadline }) {
const [remaining, setRemaining] = useState(deadline ? Math.max(0, deadline - Date.now()) : 0);
useEffect(() => {
@@ -96,6 +114,7 @@ function ReservationCard({ r, onViewDetails, onPay, payingId }) {
const deadline = isOwnerConfirmed && r.ownerApprovalDate
? new Date(r.ownerApprovalDate).getTime() + parseTimeSpan(r.allowedPaymentPeriod)
: null;
+ const isExpired = deadline ? Date.now() > deadline : false;
const isPaying = payingId === r.id;
return (
@@ -124,16 +143,19 @@ function ReservationCard({ r, onViewDetails, onPay, payingId }) {
{new Date(r.endDate).toLocaleDateString('ar')}
- {isOwnerConfirmed &&
-
متبقي للدفع:
-
+ {isOwnerConfirmed &&
+
+ متبقي للدفع:
+
+
+ {r.allowedPaymentPeriod &&
مدة الدفع: {formatWindowDuration(r.allowedPaymentPeriod)}
}
}
- {isOwnerConfirmed &&
- {isOwnerConfirmed &&
-
متبقي للدفع:
-
-
{ onPay(r); onClose(); }} disabled={isPaying}
- className={`px-6 py-2 rounded-xl font-medium transition-colors flex items-center gap-2 ${isPaying ? 'bg-gray-300 text-gray-500 cursor-not-allowed' : 'bg-amber-500 text-white hover:bg-amber-600'}`}>
+ {isOwnerConfirmed &&
+
+ متبقي للدفع:
+
+
+ {r.allowedPaymentPeriod &&
مدة الدفع: {formatWindowDuration(r.allowedPaymentPeriod)}
}
+ {!isExpired &&
{ onPay(r); onClose(); }} disabled={isPaying}
+ className={`w-full py-2 rounded-xl font-medium transition-colors flex items-center justify-center gap-2 ${isPaying ? 'bg-gray-300 text-gray-500 cursor-not-allowed' : 'bg-amber-500 text-white hover:bg-amber-600'}`}>
{isPaying ? : } {isPaying ? 'جاري الدفع...' : 'ادفع الآن'}
-
+ }
}
@@ -241,7 +267,12 @@ export default function UserReservationsPage() {
const handlePay = async (r) => {
setPayingId(r.id);
try {
- await payDeposit({ reservationId: r.id });
+ await payDeposit({
+ reservationId: r.id,
+ paymentTypeId: 1,
+ transactionType: 1,
+ comment: null,
+ });
toast.success('تم دفع السلفة بنجاح!');
loadReservations();
} catch (err) {