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
@@ -50,6 +50,7 @@ describe('useSubscriptionStatus', () => {
id: v4(),
status: subscriptionStatus,
metadata: {},
phases: [],
},
});
});
@@ -1,20 +1,16 @@
import { useRecoilValue } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { BillingProductKey } from '~/generated/graphql';
export const useIsSomeMeteredProductCapReached = (): boolean => {
const currentWorkspace = useRecoilValue(currentWorkspaceState);
const billingSubscriptionItems = useRecoilValue(currentWorkspaceState)
?.currentBillingSubscription?.billingSubscriptionItems;
const meteredProductKeys = Object.values(BillingProductKey).filter(
(productKey) => productKey !== BillingProductKey.BASE_PRODUCT,
if (!billingSubscriptionItems) {
return false;
}
return billingSubscriptionItems.some(
({ hasReachedCurrentPeriodCap }) => hasReachedCurrentPeriodCap,
);
return meteredProductKeys.some((productKey) => {
return (
currentWorkspace?.currentBillingSubscription?.billingSubscriptionItems?.find(
(item) => item.billingProduct?.metadata.productKey === productKey,
)?.hasReachedCurrentPeriodCap ?? false
);
});
};