All files / src/utils ticketStatus.ts

61.11% Statements 11/18
0% Branches 0/3
60% Functions 3/5
68.75% Lines 11/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61    4x             4x                                             4x 3x     4x 3x     4x             4x             4x 1x 1x        
import type { TicketRejectReason } from '@/models/ticket';
import type { TicketStatus } from '@/models/event';
import i18n from '@/i18n';
 
export interface TicketStatusBadgeColors {
  backgroundColor: string;
  textColor: string;
}
 
const TICKET_STATUS_COLORS: Record<TicketStatus, TicketStatusBadgeColors> = {
  ACTIVE: {
    backgroundColor: '#DCFCE7',
    textColor: '#16A34A',
  },
  PENDING: {
    backgroundColor: '#FEF3C7',
    textColor: '#D97706',
  },
  EXPIRED: {
    backgroundColor: '#FEF3C7',
    textColor: '#D97706',
  },
  USED: {
    backgroundColor: '#E2E8F0',
    textColor: '#64748B',
  },
  CANCELED: {
    backgroundColor: '#FEE2E2',
    textColor: '#EF4444',
  },
};
 
export function getTicketStatusBadgeColors(status: TicketStatus): TicketStatusBadgeColors {
  return TICKET_STATUS_COLORS[status];
}
 
export function formatTicketStatusLabel(status: TicketStatus): string {
  return i18n.t(`tickets.status.${status}`);
}
 
export function getAttendeeLabel(count?: number | null) {
  Iif (count == null) {
    return i18n.t('common.notAvailable');
  }
  return String(count);
}
 
export function getTicketScanRejectMessage(reason?: TicketRejectReason | null): string {
  Iif (!reason) return i18n.t('tickets.scan.rejectDefault');
  return i18n.t(`tickets.scan.rejectReasons.${reason}`, {
    defaultValue: i18n.t('tickets.scan.rejectDefault'),
  });
}
 
export function getTicketQrAccessMessage(reason?: string | null): string {
  Iif (!reason) return i18n.t('tickets.qr.accessUnavailable');
  return i18n.t(`tickets.qr.accessReasons.${reason}`, {
    defaultValue: i18n.t('tickets.qr.accessUnavailable'),
  });
}