Skip to content
2 changes: 1 addition & 1 deletion src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,7 @@ const CONST = {
ARE_WORKFLOWS_ENABLED: 'areWorkflowsEnabled',
ARE_REPORT_FIELDS_ENABLED: 'areReportFieldsEnabled',
ARE_CONNECTIONS_ENABLED: 'areConnectionsEnabled',
ARE_RECEIPT_PARTNERS_ENABLED: 'areReceiptPartnersEnabled',
ARE_RECEIPT_PARTNERS_ENABLED: 'receiptPartners',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't we rename the const itself to reflect the key name? I understand that ARE_RECEIPT_PARTNERS_ENABLED suggest more of a boolean value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was thinking to do that, but other namings are the same and decided to use the same pattern:
ARE_TAXES_ENABLED: 'tax' as an example

ARE_COMPANY_CARDS_ENABLED: 'areCompanyCardsEnabled',
ARE_EXPENSIFY_CARDS_ENABLED: 'areExpensifyCardsEnabled',
ARE_INVOICES_ENABLED: 'areInvoicesEnabled',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
type InviteWorkspaceEmployeesToUberParams = {
policyID: string;
emails: string[];
/** The list of emails to invite to Uber for Business in CSV format */
Comment thread
waterim marked this conversation as resolved.
Resolved
emailList: string;
};

export default InviteWorkspaceEmployeesToUberParams;
3 changes: 3 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ function isPolicyFeatureEnabled(policy: OnyxEntry<Policy>, featureName: PolicyFe
if (featureName === CONST.POLICY.MORE_FEATURES.ARE_CONNECTIONS_ENABLED) {
return policy?.[featureName] ? !!policy?.[featureName] : !isEmptyObject(policy?.connections);
}
if (featureName === CONST.POLICY.MORE_FEATURES.ARE_RECEIPT_PARTNERS_ENABLED) {
return policy?.receiptPartners?.enabled ?? false;
}

return !!policy?.[featureName];
}
Expand Down
26 changes: 16 additions & 10 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2925,12 +2925,12 @@ function inviteWorkspaceEmployeesToUber(policyID: string, emails: string[]) {

const params: InviteWorkspaceEmployeesToUberParams = {
policyID,
emails,
emailList: emails.join(','),
};

// Build optimistic employees mapping: mark invited emails as invited
const invitedEmployees = emails.reduce<Record<string, {status: string}>>((acc, email) => {
acc[email] = {status: 'invited'};
acc[email] = {status: CONST.POLICY.RECEIPT_PARTNERS.UBER_EMPLOYEE_STATUS.INVITED};
return acc;
}, {});

Expand Down Expand Up @@ -3707,9 +3707,11 @@ function enablePolicyReceiptPartners(policyID: string, enabled: boolean, shouldN
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areReceiptPartnersEnabled: enabled,
pendingFields: {
areReceiptPartnersEnabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
receiptPartners: {
Comment thread
waterim marked this conversation as resolved.
Resolved
enabled,
pendingFields: {
enabled: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE,
},
Comment on lines +3710 to +3714

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

},
},
},
Expand All @@ -3719,8 +3721,10 @@ function enablePolicyReceiptPartners(policyID: string, enabled: boolean, shouldN
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
pendingFields: {
areReceiptPartnersEnabled: null,
receiptPartners: {
pendingFields: {
enabled: null,
},
},
},
},
Expand All @@ -3730,9 +3734,11 @@ function enablePolicyReceiptPartners(policyID: string, enabled: boolean, shouldN
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
areReceiptPartnersEnabled: !enabled,
pendingFields: {
areReceiptPartnersEnabled: null,
receiptPartners: {
enabled: !enabled,
pendingFields: {
enabled: null,
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac
[CONST.POLICY.MORE_FEATURES.ARE_RULES_ENABLED]: policy?.areRulesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_INVOICES_ENABLED]: policy?.areInvoicesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_PER_DIEM_RATES_ENABLED]: policy?.arePerDiemRatesEnabled,
[CONST.POLICY.MORE_FEATURES.ARE_RECEIPT_PARTNERS_ENABLED]: isUberForBusinessEnabled && (policy?.areReceiptPartnersEnabled ?? false),
[CONST.POLICY.MORE_FEATURES.ARE_RECEIPT_PARTNERS_ENABLED]: isUberForBusinessEnabled && (policy?.receiptPartners?.enabled ?? false),
}),
[policy, isUberForBusinessEnabled],
) as PolicyFeatureStates;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
icon: Illustrations.ReceiptPartners,
titleTranslationKey: 'workspace.moreFeatures.receiptPartners.title',
subtitleTranslationKey: 'workspace.moreFeatures.receiptPartners.subtitle',
isActive: policy?.areReceiptPartnersEnabled ?? false,
pendingAction: policy?.pendingFields?.areReceiptPartnersEnabled,
isActive: policy?.receiptPartners?.enabled ?? false,
pendingAction: policy?.receiptPartners?.pendingFields?.enabled,
disabledAction: () => {
if (!isUberConnected) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Button from '@components/Button';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import * as Expensicons from '@components/Icon/Expensicons';
import * as Illustrations from '@components/Icon/Illustrations';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import type {ListItem} from '@components/SelectionList/types';
Expand All @@ -16,6 +17,7 @@ import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePolicy from '@hooks/usePolicy';
import useThemeStyles from '@hooks/useThemeStyles';
import {inviteWorkspaceEmployeesToUber} from '@libs/actions/Policy/Policy';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Navigation from '@libs/Navigation/Navigation';
import OnyxTabNavigator, {TabScreenWithFocusTrapWrapper, TopTab} from '@libs/Navigation/OnyxTabNavigator';
Expand Down Expand Up @@ -55,6 +57,16 @@ function EditInviteReceiptPartnerPolicyPage({route}: EditInviteReceiptPartnerPol
const policyID = route.params.policyID;
const policy = usePolicy(policyID);

const inviteOrResend = useCallback(
(email: string) => {
if (!policyID) {
return;
}
inviteWorkspaceEmployeesToUber(policyID, [email]);
},
[policyID],
);

// Maintain independent search state per tab to avoid carryover across tabs
const [allSearchTerm, allDebouncedSearchTerm, setAllSearchTerm] = useDebouncedState('');
const [linkedSearchTerm, linkedDebouncedSearchTerm, setLinkedSearchTerm] = useDebouncedState('');
Expand Down Expand Up @@ -123,7 +135,7 @@ function EditInviteReceiptPartnerPolicyPage({route}: EditInviteReceiptPartnerPol
<Button
small
text={translate('workspace.receiptPartners.uber.status.resend')}
onPress={() => {}}
onPress={() => inviteOrResend(email)}
style={[styles.ml3]}
/>
);
Expand All @@ -134,7 +146,7 @@ function EditInviteReceiptPartnerPolicyPage({route}: EditInviteReceiptPartnerPol
<Button
small
text={translate('workspace.receiptPartners.uber.status.invite')}
onPress={() => {}}
onPress={() => inviteOrResend(email)}
success
style={[styles.ml3]}
/>
Expand Down Expand Up @@ -169,10 +181,12 @@ function EditInviteReceiptPartnerPolicyPage({route}: EditInviteReceiptPartnerPol
isDisabled: true,
});

list.push({...option, rightElement} as MemberForList & ListItem);
const rightElementWithOfflineFeedback = <OfflineWithFeedback pendingAction={policy?.receiptPartners?.uber?.pendingFields?.employees}>{rightElement}</OfflineWithFeedback>;

list.push({...option, rightElement: rightElementWithOfflineFeedback} as MemberForList & ListItem);
});
return sortAlphabetically(list, 'text', localeCompare);
}, [deriveStatus, localeCompare, policy?.employeeList, translate, isOffline, styles.ml3]);
}, [deriveStatus, localeCompare, policy?.employeeList, translate, isOffline, styles.ml3, inviteOrResend, policy?.receiptPartners?.uber?.pendingFields?.employees]);

const applyTabStatusFilter = useCallback(
(tab: ReceiptPartnersTab, data: MemberForList[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,30 @@ function InviteReceiptPartnerPolicyPage({route}: InviteReceiptPartnerPolicyPageP
const policy = usePolicy(policyID);
const shouldShowTextInput = policy?.employeeList && Object.keys(policy.employeeList).length >= CONST.STANDARD_LIST_ITEM_LIMIT;
const textInputLabel = shouldShowTextInput ? translate('common.search') : undefined;

const workspaceMembers = useMemo(() => {
let membersList: MemberForList[] = [];
if (!policy?.employeeList) {
return membersList;
}

// Get the list of employees from the U4B organization
const uberEmployees = policy?.receiptPartners?.uber?.employees ?? {};

Object.entries(policy.employeeList).forEach(([email, policyEmployee]) => {
if (isDeletedPolicyEmployee(policyEmployee, isOffline)) {
return;
}

// Skip employees who are in the "Linked" section
const employeeStatus = uberEmployees[email]?.status;
if (
employeeStatus === CONST.POLICY.RECEIPT_PARTNERS.UBER_EMPLOYEE_STATUS.LINKED ||
employeeStatus === CONST.POLICY.RECEIPT_PARTNERS.UBER_EMPLOYEE_STATUS.LINKED_PENDING_APPROVAL ||
employeeStatus === CONST.POLICY.RECEIPT_PARTNERS.UBER_EMPLOYEE_STATUS.SUSPENDED
) {
return;
}

const personalDetail = getPersonalDetailByEmail(email);
if (personalDetail) {
const memberForList = formatMemberForList({
Expand Down Expand Up @@ -82,7 +94,7 @@ function InviteReceiptPartnerPolicyPage({route}: InviteReceiptPartnerPolicyPageP
membersList = sortAlphabetically(membersList, 'text', localeCompare);

return membersList;
}, [isOffline, policy?.employeeList, localeCompare]);
}, [isOffline, policy?.employeeList, policy?.receiptPartners?.uber?.employees, localeCompare]);

const sections = useMemo(() => {
if (workspaceMembers.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import useIsPolicyConnectedToUberReceiptPartner from '@hooks/useIsPolicyConnecte
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePolicy from '@hooks/usePolicy';
import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -53,6 +54,9 @@ function WorkspaceReceiptPartnersPage({route}: WorkspaceReceiptPartnersPageProps
const isAutoInvite = !!integrations?.uber?.autoInvite;
const isUberConnected = useIsPolicyConnectedToUberReceiptPartner({policyID});

// Track focus and connection change to route to the invite flow once after successful connection
const prevIsUberConnected = usePrevious(isUberConnected);

const startIntegrationFlow = useCallback(
({name}: {name: string}) => {
switch (name) {
Expand All @@ -78,6 +82,14 @@ function WorkspaceReceiptPartnersPage({route}: WorkspaceReceiptPartnersPageProps
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

// When Uber connection status flips from false -> true, navigate to the invite flow once
useEffect(() => {
if (!isUberConnected || prevIsUberConnected) {
return;
}
Navigation.navigate(ROUTES.WORKSPACE_RECEIPT_PARTNERS_INVITE.getRoute(policyID, CONST.POLICY.RECEIPT_PARTNERS.NAME.UBER));
}, [prevIsUberConnected, isUberConnected, policyID]);

const calculateAndSetThreeDotsMenuPosition = useCallback(() => {
if (shouldUseNarrowLayout) {
return Promise.resolve({horizontal: 0, vertical: 0});
Expand Down Expand Up @@ -140,8 +152,9 @@ function WorkspaceReceiptPartnersPage({route}: WorkspaceReceiptPartnersPageProps
return;
}
removePolicyReceiptPartnersConnection(policyID, selectedPartner, integrations?.[selectedPartner]);
fetchReceiptPartners();
onCloseModal();
}, [policyID, selectedPartner, integrations, onCloseModal]);
}, [policyID, selectedPartner, integrations, onCloseModal, fetchReceiptPartners]);

const connectionsMenuItems: MenuItemData[] = useMemo(() => {
if (policyID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function WorkspaceReceiptPartnersPromotionBanner({policy, readOnly}: WorkspaceRe
const {isBetaEnabled} = usePermissions();
const policyID = policy?.id;
const {setAsDismissed, isDismissed} = useDismissedUberBanners({policyID});
const shouldDismissBanner = !!policy?.areReceiptPartnersEnabled || !isBetaEnabled(CONST.BETAS.UBER_FOR_BUSINESS) || isDismissed || readOnly;
const shouldDismissBanner = !!policy?.receiptPartners?.enabled || !isBetaEnabled(CONST.BETAS.UBER_FOR_BUSINESS) || isDismissed || readOnly;

const handleConnectUber = useCallback(() => {
if (!policyID) {
Expand Down
10 changes: 6 additions & 4 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ type UberReceiptPartner = {
};

/** Policy Receipt partners */
type ReceiptPartners = Record<string, OnyxCommon.OnyxValueWithOfflineFeedback<UberReceiptPartner>>;
type ReceiptPartners = OnyxCommon.OnyxValueWithOfflineFeedback<
{
/** Whether receipt partners are enabled */
enabled?: boolean;
} & Record<string, OnyxCommon.OnyxValueWithOfflineFeedback<UberReceiptPartner>>
>;

/** Policy disabled fields */
type DisabledFields = {
Expand Down Expand Up @@ -1898,9 +1903,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Whether the Report Fields feature is enabled */
areReportFieldsEnabled?: boolean;

/** Whether the Receipt Partners feature is enabled */
areReceiptPartnersEnabled?: boolean;

/** Whether the Connections feature is enabled */
areConnectionsEnabled?: boolean;

Expand Down