The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Show an Apps tab status only when a connection is broken (#29060)
nitin6408a119c6e4
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesAppStatusCell.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesAppStatusCell.tsxindex f4e5413b0f4..d61d2bbdff8 100644--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesAppStatusCell.tsx+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesAppStatusCell.tsx@@ -1,9 +1,12 @@+import { SettingsConnectedAccountSyncStatus } from '@/settings/app-preferences/components/SettingsConnectedAccountSyncStatus';import { useMyAccountGroups } from '@/settings/app-preferences/hooks/useMyAccountGroups';import { type AppPreferencesRow } from '@/settings/app-preferences/types/AppPreferencesRow';import { getBuiltInAccountAppsUsingAccount } from '@/settings/app-preferences/utils/getBuiltInAccountAppsUsingAccount';-import { canStartConnectionProviderAuthorization } from '@/settings/applications/utils/canStartConnectionProviderAuthorization';+import { SyncStatus } from '@/settings/accounts/constants/SyncStatus';+import { computeSyncStatus } from '@/settings/accounts/utils/computeSyncStatus';+import { isApplicationConnectionReconnectNeeded } from '@/settings/applications/utils/isApplicationConnectionReconnectNeeded';import { useLingui } from '@lingui/react/macro';-import { isNonEmptyArray } from 'twenty-shared/utils';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';import { Status } from 'twenty-ui/primitives/data-display';type SettingsAppPreferencesAppStatusCellProps = {@@ -16,43 +19,60 @@ export const SettingsAppPreferencesAppStatusCell = ({const { t } = useLingui();const { groups, loading } = useMyAccountGroups();- if (item.type === 'installed') {- const { application, connectionProviders, missingRequiredVariables } =- item.applicationWithPreferences;+ if (loading) {+ return null;+ }- if (isNonEmptyArray(missingRequiredVariables)) {- return <Status color="red">{t`Missing configuration`}</Status>;- }+ if (item.type === 'builtIn') {+ const activeAccounts = groups+ .map((group) => group.builtInAccount)+ .filter(isDefined)+ .filter(+ (account) =>+ !isDefined(account.archivedAt) &&+ getBuiltInAccountAppsUsingAccount(account).some(+ (app) => app.id === item.builtInAccountApp.id,+ ),+ );+ const findAccountWithStatus = (status: SyncStatus) =>+ activeAccounts.find(+ (account) =>+ computeSyncStatus(+ account.messageChannels[0],+ account.calendarChannels[0],+ ) === status,+ );+ const brokenAccount =+ findAccountWithStatus(SyncStatus.FAILED) ??+ findAccountWithStatus(SyncStatus.PENDING_CONFIGURATION);- const applicationAccounts = groups.flatMap((group) =>- group.appAccounts.filter(- (account) => account.applicationId === application.id,- ),- );- const hasConfiguredProvider = connectionProviders.some(- canStartConnectionProviderAuthorization,- );-- if (- loading ||- !hasConfiguredProvider ||- isNonEmptyArray(applicationAccounts)- ) {+ if (!isDefined(brokenAccount)) {return null;}- return <Status color="red">{t`Missing account`}</Status>;+ return <SettingsConnectedAccountSyncStatus account={brokenAccount} />;}- const hasAccount = groups.some((group) =>- getBuiltInAccountAppsUsingAccount(group.builtInAccount).some(- (app) => app.id === item.builtInAccountApp.id,+ const { application, connectionProviders, missingRequiredVariables } =+ item.applicationWithPreferences;+ const activeConnections = groups.flatMap((group) =>+ group.appAccounts.filter(+ (account) =>+ account.applicationId === application.id &&+ !isDefined(account.archivedAt),),);- if (loading || hasAccount) {+ if (activeConnections.some(isApplicationConnectionReconnectNeeded)) {+ return <Status color="red">{t`Reconnect needed`}</Status>;+ }++ const isAppInUse =+ !isNonEmptyArray(connectionProviders) || isNonEmptyArray(activeConnections);++ if (!isAppInUse || !isNonEmptyArray(missingRequiredVariables)) {return null;}- return <Status color="red">{t`Missing account`}</Status>;+ return <Status color="red">{t`Missing configuration`}</Status>;};diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsAccounts.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsAccounts.stories.tsxindex 67b9af756dd..3fa7d36fb51 100644--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsAccounts.stories.tsx+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsAccounts.stories.tsx@@ -22,16 +22,18 @@ import {CONNECTED_ACCOUNTS,FATHOM_APPLICATION_ID,GOOGLE_ACCOUNT_ID,+ GOOGLE_MESSAGE_CHANNEL_ID,+ MESSAGE_CHANNELS,MICROSOFT_ACCOUNT_ID,deleteConnectedAccount,seedAccountGroupsStory,} from '~/pages/settings/accounts/__stories__/mockedAccountGroups';import {+ APPLICATION_PREFERENCES_DETAIL_GRAPHQL_HANDLERS,APPLICATION_PREFERENCES_GRAPHQL_HANDLERS,failNextApplicationPreferencesRequest,seedApplicationPreferencesStory,} from '~/pages/settings/accounts/__stories__/mockedApplicationPreferences';-import { unconfigureLinearClientCredentials } from '~/pages/settings/accounts/__stories__/mockedLinearApplicationPreferences';const meta: Meta<PageDecoratorArgs> = {title: 'Pages/Settings/Accounts/SettingsAccounts',@@ -62,6 +64,16 @@ const getTableRow = (canvasElement: HTMLElement, text: string) => {return within(row);};+const getStatusCell = ({+ canvasElement,+ text,+}: {+ canvasElement: HTMLElement;+ text: string;+}) =>+ within(canvasElement).getByText(text).closest('[data-table-row]')+ ?.children[1];+const getTab = ({canvasElement,tabId,@@ -250,7 +262,6 @@ export const AppPreferencesListEnabledApps: Story = {await canvas.findByRole('link', { name: 'Gmail and Calendar' }),).toBeVisible();expect(canvas.queryByText('IMAP')).not.toBeInTheDocument();- expect(canvas.queryByText('Missing account')).not.toBeInTheDocument();await userEvent.click(canvas.getByRole('link', { name: 'Outlook' }));@@ -324,43 +335,55 @@ export const DeleteKeepsAppConnections: Story = {},};-export const AppsWithoutAccountShowMissingAccount: Story = {+export const AppsFlagOnlyBrokenAccounts: Story = {...accountGroupsStory,+ beforeEach: seedApplicationPreferencesStory,parameters: {msw: {handlers: [graphql.query('MyConnectedAccounts', () =>HttpResponse.json({data: {- myConnectedAccounts: CONNECTED_ACCOUNTS.filter(- (account) =>- account.id !== GOOGLE_ACCOUNT_ID &&- account.id !== MICROSOFT_ACCOUNT_ID,+ myConnectedAccounts: CONNECTED_ACCOUNTS.map((account) =>+ account.id === MICROSOFT_ACCOUNT_ID+ ? { ...account, archivedAt: '2026-09-03T00:00:00.000Z' }+ : account,),},}),),- ...ACCOUNT_GROUPS_GRAPHQL_HANDLERS,+ graphql.query('MyMessageChannels', () =>+ HttpResponse.json({+ data: {+ myMessageChannels: MESSAGE_CHANNELS.map((channel) =>+ channel.id === GOOGLE_MESSAGE_CHANNEL_ID ||+ channel.connectedAccountId === MICROSOFT_ACCOUNT_ID+ ? { ...channel, syncStatus: 'FAILED_UNKNOWN' }+ : channel,+ ),+ },+ }),+ ),+ ...APPLICATION_PREFERENCES_GRAPHQL_HANDLERS,],},},play: async ({ canvasElement }) => {const canvas = within(canvasElement);- await canvas.findByText(- 'Choose your preferences for the apps installed on your workspace by the admin',- undefined,- { timeout: 3000 },- );+ await canvas.findByText('Linear', undefined, { timeout: 3000 });expect(- await getTableRow(canvasElement, 'Outlook').findByText('Missing account'),+ await getTableRow(canvasElement, 'Gmail and Calendar').findByText(+ 'Sync failed',+ ),).toBeVisible();expect(- getTableRow(canvasElement, 'Gmail and Calendar').queryByText(- 'Missing account',- ),- ).not.toBeInTheDocument();+ getStatusCell({ canvasElement, text: 'Outlook' }),+ ).toBeEmptyDOMElement();+ expect(+ getStatusCell({ canvasElement, text: 'Linear' }),+ ).toBeEmptyDOMElement();},};@@ -412,10 +435,6 @@ export const AppPreferencesListInstalledApps: Story = {fathomRow.compareDocumentPosition(granolaRow) &Node.DOCUMENT_POSITION_FOLLOWING,).toBeTruthy();- expect(- within(fathomRow).queryByText('Missing account'),- ).not.toBeInTheDocument();-await userEvent.click(fathomRow);expect(@@ -426,53 +445,28 @@ export const AppPreferencesListInstalledApps: Story = {},};-export const AppPreferencesListFlagsMissingConfiguration: Story = {+export const InstalledAppsFlagReconnectAndMissingConfiguration: Story = {...accountGroupsStory,beforeEach: seedApplicationPreferencesStory,parameters: {- msw: { handlers: APPLICATION_PREFERENCES_GRAPHQL_HANDLERS },+ msw: { handlers: APPLICATION_PREFERENCES_DETAIL_GRAPHQL_HANDLERS },},play: async ({ canvasElement }) => {- await within(canvasElement).findByText('Fathom', undefined, {- timeout: 3000,- });+ const canvas = within(canvasElement);++ await canvas.findByText('Fathom', undefined, { timeout: 3000 });expect(- getTableRow(canvasElement, 'Fathom').getByText('Missing configuration'),- ).toBeVisible();- expect(- getTableRow(canvasElement, 'Granola').queryByText(+ await getTableRow(canvasElement, 'Fathom').findByText('Missing configuration',),- ).not.toBeInTheDocument();- expect(- getTableRow(canvasElement, 'Linear').queryByText('Missing configuration'),- ).not.toBeInTheDocument();+ ).toBeVisible();expect(- await getTableRow(canvasElement, 'Linear').findByText('Missing account'),+ await getTableRow(canvasElement, 'Linear').findByText('Reconnect needed'),).toBeVisible();- },-};--export const AppsWhoseProviderIsNotSetUpShowNoMissingAccount: Story = {- ...accountsTabStory,- beforeEach: async () => {- await seedApplicationPreferencesStory();- unconfigureLinearClientCredentials();- },- parameters: {- msw: { handlers: APPLICATION_PREFERENCES_GRAPHQL_HANDLERS },- },- play: async ({ canvasElement }) => {- const canvas = within(canvasElement);-- await canvas.findByText('[email protected]', undefined, { timeout: 3000 });- await userEvent.click(getTab({ canvasElement, tabId: 'apps' }));- await canvas.findByText('Linear', undefined, { timeout: 3000 });-expect(- getTableRow(canvasElement, 'Linear').queryByText('Missing account'),- ).not.toBeInTheDocument();+ getStatusCell({ canvasElement, text: 'Granola' }),+ ).toBeEmptyDOMElement();},};