Skip to content

Commit 274b9d6

Browse files
authored
Merge pull request #78789 from shubham1206agra/refactor-getPersonalPolicy-3
Refactor: Deprecate getPersonalPolicy (part 3)
2 parents 5d76f71 + 52bb648 commit 274b9d6

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
@@ -346,6 +346,7 @@ function hasActiveChatEnabledPolicies(policies: Array<OnyxEntry<PolicySelector>>
346346

347347
type DeleteWorkspaceActionParams = {
348348
policyID: string;
349+
personalPolicyID: string | undefined;
349350
activePolicyID: string | undefined;
350351
policyName: string;
351352
lastAccessedWorkspacePolicyID: string | undefined;
@@ -378,6 +379,7 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
378379
lastUsedPaymentMethods,
379380
bankAccountList,
380381
localeCompare,
382+
personalPolicyID,
381383
} = params;
382384

383385
// This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
@@ -470,7 +472,7 @@ function deleteWorkspace(params: DeleteWorkspaceActionParams) {
470472
.filter((p) => p && p.id !== activePolicyID && p.type !== CONST.POLICY.TYPE.PERSONAL && p.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE)
471473
.sort((policyA, policyB) => localeCompare(policyB?.created ?? '', policyA?.created ?? ''))
472474
.at(0);
473-
const newActivePolicyID = mostRecentlyCreatedGroupPolicy?.id ?? PolicyUtils.getPersonalPolicy()?.id;
475+
const newActivePolicyID = mostRecentlyCreatedGroupPolicy?.id ?? personalPolicyID;
474476

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

src/pages/workspace/WorkspaceOverviewPage.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
7575
const [currencyList = getEmptyObject<CurrencyList>()] = useOnyx(ONYXKEYS.CURRENCY_LIST, {canBeMissing: true});
7676
const [account] = useOnyx(ONYXKEYS.ACCOUNT, {canBeMissing: true});
7777
const [fundList] = useOnyx(ONYXKEYS.FUND_LIST, {canBeMissing: true});
78+
const [personalPolicyID] = useOnyx(ONYXKEYS.PERSONAL_POLICY_ID, {canBeMissing: true});
7879
const [isComingFromGlobalReimbursementsFlow] = useOnyx(ONYXKEYS.IS_COMING_FROM_GLOBAL_REIMBURSEMENTS_FLOW, {canBeMissing: true});
7980
const [lastAccessedWorkspacePolicyID] = useOnyx(ONYXKEYS.LAST_ACCESSED_WORKSPACE_POLICY_ID, {canBeMissing: true});
8081
const [reimbursementAccountError] = useOnyx(ONYXKEYS.REIMBURSEMENT_ACCOUNT, {canBeMissing: true, selector: reimbursementAccountErrorSelector});
@@ -229,6 +230,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
229230
bankAccountList,
230231
lastUsedPaymentMethods: lastPaymentMethod,
231232
localeCompare,
233+
personalPolicyID,
232234
});
233235
if (isOffline) {
234236
setIsDeleteModalOpen(false);
@@ -247,6 +249,7 @@ function WorkspaceOverviewPage({policyDraft, policy: policyProp, route}: Workspa
247249
isOffline,
248250
activePolicyID,
249251
bankAccountList,
252+
personalPolicyID,
250253
]);
251254

252255
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
@@ -5747,6 +5747,7 @@ describe('actions/IOU', () => {
57475747
// eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style
57485748
deleteWorkspace({
57495749
policyID: policy.id,
5750+
personalPolicyID: undefined,
57505751
activePolicyID: undefined,
57515752
policyName: policy.name,
57525753
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)