The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
import { assertIsDefinedOrThrow, findOrThrow } from 'twenty-shared/utils';
import { doNotTranslate } from 'twenty-shared/i18n';
import { usePlans } from './usePlans';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { getSubscriptionPlanKey } from '@/settings/billing/utils/getSubscriptionPlanKey';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
export const useCurrentPlan = () => {
const { listPlans } = usePlans();
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
assertIsDefinedOrThrow(currentWorkspace);
const currentPlanKey = getSubscriptionPlanKey(
currentWorkspace.currentBillingSubscription,
);
const currentPlan = findOrThrow(
listPlans(),
(plan) => plan.planKey === currentPlanKey,
new Error(doNotTranslate('Current plan not found')),
);
return { currentPlan };
};