The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Show a connect card for installed apps without connections (#29227)
nitin47d19210bcea
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesConnectionsTab.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesConnectionsTab.tsxindex 75109393ad5..8d84a156c98 100644--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesConnectionsTab.tsx+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesConnectionsTab.tsx@@ -1,4 +1,5 @@import { SettingsAppPreferencesConnectionsTable } from '@/settings/app-preferences/components/SettingsAppPreferencesConnectionsTable';+import { SettingsApplicationConnectCard } from '@/settings/app-preferences/components/SettingsApplicationConnectCard';import { useMyPersonalConnectedAccounts } from '@/settings/app-preferences/hooks/useMyPersonalConnectedAccounts';import { type ApplicationWithPreferences } from '@/settings/app-preferences/types/ApplicationWithPreferences';import { getApplicationPreferencesGeneralPath } from '@/settings/app-preferences/utils/getApplicationPreferencesGeneralPath';@@ -6,20 +7,13 @@ import { SettingsApplicationAddConnectionButton } from '@/settings/applications/import { SettingsApplicationConnectionProviderSection } from '@/settings/applications/components/SettingsApplicationConnectionProviderSection';import { SettingsApplicationLoadErrorBanner } from '@/settings/applications/components/SettingsApplicationLoadErrorBanner';import { canStartConnectionProviderAuthorization } from '@/settings/applications/utils/canStartConnectionProviderAuthorization';-import { styled } from '@linaria/react';import { useLingui } from '@lingui/react/macro';import { ConnectedAccountProvider } from 'twenty-shared/types';import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';-import { themeCssVariables } from 'twenty-ui/theme';const APP_CONNECTED_ACCOUNT_PROVIDERS: ReadonlySet<ConnectedAccountProvider> =new Set([ConnectedAccountProvider.APP]);-const StyledEmptyState = styled.div`- color: ${themeCssVariables.font.color.tertiary};- font-size: ${themeCssVariables.font.size.md};-`;-type SettingsAppPreferencesConnectionsTabProps = {applicationId: string;connectionProviders: ApplicationWithPreferences['connectionProviders'];@@ -62,21 +56,15 @@ export const SettingsAppPreferencesConnectionsTab = ({message={t`Your connections could not be loaded. Check your connection and try again.`}onRetry={() => refetch().catch(() => undefined)}/>- ) : (+ ) : loading || isNonEmptyArray(providerConnections) ? (<>- {loading || isNonEmptyArray(providerConnections) ? (- <SettingsAppPreferencesConnectionsTable- applicationId={applicationId}- providerName={provider.name}- connections={providerConnections}- canStartAuthorization={canStartAuthorization}- isLoading={loading}- />- ) : (- canStartAuthorization && (- <StyledEmptyState>{t`You have no ${provider.displayName} connection yet.`}</StyledEmptyState>- )- )}+ <SettingsAppPreferencesConnectionsTable+ applicationId={applicationId}+ providerName={provider.name}+ connections={providerConnections}+ canStartAuthorization={canStartAuthorization}+ isLoading={loading}+ />{canStartAuthorization && (<SettingsApplicationAddConnectionButtonapplicationId={applicationId}@@ -87,6 +75,14 @@ export const SettingsAppPreferencesConnectionsTab = ({/>)}</>+ ) : (+ canStartAuthorization && (+ <SettingsApplicationConnectCard+ applicationId={applicationId}+ connectionProvider={provider}+ title={t`Connect with ${provider.displayName}`}+ />+ ))}</SettingsApplicationConnectionProviderSection>);diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCard.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCard.tsxnew file mode 100644index 00000000000..9ec0961ec0c--- /dev/null+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCard.tsx@@ -0,0 +1,43 @@+import { AppChip } from '@/applications/components/AppChip';+import { type ApplicationWithPreferences } from '@/settings/app-preferences/types/ApplicationWithPreferences';+import { getApplicationPreferencesGeneralPath } from '@/settings/app-preferences/utils/getApplicationPreferencesGeneralPath';+import { useTriggerAppOAuth } from '@/settings/applications/hooks/useTriggerAppOAuth';+import { SettingsCard } from '@/settings/components/SettingsCard';++type SettingsApplicationConnectCardProps = {+ applicationId: string;+ connectionProvider: Pick<+ ApplicationWithPreferences['connectionProviders'][number],+ 'name' | 'logoUrl'+ >;+ title: string;+};++export const SettingsApplicationConnectCard = ({+ applicationId,+ connectionProvider,+ title,+}: SettingsApplicationConnectCardProps) => {+ const { triggerAppOAuth } = useTriggerAppOAuth();++ return (+ <SettingsCard+ Icon={+ <AppChip+ applicationId={applicationId}+ logoUrl={connectionProvider.logoUrl}+ size="md"+ chipOnly+ />+ }+ title={title}+ onClick={() =>+ triggerAppOAuth({+ applicationId,+ providerName: connectionProvider.name,+ redirectLocation: getApplicationPreferencesGeneralPath(applicationId),+ })+ }+ />+ );+};diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCards.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCards.tsxindex c2690cf0d46..942bc945966 100644--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCards.tsx+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsApplicationConnectCards.tsx@@ -1,11 +1,8 @@-import { AppChip } from '@/applications/components/AppChip';import { getApplicationDisplayName } from '@/applications/utils/getApplicationDisplayName';import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';+import { SettingsApplicationConnectCard } from '@/settings/app-preferences/components/SettingsApplicationConnectCard';import { useApplicationsWithPreferences } from '@/settings/app-preferences/hooks/useApplicationsWithPreferences';-import { getApplicationPreferencesGeneralPath } from '@/settings/app-preferences/utils/getApplicationPreferencesGeneralPath';-import { useTriggerAppOAuth } from '@/settings/applications/hooks/useTriggerAppOAuth';import { canStartConnectionProviderAuthorization } from '@/settings/applications/utils/canStartConnectionProviderAuthorization';-import { SettingsCard } from '@/settings/components/SettingsCard';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useLingui } from '@lingui/react/macro';@@ -13,7 +10,6 @@ export const SettingsApplicationConnectCards = () => {const { t } = useLingui();const currentWorkspace = useAtomStateValue(currentWorkspaceState);const { applicationsWithPreferences } = useApplicationsWithPreferences();- const { triggerAppOAuth } = useTriggerAppOAuth();const connectableProviders = applicationsWithPreferences.flatMap(({ application, connectionProviders }) => {@@ -46,21 +42,11 @@ export const SettingsApplicationConnectCards = () => {: applicationName;return (- <SettingsCard+ <SettingsApplicationConnectCardkey={connectionProvider.id}- Icon={- <AppChip applicationId={application.id} size="md" chipOnly />- }+ applicationId={application.id}+ connectionProvider={connectionProvider}title={t`Connect with ${appName}`}- onClick={() =>- triggerAppOAuth({- applicationId: application.id,- providerName: connectionProvider.name,- redirectLocation: getApplicationPreferencesGeneralPath(- application.id,- ),- })- }/>);},diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsxindex 805a46f570c..cea0bb3d69b 100644--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferences.stories.tsx@@ -312,7 +312,7 @@ export const MemberLandsOnGeneralWithoutWorkspaceActions: Story = {),).toBeVisible();expect(- await canvas.findByText('You have no Fathom connection yet.', undefined, {+ await canvas.findByText('Connect with Fathom', undefined, {timeout: 3000,}),).toBeVisible();diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferencesConnections.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferencesConnections.stories.tsxindex b29a05224c9..d4cc132308f 100644--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferencesConnections.stories.tsx+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsApplicationPreferencesConnections.stories.tsx@@ -264,21 +264,35 @@ export const UnconfiguredProviderExplainsWhoMustSetItUp: Story = {},};-export const ProviderWithoutConnectionsSaysSo: Story = {+export const ProviderWithoutConnectionsOffersAConnectCard: Story = {parameters: {msw: { handlers: APPLICATION_PREFERENCES_GRAPHQL_HANDLERS },},play: async ({ canvasElement }) => {const canvas = within(canvasElement);+ const connectCard = await canvas.findByText(+ 'Connect with Linear',+ undefined,+ { timeout: 3000 },+ );++ expect(connectCard).toBeVisible();expect(- await canvas.findByText('You have no Linear connection yet.', undefined, {- timeout: 3000,- }),- ).toBeVisible();- expect(- canvas.getByRole('button', { name: 'Add connection' }),- ).toBeVisible();+ canvas.queryByRole('button', { name: 'Add connection' }),+ ).not.toBeInTheDocument();++ const redirectUrl = await clickAndCaptureOAuthRedirect(connectCard);++ expect(`${redirectUrl.origin}${redirectUrl.pathname}`).toBe(+ `${REACT_APP_SERVER_BASE_URL}/auth/apps/authorize`,+ );+ expect(Object.fromEntries(redirectUrl.searchParams)).toEqual({+ applicationId: LINEAR_APPLICATION_ID,+ providerName: 'linear',+ transientToken: MOCKED_TRANSIENT_TOKEN,+ redirectLocation: LINEAR_GENERAL_TAB_REDIRECT_LOCATION,+ });},};@@ -298,9 +312,7 @@ export const UnconfiguredProviderWithoutConnectionsShowsOnlyTheBanner: Story = {timeout: 3000,}),).toBeVisible();- expect(- canvas.queryByText('You have no Linear connection yet.'),- ).not.toBeInTheDocument();+ expect(canvas.queryByText('Connect with Linear')).not.toBeInTheDocument();},};@@ -319,9 +331,7 @@ export const LoadErrorOffersRetryInsteadOfTheEmptyState: Story = {{ timeout: 3000 },),).toBeVisible();- expect(- canvas.queryByText('You have no Linear connection yet.'),- ).not.toBeInTheDocument();+ expect(canvas.queryByText('Connect with Linear')).not.toBeInTheDocument();expect(canvas.queryByRole('button', { name: 'Add connection' }),).not.toBeInTheDocument();