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

Exclude guides from preferred exporter #41548

Merged
merged 4 commits into from
May 3, 2024
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
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
Loading