Skip to content

Commit 52bb648

Browse files
Refactor: Deprecate getPersonalPolicy (part 3)
1 parent 977255d commit 52bb648

File tree

5 files changed

+14
-1
lines changed

5 files changed

+14
-1
lines changed

src/libs/actions/Policy/Policy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ function hasActiveChatEnabledPolicies(policies: Array<OnyxEntry<PolicySelector>>
353353

354354
type DeleteWorkspaceActionParams = {
355355
policyID: string;
356+
personalPolicyID: string | undefined;
356357
activePolicyID: string | undefined;
357358
policyName: string;
358359
lastAccessedWorkspacePolicyID: string | undefined;
@@ -385,6 +386,7 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
385386
lastUsedPaymentMethods,
386387
bankAccountList,
387388
localeCompare,
389+
personalPolicyID,
388390
} = params;
389391

390392
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
@@ -477,7 +479,7 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
477479
.filter((p) => p && p.id !== activePolicyID && p.type !== CONST.POLICY.TYPE.PERSONAL && p.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
478480
.sort((policyA, policyB) => localeCompare(policyB?.created ?? '', policyA?.created ?? ''))
479481
.at(0);
480-
const newActivePolicyID = mostRecentlyCreatedGroupPolicy?.id ?? PolicyUtils.getPersonalPolicy()?.id;
482+
const newActivePolicyID = mostRecentlyCreatedGroupPolicy?.id ?? personalPolicyID;
481483

482484
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
483485
optimisticData.push({

src/pages/workspace/WorkspaceOverviewPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
7676
const [currencyList = getEmptyObject<CurrencyList>()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true});
7777
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
7878
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
79+
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
7980
const [isComingFromGlobalReimbursementsFlow] = useOnyx(ONYXKEYS.IS_COMING_FROM_GLOBAL_REIMBURSEMENTS_FLOW, {canBeMissing: true});
8081
const [lastAccessedWorkspacePolicyID] = useOnyx(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, {canBeMissing: true});
8182
const [reimbursementAccountError] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true, selector: reimbursementAccountErrorSelector});
@@ -230,6 +231,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
230231
bankAccountList,
231232
lastUsedPaymentMethods: lastPaymentMethod,
232233
localeCompare,
234+
personalPolicyID,
233235
});
234236
if (isOffline) {
235237
setIsDeleteModalOpen(false);
@@ -248,6 +250,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
248250
isOffline,
249251
activePolicyID,
250252
bankAccountList,
253+
personalPolicyID,
251254
]);
252255

253256
const handleLeaveWorkspace = useCallback(() => {

src/pages/workspace/WorkspacesListPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function WorkspacesListPage() {
148148

149149
const [allDomains] = useOnyx(ONYXKEYS.COLLECTION.DOMAIN, {canBeMissing: false});
150150
const [adminAccess] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_ADMIN_ACCESS, {canBeMissing: false});
151+
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
151152

152153
// This hook preloads the screens of adjacent tabs to make changing tabs faster.
153154
usePreloadFullScreenNavigators();
@@ -218,6 +219,7 @@ function WorkspacesListPage() {
218219
bankAccountList,
219220
lastUsedPaymentMethods: lastPaymentMethod,
220221
localeCompare,
222+
personalPolicyID,
221223
});
222224
if (isOffline) {
223225
setIsDeleteModalOpen(false);

tests/actions/IOUTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5579,6 +5579,7 @@ describe('actions/IOU', () => {
55795579
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
55805580
deleteWorkspace({
55815581
policyID: policy.id,
5582+
personalPolicyID: undefined,
55825583
activePolicyID: undefined,
55835584
policyName: policy.name,
55845585
lastAccessedWorkspacePolicyID: undefined,

tests/actions/PolicyTest.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,7 @@ describe('actions/Policy', () => {
10601060
mockFetch?.fail?.();
10611061
Policy.deleteWorkspace({
10621062
policyID: fakePolicy.id,
1063+
personalPolicyID: undefined,
10631064
activePolicyID: undefined,
10641065
policyName: fakePolicy.name,
10651066
lastAccessedWorkspacePolicyID: undefined,
@@ -1151,6 +1152,7 @@ describe('actions/Policy', () => {
11511152

11521153
Policy.deleteWorkspace({
11531154
policyID,
1155+
personalPolicyID: undefined,
11541156
activePolicyID: undefined,
11551157
policyName: 'test',
11561158
lastAccessedWorkspacePolicyID: undefined,
@@ -1207,6 +1209,7 @@ describe('actions/Policy', () => {
12071209

12081210
Policy.deleteWorkspace({
12091211
policyID: randomGroupPolicy.id,
1212+
personalPolicyID: personalPolicy.id,
12101213
activePolicyID: randomGroupPolicy.id,
12111214
policyName: randomGroupPolicy.name,
12121215
lastAccessedWorkspacePolicyID: undefined,
@@ -1243,6 +1246,7 @@ describe('actions/Policy', () => {
12431246

12441247
Policy.deleteWorkspace({
12451248
policyID: policyToDelete.id,
1249+
personalPolicyID: undefined,
12461250
activePolicyID: undefined,
12471251
policyName: policyToDelete.name,
12481252
lastAccessedWorkspacePolicyID,
@@ -1281,6 +1285,7 @@ describe('actions/Policy', () => {
12811285

12821286
Policy.deleteWorkspace({
12831287
policyID: policyToDelete.id,
1288+
personalPolicyID: undefined,
12841289
activePolicyID: undefined,
12851290
policyName: policyToDelete.name,
12861291
lastAccessedWorkspacePolicyID,

0 commit comments

Comments
 (0)