Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/hooks/useIsPolicyConnectedToUberReceiptPartner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import usePolicy from './usePolicy';

export default function useIsPolicyConnectedToUberReceiptPartner({policyID}: {policyID?: string}) {
const policy = usePolicy(policyID);

return !!policy?.receiptPartners?.uber?.enabled;
}
4 changes: 2 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
};

const allPolicies: OnyxCollection<Policy> = {};
Onyx.connect({

Check warning on line 185 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
callback: (val, key) => {
if (!key) {
Expand Down Expand Up @@ -215,7 +215,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 218 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -224,7 +224,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 227 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -234,7 +234,7 @@

let sessionEmail = '';
let sessionAccountID = 0;
Onyx.connect({

Check warning on line 237 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (val) => {
sessionEmail = val?.email ?? '';
Expand All @@ -243,38 +243,38 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
Onyx.connect({

Check warning on line 246 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => (allPersonalDetails = val),
});

let reimbursementAccount: OnyxEntry<ReimbursementAccount>;
Onyx.connect({

Check warning on line 252 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
callback: (val) => (reimbursementAccount = val),
});

let allRecentlyUsedCurrencies: string[];
Onyx.connect({

Check warning on line 258 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.RECENTLY_USED_CURRENCIES,
callback: (val) => (allRecentlyUsedCurrencies = val ?? []),
});

let activePolicyID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 264 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => (activePolicyID = value),
});

let allTransactionViolations: OnyxCollection<TransactionViolations> = {};
Onyx.connect({

Check warning on line 270 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => (allTransactionViolations = value),
});

let introSelected: OnyxEntry<IntroSelected>;
Onyx.connect({

Check warning on line 277 in src/libs/actions/Policy/Policy.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (value) => (introSelected = value),
});
Expand Down Expand Up @@ -2804,7 +2804,7 @@
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
receiptPartners: {
[partnerName]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE},
[partnerName]: {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, enabled: false},
},
},
},
Expand All @@ -2816,7 +2816,7 @@
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
receiptPartners: {
[partnerName]: {pendingAction: null},
[partnerName]: null,
},
},
},
Expand Down
8 changes: 6 additions & 2 deletions src/pages/workspace/WorkspaceMoreFeaturesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Section from '@components/Section';
import Text from '@components/Text';
import useCardFeeds from '@hooks/useCardFeeds';
import useDefaultFundID from '@hooks/useDefaultFundID';
import useIsPolicyConnectedToUberReceiptPartner from '@hooks/useIsPolicyConnectedToUberReceiptPartner';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useOnyx from '@hooks/useOnyx';
Expand Down Expand Up @@ -91,6 +92,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
selector: filterInactiveCards,
canBeMissing: true,
});
const isUberConnected = useIsPolicyConnectedToUberReceiptPartner({policyID});
const [cardFeeds] = useCardFeeds(policyID);
const [isOrganizeWarningModalOpen, setIsOrganizeWarningModalOpen] = useState(false);
const [isIntegrateWarningModalOpen, setIsIntegrateWarningModalOpen] = useState(false);
Expand Down Expand Up @@ -333,7 +335,9 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
isActive: policy?.areReceiptPartnersEnabled ?? false,
pendingAction: policy?.pendingFields?.areReceiptPartnersEnabled,
disabledAction: () => {
// TODO: When Uber integration is added, check if any integration exists if(!hasReceiptPartnersIntegration) return;
if (!isUberConnected) {
return;
}
setIsReceiptPartnersWarningModalOpen(true);
},
action: (isEnabled: boolean) => {
Expand All @@ -342,7 +346,7 @@ function WorkspaceMoreFeaturesPage({policy, route}: WorkspaceMoreFeaturesPagePro
}
enablePolicyReceiptPartners(policyID, isEnabled);
},
disabled: false, // TODO: When Uber integration is added, set to hasReceiptPartnersIntegration
disabled: isUberConnected,
errors: getLatestErrorField(policy ?? {}, CONST.POLICY.MORE_FEATURES.ARE_RECEIPT_PARTNERS_ENABLED),
onCloseError: () => {
if (!policyID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Section from '@components/Section';
import ThreeDotsMenu from '@components/ThreeDotsMenu';
import useIsPolicyConnectedToUberReceiptPartner from '@hooks/useIsPolicyConnectedToUberReceiptPartner';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePolicy from '@hooks/usePolicy';
Expand Down Expand Up @@ -50,13 +51,10 @@ function WorkspaceReceiptPartnersPage({route}: WorkspaceReceiptPartnersPageProps
const integrations = policy?.receiptPartners;
const isAutoRemove = !!integrations?.uber?.autoRemove;
const isAutoInvite = !!integrations?.uber?.autoInvite;
const [isConnected, setIsConnected] = useState(false);
const isUberConnected = !!integrations?.uber?.organizationID || isConnected;
const isUberConnected = useIsPolicyConnectedToUberReceiptPartner({policyID});

const startIntegrationFlow = useCallback(
({name}: {name: string}) => {
// TODO remove this when integration flow will be ready
setIsConnected(true);
switch (name) {
case CONST.POLICY.RECEIPT_PARTNERS.NAME.UBER: {
const {connectFormData} = integrations?.uber ?? {};
Expand Down Expand Up @@ -147,7 +145,6 @@ function WorkspaceReceiptPartnersPage({route}: WorkspaceReceiptPartnersPageProps
return;
}
removePolicyReceiptPartnersConnection(policyID, selectedPartner, integrations?.[selectedPartner]);
setIsConnected(false);
onCloseModal();
}, [policyID, selectedPartner, integrations, onCloseModal]);

Expand Down
4 changes: 4 additions & 0 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ type UberReceiptPartner = {
* auto remove for uber connection
*/
autoRemove?: boolean;
/**
* Whether uber is enabled for user
*/
enabled?: boolean;
/**
* organization id for connected uber
*/
Expand Down
Loading