Skip to content

The open alternative to Salesforce, designed for AI.

Add app preferences pages for Gmail, Google Calendar, Outlook and IMAP (#27709)

nitin4b9db97a9496
diff --git a/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx b/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
index 308f5f1ab43..5f70355c5b3 100644
--- a/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
+++ b/packages/twenty-front/src/modules/app/components/SettingsRoutes.tsx
@@ -419,6 +419,14 @@ const SettingsAccountDetail = lazy(() =>
})),
);
+const SettingsNativeAccountApp = lazy(() =>
+ import('~/pages/settings/accounts/SettingsNativeAccountApp').then(
+ (module) => ({
+ default: module.SettingsNativeAccountApp,
+ }),
+ ),
+);
+
const SettingsAccountsEmails = lazy(() =>
import('~/pages/settings/accounts/SettingsAccountsEmails').then((module) => ({
default: module.SettingsAccountsEmails,
@@ -764,6 +772,10 @@ const createSettingsRouteElements = ({
path={SettingsPath.AccountDetail}
element={<SettingsAccountDetail />}
/>
+ <Route
+ path={SettingsPath.NativeAccountApp}
+ element={<SettingsNativeAccountApp />}
+ />
<Route
path={SettingsPath.AccountsEmails}
element={<SettingsAccountsEmails />}
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupTableRow.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupTableRow.tsx
index 228b42d54a8..f839acab52d 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupTableRow.tsx
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupTableRow.tsx
@@ -2,9 +2,10 @@ import { SettingsAccountGroupUsedBy } from '@/settings/app-preferences/component
import { SettingsAppPreferencesRowDropdownMenu } from '@/settings/app-preferences/components/SettingsAppPreferencesRowDropdownMenu';
import { SettingsConnectedAccountIcon } from '@/settings/accounts/components/SettingsConnectedAccountIcon';
import { SettingsConnectedAccountSyncStatus } from '@/settings/app-preferences/components/SettingsConnectedAccountSyncStatus';
-import { SETTINGS_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS } from '@/settings/app-preferences/constants/SettingsAccountGroupTableGridTemplateColumns';
+import { SettingsNativeAccountAppPermissionsCell } from '@/settings/app-preferences/components/SettingsNativeAccountAppPermissionsCell';
import { SyncStatus } from '@/settings/accounts/constants/SyncStatus';
import { type ConnectedAccountGroup } from '@/settings/app-preferences/types/ConnectedAccountGroup';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
import { computeSyncStatus } from '@/settings/accounts/utils/computeSyncStatus';
import { getConnectedAccountSettingsChannels } from '@/settings/app-preferences/utils/getConnectedAccountSettingsChannels';
import { TableCell } from '@/ui/layout/table/components/TableCell';
@@ -23,10 +24,14 @@ const SYNC_STATUSES_NEEDING_ACTION: ReadonlySet<SyncStatus> = new Set([
type SettingsAccountGroupTableRowProps = {
group: ConnectedAccountGroup;
+ gridTemplateColumns: string;
+ nativeAccountApp?: NativeAccountApp;
};
export const SettingsAccountGroupTableRow = ({
group,
+ gridTemplateColumns,
+ nativeAccountApp,
}: SettingsAccountGroupTableRowProps) => {
const theme = useTheme();
const navigateSettings = useNavigateSettings();
@@ -64,7 +69,7 @@ export const SettingsAccountGroupTableRow = ({
return (
<TableRow
- gridTemplateColumns={SETTINGS_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS}
+ gridTemplateColumns={gridTemplateColumns}
onClick={
hasSettings
? () =>
@@ -86,9 +91,16 @@ export const SettingsAccountGroupTableRow = ({
) : (
accountCell
)}
- <TableCell align="right">
- <SettingsAccountGroupUsedBy group={group} />
- </TableCell>
+ {isDefined(nativeAccountApp) ? (
+ <SettingsNativeAccountAppPermissionsCell
+ nativeAccountApp={nativeAccountApp}
+ account={nativeAccount}
+ />
+ ) : (
+ <TableCell align="right">
+ <SettingsAccountGroupUsedBy group={group} />
+ </TableCell>
+ )}
<TableCell align="right" onClick={(event) => event.stopPropagation()}>
{isDefined(nativeAccount) && (
<SettingsAppPreferencesRowDropdownMenu account={nativeAccount} />
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupUsedBy.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupUsedBy.tsx
index a71e074420e..7ccebf57b50 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupUsedBy.tsx
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupUsedBy.tsx
@@ -2,20 +2,12 @@ import { AppChip } from '@/applications/components/AppChip';
import { getApplicationDisplayName } from '@/applications/utils/getApplicationDisplayName';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { type ConnectedAccountGroup } from '@/settings/app-preferences/types/ConnectedAccountGroup';
-import { getConnectedAccountSettingsChannels } from '@/settings/app-preferences/utils/getConnectedAccountSettingsChannels';
+import { getNativeAccountAppsUsingAccount } from '@/settings/app-preferences/utils/getNativeAccountAppsUsingAccount';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { type ReactNode } from 'react';
-import { ConnectedAccountProvider } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
-import {
- IconCalendarEvent,
- IconGmail,
- IconGoogleCalendar,
- IconMail,
- IconMicrosoftOutlook,
-} from 'twenty-ui/icon';
import { Tooltip } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables, useTheme } from 'twenty-ui/theme';
@@ -45,63 +37,16 @@ export const SettingsAccountGroupUsedBy = ({
const { t } = useLingui();
const theme = useTheme();
const currentWorkspace = useAtomStateValue(currentWorkspaceState);
- const iconSize = theme.icon.size.md;
- const { messageChannel, calendarChannel } =
- getConnectedAccountSettingsChannels(group.nativeAccount);
- const usesEmails = isDefined(messageChannel);
- const usesCalendar = isDefined(calendarChannel);
-
- const getNativeUsages = (): (Usage | undefined)[] => {
- switch (group.nativeAccount?.provider) {
- case ConnectedAccountProvider.GOOGLE:
- return [
- usesEmails
- ? {
- key: 'gmail',
- title: t`Gmail`,
- icon: <IconGmail size={iconSize} />,
- }
- : undefined,
- usesCalendar
- ? {
- key: 'google-calendar',
- title: t`Google Calendar`,
- icon: <IconGoogleCalendar size={iconSize} />,
- }
- : undefined,
- ];
- case ConnectedAccountProvider.MICROSOFT:
- return [
- usesEmails || usesCalendar
- ? {
- key: 'outlook',
- title: t`Outlook`,
- icon: <IconMicrosoftOutlook size={iconSize} />,
- }
- : undefined,
- ];
- case ConnectedAccountProvider.IMAP_SMTP_CALDAV:
- return [
- usesEmails
- ? {
- key: 'emails',
- title: t`Emails`,
- icon: <IconMail size={iconSize} />,
- }
- : undefined,
- usesCalendar
- ? {
- key: 'calendar',
- title: t`Calendar`,
- icon: <IconCalendarEvent size={iconSize} />,
- }
- : undefined,
- ];
- default:
- return [];
- }
- };
+ const nativeUsages = getNativeAccountAppsUsingAccount(
+ group.nativeAccount,
+ ).map(
+ (app): Usage => ({
+ key: app.id,
+ title: t(app.name),
+ icon: <app.Icon size={theme.icon.size.md} />,
+ }),
+ );
const applicationIds = new Set(
group.appAccounts.map((account) => account.applicationId).filter(isDefined),
@@ -123,15 +68,13 @@ export const SettingsAccountGroupUsedBy = ({
return (
<StyledUsedBy>
- {[...getNativeUsages().filter(isDefined), ...appUsages].map(
- ({ key, title, icon }) => (
- <Tooltip key={key} content={title}>
- <StyledUsage role="img" aria-label={title}>
- {icon}
- </StyledUsage>
- </Tooltip>
- ),
- )}
+ {[...nativeUsages, ...appUsages].map(({ key, title, icon }) => (
+ <Tooltip key={key} content={title}>
+ <StyledUsage role="img" aria-label={title}>
+ {icon}
+ </StyledUsage>
+ </Tooltip>
+ ))}
</StyledUsedBy>
);
};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupsSection.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupsSection.tsx
index 60c1757a10d..3517fdcf932 100644
--- a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupsSection.tsx
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAccountGroupsSection.tsx
@@ -1,7 +1,10 @@
import { SettingsAccountGroupTableRow } from '@/settings/app-preferences/components/SettingsAccountGroupTableRow';
-import { SettingsAccountsListEmptyStateCard } from '@/settings/accounts/components/SettingsAccountsListEmptyStateCard';
+import { SettingsAppPreferencesListEmptyStateCard } from '@/settings/app-preferences/components/SettingsAppPreferencesListEmptyStateCard';
import { SETTINGS_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS } from '@/settings/app-preferences/constants/SettingsAccountGroupTableGridTemplateColumns';
+import { SETTINGS_NATIVE_ACCOUNT_APP_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS } from '@/settings/app-preferences/constants/SettingsNativeAccountAppAccountGroupTableGridTemplateColumns';
import { useMyAccountGroups } from '@/settings/app-preferences/hooks/useMyAccountGroups';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { getNativeAccountAppsUsingAccount } from '@/settings/app-preferences/utils/getNativeAccountAppsUsingAccount';
import { SettingsSectionSkeletonLoader } from '@/settings/components/SettingsSectionSkeletonLoader';
import { Table } from '@/ui/layout/table/components/Table';
import { TableHeader } from '@/ui/layout/table/components/TableHeader';
@@ -9,6 +12,7 @@ import { TableRow } from '@/ui/layout/table/components/TableRow';
import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { SettingsPath } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
import { Section } from 'twenty-ui/components/layout';
import { IconPlus } from 'twenty-ui/icon';
import { Button } from 'twenty-ui/primitives/input';
@@ -27,10 +31,28 @@ const StyledAddAccountContainer = styled.div`
padding-top: ${themeCssVariables.spacing[2]};
`;
-export const SettingsAccountGroupsSection = () => {
+type SettingsAccountGroupsSectionProps = {
+ nativeAccountApp?: NativeAccountApp;
+};
+
+export const SettingsAccountGroupsSection = ({
+ nativeAccountApp,
+}: SettingsAccountGroupsSectionProps) => {
const { t } = useLingui();
const navigateSettings = useNavigateSettings();
- const { groups, loading } = useMyAccountGroups();
+ const { groups: allGroups, loading } = useMyAccountGroups();
+
+ const groups = isDefined(nativeAccountApp)
+ ? allGroups.filter((group) =>
+ getNativeAccountAppsUsingAccount(group.nativeAccount).some(
+ (app) => app.id === nativeAccountApp.id,
+ ),
+ )
+ : allGroups;
+
+ const gridTemplateColumns = isDefined(nativeAccountApp)
+ ? SETTINGS_NATIVE_ACCOUNT_APP_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS
+ : SETTINGS_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS;
if (loading) {
return <SettingsSectionSkeletonLoader />;
@@ -43,22 +65,29 @@ export const SettingsAccountGroupsSection = () => {
description={t`Shared accounts between apps`}
/>
{groups.length === 0 ? (
- <SettingsAccountsListEmptyStateCard />
+ <SettingsAppPreferencesListEmptyStateCard
+ provider={nativeAccountApp?.provider}
+ />
) : (
<>
<Table>
- <TableRow
- gridTemplateColumns={
- SETTINGS_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS
- }
- >
+ <TableRow gridTemplateColumns={gridTemplateColumns}>
<TableHeader>{t`Account`}</TableHeader>
- <TableHeader align="right">{t`Used by`}</TableHeader>
+ {isDefined(nativeAccountApp) ? (
+ <TableHeader>{t`Permissions`}</TableHeader>
+ ) : (
+ <TableHeader align="right">{t`Used by`}</TableHeader>
+ )}
<TableHeader />
</TableRow>
<StyledTableRows>
{groups.map((group) => (
- <SettingsAccountGroupTableRow key={group.id} group={group} />
+ <SettingsAccountGroupTableRow
+ key={group.id}
+ group={group}
+ gridTemplateColumns={gridTemplateColumns}
+ nativeAccountApp={nativeAccountApp}
+ />
))}
</StyledTableRows>
</Table>
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesListEmptyStateCard.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesListEmptyStateCard.tsx
new file mode 100644
index 00000000000..9a3cbabc23b
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesListEmptyStateCard.tsx
@@ -0,0 +1,90 @@
+import { isGoogleCalendarEnabledState } from '@/client-config/states/isGoogleCalendarEnabledState';
+import { isGoogleMessagingEnabledState } from '@/client-config/states/isGoogleMessagingEnabledState';
+import { isImapSmtpCaldavEnabledState } from '@/client-config/states/isImapSmtpCaldavEnabledState';
+import { isMicrosoftCalendarEnabledState } from '@/client-config/states/isMicrosoftCalendarEnabledState';
+import { isMicrosoftMessagingEnabledState } from '@/client-config/states/isMicrosoftMessagingEnabledState';
+import { useTriggerApisOAuth } from '@/settings/accounts/hooks/useTriggerApiOAuth';
+import { SettingsCard } from '@/settings/components/SettingsCard';
+import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink/UndecoratedLink';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { ConnectedAccountProvider, SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
+import { IconAt, IconGoogle, IconMicrosoft } from 'twenty-ui/icon';
+import { useTheme, themeCssVariables } from 'twenty-ui/theme';
+
+const StyledCardsContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[2]};
+`;
+
+type SettingsAppPreferencesListEmptyStateCardProps = {
+ provider?: ConnectedAccountProvider;
+};
+
+export const SettingsAppPreferencesListEmptyStateCard = ({
+ provider,
+}: SettingsAppPreferencesListEmptyStateCardProps) => {
+ const theme = useTheme();
+ const { triggerApisOAuth } = useTriggerApisOAuth();
+
+ const { t } = useLingui();
+
+ const isGoogleMessagingEnabled = useAtomStateValue(
+ isGoogleMessagingEnabledState,
+ );
+ const isMicrosoftMessagingEnabled = useAtomStateValue(
+ isMicrosoftMessagingEnabledState,
+ );
+
+ const isGoogleCalendarEnabled = useAtomStateValue(
+ isGoogleCalendarEnabledState,
+ );
+
+ const isMicrosoftCalendarEnabled = useAtomStateValue(
+ isMicrosoftCalendarEnabledState,
+ );
+
+ const isImapSmtpCaldavEnabled = useAtomStateValue(
+ isImapSmtpCaldavEnabledState,
+ );
+
+ const isProviderShown = (shownProvider: ConnectedAccountProvider) =>
+ !isDefined(provider) || provider === shownProvider;
+
+ return (
+ <StyledCardsContainer>
+ {isProviderShown(ConnectedAccountProvider.GOOGLE) &&
+ (isGoogleMessagingEnabled || isGoogleCalendarEnabled) && (
+ <SettingsCard
+ Icon={<IconGoogle size={theme.icon.size.md} />}
+ title={t`Connect with Google`}
+ onClick={() => triggerApisOAuth(ConnectedAccountProvider.GOOGLE)}
+ />
+ )}
+
+ {isProviderShown(ConnectedAccountProvider.MICROSOFT) &&
+ (isMicrosoftMessagingEnabled || isMicrosoftCalendarEnabled) && (
+ <SettingsCard
+ Icon={<IconMicrosoft size={theme.icon.size.md} />}
+ title={t`Connect with Microsoft`}
+ onClick={() => triggerApisOAuth(ConnectedAccountProvider.MICROSOFT)}
+ />
+ )}
+
+ {isProviderShown(ConnectedAccountProvider.IMAP_SMTP_CALDAV) &&
+ isImapSmtpCaldavEnabled && (
+ <UndecoratedLink
+ to={getSettingsPath(SettingsPath.NewImapSmtpCaldavConnection)}
+ >
+ <SettingsCard
+ Icon={<IconAt size={theme.icon.size.md} />}
+ title={t`Connect via IMAP/SMTP`}
+ />
+ </UndecoratedLink>
+ )}
+ </StyledCardsContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesMessageChannelDetails.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesMessageChannelDetails.tsx
new file mode 100644
index 00000000000..c6e754aaaf2
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesMessageChannelDetails.tsx
@@ -0,0 +1,160 @@
+import { useMutation } from '@apollo/client/react';
+import { styled } from '@linaria/react';
+import { t } from '@lingui/core/macro';
+
+import {
+ type MessageChannelContactAutoCreationPolicy,
+ MessageChannelType,
+ type MessageFolderImportPolicy,
+} from 'twenty-shared/types';
+import { Section } from 'twenty-ui/components/layout';
+import { IconBriefcase, IconUsers } from 'twenty-ui/icon';
+import { Card } from 'twenty-ui/primitives/surfaces';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+import { type MessageChannel } from '@/accounts/types/MessageChannel';
+import { SettingsAccountsMessageAutoCreationCard } from '@/settings/accounts/components/SettingsAccountsMessageAutoCreationCard';
+import { SettingsAccountsMessageFolderCard } from '@/settings/accounts/components/SettingsAccountsMessageFolderCard';
+import { SettingsAccountsMessageVisibilityCard } from '@/settings/accounts/components/SettingsAccountsMessageVisibilityCard';
+import { UPDATE_MESSAGE_CHANNEL } from '@/settings/accounts/graphql/mutations/updateMessageChannel';
+import { SettingsOptionCardContentSwitch } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSwitch';
+import { type MessageChannelVisibility } from '~/generated-metadata/graphql';
+
+type SettingsAppPreferencesMessageChannelDetailsProps = {
+ messageChannel: Pick<
+ MessageChannel,
+ | 'id'
+ | 'visibility'
+ | 'contactAutoCreationPolicy'
+ | 'excludeNonProfessionalEmails'
+ | 'excludeGroupEmails'
+ | 'isSyncEnabled'
+ | 'messageFolderImportPolicy'
+ | 'type'
+ >;
+};
+
+type MessageChannelUpdateInput = Partial<{
+ visibility: MessageChannelVisibility;
+ contactAutoCreationPolicy: MessageChannelContactAutoCreationPolicy;
+ excludeGroupEmails: boolean;
+ excludeNonProfessionalEmails: boolean;
+ messageFolderImportPolicy: MessageFolderImportPolicy;
+}>;
+
+const StyledDetailsContainer = styled.div`
+ display: flex;
+ flex-direction: column;
+ gap: ${themeCssVariables.spacing[6]};
+`;
+
+export const SettingsAppPreferencesMessageChannelDetails = ({
+ messageChannel,
+}: SettingsAppPreferencesMessageChannelDetailsProps) => {
+ const [updateMessageChannel] = useMutation(UPDATE_MESSAGE_CHANNEL);
+
+ const updateChannel = (update: MessageChannelUpdateInput) => {
+ updateMessageChannel({
+ variables: { input: { id: messageChannel.id, update } },
+ });
+ };
+
+ const handleVisibilityChange = (value: MessageChannelVisibility) => {
+ updateChannel({ visibility: value });
+ };
+
+ const handleContactAutoCreationChange = (
+ value: MessageChannelContactAutoCreationPolicy,
+ ) => {
+ updateChannel({ contactAutoCreationPolicy: value });
+ };
+
+ const handleIsGroupEmailExcludedToggle = (value: boolean) => {
+ updateChannel({ excludeGroupEmails: value });
+ };
+
+ const handleIsNonProfessionalEmailExcludedToggle = (value: boolean) => {
+ updateChannel({ excludeNonProfessionalEmails: value });
+ };
+
+ const handleMessageFolderImportPolicyChange = (
+ value: MessageFolderImportPolicy,
+ ) => {
+ updateChannel({ messageFolderImportPolicy: value });
+ };
+
+ const supportsFolderImportPolicy =
+ messageChannel.type === MessageChannelType.EMAIL;
+
+ const isGroupMailbox = messageChannel.type === MessageChannelType.EMAIL_GROUP;
+
+ return (
+ <StyledDetailsContainer>
+ {supportsFolderImportPolicy && (
+ <Section.Root>
+ <Section.Header
+ title={t`Import`}
+ description={t`Emails from the blocklist will be ignored regardless of this setting.`}
+ />
+ <SettingsAccountsMessageFolderCard
+ onChange={handleMessageFolderImportPolicyChange}
+ value={messageChannel.messageFolderImportPolicy}
+ />
+ </Section.Root>
+ )}
+ {!isGroupMailbox && (
+ <Section.Root>
+ <Section.Header
+ title={t`Visibility`}
+ description={t`Define what will be visible to other users in your workspace`}
+ />
+ <SettingsAccountsMessageVisibilityCard
+ value={messageChannel.visibility}
+ onChange={handleVisibilityChange}
+ />
+ </Section.Root>
+ )}
+ <Section.Root>
+ <Section.Header
+ title={t`Contact auto-creation`}
+ description={t`Automatically create People records when receiving or sending emails`}
+ />
+ <SettingsAccountsMessageAutoCreationCard
+ value={messageChannel.contactAutoCreationPolicy}
+ onChange={handleContactAutoCreationChange}
+ />
+ </Section.Root>
+ <Section.Root>
+ <Section.Header
+ title={t`Options`}
+ description={t`Configure what emails should get synced`}
+ />
+ <Card.Root rounded>
+ <SettingsOptionCardContentSwitch
+ Icon={IconUsers}
+ title={t`Exclude group emails`}
+ description={t`Don't import emails from team@ support@ noreply@...`}
+ divider
+ checked={messageChannel.excludeGroupEmails}
+ onChange={() =>
+ handleIsGroupEmailExcludedToggle(
+ !messageChannel.excludeGroupEmails,
+ )
+ }
+ />
+ <SettingsOptionCardContentSwitch
+ Icon={IconBriefcase}
+ title={t`Exclude non-professional emails`}
+ description={t`Don't create contacts from/to Gmail, Outlook emails`}
+ checked={messageChannel.excludeNonProfessionalEmails}
+ onChange={() => {
+ handleIsNonProfessionalEmailExcludedToggle(
+ !messageChannel.excludeNonProfessionalEmails,
+ );
+ }}
+ />
+ </Card.Root>
+ </Section.Root>
+ </StyledDetailsContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesSections.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesSections.tsx
new file mode 100644
index 00000000000..cf05f4dd528
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsAppPreferencesSections.tsx
@@ -0,0 +1,19 @@
+import { SettingsAccountsBlocklistSection } from '@/settings/accounts/components/SettingsAccountsBlocklistSection';
+import { SettingsAccountGroupsSection } from '@/settings/app-preferences/components/SettingsAccountGroupsSection';
+import { SettingsNativeAccountAppsSection } from '@/settings/app-preferences/components/SettingsNativeAccountAppsSection';
+import { useEnabledNativeAccountApps } from '@/settings/app-preferences/hooks/useEnabledNativeAccountApps';
+
+export const SettingsAppPreferencesSections = () => {
+ const { enabledNativeAccountApps } = useEnabledNativeAccountApps();
+
+ return (
+ <>
+ <SettingsAccountGroupsSection />
+ {enabledNativeAccountApps.length > 0 ? (
+ <SettingsNativeAccountAppsSection />
+ ) : (
+ <SettingsAccountsBlocklistSection />
+ )}
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppNameCell.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppNameCell.tsx
new file mode 100644
index 00000000000..1990398fca2
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppNameCell.tsx
@@ -0,0 +1,39 @@
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink/UndecoratedLink';
+import { styled } from '@linaria/react';
+import { useLingui } from '@lingui/react/macro';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath } from 'twenty-shared/utils';
+import { themeCssVariables, useTheme } from 'twenty-ui/theme';
+
+const StyledNameCell = styled.div`
+ align-items: center;
+ color: ${themeCssVariables.font.color.primary};
+ display: flex;
+ gap: ${themeCssVariables.spacing[2]};
+`;
+
+type SettingsNativeAccountAppNameCellProps = {
+ item: NativeAccountApp;
+};
+
+export const SettingsNativeAccountAppNameCell = ({
+ item,
+}: SettingsNativeAccountAppNameCellProps) => {
+ const { t } = useLingui();
+ const theme = useTheme();
+
+ return (
+ <UndecoratedLink
+ to={getSettingsPath(SettingsPath.NativeAccountApp, {
+ nativeAccountAppId: item.id,
+ })}
+ onClick={(event) => event.stopPropagation()}
+ >
+ <StyledNameCell>
+ <item.Icon size={theme.icon.size.md} />
+ {t(item.name)}
+ </StyledNameCell>
+ </UndecoratedLink>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppPermissionsCell.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppPermissionsCell.tsx
new file mode 100644
index 00000000000..4f1afbc08de
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppPermissionsCell.tsx
@@ -0,0 +1,30 @@
+import { type ConnectedAccount } from '@/accounts/types/ConnectedAccount';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { TableCell } from '@/ui/layout/table/components/TableCell';
+import { useLingui } from '@lingui/react/macro';
+import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
+
+type SettingsNativeAccountAppPermissionsCellProps = {
+ nativeAccountApp: NativeAccountApp;
+ account: Pick<ConnectedAccount, 'scopes'> | undefined;
+};
+
+export const SettingsNativeAccountAppPermissionsCell = ({
+ nativeAccountApp,
+ account,
+}: SettingsNativeAccountAppPermissionsCellProps) => {
+ const { t } = useLingui();
+ const grantedScopes = account?.scopes ?? [];
+
+ const permissionLabels = nativeAccountApp.permissions
+ .filter((permission) =>
+ permission.scopes.some((scope) => grantedScopes.includes(scope)),
+ )
+ .map((permission) => t(permission.label));
+
+ return (
+ <TableCell minWidth="0">
+ <OverflowingTextWithTooltip text={permissionLabels.join(', ')} />
+ </TableCell>
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppStatusCell.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppStatusCell.tsx
new file mode 100644
index 00000000000..23f89fe1c8b
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppStatusCell.tsx
@@ -0,0 +1,28 @@
+import { useMyAccountGroups } from '@/settings/app-preferences/hooks/useMyAccountGroups';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { getNativeAccountAppsUsingAccount } from '@/settings/app-preferences/utils/getNativeAccountAppsUsingAccount';
+import { useLingui } from '@lingui/react/macro';
+import { Status } from 'twenty-ui/primitives/data-display';
+
+type SettingsNativeAccountAppStatusCellProps = {
+ item: NativeAccountApp;
+};
+
+export const SettingsNativeAccountAppStatusCell = ({
+ item,
+}: SettingsNativeAccountAppStatusCellProps) => {
+ const { t } = useLingui();
+ const { groups, loading } = useMyAccountGroups();
+
+ const hasAccount = groups.some((group) =>
+ getNativeAccountAppsUsingAccount(group.nativeAccount).some(
+ (app) => app.id === item.id,
+ ),
+ );
+
+ if (loading || hasAccount) {
+ return null;
+ }
+
+ return <Status color="red">{t`Missing account`}</Status>;
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppsSection.tsx b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppsSection.tsx
new file mode 100644
index 00000000000..94cfa5d952a
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/components/SettingsNativeAccountAppsSection.tsx
@@ -0,0 +1,37 @@
+import { SettingsNativeAccountAppNameCell } from '@/settings/app-preferences/components/SettingsNativeAccountAppNameCell';
+import { SettingsNativeAccountAppStatusCell } from '@/settings/app-preferences/components/SettingsNativeAccountAppStatusCell';
+import { useEnabledNativeAccountApps } from '@/settings/app-preferences/hooks/useEnabledNativeAccountApps';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { SettingsTableListSection } from '@/settings/components/SettingsTableListSection';
+import { useLingui } from '@lingui/react/macro';
+import { SettingsPath } from 'twenty-shared/types';
+import { useNavigateSettings } from '~/hooks/useNavigateSettings';
+
+export const SettingsNativeAccountAppsSection = () => {
+ const { t } = useLingui();
+ const navigateSettings = useNavigateSettings();
+ const { enabledNativeAccountApps } = useEnabledNativeAccountApps();
+
+ return (
+ <SettingsTableListSection<NativeAccountApp>
+ title={t`App preferences`}
+ description={t`Choose your preferences for the apps installed on your workspace by the admin`}
+ items={enabledNativeAccountApps}
+ columns={[
+ { label: t`App`, Cell: SettingsNativeAccountAppNameCell },
+ {
+ label: t`Status`,
+ align: 'right',
+ Cell: SettingsNativeAccountAppStatusCell,
+ },
+ ]}
+ gridAutoColumns="1fr 1fr"
+ showRowChevron
+ onRowClick={(app) =>
+ navigateSettings(SettingsPath.NativeAccountApp, {
+ nativeAccountAppId: app.id,
+ })
+ }
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/constants/NativeAccountApps.ts b/packages/twenty-front/src/modules/settings/app-preferences/constants/NativeAccountApps.ts
new file mode 100644
index 00000000000..9c0d661744b
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/constants/NativeAccountApps.ts
@@ -0,0 +1,69 @@
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { msg } from '@lingui/core/macro';
+import { ConnectedAccountProvider } from 'twenty-shared/types';
+import {
+ IconAt,
+ IconGmail,
+ IconGoogleCalendar,
+ IconMicrosoftOutlook,
+} from 'twenty-ui/icon';
+
+export const NATIVE_ACCOUNT_APPS: NativeAccountApp[] = [
+ {
+ id: 'gmail',
+ name: msg`Gmail`,
+ Icon: IconGmail,
+ provider: ConnectedAccountProvider.GOOGLE,
+ hasEmails: true,
+ hasCalendar: false,
+ permissions: [
+ {
+ label: msg`Read emails`,
+ scopes: ['https://www.googleapis.com/auth/gmail.readonly'],
+ },
+ {
+ label: msg`Send emails`,
+ scopes: [
+ 'https://www.googleapis.com/auth/gmail.send',
+ 'https://www.googleapis.com/auth/gmail.compose',
+ ],
+ },
+ ],
+ },
+ {
+ id: 'google-calendar',
+ name: msg`Google Calendar`,
+ Icon: IconGoogleCalendar,
+ provider: ConnectedAccountProvider.GOOGLE,
+ hasEmails: false,
+ hasCalendar: true,
+ permissions: [
+ {
+ label: msg`Manage events`,
+ scopes: ['https://www.googleapis.com/auth/calendar.events'],
+ },
+ ],
+ },
+ {
+ id: 'outlook',
+ name: msg`Outlook`,
+ Icon: IconMicrosoftOutlook,
+ provider: ConnectedAccountProvider.MICROSOFT,
+ hasEmails: true,
+ hasCalendar: true,
+ permissions: [
+ { label: msg`Read emails`, scopes: ['Mail.ReadWrite'] },
+ { label: msg`Send emails`, scopes: ['Mail.Send'] },
+ { label: msg`Manage events`, scopes: ['Calendars.ReadWrite'] },
+ ],
+ },
+ {
+ id: 'imap',
+ name: msg`IMAP`,
+ Icon: IconAt,
+ provider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
+ hasEmails: true,
+ hasCalendar: true,
+ permissions: [],
+ },
+];
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppAccountGroupTableGridTemplateColumns.ts b/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppAccountGroupTableGridTemplateColumns.ts
new file mode 100644
index 00000000000..84c5a5e1c5c
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppAccountGroupTableGridTemplateColumns.ts
@@ -0,0 +1,3 @@
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const SETTINGS_NATIVE_ACCOUNT_APP_ACCOUNT_GROUP_TABLE_GRID_TEMPLATE_COLUMNS = `200px minmax(0, 1fr) ${themeCssVariables.spacing[8]}`;
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppTabListComponentId.ts b/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppTabListComponentId.ts
new file mode 100644
index 00000000000..2617c74ba47
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/constants/SettingsNativeAccountAppTabListComponentId.ts
@@ -0,0 +1,2 @@
+export const SETTINGS_NATIVE_ACCOUNT_APP_TAB_LIST_COMPONENT_ID =
+ 'settings-native-account-app-tab-list';
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/hooks/useEnabledNativeAccountApps.ts b/packages/twenty-front/src/modules/settings/app-preferences/hooks/useEnabledNativeAccountApps.ts
new file mode 100644
index 00000000000..c5a4a698bf7
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/hooks/useEnabledNativeAccountApps.ts
@@ -0,0 +1,39 @@
+import { isGoogleCalendarEnabledState } from '@/client-config/states/isGoogleCalendarEnabledState';
+import { isGoogleMessagingEnabledState } from '@/client-config/states/isGoogleMessagingEnabledState';
+import { isImapSmtpCaldavEnabledState } from '@/client-config/states/isImapSmtpCaldavEnabledState';
+import { isMicrosoftCalendarEnabledState } from '@/client-config/states/isMicrosoftCalendarEnabledState';
+import { isMicrosoftMessagingEnabledState } from '@/client-config/states/isMicrosoftMessagingEnabledState';
+import { NATIVE_ACCOUNT_APPS } from '@/settings/app-preferences/constants/NativeAccountApps';
+import { type NativeAccountApp } from '@/settings/app-preferences/types/NativeAccountApp';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+
+export const useEnabledNativeAccountApps = () => {
+ const isGoogleMessagingEnabled = useAtomStateValue(
+ isGoogleMessagingEnabledState,
+ );
+ const isGoogleCalendarEnabled = useAtomStateValue(
+ isGoogleCalendarEnabledState,
+ );
+ const isMicrosoftMessagingEnabled = useAtomStateValue(
+ isMicrosoftMessagingEnabledState,
+ );
+ const isMicrosoftCalendarEnabled = useAtomStateValue(
+ isMicrosoftCalendarEnabledState,
+ );
+ const isImapSmtpCaldavEnabled = useAtomStateValue(
+ isImapSmtpCaldavEnabledState,
+ );
+
+ const isAppEnabled: Record<NativeAccountApp['id'], boolean> = {
+ gmail: isGoogleMessagingEnabled,
+ 'google-calendar': isGoogleCalendarEnabled,
+ outlook: isMicrosoftMessagingEnabled || isMicrosoftCalendarEnabled,
+ imap: isImapSmtpCaldavEnabled,
+ };
+
+ return {
+ enabledNativeAccountApps: NATIVE_ACCOUNT_APPS.filter(
+ (app) => isAppEnabled[app.id],
+ ),
+ };
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountApp.ts b/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountApp.ts
new file mode 100644
index 00000000000..4695404ee4a
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountApp.ts
@@ -0,0 +1,14 @@
+import { type NativeAccountAppPermission } from '@/settings/app-preferences/types/NativeAccountAppPermission';
+import { type MessageDescriptor } from '@lingui/core';
+import { type ConnectedAccountProvider } from 'twenty-shared/types';
+import { type IconComponent } from 'twenty-ui/icon';
+
+export type NativeAccountApp = {
+ id: 'gmail' | 'google-calendar' | 'outlook' | 'imap';
+ name: MessageDescriptor;
+ Icon: IconComponent;
+ provider: ConnectedAccountProvider;
+ hasEmails: boolean;
+ hasCalendar: boolean;
+ permissions: NativeAccountAppPermission[];
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountAppPermission.ts b/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountAppPermission.ts
new file mode 100644
index 00000000000..548679c7575
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/types/NativeAccountAppPermission.ts
@@ -0,0 +1,6 @@
+import { type MessageDescriptor } from '@lingui/core';
+
+export type NativeAccountAppPermission = {
+ label: MessageDescriptor;
+ scopes: string[];
+};
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getNativeAccountAppsUsingAccount.test.ts b/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getNativeAccountAppsUsingAccount.test.ts
new file mode 100644
index 00000000000..16ef0a72624
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/utils/__tests__/getNativeAccountAppsUsingAccount.test.ts
@@ -0,0 +1,110 @@
+import { getNativeAccountAppsUsingAccount } from '@/settings/app-preferences/utils/getNativeAccountAppsUsingAccount';
+import {
+ CalendarChannelSyncStage,
+ ConnectedAccountProvider,
+ MessageChannelSyncStage,
+ MessageChannelType,
+} from 'twenty-shared/types';
+
+const mailbox = {
+ type: MessageChannelType.EMAIL,
+ syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_PENDING,
+};
+const calendar = {
+ syncStage: CalendarChannelSyncStage.CALENDAR_EVENT_LIST_FETCH_PENDING,
+};
+const mailboxWaitingForSetup = {
+ type: MessageChannelType.EMAIL,
+ syncStage: MessageChannelSyncStage.PENDING_CONFIGURATION,
+};
+const groupInbox = {
+ type: MessageChannelType.EMAIL_GROUP,
+ syncStage: MessageChannelSyncStage.MESSAGE_LIST_FETCH_PENDING,
+};
+
+const getAppIds = (
+ account: Parameters<typeof getNativeAccountAppsUsingAccount>[0],
+) => getNativeAccountAppsUsingAccount(account).map((app) => app.id);
+
+describe('getNativeAccountAppsUsingAccount', () => {
+ it('splits a Google account into Gmail and Google Calendar', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.GOOGLE,
+ messageChannels: [mailbox],
+ calendarChannels: [calendar],
+ }),
+ ).toEqual(['gmail', 'google-calendar']);
+ });
+
+ it('only lists the Google apps whose channel exists', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.GOOGLE,
+ messageChannels: [],
+ calendarChannels: [calendar],
+ }),
+ ).toEqual(['google-calendar']);
+ });
+
+ it('counts channels that still need setup', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.GOOGLE,
+ messageChannels: [mailboxWaitingForSetup],
+ calendarChannels: [],
+ }),
+ ).toEqual(['gmail']);
+ });
+
+ it('ignores message channels that are not mailboxes', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
+ messageChannels: [groupInbox],
+ calendarChannels: [],
+ }),
+ ).toEqual([]);
+ });
+
+ it('lists Outlook once for a Microsoft account with mail and calendar', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.MICROSOFT,
+ messageChannels: [mailbox],
+ calendarChannels: [calendar],
+ }),
+ ).toEqual(['outlook']);
+ });
+
+ it('lists Outlook for a Microsoft account with only mail', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.MICROSOFT,
+ messageChannels: [mailbox],
+ calendarChannels: [],
+ }),
+ ).toEqual(['outlook']);
+ });
+
+ it('lists IMAP once for an IMAP account with mail and calendar', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
+ messageChannels: [mailbox],
+ calendarChannels: [calendar],
+ }),
+ ).toEqual(['imap']);
+ });
+
+ it('lists nothing without an account or without channels', () => {
+ expect(
+ getAppIds({
+ provider: ConnectedAccountProvider.IMAP_SMTP_CALDAV,
+ messageChannels: [],
+ calendarChannels: [],
+ }),
+ ).toEqual([]);
+ expect(getAppIds(undefined)).toEqual([]);
+ });
+});
diff --git a/packages/twenty-front/src/modules/settings/app-preferences/utils/getNativeAccountAppsUsingAccount.ts b/packages/twenty-front/src/modules/settings/app-preferences/utils/getNativeAccountAppsUsingAccount.ts
new file mode 100644
index 00000000000..57b6c99f496
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/app-preferences/utils/getNativeAccountAppsUsingAccount.ts
@@ -0,0 +1,29 @@
+import { type CalendarChannel } from '@/accounts/types/CalendarChannel';
+import { type MessageChannel } from '@/accounts/types/MessageChannel';
+import { NATIVE_ACCOUNT_APPS } from '@/settings/app-preferences/constants/NativeAccountApps';
+import {
+ type ConnectedAccountProvider,
+ MessageChannelType,
+} from 'twenty-shared/types';
+
+export const getNativeAccountAppsUsingAccount = (
+ account:
+ | {
+ provider: ConnectedAccountProvider;
+ messageChannels: Pick<MessageChannel, 'type'>[];
+ calendarChannels: Pick<CalendarChannel, 'syncStage'>[];
+ }
+ | undefined,
+) => {
+ const hasMailbox =
+ account?.messageChannels.some(
+ (channel) => channel.type === MessageChannelType.EMAIL,
+ ) ?? false;
+ const hasCalendar = (account?.calendarChannels.length ?? 0) > 0;
+
+ return NATIVE_ACCOUNT_APPS.filter(
+ (app) =>
+ app.provider === account?.provider &&
+ ((app.hasEmails && hasMailbox) || (app.hasCalendar && hasCalendar)),
+ );
+};
diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsAccountDetail.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsAccountDetail.tsx
index efe324e3fe7..64ba693a60a 100644
--- a/packages/twenty-front/src/pages/settings/accounts/SettingsAccountDetail.tsx
+++ b/packages/twenty-front/src/pages/settings/accounts/SettingsAccountDetail.tsx
@@ -1,16 +1,13 @@
import { SettingsAccountsCalendarChannelDetails } from '@/settings/accounts/components/SettingsAccountsCalendarChannelDetails';
-import { SettingsAccountsMessageChannelDetails } from '@/settings/accounts/components/SettingsAccountsMessageChannelDetails';
import { SettingsConnectedAccountIcon } from '@/settings/accounts/components/SettingsConnectedAccountIcon';
import { SETTINGS_ACCOUNT_GROUP_TAB_LIST_COMPONENT_ID } from '@/settings/app-preferences/constants/SettingsAccountGroupTabListComponentId';
import { useMyAccountGroups } from '@/settings/app-preferences/hooks/useMyAccountGroups';
-import { settingsAccountsSelectedMessageChannelState } from '@/settings/accounts/states/settingsAccountsSelectedMessageChannelState';
import { getConnectedAccountSettingsChannels } from '@/settings/app-preferences/utils/getConnectedAccountSettingsChannels';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { SettingsSectionSkeletonLoader } from '@/settings/components/SettingsSectionSkeletonLoader';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
import { SettingsTabBar } from '@/settings/components/layout/SettingsTabBar';
import { useSettingsActiveTabId } from '@/settings/components/layout/useSettingsActiveTabId';
-import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { useLingui } from '@lingui/react/macro';
import { Navigate, useParams } from 'react-router-dom';
@@ -19,7 +16,7 @@ import { getSettingsPath, isDefined } from 'twenty-shared/utils';
import { IconCalendarEvent, IconMail } from 'twenty-ui/icon';
import { useTheme } from 'twenty-ui/theme';
import { FeatureFlagKey } from '~/generated-metadata/graphql';
-import { SettingsAccountsConfigurationSelectedMessageChannelEffect } from '~/pages/settings/accounts/SettingsAccountsConfigurationSelectedMessageChannelEffect';
+import { SettingsAppPreferencesSelectedMessageChannelDetails } from '~/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails';
export const SettingsAccountDetail = () => {
const { t } = useLingui();
@@ -29,9 +26,7 @@ export const SettingsAccountDetail = () => {
);
const { connectedAccountId } = useParams<{ connectedAccountId: string }>();
const { groups, loading } = useMyAccountGroups();
- const settingsAccountsSelectedMessageChannel = useAtomStateValue(
- settingsAccountsSelectedMessageChannelState,
- );
+ const tabListComponentInstanceId = `${SETTINGS_ACCOUNT_GROUP_TAB_LIST_COMPONENT_ID}-${connectedAccountId}`;
const nativeAccount = groups.find(
(group) => group.nativeAccount?.id === connectedAccountId,
@@ -49,7 +44,7 @@ export const SettingsAccountDetail = () => {
].filter(isDefined);
const activeTabId = useSettingsActiveTabId(
- SETTINGS_ACCOUNT_GROUP_TAB_LIST_COMPONENT_ID,
+ tabListComponentInstanceId,
tabs.map((tab) => tab.id),
);
@@ -64,18 +59,9 @@ export const SettingsAccountDetail = () => {
const renderContent = () => {
if (activeTabId === 'emails' && isDefined(messageChannel)) {
return (
- <>
- <SettingsAccountsConfigurationSelectedMessageChannelEffect
- messageChannel={messageChannel}
- />
- {settingsAccountsSelectedMessageChannel?.id === messageChannel.id ? (
- <SettingsAccountsMessageChannelDetails
- messageChannel={messageChannel}
- />
- ) : (
- <SettingsSectionSkeletonLoader />
- )}
- </>
+ <SettingsAppPreferencesSelectedMessageChannelDetails
+ messageChannel={messageChannel}
+ />
);
}
@@ -114,7 +100,7 @@ export const SettingsAccountDetail = () => {
<SettingsTabBar
aria-label={t`Account settings`}
tabs={tabs}
- componentInstanceId={SETTINGS_ACCOUNT_GROUP_TAB_LIST_COMPONENT_ID}
+ componentInstanceId={tabListComponentInstanceId}
/>
) : undefined
}
diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsAccounts.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsAccounts.tsx
index 3ddaf685304..e2244a5a3f5 100644
--- a/packages/twenty-front/src/pages/settings/accounts/SettingsAccounts.tsx
+++ b/packages/twenty-front/src/pages/settings/accounts/SettingsAccounts.tsx
@@ -1,6 +1,5 @@
-import { SettingsAccountGroupsSection } from '@/settings/app-preferences/components/SettingsAccountGroupsSection';
-import { SettingsAccountsBlocklistSection } from '@/settings/accounts/components/SettingsAccountsBlocklistSection';
import { SettingsAccountsLegacySections } from '@/settings/accounts/components/SettingsAccountsLegacySections';
+import { SettingsAppPreferencesSections } from '@/settings/app-preferences/components/SettingsAppPreferencesSections';
import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
@@ -30,10 +29,7 @@ export const SettingsAccounts = () => {
>
<SettingsPageContainer>
{isAppPreferencesEnabled ? (
- <>
- <SettingsAccountGroupsSection />
- <SettingsAccountsBlocklistSection />
- </>
+ <SettingsAppPreferencesSections />
) : (
<SettingsAccountsLegacySections />
)}
diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails.tsx
new file mode 100644
index 00000000000..0c1e952518e
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails.tsx
@@ -0,0 +1,33 @@
+import { type MessageChannel } from '@/accounts/types/MessageChannel';
+import { SettingsAppPreferencesMessageChannelDetails } from '@/settings/app-preferences/components/SettingsAppPreferencesMessageChannelDetails';
+import { settingsAccountsSelectedMessageChannelState } from '@/settings/accounts/states/settingsAccountsSelectedMessageChannelState';
+import { SettingsSectionSkeletonLoader } from '@/settings/components/SettingsSectionSkeletonLoader';
+import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { SettingsAccountsConfigurationSelectedMessageChannelEffect } from '~/pages/settings/accounts/SettingsAccountsConfigurationSelectedMessageChannelEffect';
+
+type SettingsAppPreferencesSelectedMessageChannelDetailsProps = {
+ messageChannel: MessageChannel;
+};
+
+export const SettingsAppPreferencesSelectedMessageChannelDetails = ({
+ messageChannel,
+}: SettingsAppPreferencesSelectedMessageChannelDetailsProps) => {
+ const settingsAccountsSelectedMessageChannel = useAtomStateValue(
+ settingsAccountsSelectedMessageChannelState,
+ );
+
+ return (
+ <>
+ <SettingsAccountsConfigurationSelectedMessageChannelEffect
+ messageChannel={messageChannel}
+ />
+ {settingsAccountsSelectedMessageChannel?.id === messageChannel.id ? (
+ <SettingsAppPreferencesMessageChannelDetails
+ messageChannel={messageChannel}
+ />
+ ) : (
+ <SettingsSectionSkeletonLoader />
+ )}
+ </>
+ );
+};
diff --git a/packages/twenty-front/src/pages/settings/accounts/SettingsNativeAccountApp.tsx b/packages/twenty-front/src/pages/settings/accounts/SettingsNativeAccountApp.tsx
new file mode 100644
index 00000000000..d88d20e3c57
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/accounts/SettingsNativeAccountApp.tsx
@@ -0,0 +1,176 @@
+import { type ConnectedAccount } from '@/accounts/types/ConnectedAccount';
+import { SettingsAccountGroupsSection } from '@/settings/app-preferences/components/SettingsAccountGroupsSection';
+import { SettingsAccountsBlocklistSection } from '@/settings/accounts/components/SettingsAccountsBlocklistSection';
+import { SettingsAccountsCalendarChannelDetails } from '@/settings/accounts/components/SettingsAccountsCalendarChannelDetails';
+import { SettingsAppPreferencesSelectedMessageChannelDetails } from '~/pages/settings/accounts/SettingsAppPreferencesSelectedMessageChannelDetails';
+import { SettingsConnectedAccountIcon } from '@/settings/accounts/components/SettingsConnectedAccountIcon';
+import { SETTINGS_NATIVE_ACCOUNT_APP_TAB_LIST_COMPONENT_ID } from '@/settings/app-preferences/constants/SettingsNativeAccountAppTabListComponentId';
+import { useEnabledNativeAccountApps } from '@/settings/app-preferences/hooks/useEnabledNativeAccountApps';
+import { useMyAccountGroups } from '@/settings/app-preferences/hooks/useMyAccountGroups';
+import { getConnectedAccountSettingsChannels } from '@/settings/app-preferences/utils/getConnectedAccountSettingsChannels';
+import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer';
+import { SettingsSectionSkeletonLoader } from '@/settings/components/SettingsSectionSkeletonLoader';
+import { SettingsPageLayout } from '@/settings/components/layout/SettingsPageLayout';
+import { SettingsTabBar } from '@/settings/components/layout/SettingsTabBar';
+import { useSettingsActiveTabId } from '@/settings/components/layout/useSettingsActiveTabId';
+import { Select } from '@/ui/input/components/Select';
+import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
+import { useLingui } from '@lingui/react/macro';
+import { useState } from 'react';
+import { Navigate, useParams } from 'react-router-dom';
+import { SettingsPath } from 'twenty-shared/types';
+import { getSettingsPath, isDefined } from 'twenty-shared/utils';
+import { IconCalendarEvent, IconMail, IconSettings } from 'twenty-ui/icon';
+import { useTheme } from 'twenty-ui/theme';
+import { FeatureFlagKey } from '~/generated-metadata/graphql';
+
+export const SettingsNativeAccountApp = () => {
+ const { t } = useLingui();
+ const theme = useTheme();
+ const isAppPreferencesEnabled = useIsFeatureEnabled(
+ FeatureFlagKey.IS_APP_PREFERENCES_ENABLED,
+ );
+ const { nativeAccountAppId } = useParams<{ nativeAccountAppId: string }>();
+ const { enabledNativeAccountApps } = useEnabledNativeAccountApps();
+ const app = enabledNativeAccountApps.find(
+ (enabledApp) => enabledApp.id === nativeAccountAppId,
+ );
+ const { groups, loading } = useMyAccountGroups();
+ const [selectedAccountId, setSelectedAccountId] = useState<string>();
+
+ const isInitialLoading = loading && groups.length === 0;
+ const tabListComponentInstanceId = `${SETTINGS_NATIVE_ACCOUNT_APP_TAB_LIST_COMPONENT_ID}-${nativeAccountAppId}`;
+
+ const providerAccounts = groups
+ .map((group) => group.nativeAccount)
+ .filter(isDefined)
+ .filter((account) => account.provider === app?.provider);
+ const emailAccounts = app?.hasEmails
+ ? providerAccounts.filter((account) =>
+ isDefined(getConnectedAccountSettingsChannels(account).messageChannel),
+ )
+ : [];
+ const calendarAccounts = app?.hasCalendar
+ ? providerAccounts.filter((account) =>
+ isDefined(getConnectedAccountSettingsChannels(account).calendarChannel),
+ )
+ : [];
+
+ const tabs = [
+ { id: 'general', title: t`General`, Icon: IconSettings },
+ emailAccounts.length > 0
+ ? { id: 'emails', title: t`Emails`, Icon: IconMail }
+ : undefined,
+ calendarAccounts.length > 0
+ ? { id: 'calendar', title: t`Calendar`, Icon: IconCalendarEvent }
+ : undefined,
+ ].filter(isDefined);
+
+ const activeTabId = useSettingsActiveTabId(
+ tabListComponentInstanceId,
+ tabs.map((tab) => tab.id),
+ );
+
+ if (!isAppPreferencesEnabled || !isDefined(app)) {
+ return <Navigate to={getSettingsPath(SettingsPath.Accounts)} replace />;
+ }
+
+ const appName = t(app.name);
+
+ const getSelectedAccount = (accounts: ConnectedAccount[]) =>
+ accounts.find((account) => account.id === selectedAccountId) ?? accounts[0];
+
+ const renderAccountSelect = (
+ accounts: ConnectedAccount[],
+ selectedAccount: ConnectedAccount,
+ ) => (
+ <Select
+ dropdownId="settings-native-account-app-account"
+ label={t`Account`}
+ fullWidth
+ value={selectedAccount.id}
+ options={accounts.map((account) => ({
+ value: account.id,
+ label: account.handle,
+ Icon: SettingsConnectedAccountIcon({ account }),
+ }))}
+ onChange={setSelectedAccountId}
+ />
+ );
+
+ const renderContent = () => {
+ if (isInitialLoading) {
+ return <SettingsSectionSkeletonLoader />;
+ }
+
+ if (activeTabId === 'emails') {
+ const selectedAccount = getSelectedAccount(emailAccounts);
+ const { messageChannel } =
+ getConnectedAccountSettingsChannels(selectedAccount);
+
+ return (
+ <>
+ {renderAccountSelect(emailAccounts, selectedAccount)}
+ {isDefined(messageChannel) && (
+ <SettingsAppPreferencesSelectedMessageChannelDetails
+ messageChannel={messageChannel}
+ />
+ )}
+ </>
+ );
+ }
+
+ if (activeTabId === 'calendar') {
+ const selectedAccount = getSelectedAccount(calendarAccounts);
+ const { calendarChannel } =
+ getConnectedAccountSettingsChannels(selectedAccount);
+
+ return (
+ <>
+ {renderAccountSelect(calendarAccounts, selectedAccount)}
+ {isDefined(calendarChannel) && (
+ <SettingsAccountsCalendarChannelDetails
+ calendarChannel={calendarChannel}
+ />
+ )}
+ </>
+ );
+ }
+
+ return (
+ <>
+ <SettingsAccountGroupsSection nativeAccountApp={app} />
+ <SettingsAccountsBlocklistSection />
+ </>
+ );
+ };
+
+ return (
+ <SettingsPageLayout
+ title={appName}
+ icon={<app.Icon size={theme.icon.size.md} />}
+ links={[
+ {
+ children: t`User`,
+ href: getSettingsPath(SettingsPath.ProfilePage),
+ },
+ {
+ children: t`App preferences`,
+ href: getSettingsPath(SettingsPath.Accounts),
+ },
+ { children: appName },
+ ]}
+ secondaryBar={
+ isInitialLoading ? undefined : (
+ <SettingsTabBar
+ aria-label={t`${appName} preferences`}
+ tabs={tabs}
+ componentInstanceId={tabListComponentInstanceId}
+ />
+ )
+ }
+ >
+ <SettingsPageContainer>{renderContent()}</SettingsPageContainer>
+ </SettingsPageLayout>
+ );
+};
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.tsx
index 6190c9a8225..163d3d1a65b 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
@@ -1,4 +1,5 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { HttpResponse, graphql } from 'msw';
import { expect, userEvent, waitFor, within } from 'storybook/test';
import { isDefined } from 'twenty-shared/utils';
@@ -8,10 +9,17 @@ import {
} from '~/testing/decorators/PageDecorator';
import { graphqlMocks } from '~/testing/graphqlMocks';
+import { isGoogleCalendarEnabledState } from '@/client-config/states/isGoogleCalendarEnabledState';
+import { isGoogleMessagingEnabledState } from '@/client-config/states/isGoogleMessagingEnabledState';
+import { isMicrosoftCalendarEnabledState } from '@/client-config/states/isMicrosoftCalendarEnabledState';
+import { isMicrosoftMessagingEnabledState } from '@/client-config/states/isMicrosoftMessagingEnabledState';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { SettingsAccounts } from '~/pages/settings/accounts/SettingsAccounts';
import {
ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
+ CONNECTED_ACCOUNTS,
GOOGLE_ACCOUNT_ID,
+ MICROSOFT_ACCOUNT_ID,
deleteConnectedAccount,
seedAccountGroupsStory,
} from '~/pages/settings/accounts/__stories__/mockedAccountGroups';
@@ -33,13 +41,13 @@ export default meta;
export type Story = StoryObj<typeof SettingsAccounts>;
-const getAccountRow = (canvasElement: HTMLElement, handle: string) => {
+const getTableRow = (canvasElement: HTMLElement, text: string) => {
const row = within(canvasElement)
- .getByText(handle)
+ .getByText(text)
.closest<HTMLElement>('[data-table-row]');
if (!isDefined(row)) {
- throw new Error(`No account row for ${handle}`);
+ throw new Error(`No table row for ${text}`);
}
return within(row);
@@ -77,7 +85,7 @@ export const AccountsGroupedByEmail: Story = {
expect(canvas.getAllByText('App preferences').length).toBeGreaterThan(0);
expect(canvas.queryByText('Connected accounts')).not.toBeInTheDocument();
- const timRow = getAccountRow(canvasElement, '[email protected]');
+ const timRow = getTableRow(canvasElement, '[email protected]');
expect(timRow.getByRole('img', { name: 'Gmail' })).toBeVisible();
expect(timRow.getByRole('img', { name: 'Google Calendar' })).toBeVisible();
@@ -91,11 +99,11 @@ export const AccountsGroupedByEmail: Story = {
);
expect(canvas.queryByText('[email protected]')).not.toBeInTheDocument();
- const outlookRow = getAccountRow(canvasElement, '[email protected]');
+ const outlookRow = getTableRow(canvasElement, '[email protected]');
expect(outlookRow.getAllByRole('img', { name: 'Outlook' })).toHaveLength(1);
- const notesRow = getAccountRow(canvasElement, '[email protected]');
+ const notesRow = getTableRow(canvasElement, '[email protected]');
expect(notesRow.getByRole('img', { name: 'Fathom' })).toBeVisible();
expect(
@@ -113,6 +121,35 @@ export const AccountsGroupedByEmail: Story = {
},
};
+export const AppPreferencesListEnabledApps: Story = {
+ ...accountGroupsStory,
+ args: {
+ additionalRoutes: ['/settings/accounts/apps/outlook'],
+ },
+ 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('[email protected]');
+
+ expect(canvas.getByRole('link', { name: 'Gmail' })).toBeVisible();
+ expect(canvas.getByRole('link', { name: 'Google Calendar' })).toBeVisible();
+ expect(canvas.queryByText('IMAP')).not.toBeInTheDocument();
+ expect(canvas.queryByText('Missing account')).not.toBeInTheDocument();
+ expect(canvas.queryByText('Blocklist')).not.toBeInTheDocument();
+
+ await userEvent.click(canvas.getByRole('link', { name: 'Outlook' }));
+
+ expect(
+ await canvas.findByText('Navigated to /settings/accounts/apps/outlook'),
+ ).toBeVisible();
+ },
+};
+
export const RowOpensAccountPage: Story = {
...accountGroupsStory,
play: async ({ canvasElement }) => {
@@ -120,7 +157,7 @@ export const RowOpensAccountPage: Story = {
await canvas.findByText('Used by', undefined, { timeout: 3000 });
await userEvent.click(
- getAccountRow(canvasElement, '[email protected]').getByRole('img', {
+ getTableRow(canvasElement, '[email protected]').getByRole('img', {
name: 'Gmail',
}),
);
@@ -143,7 +180,7 @@ export const DeleteKeepsAppConnections: Story = {
const openDeleteDialog = async () => {
await userEvent.click(
- getAccountRow(canvasElement, '[email protected]').getByRole('button', {
+ getTableRow(canvasElement, '[email protected]').getByRole('button', {
name: 'More options',
}),
);
@@ -164,7 +201,7 @@ export const DeleteKeepsAppConnections: Story = {
);
const remainingRow = await waitFor(() =>
- getAccountRow(canvasElement, '[email protected]'),
+ getTableRow(canvasElement, '[email protected]'),
);
expect(remainingRow.getByRole('img', { name: 'Fathom' })).toBeVisible();
@@ -176,3 +213,69 @@ export const DeleteKeepsAppConnections: Story = {
expect(canvas.queryByText(/Navigated to/)).not.toBeInTheDocument();
},
};
+
+export const AppsWithoutAccountShowMissingAccount: Story = {
+ ...accountGroupsStory,
+ parameters: {
+ msw: {
+ handlers: [
+ graphql.query('MyConnectedAccounts', () =>
+ HttpResponse.json({
+ data: {
+ myConnectedAccounts: CONNECTED_ACCOUNTS.filter(
+ (account) =>
+ account.id !== GOOGLE_ACCOUNT_ID &&
+ account.id !== MICROSOFT_ACCOUNT_ID,
+ ),
+ },
+ }),
+ ),
+ ...ACCOUNT_GROUPS_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 },
+ );
+
+ expect(
+ await getTableRow(canvasElement, 'Outlook').findByText('Missing account'),
+ ).toBeVisible();
+ expect(
+ getTableRow(canvasElement, 'Google Calendar').getByText(
+ 'Missing account',
+ ),
+ ).toBeVisible();
+ expect(
+ getTableRow(canvasElement, 'Gmail').queryByText('Missing account'),
+ ).not.toBeInTheDocument();
+ },
+};
+
+export const BlocklistStaysWhenNoAppIsEnabled: Story = {
+ ...accountGroupsStory,
+ beforeEach: async () => {
+ await seedAccountGroupsStory();
+ jotaiStore.set(isGoogleMessagingEnabledState.atom, false);
+ jotaiStore.set(isGoogleCalendarEnabledState.atom, false);
+ jotaiStore.set(isMicrosoftMessagingEnabledState.atom, false);
+ jotaiStore.set(isMicrosoftCalendarEnabledState.atom, false);
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByText('Blocklist', undefined, { timeout: 3000 }),
+ ).toBeVisible();
+ expect(
+ canvas.queryByText(
+ 'Choose your preferences for the apps installed on your workspace by the admin',
+ ),
+ ).not.toBeInTheDocument();
+ },
+};
diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsNativeAccountApp.stories.tsx b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsNativeAccountApp.stories.tsx
new file mode 100644
index 00000000000..0abd2b0e635
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/SettingsNativeAccountApp.stories.tsx
@@ -0,0 +1,157 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { HttpResponse, graphql } from 'msw';
+import { expect, userEvent, within } from 'storybook/test';
+
+import {
+ PageDecorator,
+ type PageDecoratorArgs,
+} from '~/testing/decorators/PageDecorator';
+
+import { SettingsNativeAccountApp } from '~/pages/settings/accounts/SettingsNativeAccountApp';
+import {
+ ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
+ CONNECTED_ACCOUNTS,
+ MICROSOFT_ACCOUNT_ID,
+ seedAccountGroupsStory,
+} from '~/pages/settings/accounts/__stories__/mockedAccountGroups';
+
+const meta: Meta<PageDecoratorArgs> = {
+ title: 'Pages/Settings/Accounts/SettingsNativeAccountApp',
+ component: SettingsNativeAccountApp,
+ decorators: [PageDecorator],
+ args: {
+ routePath: '/settings/accounts/apps/:nativeAccountAppId',
+ routeParams: { ':nativeAccountAppId': 'gmail' },
+ additionalRoutes: ['/settings/accounts'],
+ },
+ beforeEach: seedAccountGroupsStory,
+ parameters: {
+ layout: 'fullscreen',
+ msw: { handlers: ACCOUNT_GROUPS_GRAPHQL_HANDLERS },
+ },
+};
+
+export default meta;
+
+export type Story = StoryObj<typeof SettingsNativeAccountApp>;
+
+export const GmailGeneralShowsAccountsAndBlocklist: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ await canvas.findByTestId('tab-general', undefined, { timeout: 3000 }),
+ );
+
+ expect(await canvas.findByText('Blocklist')).toBeVisible();
+ expect(await canvas.findByText('[email protected]')).toBeVisible();
+ expect(canvas.getByText('[email protected]')).toBeVisible();
+ expect(canvas.queryByText('[email protected]')).not.toBeInTheDocument();
+ expect(canvas.queryByText('Used by')).not.toBeInTheDocument();
+ expect(canvas.getByText('Permissions')).toBeVisible();
+ expect(canvas.getByText('Read emails, Send emails')).toBeVisible();
+ expect(canvas.getByText('Read emails')).toBeVisible();
+ expect(
+ canvas.queryByRole('img', { name: 'Google Calendar' }),
+ ).not.toBeInTheDocument();
+ expect(canvas.getByTestId('tab-emails')).toBeVisible();
+ expect(canvas.queryByTestId('tab-calendar')).not.toBeInTheDocument();
+ },
+};
+
+export const GmailEmailsTabSwitchesAccount: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(
+ await canvas.findByTestId('tab-emails', undefined, { timeout: 3000 }),
+ );
+
+ expect(
+ await canvas.findByRole('radio', { name: 'Metadata' }),
+ ).not.toBeChecked();
+
+ await userEvent.click(canvas.getByText('[email protected]'));
+ await userEvent.click(await body.findByText('[email protected]'));
+
+ expect(await canvas.findByText('[email protected]')).toBeVisible();
+ expect(
+ await canvas.findByRole('radio', { name: 'Metadata' }),
+ ).toBeChecked();
+ },
+};
+
+export const OutlookHasEmailsAndCalendarTabs: Story = {
+ args: {
+ routeParams: { ':nativeAccountAppId': 'outlook' },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ await canvas.findByTestId('tab-general', undefined, { timeout: 3000 }),
+ );
+
+ expect(
+ await canvas.findByText('Read emails, Send emails, Manage events'),
+ ).toBeVisible();
+
+ await userEvent.click(canvas.getByTestId('tab-emails'));
+
+ expect(await canvas.findByText('Visibility')).toBeVisible();
+
+ await userEvent.click(canvas.getByTestId('tab-calendar'));
+
+ expect(await canvas.findByText('Event visibility')).toBeVisible();
+ expect(canvas.getByText('[email protected]')).toBeVisible();
+ },
+};
+
+export const DisabledAppGoesBackToAccounts: Story = {
+ args: {
+ routeParams: { ':nativeAccountAppId': 'imap' },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByText('Navigated to /settings/accounts', undefined, {
+ timeout: 3000,
+ }),
+ ).toBeVisible();
+ },
+};
+
+export const OutlookWithoutAccountOffersMicrosoftOnly: Story = {
+ args: {
+ routeParams: { ':nativeAccountAppId': 'outlook' },
+ },
+ parameters: {
+ msw: {
+ handlers: [
+ graphql.query('MyConnectedAccounts', () =>
+ HttpResponse.json({
+ data: {
+ myConnectedAccounts: CONNECTED_ACCOUNTS.filter(
+ (account) => account.id !== MICROSOFT_ACCOUNT_ID,
+ ),
+ },
+ }),
+ ),
+ ...ACCOUNT_GROUPS_GRAPHQL_HANDLERS,
+ ],
+ },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(
+ await canvas.findByText('Connect with Microsoft', undefined, {
+ timeout: 3000,
+ }),
+ ).toBeVisible();
+ expect(canvas.queryByText('Connect with Google')).not.toBeInTheDocument();
+ expect(canvas.getByText('Blocklist')).toBeVisible();
+ },
+};
diff --git a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
index 45fdc67223f..163b21133de 100644
--- a/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
+++ b/packages/twenty-front/src/pages/settings/accounts/__stories__/mockedAccountGroups.ts
@@ -4,6 +4,11 @@ import { fn } from 'storybook/test';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { getEmptyPageInfo } from '@/object-record/cache/utils/getEmptyPageInfo';
+import { isGoogleCalendarEnabledState } from '@/client-config/states/isGoogleCalendarEnabledState';
+import { isGoogleMessagingEnabledState } from '@/client-config/states/isGoogleMessagingEnabledState';
+import { isImapSmtpCaldavEnabledState } from '@/client-config/states/isImapSmtpCaldavEnabledState';
+import { isMicrosoftCalendarEnabledState } from '@/client-config/states/isMicrosoftCalendarEnabledState';
+import { isMicrosoftMessagingEnabledState } from '@/client-config/states/isMicrosoftMessagingEnabledState';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
import { FeatureFlagKey } from '~/generated-metadata/graphql';
import { graphqlMocks } from '~/testing/graphqlMocks';
@@ -20,12 +25,13 @@ const GRANOLA_APPLICATION_ID = '20202020-1a2b-4c3d-8e4f-000000000022';
const CREATED_AT = '2026-09-01T00:00:00.000Z';
export const GOOGLE_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000011';
+export const MICROSOFT_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000014';
export const FATHOM_ONLY_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000013';
const FATHOM_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000012';
-const MICROSOFT_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000014';
const MY_SHARED_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000015';
const TEAMMATE_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000016';
const EMAIL_GROUP_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000017';
+const SECOND_GOOGLE_ACCOUNT_ID = '20202020-1a2b-4c3d-8e4f-000000000018';
const buildConnectedAccount = (account: {
id: string;
@@ -34,6 +40,7 @@ const buildConnectedAccount = (account: {
userWorkspaceId: string;
applicationId?: string;
visibility?: string;
+ scopes?: string[];
}) => ({
__typename: 'ConnectedAccountPublicDTO',
authFailedAt: null,
@@ -53,12 +60,16 @@ const buildConnectedAccount = (account: {
...account,
});
-const buildMessageChannel = (id: string, connectedAccountId: string) => ({
+const buildMessageChannel = (
+ id: string,
+ connectedAccountId: string,
+ visibility = 'SHARE_EVERYTHING',
+) => ({
__typename: 'MessageChannel',
id,
handle: 'mailbox',
displayName: null,
- visibility: 'SHARE_EVERYTHING',
+ visibility,
type: 'EMAIL',
isContactAutoCreationEnabled: true,
contactAutoCreationPolicy: 'SENT',
@@ -95,12 +106,20 @@ const buildCalendarChannel = (id: string, connectedAccountId: string) => ({
updatedAt: CREATED_AT,
});
-const CONNECTED_ACCOUNTS = [
+export const CONNECTED_ACCOUNTS = [
buildConnectedAccount({
id: GOOGLE_ACCOUNT_ID,
handle: '[email protected]',
provider: 'google',
userWorkspaceId: MY_USER_WORKSPACE_ID,
+ scopes: [
+ 'email',
+ 'profile',
+ 'https://www.googleapis.com/auth/calendar.events',
+ 'https://www.googleapis.com/auth/gmail.compose',
+ 'https://www.googleapis.com/auth/gmail.readonly',
+ 'https://www.googleapis.com/auth/gmail.send',
+ ],
}),
buildConnectedAccount({
id: FATHOM_ACCOUNT_ID,
@@ -121,6 +140,14 @@ const CONNECTED_ACCOUNTS = [
handle: '[email protected]',
provider: 'microsoft',
userWorkspaceId: MY_USER_WORKSPACE_ID,
+ scopes: [
+ 'openid',
+ 'email',
+ 'Mail.ReadWrite',
+ 'Mail.Send',
+ 'Calendars.ReadWrite',
+ 'User.Read',
+ ],
}),
buildConnectedAccount({
id: MY_SHARED_ACCOUNT_ID,
@@ -138,6 +165,13 @@ const CONNECTED_ACCOUNTS = [
applicationId: GRANOLA_APPLICATION_ID,
visibility: 'workspace',
}),
+ buildConnectedAccount({
+ id: SECOND_GOOGLE_ACCOUNT_ID,
+ handle: '[email protected]',
+ provider: 'google',
+ userWorkspaceId: MY_USER_WORKSPACE_ID,
+ scopes: ['email', 'https://www.googleapis.com/auth/gmail.readonly'],
+ }),
buildConnectedAccount({
id: EMAIL_GROUP_ACCOUNT_ID,
handle: '[email protected]',
@@ -160,6 +194,11 @@ const MESSAGE_CHANNELS = [
'20202020-1a2b-4c3d-8e4f-000000000033',
MICROSOFT_ACCOUNT_ID,
),
+ buildMessageChannel(
+ '20202020-1a2b-4c3d-8e4f-000000000034',
+ SECOND_GOOGLE_ACCOUNT_ID,
+ 'METADATA',
+ ),
];
const CALENDAR_CHANNELS = [
@@ -238,10 +277,11 @@ export const seedAccountGroupsStory = async () => {
deleteConnectedAccount.mockClear();
await mockedApolloClient.clearStore();
- const previousWorkspace = jotaiStore.get(currentWorkspaceState.atom);
- const previousWorkspaceMember = jotaiStore.get(
- currentWorkspaceMemberState.atom,
- );
+ jotaiStore.set(isGoogleMessagingEnabledState.atom, true);
+ jotaiStore.set(isGoogleCalendarEnabledState.atom, true);
+ jotaiStore.set(isMicrosoftMessagingEnabledState.atom, true);
+ jotaiStore.set(isMicrosoftCalendarEnabledState.atom, true);
+ jotaiStore.set(isImapSmtpCaldavEnabledState.atom, false);
jotaiStore.set(currentWorkspaceState.atom, {
...mockCurrentWorkspace,
@@ -270,9 +310,4 @@ export const seedAccountGroupsStory = async () => {
...mockedWorkspaceMemberData,
userWorkspaceId: MY_USER_WORKSPACE_ID,
});
-
- return () => {
- jotaiStore.set(currentWorkspaceState.atom, previousWorkspace);
- jotaiStore.set(currentWorkspaceMemberState.atom, previousWorkspaceMember);
- };
};
diff --git a/packages/twenty-shared/src/types/SettingsPath.ts b/packages/twenty-shared/src/types/SettingsPath.ts
index b11f41f4663..dcb1614a9a5 100644
--- a/packages/twenty-shared/src/types/SettingsPath.ts
+++ b/packages/twenty-shared/src/types/SettingsPath.ts
@@ -4,6 +4,7 @@ export enum SettingsPath {
Experience = 'experience',
Accounts = 'accounts',
AccountDetail = 'accounts/detail/:connectedAccountId',
+ NativeAccountApp = 'accounts/apps/:nativeAccountAppId',
NewAccount = 'accounts/new',
AccountsConfiguration = 'accounts/configuration/:connectedAccountId',
AccountsCalendars = 'accounts/calendars',