fix(twenty-front): allow to connect available provider only (#9080)

Fix #8710

## Summary
The Pull Request updates components related to the settings account
management feature. The changes ensure the behavior of buttons and the
UI dynamically adapts based on the availability of authentication
providers retrieved from the current workspace state.

- Added checks for Google and Microsoft authentication enablement and
used these conditions to display buttons dynamically in both components.
- Updated `SettingsAccountsConnectedAccountsListCard` to dynamically
enable the footer button based on workspace authentication settings.
- Revised `SettingsAccountsListEmptyStateCard` to conditionally render
account connection buttons depending on the availability of enabled
authentication providers in the current workspace state.
This commit is contained in:
Antoine Moreaux
2024-12-16 18:44:30 +01:00
committed by GitHub
parent 311b5f64c4
commit 33b028658e
2 changed files with 22 additions and 8 deletions

View File

@ -8,6 +8,9 @@ import { SettingsPath } from '@/types/SettingsPath';
import { SettingsAccountsConnectedAccountsRowRightContainer } from '@/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer'; import { SettingsAccountsConnectedAccountsRowRightContainer } from '@/settings/accounts/components/SettingsAccountsConnectedAccountsRowRightContainer';
import { SettingsListCard } from '../../components/SettingsListCard'; import { SettingsListCard } from '../../components/SettingsListCard';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useRecoilValue } from 'recoil';
import { isDefined } from '~/utils/isDefined';
const ProviderIcons: { [k: string]: IconComponent } = { const ProviderIcons: { [k: string]: IconComponent } = {
google: IconGoogle, google: IconGoogle,
@ -22,11 +25,17 @@ export const SettingsAccountsConnectedAccountsListCard = ({
loading?: boolean; loading?: boolean;
}) => { }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const currentWorkspace = useRecoilValue(currentWorkspaceState);
if (!accounts.length) { if (!accounts.length) {
return <SettingsAccountsListEmptyStateCard />; return <SettingsAccountsListEmptyStateCard />;
} }
const atLeastOneProviderAvailable =
isDefined(currentWorkspace) &&
(currentWorkspace?.isGoogleAuthEnabled ||
currentWorkspace?.isMicrosoftAuthEnabled);
return ( return (
<SettingsListCard <SettingsListCard
items={accounts} items={accounts}
@ -36,7 +45,7 @@ export const SettingsAccountsConnectedAccountsListCard = ({
RowRightComponent={({ item: account }) => ( RowRightComponent={({ item: account }) => (
<SettingsAccountsConnectedAccountsRowRightContainer account={account} /> <SettingsAccountsConnectedAccountsRowRightContainer account={account} />
)} )}
hasFooter hasFooter={atLeastOneProviderAvailable}
footerButtonLabel="Add account" footerButtonLabel="Add account"
onFooterButtonClick={() => onFooterButtonClick={() =>
navigate(getSettingsPagePath(SettingsPath.NewAccount)) navigate(getSettingsPagePath(SettingsPath.NewAccount))

View File

@ -9,6 +9,8 @@ import {
IconGoogle, IconGoogle,
IconMicrosoft, IconMicrosoft,
} from 'twenty-ui'; } from 'twenty-ui';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useRecoilValue } from 'recoil';
const StyledHeader = styled(CardHeader)` const StyledHeader = styled(CardHeader)`
align-items: center; align-items: center;
@ -30,6 +32,7 @@ export const SettingsAccountsListEmptyStateCard = ({
label, label,
}: SettingsAccountsListEmptyStateCardProps) => { }: SettingsAccountsListEmptyStateCardProps) => {
const { triggerApisOAuth } = useTriggerApisOAuth(); const { triggerApisOAuth } = useTriggerApisOAuth();
const currentWorkspace = useRecoilValue(currentWorkspaceState);
const isMicrosoftSyncEnabled = useIsFeatureEnabled( const isMicrosoftSyncEnabled = useIsFeatureEnabled(
'IS_MICROSOFT_SYNC_ENABLED', 'IS_MICROSOFT_SYNC_ENABLED',
); );
@ -38,13 +41,15 @@ export const SettingsAccountsListEmptyStateCard = ({
<Card> <Card>
<StyledHeader>{label || 'No connected account'}</StyledHeader> <StyledHeader>{label || 'No connected account'}</StyledHeader>
<StyledBody> <StyledBody>
<Button {currentWorkspace?.isGoogleAuthEnabled && (
Icon={IconGoogle} <Button
title="Connect with Google" Icon={IconGoogle}
variant="secondary" title="Connect with Google"
onClick={() => triggerApisOAuth('google')} variant="secondary"
/> onClick={() => triggerApisOAuth('google')}
{isMicrosoftSyncEnabled && ( />
)}
{isMicrosoftSyncEnabled && currentWorkspace?.isMicrosoftAuthEnabled && (
<Button <Button
Icon={IconMicrosoft} Icon={IconMicrosoft}
title="Connect with Microsoft" title="Connect with Microsoft"