Skip to content

Commit

Permalink
Merge pull request #41548 from Expensify/aldo_fix-exporter-hide-guides
Browse files Browse the repository at this point in the history
Exclude guides from preferred exporter
  • Loading branch information
aldo-expensify authored May 3, 2024
2 parents 89a11e7 + 7fe7f61 commit 75b3863
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import SelectionList from '@components/SelectionList';
import RadioListItem from '@components/SelectionList/RadioListItem';
import type {ListItem} from '@components/SelectionList/types';
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 * as PolicyUtils from '@libs/PolicyUtils';
import {getAdminEmployees} from '@libs/PolicyUtils';
import Navigation from '@navigation/Navigation';
import AccessOrNotFoundWrapper from '@pages/workspace/AccessOrNotFoundWrapper';
Expand All @@ -25,22 +27,29 @@ function QuickbooksPreferredExporterConfigurationPage({policy}: WithPolicyConnec
const styles = useThemeStyles();
const {export: exportConfiguration} = policy?.connections?.quickbooksOnline?.config ?? {};
const exporters = getAdminEmployees(policy);
const {login: currentUserLogin} = useCurrentUserPersonalDetails();

const policyID = policy?.id ?? '';
const data: CardListItem[] = useMemo(
() =>
exporters?.reduce<CardListItem[]>((vendors, vendor) => {
if (vendor.email) {
vendors.push({
value: vendor.email,
text: vendor.email,
keyForList: vendor.email,
isSelected: exportConfiguration?.exporter === vendor.email,
});
exporters?.reduce<CardListItem[]>((options, exporter) => {
if (!exporter.email) {
return options;
}
return vendors;

// Don't show guides if the current user is not a guide themselves or an Expensify employee
if (PolicyUtils.isExpensifyTeam(exporter.email) && !PolicyUtils.isExpensifyTeam(policy?.owner) && !PolicyUtils.isExpensifyTeam(currentUserLogin)) {
return options;
}
options.push({
value: exporter.email,
text: exporter.email,
keyForList: exporter.email,
isSelected: exportConfiguration?.exporter === exporter.email,
});
return options;
}, []),
[exportConfiguration, exporters],
[exportConfiguration, exporters, currentUserLogin, policy?.owner],
);

const selectExporter = useCallback(
Expand Down

0 comments on commit 75b3863

Please sign in to comment.