Skip to content

Commit

Permalink
Merge pull request #42346 from rushatgabhane/xero-exporter
Browse files Browse the repository at this point in the history
[Wave Collect][Xero] Hide guides as exporters
  • Loading branch information
lakchote authored May 20, 2024
2 parents f521fa5 + 636cbf1 commit ed18ae8
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import RadioListItem from '@components/SelectionList/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
import SelectionScreen from '@components/SelectionScreen';
import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Connections from '@libs/actions/connections';
import {getAdminEmployees} from '@libs/PolicyUtils';
import {getAdminEmployees, isExpensifyTeam} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import type {WithPolicyConnectionsProps} from '@pages/workspace/withPolicyConnections';
import withPolicyConnections from '@pages/workspace/withPolicyConnections';
Expand All @@ -25,6 +26,7 @@ function XeroPreferredExporterSelectPage({policy}: WithPolicyConnectionsProps) {
const styles = useThemeStyles();
const policyOwner = policy?.owner ?? '';
const exporters = getAdminEmployees(policy);
const {login: currentUserLogin} = useCurrentUserPersonalDetails();

const policyID = policy?.id ?? '';
const data: CardListItem[] = useMemo(() => {
Expand All @@ -38,18 +40,26 @@ function XeroPreferredExporterSelectPage({policy}: WithPolicyConnectionsProps) {
},
];
}
return exporters?.reduce<CardListItem[]>((vendors, vendor) => {
if (vendor.email) {
vendors.push({
value: vendor.email,
text: vendor.email,
keyForList: vendor.email,
isSelected: exportConfiguration?.exporter === vendor.email,
});

return exporters?.reduce<CardListItem[]>((options, exporter) => {
if (!exporter.email) {
return options;
}

// Don't show guides if the current user is not a guide themselves or an Expensify employee
if (isExpensifyTeam(exporter.email) && !isExpensifyTeam(policyOwner) && !isExpensifyTeam(currentUserLogin)) {
return options;
}
return vendors;

options.push({
value: exporter.email,
text: exporter.email,
keyForList: exporter.email,
isSelected: exportConfiguration?.exporter === exporter.email,
});
return options;
}, []);
}, [exportConfiguration, exporters, policyOwner]);
}, [exportConfiguration, exporters, policyOwner, currentUserLogin]);

const selectExporter = useCallback(
(row: CardListItem) => {
Expand Down

0 comments on commit ed18ae8

Please sign in to comment.