Skip to content

The open alternative to Salesforce, designed for AI.

Show the Emails and Calendar tabs of a built-in app only once a channel exists (#29027)

nitindecd9f9e423a
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getBuiltInAccountAppChannelTabsVisibility.test.ts b/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getBuiltInAccountAppChannelTabsVisibility.test.ts
index da519ca8a3f..1c3ed538ec3 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getBuiltInAccountAppChannelTabsVisibility.test.ts
+++ b/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getBuiltInAccountAppChannelTabsVisibility.test.ts
@@ -22,19 +22,6 @@ const PENDING_CALENDAR = {
const OUTLOOK = { hasEmails: true, hasCalendar: true };
describe('getBuiltInAccountAppChannelTabsVisibility', () => {
- it('shows the tabs the app supports when there are no accounts', () => {
- expect(
- getBuiltInAccountAppChannelTabsVisibility({
- app: OUTLOOK,
- accounts: [],
- isLoading: false,
- }),
- ).toEqual({
- isEmailsTabVisible: true,
- isCalendarTabVisible: true,
- });
- });
-
it('hides the tabs the app does not support', () => {
expect(
getBuiltInAccountAppChannelTabsVisibility({
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/utils/getBuiltInAccountAppChannelTabsVisibility.ts b/packages/twenty-front/src/modules/settings/app-preferences/utils/getBuiltInAccountAppChannelTabsVisibility.ts
index c0800c362b9..e9cee44481d 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/utils/getBuiltInAccountAppChannelTabsVisibility.ts
+++ b/packages/twenty-front/src/modules/settings/app-preferences/utils/getBuiltInAccountAppChannelTabsVisibility.ts
@@ -23,7 +23,6 @@ type IsChannelTabVisibleArgs = {
isLoading: boolean;
};
-// A tab only offers to connect when no account exists; setup and reconnection live in the account row menu.
// Accounts load before their channels, so a missing channel only hides the tab once loading is done.
const isChannelTabVisible = ({
isSupported,
@@ -44,7 +43,7 @@ const isChannelTabVisible = ({
return false;
}
- return isLoading || !hasAccounts;
+ return isLoading && hasAccounts;
};
export const getBuiltInAccountAppChannelTabsVisibility = ({
diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsBuiltInAccountApp.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsBuiltInAccountApp.tsx
index 1bce1a5f760..7612c06b542 100644
--- a/packages/twenty-front/src/pages/settings/accounts/SettingsBuiltInAccountApp.tsx
+++ b/packages/twenty-front/src/pages/settings/accounts/SettingsBuiltInAccountApp.tsx
@@ -1,6 +1,5 @@
import { type ConnectedAccount } from '@/accounts/types/ConnectedAccount';
import { SettingsAccountGroupsSection } from '@/settings/app-preferences/components/SettingsAccountGroupsSection';
-import { SettingsAppPreferencesListEmptyStateCard } from '@/settings/app-preferences/components/SettingsAppPreferencesListEmptyStateCard';
import { SettingsAccountsBlocklistSection } from '@/settings/accounts/components/SettingsAccountsBlocklistSection';
import { SettingsAccountsCalendarChannelDetails } from '@/settings/accounts/components/SettingsAccountsCalendarChannelDetails';
import { SettingsAppPreferencesSelectedMessageChannelDetails } from '~/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails';
@@ -110,16 +109,10 @@ export const SettingsBuiltInAccountApp = () => {
const renderContent = () => {
if (activeTabId === 'emails') {
- if (loading && emailAccounts.length === 0) {
- return <SettingsSectionSkeletonLoader />;
- }
-
const selectedAccount = getSelectedAccount(emailAccounts);
if (!isDefined(selectedAccount)) {
- return (
- <SettingsAppPreferencesListEmptyStateCard provider={app.provider} />
- );
+ return <SettingsSectionSkeletonLoader />;
}
const { messageChannel } =
@@ -138,16 +131,10 @@ export const SettingsBuiltInAccountApp = () => {
}
if (activeTabId === 'calendar') {
- if (loading && calendarAccounts.length === 0) {
- return <SettingsSectionSkeletonLoader />;
- }
-
const selectedAccount = getSelectedAccount(calendarAccounts);
if (!isDefined(selectedAccount)) {
- return (
- <SettingsAppPreferencesListEmptyStateCard provider={app.provider} />
- );
+ return <SettingsSectionSkeletonLoader />;
}
const { calendarChannel } =
@@ -189,11 +176,13 @@ export const SettingsBuiltInAccountApp = () => {
{ children: appName },
]}
secondaryBar={
- <SettingsTabBar
- aria-label={t`${appName} preferences`}
- tabs={tabs}
- componentInstanceId={tabListComponentInstanceId}
- />
+ tabs.length > 1 ? (
+ <SettingsTabBar
+ aria-label={t`${appName} preferences`}
+ tabs={tabs}
+ componentInstanceId={tabListComponentInstanceId}
+ />
+ ) : undefined
}
>
<SettingsAccountsMessageChannelsSSEEffect />
diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsBuiltInAccountApp.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsBuiltInAccountApp.stories.tsx
index 161086005af..9d422d39f0b 100644
--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsBuiltInAccountApp.stories.tsx
+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsBuiltInAccountApp.stories.tsx
@@ -1,5 +1,5 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
-import { HttpResponse, delay, graphql } from 'msw';
+import { HttpResponse, delay, graphql, http } from 'msw';
import { expect, userEvent, within } from 'storybook/test';
import {
@@ -12,6 +12,7 @@ import { isMicrosoftCalendarEnabledState } from '@/client-config/states/isMicros
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { SettingsBuiltInAccountApp } from '~/pages/settings/accounts/SettingsBuiltInAccountApp';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
+import { mockedClientConfig } from '~/testing/mock-data/config';
import { clickAndCaptureOAuthRedirect } from '~/pages/settings/accounts/__stories__/clickAndCaptureOAuthRedirect';
import {
ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
@@ -74,7 +75,10 @@ export const TabBarAndHeadersStayWhileLoading: Story = {
parameters: {
msw: {
handlers: [
- graphql.query('MyConnectedAccounts', async () => {
+ graphql.query('MyMessageChannels', async () => {
+ await delay('infinite');
+ }),
+ graphql.query('MyCalendarChannels', async () => {
await delay('infinite');
}),
...ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
@@ -89,7 +93,7 @@ export const TabBarAndHeadersStayWhileLoading: Story = {
timeout: 3000,
}),
).toBeVisible();
- expect(canvas.getByTestId('tab-general')).toBeVisible();
+ expect(await canvas.findByTestId('tab-general')).toBeVisible();
expect(canvas.getByTestId('tab-emails')).toBeVisible();
expect(canvas.getByTestId('tab-calendar')).toBeVisible();
expect(canvas.getByText('Blocklist')).toBeVisible();
@@ -166,6 +170,19 @@ export const OutlookWithoutCalendarServiceHasNoCalendarTab: Story = {
args: {
routeParams: { ':builtInAccountAppId': 'outlook' },
},
+ parameters: {
+ msw: {
+ handlers: [
+ http.get(`${REACT_APP_SERVER_BASE_URL}/client-config`, () =>
+ HttpResponse.json({
+ ...mockedClientConfig,
+ isMicrosoftCalendarEnabled: false,
+ }),
+ ),
+ ...ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
+ ],
+ },
+ },
beforeEach: async () => {
await seedAccountGroupsStory();
jotaiStore.set(isMicrosoftCalendarEnabledState.atom, false);
@@ -257,6 +274,7 @@ export const OutlookWithoutAccountOffersMicrosoftOnly: Story = {
}),
).toBeVisible();
expect(canvas.queryByText('Connect with Google')).not.toBeInTheDocument();
+ expect(canvas.queryByTestId('tab-general')).not.toBeInTheDocument();
expect(canvas.getByText('Blocklist')).toBeVisible();
},
};