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:
+1
@@ -50,6 +50,7 @@ describe('useSubscriptionStatus', () => {
|
||||
id: v4(),
|
||||
status: subscriptionStatus,
|
||||
metadata: {},
|
||||
phases: [],
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
+8
-12
@@ -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
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user