The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Hide credits used column in app stats when billing is disabled (#28616)
martmullf836a286d167
diff --git a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstallStats.tsx b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstallStats.tsxindex 4b2dfb6a04a..2ea99b206fb 100644--- a/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstallStats.tsx+++ b/packages/twenty-front/src/pages/settings/applications/components/SettingsApplicationRegistrationInstallStats.tsx@@ -1,6 +1,7 @@import { useQuery } from '@apollo/client/react';import { useLingui } from '@lingui/react/macro';+import { billingState } from '@/client-config/states/billingState';import { useApolloAdminClient } from '@/settings/admin-panel/apollo/hooks/useApolloAdminClient';import { USAGE_LIMIT_OPERATION_TYPE_ICONS } from '@/settings/billing/constants/UsageLimitOperationTypeIcons';import { isKeyOfRecord } from '@/settings/billing/utils/isKeyOfRecord';@@ -10,6 +11,7 @@ import {} from '@/settings/components/SettingsStatsGrid';import { getCurrentMonthPeriodDates } from '@/settings/usage/utils/getCurrentMonthPeriodDates';import { getUsageOperationTypeLabel } from '@/settings/usage/utils/getUsageOperationTypeLabel';+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { isDefined } from 'twenty-shared/utils';import {IconBrandDocker,@@ -33,6 +35,8 @@ export const SettingsApplicationRegistrationInstallStats = ({}) => {const { t, i18n } = useLingui();const apolloAdminClient = useApolloAdminClient();+ const billing = useAtomStateValue(billingState);+ const isBillingEnabled = billing?.isBillingEnabled ?? false;const periodDates = getCurrentMonthPeriodDates();const applicationRegistrationId = registration.id;@@ -136,5 +140,11 @@ export const SettingsApplicationRegistrationInstallStats = ({),];- return <SettingsStatsGrid columns={[installStats, creditsUsedStats]} />;+ return (+ <SettingsStatsGrid+ columns={+ isBillingEnabled ? [installStats, creditsUsedStats] : [installStats]+ }+ />+ );};diff --git a/packages/twenty-front/src/pages/settings/applications/components/__tests__/SettingsApplicationRegistrationInstallStats.test.tsx b/packages/twenty-front/src/pages/settings/applications/components/__tests__/SettingsApplicationRegistrationInstallStats.test.tsxindex cb3c764ee2d..434b59dcc64 100644--- a/packages/twenty-front/src/pages/settings/applications/components/__tests__/SettingsApplicationRegistrationInstallStats.test.tsx+++ b/packages/twenty-front/src/pages/settings/applications/components/__tests__/SettingsApplicationRegistrationInstallStats.test.tsx@@ -6,12 +6,14 @@ import { I18nProvider } from '@lingui/react';import { render, screen } from '@testing-library/react';import { createStore, Provider as JotaiProvider } from 'jotai';+import { billingState } from '@/client-config/states/billingState';import { getCurrentMonthPeriodDates } from '@/settings/usage/utils/getCurrentMonthPeriodDates';import { ApolloAdminClientContext } from '@/settings/admin-panel/apollo/contexts/ApolloAdminClientContext';import { FindAdminApplicationRegistrationStatsDocument } from '~/generated-admin/graphql';import {type ApplicationRegistrationStats,+ type Billing,FindApplicationRegistrationStatsDocument,UsageOperationType,} from '~/generated-metadata/graphql';@@ -34,7 +36,15 @@ const STATS: ApplicationRegistrationStats = {],};-const renderStats = (stats = STATS, isAdminView = false) => {+const renderStats = (+ stats = STATS,+ isAdminView = false,+ isBillingEnabled = true,+) => {+ const store = createStore();++ store.set(billingState.atom, { isBillingEnabled } as Billing);+const client = new ApolloClient({cache: new InMemoryCache(),link: new MockLink([@@ -61,7 +71,7 @@ const renderStats = (stats = STATS, isAdminView = false) => {});return render(- <JotaiProvider store={createStore()}>+ <JotaiProvider store={store}><I18nProvider i18n={i18n}><ApolloAdminClientContext.Provider value={client}><ApolloProvider client={client}>@@ -109,4 +119,14 @@ describe('Application registration statistics', () => {).toBeVisible();},);++ it('hides credit consumption when billing is disabled', async () => {+ renderStats(STATS, false, false);++ await screen.findByText('1.2.3');+ expect(+ screen.queryByText('Credits used this month'),+ ).not.toBeInTheDocument();+ expect(screen.queryByText('Code Execution')).not.toBeInTheDocument();+ });});