feat: 完善课程订阅
This commit is contained in:
81
packages/app/src/utils/booking-helpers.ts
Normal file
81
packages/app/src/utils/booking-helpers.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { BookingStatus } from '@mp-pilates/shared'
|
||||
|
||||
/** 格式化日期显示:今天/明天/M月D日 星期X */
|
||||
export function formatDateDisplay(dateStr: string): string {
|
||||
const normalized = dateStr.slice(0, 10)
|
||||
const [y, m, d] = normalized.split('-').map(Number)
|
||||
const localDate = new Date(y, m - 1, d)
|
||||
|
||||
const today = new Date()
|
||||
const todayStr = `${today.getFullYear()}-${String(today.getMonth() + 1).padStart(2, '0')}-${String(today.getDate()).padStart(2, '0')}`
|
||||
|
||||
const tomorrow = new Date(today.getTime() + 86400000)
|
||||
const tomorrowStr = `${tomorrow.getFullYear()}-${String(tomorrow.getMonth() + 1).padStart(2, '0')}-${String(tomorrow.getDate()).padStart(2, '0')}`
|
||||
|
||||
if (normalized === todayStr) return `今天 ${m}月${d}日`
|
||||
if (normalized === tomorrowStr) return `明天 ${m}月${d}日`
|
||||
|
||||
const weekdayLabels = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
|
||||
return `${m}月${d}日 ${weekdayLabels[localDate.getDay()]}`
|
||||
}
|
||||
|
||||
// ─── Booking status helpers ───────────────────────────────────────────────────
|
||||
|
||||
export const BOOKING_STATUS_LABELS: Record<string, string> = {
|
||||
[BookingStatus.PENDING_CONFIRMATION]: '待确认',
|
||||
[BookingStatus.CONFIRMED]: '已确认',
|
||||
[BookingStatus.CANCELLED]: '已取消',
|
||||
[BookingStatus.COMPLETED]: '已完成',
|
||||
[BookingStatus.NO_SHOW]: '未出席',
|
||||
}
|
||||
|
||||
export const BOOKING_STATUS_BADGE_CLASSES: Record<string, string> = {
|
||||
[BookingStatus.PENDING_CONFIRMATION]: 'badge--pending',
|
||||
[BookingStatus.CONFIRMED]: 'badge--confirmed',
|
||||
[BookingStatus.CANCELLED]: 'badge--cancelled',
|
||||
[BookingStatus.COMPLETED]: 'badge--completed',
|
||||
[BookingStatus.NO_SHOW]: 'badge--noshow',
|
||||
}
|
||||
|
||||
export const BOOKING_STATUS_STRIPE_CLASSES: Record<string, string> = {
|
||||
[BookingStatus.PENDING_CONFIRMATION]: 'stripe--pending',
|
||||
[BookingStatus.CONFIRMED]: 'stripe--confirmed',
|
||||
[BookingStatus.CANCELLED]: 'stripe--cancelled',
|
||||
[BookingStatus.COMPLETED]: 'stripe--completed',
|
||||
[BookingStatus.NO_SHOW]: 'stripe--noshow',
|
||||
}
|
||||
|
||||
export const BOOKING_STATUS_BANNER_CLASSES: Record<string, string> = {
|
||||
[BookingStatus.PENDING_CONFIRMATION]: 'banner--pending',
|
||||
[BookingStatus.CONFIRMED]: 'banner--confirmed',
|
||||
[BookingStatus.CANCELLED]: 'banner--cancelled',
|
||||
[BookingStatus.COMPLETED]: 'banner--completed',
|
||||
[BookingStatus.NO_SHOW]: 'banner--noshow',
|
||||
}
|
||||
|
||||
export function bookingStatusLabel(status: string): string {
|
||||
return BOOKING_STATUS_LABELS[status] ?? status
|
||||
}
|
||||
|
||||
export function bookingStatusBadgeClass(status: string): string {
|
||||
return BOOKING_STATUS_BADGE_CLASSES[status] ?? ''
|
||||
}
|
||||
|
||||
export function bookingStatusStripeClass(status: string): string {
|
||||
return BOOKING_STATUS_STRIPE_CLASSES[status] ?? ''
|
||||
}
|
||||
|
||||
export function bookingStatusBannerClass(status: string): string {
|
||||
return BOOKING_STATUS_BANNER_CLASSES[status] ?? ''
|
||||
}
|
||||
|
||||
export function bookingTimelineDotClass(status: string): string {
|
||||
switch (status) {
|
||||
case BookingStatus.PENDING_CONFIRMATION: return 'dot--pending'
|
||||
case BookingStatus.CONFIRMED: return 'dot--confirmed'
|
||||
case BookingStatus.COMPLETED: return 'dot--completed'
|
||||
case BookingStatus.CANCELLED: return 'dot--cancelled'
|
||||
case BookingStatus.NO_SHOW: return 'dot--noshow'
|
||||
default: return ''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user