Skip to content

The open alternative to Salesforce, designed for AI.

improve the limits organization plan display (#26915)

Thomas des Francs007785c5ad21
diff --git a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
index 4cd18d2b8e1..851de5fdffa 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/SettingsBillingLimitSpenderSelect.tsx
@@ -13,9 +13,14 @@ import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/consta
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { getWorkspaceAvatarColorSeed } from '@/workspace/utils/getWorkspaceAvatarColorSeed';
import { useLingui } from '@lingui/react/macro';
-import { isDefined } from 'twenty-shared/utils';
+import { Link } from 'react-router-dom';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
import { Dropdown } from 'twenty-ui/components';
+import { IconArrowUp } from 'twenty-ui/icon';
import { Avatar } from 'twenty-ui/primitives/data-display';
+import { ListItem } from 'twenty-ui/primitives/navigation';
+import { OrganizationAdornment } from '~/pages/settings/enterprise/components/OrganizationAdornment';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
const SPENDER_DROPDOWN_ID = 'usage-limit-spender';
@@ -122,6 +127,8 @@ export const SettingsBillingLimitSpenderSelect = ({
const workspaceGroup = groups.find((group) => group.id === 'workspace');
const otherGroups = groups.filter((group) => group.id !== 'workspace');
+ const isLockedByPlan =
+ !isIntraWorkspaceLimitEntitled && otherGroups.length > 0;
return (
<SettingsBillingLimitNestedSelect
@@ -140,8 +147,8 @@ export const SettingsBillingLimitSpenderSelect = ({
isDisabled={isDisabled}
>
<Dropdown.Page id="root">
- {isDefined(workspaceGroup) && (
- <Dropdown.Section>
+ <Dropdown.Section>
+ {isDefined(workspaceGroup) && (
<Dropdown.OptionItem
selected={spenderType === 'workspace'}
onSelect={() => handleSelect('workspace', '')}
@@ -158,35 +165,41 @@ export const SettingsBillingLimitSpenderSelect = ({
>
{workspaceName}
</Dropdown.OptionItem>
- </Dropdown.Section>
- )}
- {isDefined(workspaceGroup) && otherGroups.length > 0 && (
- <Dropdown.Separator />
- )}
- {otherGroups.length > 0 && (
- <Dropdown.Section>
- {otherGroups.map((group) =>
- isIntraWorkspaceLimitEntitled ? (
- <Dropdown.ActionItem
- key={group.id}
- page={group.spenderType}
- startIcon={<SelectOptionIcon Icon={group.Icon} />}
- >
- {t(group.label)}
- </Dropdown.ActionItem>
- ) : (
- <Dropdown.ActionItem
- key={group.id}
- disabled
- description={t`Organization plan`}
- descriptionPlacement="end"
- startIcon={<SelectOptionIcon Icon={group.Icon} />}
- >
- {t(group.label)}
- </Dropdown.ActionItem>
- ),
- )}
- </Dropdown.Section>
+ )}
+ {otherGroups.map((group) =>
+ isIntraWorkspaceLimitEntitled ? (
+ <Dropdown.ActionItem
+ key={group.id}
+ page={group.spenderType}
+ startIcon={<SelectOptionIcon Icon={group.Icon} />}
+ >
+ {t(group.label)}
+ </Dropdown.ActionItem>
+ ) : (
+ <ListItem
+ key={group.id}
+ startIcon={<SelectOptionIcon Icon={group.Icon} />}
+ endIcon={<OrganizationAdornment iconOnly />}
+ >
+ {t(group.label)}
+ </ListItem>
+ ),
+ )}
+ </Dropdown.Section>
+ {isLockedByPlan && (
+ <>
+ <Dropdown.Separator />
+ <Dropdown.Section>
+ <Dropdown.ActionItem
+ render={
+ <Link to={getSettingsPath(SettingsPath.BillingPlans)} />
+ }
+ startIcon={<IconArrowUp />}
+ >
+ {t`Upgrade to Organization`}
+ </Dropdown.ActionItem>
+ </Dropdown.Section>
+ </>
)}
</Dropdown.Page>
{isIntraWorkspaceLimitEntitled &&
diff --git a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx
index ba6375935ce..06d2d718927 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitForm.stories.tsx
@@ -1,6 +1,5 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { expect, within } from 'storybook/test';
-import { ComponentDecorator } from 'twenty-ui/testing';
import { SettingsBillingLimitForm } from '@/settings/billing/components/SettingsBillingLimitForm';
import { EMPTY_USAGE_LIMIT_FORM_VALUES } from '@/settings/billing/constants/EmptyUsageLimitFormValues';
@@ -8,6 +7,7 @@ import {
UsageOperationType,
UsageResourceType,
} from '~/generated-metadata/graphql';
+import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator';
const DEFINITIONS = {
__typename: 'UsageQuotaDefinitions' as const,
@@ -41,7 +41,7 @@ const FILLED_VALUES = {
const meta: Meta<typeof SettingsBillingLimitForm> = {
title: 'Modules/Settings/Billing/SettingsBillingLimitForm',
component: SettingsBillingLimitForm,
- decorators: [ComponentDecorator],
+ decorators: [ComponentWithRouterDecorator],
args: {
definitions: DEFINITIONS,
values: EMPTY_USAGE_LIMIT_FORM_VALUES,
diff --git a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx
index 30e6aee7497..4be6e2d4a03 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/__stories__/SettingsBillingLimitSpenderSelect.stories.tsx
@@ -1,15 +1,15 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
-import { ComponentDecorator } from 'twenty-ui/testing';
import { SettingsBillingLimitSpenderSelect } from '@/settings/billing/components/SettingsBillingLimitSpenderSelect';
+import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
import { mockedApiKeys } from '~/testing/mock-data/generated/metadata/api-keys/mock-api-keys-data';
const meta: Meta<typeof SettingsBillingLimitSpenderSelect> = {
title: 'Modules/Settings/Billing/SettingsBillingLimitSpenderSelect',
component: SettingsBillingLimitSpenderSelect,
- decorators: [ComponentDecorator],
+ decorators: [ComponentWithRouterDecorator],
args: {
allowedSpenderTypes: [
'workspace',
@@ -35,22 +35,22 @@ export const AllUsers: Story = {
};
export const WorkspaceOnlyPlan: Story = {
- args: { isIntraWorkspaceLimitEntitled: false },
- play: async ({ canvasElement }) => {
+ args: { isIntraWorkspaceLimitEntitled: false, onChange: fn() },
+ play: async ({ canvasElement, args }) => {
const body = within(canvasElement.ownerDocument.body);
await userEvent.click(within(canvasElement).getByRole('button'));
const popup = await body.findByRole('dialog', { name: 'Spender' });
- expect(
- within(popup).getByRole('button', { name: /User.*Organization plan/ }),
- ).toHaveAttribute('aria-disabled', 'true');
- await userEvent.click(
- within(popup).getByRole('button', { name: /User.*Organization plan/ }),
- );
+ expect(within(popup).getAllByLabelText('Organization')).toHaveLength(3);
+ await userEvent.click(within(popup).getByText('User'));
expect(
within(popup).queryByRole('button', { name: 'All users' }),
).not.toBeInTheDocument();
+ expect(args.onChange).not.toHaveBeenCalled();
+ expect(
+ within(popup).getByRole('link', { name: 'Upgrade to Organization' }),
+ ).toHaveAttribute('href', '/settings/billing/plans');
await userEvent.keyboard('{Escape}');
},
};
diff --git a/packages/twenty-front/src/modules/settings/security/components/SettingsSecuritySettings.tsx b/packages/twenty-front/src/modules/settings/security/components/SettingsSecuritySettings.tsx
index de55b11614d..ca44d633848 100644
--- a/packages/twenty-front/src/modules/settings/security/components/SettingsSecuritySettings.tsx
+++ b/packages/twenty-front/src/modules/settings/security/components/SettingsSecuritySettings.tsx
@@ -25,7 +25,10 @@ import { IconClockHour8, IconHistory, IconTrash } from 'twenty-ui/icon';
import { Card } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
import { useDebouncedCallback } from 'use-debounce';
-import { UpdateWorkspaceDocument } from '~/generated-metadata/graphql';
+import {
+ BillingEntitlementKey,
+ UpdateWorkspaceDocument,
+} from '~/generated-metadata/graphql';
import { OrganizationAdornment } from '~/pages/settings/enterprise/components/OrganizationAdornment';
import { getToastOptionsFromError } from '@/error-handler/utils/getToastOptionsFromError';
@@ -141,6 +144,11 @@ export const SettingsSecuritySettings = () => {
const hasEnterpriseAccess =
currentWorkspace?.hasValidEnterpriseValidityToken === true;
const isEventLogsEnabled = hasEnterpriseAccess && isClickHouseConfigured;
+ const hasSsoEntitlement =
+ currentWorkspace?.billingEntitlements?.some(
+ (entitlement) =>
+ entitlement.key === BillingEntitlementKey.SSO && entitlement.value,
+ ) === true;
return (
<>
@@ -153,7 +161,15 @@ export const SettingsSecuritySettings = () => {
description={t`Configure an SSO connection`}
adornment={<OrganizationAdornment />}
/>
- <SettingsSsoIdentitiesProvidersListCard />
+ {hasSsoEntitlement ? (
+ <SettingsSsoIdentitiesProvidersListCard />
+ ) : (
+ <SettingsEnterpriseFeatureGateCard
+ title={t`Organization feature`}
+ description={t`Upgrade to Organization to configure SSO.`}
+ buttonTitle={t`Activate`}
+ />
+ )}
</Section.Root>
</StyledSectionContainer>
diff --git a/packages/twenty-front/src/modules/settings/security/components/sso/SettingsSsoIdentitiesProvidersListCard.tsx b/packages/twenty-front/src/modules/settings/security/components/sso/SettingsSsoIdentitiesProvidersListCard.tsx
index 59813e5550d..e97807e7e9c 100644
--- a/packages/twenty-front/src/modules/settings/security/components/sso/SettingsSsoIdentitiesProvidersListCard.tsx
+++ b/packages/twenty-front/src/modules/settings/security/components/sso/SettingsSsoIdentitiesProvidersListCard.tsx
@@ -5,12 +5,10 @@ import { Link } from 'react-router-dom';
import { SettingsPath } from 'twenty-shared/types';
-import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { SettingsCard } from '@/settings/components/SettingsCard';
import { SettingsSsoIdentitiesProvidersListCardWrapper } from '@/settings/security/components/sso/SettingsSsoIdentitiesProvidersListCardWrapper';
import { ssoIdentitiesProvidersState } from '@/settings/security/states/ssoIdentitiesProvidersState';
import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useQuery } from '@apollo/client/react';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
@@ -19,17 +17,13 @@ import { getSettingsPath } from 'twenty-shared/utils';
import { IconKey } from 'twenty-ui/icon';
import { GetSsoIdentityProvidersDocument } from '~/generated-metadata/graphql';
-const StyledLinkContainer = styled.div<{ isDisabled: boolean }>`
- pointer-events: ${({ isDisabled }) => (isDisabled ? 'none' : 'auto')};
-
+const StyledLinkContainer = styled.div`
> a {
text-decoration: none;
}
`;
export const SettingsSsoIdentitiesProvidersListCard = () => {
- const currentWorkspace = useAtomStateValue(currentWorkspaceState);
-
const { t } = useLingui();
const [ssoIdentitiesProviders, setSsoIdentitiesProviders] = useAtomState(
@@ -42,7 +36,6 @@ export const SettingsSsoIdentitiesProvidersListCard = () => {
error: ssoError,
} = useQuery(GetSsoIdentityProvidersDocument, {
fetchPolicy: 'network-only',
- skip: currentWorkspace?.hasValidEnterpriseValidityToken !== true,
});
useEffect(() => {
@@ -55,17 +48,10 @@ export const SettingsSsoIdentitiesProvidersListCard = () => {
<>
<ToastOnQueryErrorEffect error={ssoError} />
{loading || !ssoIdentitiesProviders.length ? (
- <StyledLinkContainer
- isDisabled={
- currentWorkspace?.hasValidEnterpriseValidityToken !== true
- }
- >
+ <StyledLinkContainer>
<Link to={getSettingsPath(SettingsPath.NewSsoIdentityProvider)}>
<SettingsCard
title={t`Add SSO Identity Provider`}
- disabled={
- currentWorkspace?.hasValidEnterpriseValidityToken !== true
- }
Icon={<IconKey />}
/>
</Link>
diff --git a/packages/twenty-front/src/pages/settings/enterprise/components/OrganizationAdornment.tsx b/packages/twenty-front/src/pages/settings/enterprise/components/OrganizationAdornment.tsx
index 8631cc1945f..4c45979edaf 100644
--- a/packages/twenty-front/src/pages/settings/enterprise/components/OrganizationAdornment.tsx
+++ b/packages/twenty-front/src/pages/settings/enterprise/components/OrganizationAdornment.tsx
@@ -34,42 +34,62 @@ const pillLinkClassName = css`
}
`;
-const OrganizationAdornmentContent = () => (
- <>
- <IconLock size={12} />
- {t`Organization`}
- </>
-);
+const iconOnlyPillClassName = css`
+ block-size: 24px;
+ box-sizing: border-box;
+ inline-size: 24px;
+ justify-content: center;
+ padding: 0;
+`;
type OrganizationAdornmentProps = {
tooltipContent?: string;
+ iconOnly?: boolean;
};
export const OrganizationAdornment = ({
tooltipContent,
+ iconOnly = false,
}: OrganizationAdornmentProps) => {
const billing = useAtomStateValue(billingState);
const isBillingEnabled = billing?.isBillingEnabled ?? false;
+ const label = t`Organization`;
+ const className = cx(pillClassName, iconOnly && iconOnlyPillClassName);
+ const content = iconOnly ? (
+ <IconLock size={16} />
+ ) : (
+ <>
+ <IconLock size={12} />
+ {label}
+ </>
+ );
const adornment = isBillingEnabled ? (
<Link
- className={cx(pillClassName, pillLinkClassName)}
+ className={cx(className, pillLinkClassName)}
to={getSettingsPath(SettingsPath.BillingPlans)}
+ aria-label={iconOnly ? label : undefined}
>
- <OrganizationAdornmentContent />
+ {content}
</Link>
) : (
- <span className={pillClassName}>
- <OrganizationAdornmentContent />
+ <span
+ className={className}
+ role={iconOnly ? 'img' : undefined}
+ aria-label={iconOnly ? label : undefined}
+ >
+ {content}
</span>
);
+ const resolvedTooltipContent =
+ tooltipContent ?? (iconOnly ? label : undefined);
- if (!isNonEmptyString(tooltipContent)) {
+ if (!isNonEmptyString(resolvedTooltipContent)) {
return adornment;
}
return (
<Tooltip
- content={tooltipContent}
+ content={resolvedTooltipContent}
delay={TooltipDelay.shortDelay}
side="top"
maxWidth="260px"