Skip to content

Commit

Permalink
Merge pull request #50386 from ZhenjaHorbach/fix-connectionsMenuItems…
Browse files Browse the repository at this point in the history
…-with-undefined-items

[CP Staging] Fix connectionsMenuItems with undefined items
  • Loading branch information
MonilBhavsar authored Oct 8, 2024
2 parents 8b27c8d + 8c2953f commit cd7459f
Showing 1 changed file with 71 additions and 58 deletions.
129 changes: 71 additions & 58 deletions src/pages/workspace/accounting/PolicyAccountingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import MenuItem from '@components/MenuItem';
import MenuItemList from '@components/MenuItemList';
import type {MenuItemWithLink} from '@components/MenuItemList';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
Expand Down Expand Up @@ -228,33 +229,39 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {

const connectionsMenuItems: MenuItemData[] = useMemo(() => {
if (isEmptyObject(policy?.connections) && !isSyncInProgress) {
return accountingIntegrations.map((integration) => {
const integrationData = getAccountingIntegrationData(integration, policyID, translate);
const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {};
return {
...iconProps,
interactive: false,
wrapperStyle: [styles.sectionMenuItemTopDescription],
shouldShowRightComponent: true,
title: integrationData?.title,
rightComponent: (
<Button
onPress={() => startIntegrationFlow({name: integration})}
text={translate('workspace.accounting.setup')}
style={styles.justifyContentCenter}
small
isDisabled={isOffline}
ref={(ref) => {
if (!popoverAnchorRefs?.current) {
return;
}
// eslint-disable-next-line react-compiler/react-compiler
popoverAnchorRefs.current[integration].current = ref;
}}
/>
),
};
});
return accountingIntegrations
.map((integration) => {
const integrationData = getAccountingIntegrationData(integration, policyID, translate);
if (!integrationData) {
return undefined;
}
const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {};

return {
...iconProps,
interactive: false,
wrapperStyle: [styles.sectionMenuItemTopDescription],
shouldShowRightComponent: true,
title: integrationData?.title,
rightComponent: (
<Button
onPress={() => startIntegrationFlow({name: integration})}
text={translate('workspace.accounting.setup')}
style={styles.justifyContentCenter}
small
isDisabled={isOffline}
ref={(ref) => {
if (!popoverAnchorRefs?.current) {
return;
}
// eslint-disable-next-line react-compiler/react-compiler
popoverAnchorRefs.current[integration].current = ref;
}}
/>
),
};
})
.filter(Boolean) as MenuItemData[];
}

if (!connectedIntegration) {
Expand Down Expand Up @@ -383,38 +390,44 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) {
const otherIntegrations = accountingIntegrations.filter(
(integration) => (isSyncInProgress && integration !== connectionSyncProgress?.connectionName) || integration !== connectedIntegration,
);
return otherIntegrations.map((integration) => {
const integrationData = getAccountingIntegrationData(integration, policyID, translate);
const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {};
return {
...iconProps,
title: integrationData?.title,
rightComponent: (
<Button
onPress={() =>
startIntegrationFlow({
name: integration,
integrationToDisconnect: connectedIntegration,
shouldDisconnectIntegrationBeforeConnecting: true,
})
}
text={translate('workspace.accounting.setup')}
style={styles.justifyContentCenter}
small
isDisabled={isOffline}
ref={(r) => {
if (!popoverAnchorRefs?.current) {
return;
return otherIntegrations
.map((integration) => {
const integrationData = getAccountingIntegrationData(integration, policyID, translate);
if (!integrationData) {
return undefined;
}
const iconProps = integrationData?.icon ? {icon: integrationData.icon, iconType: CONST.ICON_TYPE_AVATAR} : {};

return {
...iconProps,
title: integrationData?.title,
rightComponent: (
<Button
onPress={() =>
startIntegrationFlow({
name: integration,
integrationToDisconnect: connectedIntegration,
shouldDisconnectIntegrationBeforeConnecting: true,
})
}
popoverAnchorRefs.current[integration].current = r;
}}
/>
),
interactive: false,
shouldShowRightComponent: true,
wrapperStyle: styles.sectionMenuItemTopDescription,
};
});
text={translate('workspace.accounting.setup')}
style={styles.justifyContentCenter}
small
isDisabled={isOffline}
ref={(r) => {
if (!popoverAnchorRefs?.current) {
return;
}
popoverAnchorRefs.current[integration].current = r;
}}
/>
),
interactive: false,
shouldShowRightComponent: true,
wrapperStyle: styles.sectionMenuItemTopDescription,
};
})
.filter(Boolean) as MenuItemWithLink[];
}, [
policy?.connections,
isSyncInProgress,
Expand Down

0 comments on commit cd7459f

Please sign in to comment.