feat(billing): refacto billing (#14243)

… prices for metered billing

---------

Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
Antoine Moreaux
2025-09-19 11:25:53 +02:00
committed by GitHub
parent 163890f6c8
commit 43e0cd5d05
351 changed files with 16091 additions and 6101 deletions
@@ -1,5 +1,8 @@
import { isDefined } from 'twenty-shared/utils';
import { formatNumber } from '~/utils/format/formatNumber';
import {
formatNumber as utilFormatNumber,
type FormatNumberOptions,
} from '~/utils/format/formatNumber';
import { formatToShortNumber } from '~/utils/format/formatToShortNumber';
export type GraphValueFormatOptions = {
@@ -8,6 +11,10 @@ export type GraphValueFormatOptions = {
prefix?: string;
suffix?: string;
customFormatter?: (value: number) => string;
formatNumberFn?: (
value: number,
options?: Omit<FormatNumberOptions, 'format'>,
) => string;
};
export const formatGraphValue = (
@@ -20,26 +27,32 @@ export const formatGraphValue = (
prefix = '',
suffix = '',
customFormatter,
formatNumberFn,
} = options || {};
const formatNumber =
formatNumberFn ??
((v: number, opts?: Omit<FormatNumberOptions, 'format'>) =>
utilFormatNumber(v, opts));
if (displayType === 'custom' && isDefined(customFormatter)) {
return customFormatter(value);
}
switch (displayType) {
case 'percentage':
return `${formatNumber(value * 100, decimals)}%`;
return `${formatNumber(value * 100, { decimals })}%`;
case 'shortNumber':
return `${prefix}${formatToShortNumber(value)}${suffix}`;
case 'currency': {
const currencyPrefix = prefix || '$';
return `${currencyPrefix}${formatNumber(value, decimals)}${suffix}`;
return `${currencyPrefix}${formatNumber(value, { decimals })}${suffix}`;
}
case 'number':
default:
return `${prefix}${formatNumber(value, decimals)}${suffix}`;
return `${prefix}${formatNumber(value, { decimals })}${suffix}`;
}
};