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 && } @@ -150,6 +172,7 @@ function DetailsModal({ r, isOpen, onClose, 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 ( @@ -186,13 +209,16 @@ function DetailsModal({ r, isOpen, onClose, onPay, payingId }) {

المعلومات المالية

الإجمالي{r.totalPrice?.toLocaleString()??'—'}
- {isOwnerConfirmed &&
- متبقي للدفع: - - + }
}
@@ -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) {