All files / src/utils eventStatus.ts

65.3% Statements 32/49
85.71% Branches 12/14
50% Functions 2/4
65.3% Lines 32/49

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 62 63 64 65 66 67 68 69 70 71 72 731x                               1x 37x 15x 15x 37x 4x 4x 18x 18x   1x                                         1x 27x 27x 5x 27x 1x 27x   27x 20x 27x 1x 1x 1x 1x 1x 1x 1x 1x 27x 27x   1x      
import i18n from '@/i18n';
 
export type EventLifecycleVariant = 'upcoming' | 'in_progress';
export type EventCardBadgeVariant = EventLifecycleVariant | 'canceled' | 'completed';
 
export interface EventLifecyclePresentation {
  label: string;
  variant: EventLifecycleVariant;
}
 
export interface EventCardBadgePresentation {
  label: string;
  variant: EventCardBadgeVariant;
}
 
/** Labels and styling for ACTIVE (shown as UPCOMING) and IN_PROGRESS on cards and detail. */
export function getEventLifecyclePresentation(status: string): EventLifecyclePresentation | null {
  if (status === 'ACTIVE') {
    return { label: i18n.t('events.status.UPCOMING'), variant: 'upcoming' };
  }
  if (status === 'IN_PROGRESS') {
    return { label: i18n.t('events.status.IN_PROGRESS_BADGE'), variant: 'in_progress' };
  }
  return null;
}
 
export function getEventCardBadgePresentation(status: string): EventCardBadgePresentation | null {
  if (status === 'ACTIVE') {
    return { label: i18n.t('events.status.UPCOMING'), variant: 'upcoming' };
  }
  if (status === 'IN_PROGRESS') {
    return { label: i18n.t('events.status.IN_PROGRESS_BADGE'), variant: 'in_progress' };
  }
  if (status === 'CANCELED') {
    return { label: i18n.t('events.status.CANCELED_BADGE'), variant: 'canceled' };
  }
  if (status === 'COMPLETED') {
    return { label: i18n.t('events.status.COMPLETED_BADGE'), variant: 'completed' };
  }
  return null;
}
 
export interface EventStatusPresentation {
  label: string;
  tone: 'active' | 'canceled' | 'completed';
}
 
export function getEventStatusPresentation(status: string): EventStatusPresentation {
  switch (status) {
    case 'ACTIVE':
      return { label: i18n.t('events.status.ACTIVE'), tone: 'active' };
    case 'IN_PROGRESS':
      return { label: i18n.t('events.status.IN_PROGRESS'), tone: 'active' };
    case 'CANCELED':
      return { label: i18n.t('events.status.CANCELED'), tone: 'canceled' };
    case 'COMPLETED':
      return { label: i18n.t('events.status.COMPLETED'), tone: 'completed' };
    default:
      return {
        label: status
          .toLowerCase()
          .split('_')
          .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
          .join(' ') || i18n.t('events.status.UNKNOWN'),
        tone: 'completed',
      };
  }
}
 
export function shouldShowProfileEvent(status: string): boolean {
  return status !== 'ACTIVE';
}