Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CP Staging] Fix connectionsMenuItems with undefined items #50386

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we could have used reduce to combine the map and filter so we do not have two

const integrationData = getAccountingIntegrationData(integration, policyID, translate);
if (!integrationData) {
return undefined;
}
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved
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
Loading