aaredb/frontend/src/components/statusUtils.ts
2024-11-04 22:20:14 +01:00

24 lines
873 B
TypeScript

// statusUtils.ts
// Utility functions to handle dewar statuses and icon colors
export type DewarStatus = 'In Preparation' | 'Ready for Shipping' | 'Shipped' | 'Not Arrived' | 'Arrived' | 'Returned' | 'Delayed';
export const STATUS_TO_STEP: Record<DewarStatus, number> = {
'In Preparation': 0,
'Ready for Shipping': 1,
'Shipped': 1,
'Delayed': 1,
'Not Arrived': 2,
'Arrived': 2,
'Returned': 3
};
export const getStatusStepIndex = (status: DewarStatus): number => STATUS_TO_STEP[status];
export const determineIconColor = (iconIndex: number, status: DewarStatus): string => {
const statusIndex = getStatusStepIndex(status);
if (status === 'Delayed' && iconIndex === 1) {
return 'orange';
}
return iconIndex <= statusIndex ? (iconIndex === statusIndex ? (status === 'Shipped' ? 'green' : 'blue') : 'green') : 'grey';
};