Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
20 lines
730 B
TypeScript
20 lines
730 B
TypeScript
type BookingExpiresAt = string | Date | Record<string, unknown> | null | undefined
|
|
|
|
const bookingExpiresAtMs = (expiresAt: BookingExpiresAt): number | null => {
|
|
if (expiresAt == null) return null
|
|
if (typeof expiresAt === 'string' || expiresAt instanceof Date) {
|
|
const ms = new Date(expiresAt).getTime()
|
|
|
|
return Number.isNaN(ms) ? null : ms
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
/** Whether a pending_payment booking's hold window has passed (client clock). */
|
|
export const isBookingPaymentExpired = (booking: { status: string; expiresAt?: BookingExpiresAt }): boolean => {
|
|
const expiresAtMs = bookingExpiresAtMs(booking.expiresAt)
|
|
|
|
return booking.status === 'pending_payment' && expiresAtMs != null && expiresAtMs <= Date.now()
|
|
}
|