|
1 | 1 | import lodashCloneDeep from 'lodash/cloneDeep'; |
2 | 2 | import lodashUnion from 'lodash/union'; |
3 | | -import type {NullishDeep, OnyxCollection, OnyxUpdate} from 'react-native-onyx'; |
| 3 | +import type {OnyxCollection, OnyxUpdate} from 'react-native-onyx'; |
4 | 4 | import Onyx from 'react-native-onyx'; |
5 | 5 | import type {PartialDeep} from 'type-fest'; |
6 | 6 | import * as API from '@libs/API'; |
@@ -29,48 +29,15 @@ import Log from '@libs/Log'; |
29 | 29 | import enhanceParameters from '@libs/Network/enhanceParameters'; |
30 | 30 | import {hasEnabledOptions} from '@libs/OptionsListUtils'; |
31 | 31 | import {getPolicy, goBackWhenEnableFeature} from '@libs/PolicyUtils'; |
32 | | -import {getAllPolicyReports, pushTransactionViolationsOnyxData} from '@libs/ReportUtils'; |
| 32 | +import {pushTransactionViolationsOnyxData} from '@libs/ReportUtils'; |
33 | 33 | import {getFinishOnboardingTaskOnyxData} from '@userActions/Task'; |
34 | 34 | import CONST from '@src/CONST'; |
35 | 35 | import ONYXKEYS from '@src/ONYXKEYS'; |
36 | | -import type {Policy, PolicyCategories, PolicyCategory, PolicyTagLists, RecentlyUsedCategories, Report, TransactionViolations} from '@src/types/onyx'; |
| 36 | +import type {Policy, PolicyCategories, PolicyCategory, PolicyTagLists, RecentlyUsedCategories, TransactionViolations} from '@src/types/onyx'; |
37 | 37 | import type {ApprovalRule, ExpenseRule, MccGroup} from '@src/types/onyx/Policy'; |
38 | 38 | import type {PolicyCategoryExpenseLimitType} from '@src/types/onyx/PolicyCategory'; |
39 | 39 | import type {OnyxData} from '@src/types/onyx/Request'; |
40 | 40 |
|
41 | | -const allPolicies: OnyxCollection<Policy> = {}; |
42 | | -Onyx.connect({ |
43 | | - key: ONYXKEYS.COLLECTION.POLICY, |
44 | | - callback: (val, key) => { |
45 | | - if (!key) { |
46 | | - return; |
47 | | - } |
48 | | - if (val === null || val === undefined) { |
49 | | - // If we are deleting a policy, we have to check every report linked to that policy |
50 | | - // and unset the draft indicator (pencil icon) alongside removing any draft comments. Clearing these values will keep the newly archived chats from being displayed in the LHN. |
51 | | - // More info: https://github.com/Expensify/App/issues/14260 |
52 | | - const policyID = key.replace(ONYXKEYS.COLLECTION.POLICY, ''); |
53 | | - const policyReports = getAllPolicyReports(policyID); |
54 | | - const cleanUpMergeQueries: Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep<Report>> = {}; |
55 | | - const cleanUpSetQueries: Record<`${typeof ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${string}` | `${typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${string}`, null> = {}; |
56 | | - policyReports.forEach((policyReport) => { |
57 | | - if (!policyReport) { |
58 | | - return; |
59 | | - } |
60 | | - const {reportID} = policyReport; |
61 | | - cleanUpSetQueries[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`] = null; |
62 | | - cleanUpSetQueries[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${reportID}`] = null; |
63 | | - }); |
64 | | - Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, cleanUpMergeQueries); |
65 | | - Onyx.multiSet(cleanUpSetQueries); |
66 | | - delete allPolicies[key]; |
67 | | - return; |
68 | | - } |
69 | | - |
70 | | - allPolicies[key] = val; |
71 | | - }, |
72 | | -}); |
73 | | - |
74 | 41 | let allRecentlyUsedCategories: OnyxCollection<RecentlyUsedCategories> = {}; |
75 | 42 | Onyx.connect({ |
76 | 43 | key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, |
@@ -1312,9 +1279,7 @@ function setPolicyCategoryMaxAmount(policyID: string, categoryName: string, maxE |
1312 | 1279 | API.write(WRITE_COMMANDS.SET_POLICY_CATEGORY_MAX_AMOUNT, parameters, onyxData); |
1313 | 1280 | } |
1314 | 1281 |
|
1315 | | -function setPolicyCategoryApprover(policyID: string, categoryName: string, approver: string) { |
1316 | | - const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]; |
1317 | | - const approvalRules = policy?.rules?.approvalRules ?? []; |
| 1282 | +function setPolicyCategoryApprover(policyID: string, categoryName: string, approver: string, approvalRules: ApprovalRule[]) { |
1318 | 1283 | let updatedApprovalRules: ApprovalRule[] = lodashCloneDeep(approvalRules); |
1319 | 1284 | const existingCategoryApproverRule = CategoryUtils.getCategoryApproverRule(updatedApprovalRules, categoryName); |
1320 | 1285 |
|
|
0 commit comments