72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
export const formatCurrency = (value: number | string | undefined): string => {
|
|
if (value === undefined || value === null) return "€0.00";
|
|
const numValue = typeof value === "string" ? parseFloat(value) : value;
|
|
if (isNaN(numValue)) return "€0.00";
|
|
return `€${numValue.toFixed(2)}`;
|
|
};
|
|
|
|
export const formatPercentage = (
|
|
value: number | string | undefined
|
|
): string => {
|
|
if (value === undefined || value === null) return "0%";
|
|
const numValue = typeof value === "string" ? parseFloat(value) : value;
|
|
if (isNaN(numValue)) return "0%";
|
|
return `${numValue.toFixed(2)}%`;
|
|
};
|
|
|
|
interface IHealthData {
|
|
total?: number;
|
|
successful?: number;
|
|
acceptance_rate?: number;
|
|
amount?: number;
|
|
atv?: number;
|
|
}
|
|
|
|
interface IStatItem {
|
|
label: string;
|
|
value: string | number;
|
|
change: string;
|
|
}
|
|
|
|
export const transformHealthDataToStats = (
|
|
healthData: IHealthData | null
|
|
): IStatItem[] => {
|
|
if (!healthData) {
|
|
return [
|
|
{ label: "TOTAL", value: 0, change: "0%" },
|
|
{ label: "SUCCESSFUL", value: 0, change: "0%" },
|
|
{ label: "ACCEPTANCE RATE", value: "0%", change: "0%" },
|
|
{ label: "AMOUNT", value: "€0.00", change: "0%" },
|
|
{ label: "ATV", value: "€0.00", change: "0%" },
|
|
];
|
|
}
|
|
|
|
return [
|
|
{
|
|
label: "TOTAL",
|
|
value: healthData.total ?? 0,
|
|
change: "0%",
|
|
},
|
|
{
|
|
label: "SUCCESSFUL",
|
|
value: healthData.successful ?? 0,
|
|
change: "0%",
|
|
},
|
|
{
|
|
label: "ACCEPTANCE RATE",
|
|
value: formatPercentage(healthData.acceptance_rate),
|
|
change: "0%",
|
|
},
|
|
{
|
|
label: "AMOUNT",
|
|
value: formatCurrency(healthData.amount),
|
|
change: "0%",
|
|
},
|
|
{
|
|
label: "ATV",
|
|
value: formatCurrency(healthData.atv),
|
|
change: "0%",
|
|
},
|
|
];
|
|
};
|