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
10 changes: 2 additions & 8 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@
PolicyCategories,
PolicyCategory,
PolicyEmployee,
ReimbursementAccount,
Report,
ReportAction,
ReportActions,
Expand Down Expand Up @@ -203,7 +202,7 @@
};

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

Check warning on line 205 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 @@ -236,7 +235,7 @@
});

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

Check warning on line 238 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 @@ -245,7 +244,7 @@
});

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

Check warning on line 247 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 @@ -255,7 +254,7 @@

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

Check warning on line 257 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 @@ -264,31 +263,25 @@
});

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

Check warning on line 266 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({
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
callback: (val) => (reimbursementAccount = val),
});

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

Check warning on line 272 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 278 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 introSelected: OnyxEntry<IntroSelected>;
Onyx.connect({

Check warning on line 284 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 @@ -384,6 +377,7 @@
policyCardFeeds: CardFeeds | undefined,
reportsToArchive: Report[],
transactionViolations: OnyxCollection<TransactionViolations> | undefined,
reimbursementAccountError: Errors | undefined,
lastUsedPaymentMethods?: LastPaymentMethod,
) {
if (!allPolicies) {
Expand Down Expand Up @@ -429,7 +423,7 @@
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.REIMBURSEMENT_ACCOUNT,
value: {
errors: reimbursementAccount?.errors ?? null,
errors: reimbursementAccountError ?? null,
},
},
{
Expand Down
6 changes: 4 additions & 2 deletions src/pages/workspace/WorkspaceOverviewPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {reimbursementAccountErrorSelector} from '@src/selectors/ReimbursementAccount';
import type {CurrencyList} from '@src/types/onyx';
import {getEmptyObject, isEmptyObject} from '@src/types/utils/EmptyObject';
import WorkspaceReceiptPartnersPromotionBanner from './receiptPartners/WorkspaceReceiptPartnersPromotionBanner';
Expand All @@ -77,6 +78,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
const [isComingFromGlobalReimbursementsFlow] = useOnyx(ONYXKEYS.IS_COMING_FROM_GLOBAL_REIMBURSEMENTS_FLOW, {canBeMissing: true});
const [lastAccessedWorkspacePolicyID] = useOnyx(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, {canBeMissing: true});
const [reimbursementAccountError] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true, selector: reimbursementAccountErrorSelector});

// When we create a new workspace, the policy prop will be empty on the first render. Therefore, we have to use policyDraft until policy has been set in Onyx.
const policy = policyDraft?.id ? policyDraft : policyProp;
Expand Down Expand Up @@ -201,10 +203,10 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
return;
}

deleteWorkspace(policy.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, lastPaymentMethod);
deleteWorkspace(policy.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, reimbursementAccountError, lastPaymentMethod);
setIsDeleteModalOpen(false);
goBackFromInvalidPolicy();
}, [policy?.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, lastPaymentMethod, reportsToArchive, transactionViolations]);
}, [policy?.id, policyName, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, reimbursementAccountError, lastPaymentMethod]);

useEffect(() => {
if (isLoadingBill) {
Expand Down
13 changes: 12 additions & 1 deletion src/pages/workspace/WorkspacesListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import {reimbursementAccountErrorSelector} from '@src/selectors/ReimbursementAccount';
import type {Policy as PolicyType} from '@src/types/onyx';
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {PolicyDetailsForNonMembers} from '@src/types/onyx/Policy';
Expand Down Expand Up @@ -117,6 +118,7 @@ function WorkspacesListPage() {
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
const [duplicateWorkspace] = useOnyx(ONYXKEYS.DUPLICATE_WORKSPACE, {canBeMissing: true});
const {isRestrictedToPreferredPolicy} = usePreferredPolicy();
const [reimbursementAccountError] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true, selector: reimbursementAccountErrorSelector});

// This hook preloads the screens of adjacent tabs to make changing tabs faster.
usePreloadFullScreenNavigators();
Expand Down Expand Up @@ -157,7 +159,16 @@ function WorkspacesListPage() {
return;
}

deleteWorkspace(policyIDToDelete, policyNameToDelete, lastAccessedWorkspacePolicyID, defaultCardFeeds, reportsToArchive, transactionViolations, lastPaymentMethod);
deleteWorkspace(
policyIDToDelete,
policyNameToDelete,
lastAccessedWorkspacePolicyID,
defaultCardFeeds,
reportsToArchive,
transactionViolations,
reimbursementAccountError,
lastPaymentMethod,
);
setIsDeleteModalOpen(false);
};

Expand Down
7 changes: 7 additions & 0 deletions src/selectors/ReimbursementAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type {OnyxEntry} from 'react-native-onyx';
import type {ReimbursementAccount} from '@src/types/onyx';

const reimbursementAccountErrorSelector = (reimbursementAccount: OnyxEntry<ReimbursementAccount>) => reimbursementAccount?.errors;

// eslint-disable-next-line import/prefer-default-export
export {reimbursementAccountErrorSelector};
26 changes: 16 additions & 10 deletions tests/actions/PolicyTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,14 +811,12 @@ describe('actions/Policy', () => {
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
policyName: fakePolicy.name,
};
const fakeReimbursementAccount = {errors: {}};
await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${fakeReport.reportID}`, fakeReport);
await Onyx.merge(ONYXKEYS.REIMBURSEMENT_ACCOUNT, fakeReimbursementAccount);

// When deleting a workspace fails
mockFetch?.fail?.();
Policy.deleteWorkspace(fakePolicy.id, fakePolicy.name, undefined, undefined, [fakeReport], undefined, undefined);
Policy.deleteWorkspace(fakePolicy.id, fakePolicy.name, undefined, undefined, [fakeReport], undefined, {});

await waitForBatchedUpdates();

Expand Down Expand Up @@ -898,13 +896,21 @@ describe('actions/Policy', () => {
{name: 'hold', type: CONST.VIOLATION_TYPES.WARNING},
]);

Policy.deleteWorkspace(policyID, 'test', undefined, undefined, [expenseChatReport], {
// eslint-disable-next-line @typescript-eslint/naming-convention
transactionViolations_3: [
{name: 'cashExpenseWithNoReceipt', type: CONST.VIOLATION_TYPES.VIOLATION},
{name: 'hold', type: CONST.VIOLATION_TYPES.WARNING},
],
});
Policy.deleteWorkspace(
policyID,
'test',
undefined,
undefined,
[expenseChatReport],
{
// eslint-disable-next-line @typescript-eslint/naming-convention
transactionViolations_3: [
{name: 'cashExpenseWithNoReceipt', type: CONST.VIOLATION_TYPES.VIOLATION},
{name: 'hold', type: CONST.VIOLATION_TYPES.WARNING},
],
},
undefined,
);

await waitForBatchedUpdates();

Expand Down
Loading