11import lodashDeepClone from 'lodash/cloneDeep' ;
2- import lodashUnion from 'lodash/union' ;
3- import type { NullishDeep , OnyxCollection } from 'react-native-onyx' ;
2+ import type { NullishDeep } from 'react-native-onyx' ;
43import Onyx from 'react-native-onyx' ;
54import * as API from '@libs/API' ;
65import { READ_COMMANDS , WRITE_COMMANDS } from '@libs/API/types' ;
7- import * as ApiUtils from '@libs/ApiUtils' ;
6+ import { getCommandURL } from '@libs/ApiUtils' ;
87import fileDownload from '@libs/fileDownload' ;
98import getIsNarrowLayout from '@libs/getIsNarrowLayout' ;
109import { translateLocal } from '@libs/Localize' ;
1110import enhanceParameters from '@libs/Network/enhanceParameters' ;
12- import * as NumberUtils from '@libs/NumberUtils' ;
11+ import { generateHexadecimalValue } from '@libs/NumberUtils' ;
1312import { goBackWhenEnableFeature } from '@libs/PolicyUtils' ;
14- import * as ReportUtils from '@libs/ReportUtils' ;
1513import CONST from '@src/CONST' ;
1614import ONYXKEYS from '@src/ONYXKEYS' ;
17- import type { Policy , RecentlyUsedCategories , Report } from '@src/types/onyx' ;
1815import type { ErrorFields , PendingAction } from '@src/types/onyx/OnyxCommon' ;
1916import type { CustomUnit , Rate } from '@src/types/onyx/Policy' ;
2017import type { OnyxData } from '@src/types/onyx/Request' ;
2118import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
2219
23- const allPolicies : OnyxCollection < Policy > = { } ;
24- Onyx . connect ( {
25- key : ONYXKEYS . COLLECTION . POLICY ,
26- callback : ( val , key ) => {
27- if ( ! key ) {
28- return ;
29- }
30- if ( val === null || val === undefined ) {
31- // If we are deleting a policy, we have to check every report linked to that policy
32- // 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.
33- // More info: https://github.com/Expensify/App/issues/14260
34- const policyID = key . replace ( ONYXKEYS . COLLECTION . POLICY , '' ) ;
35- const policyReports = ReportUtils . getAllPolicyReports ( policyID ) ;
36- const cleanUpMergeQueries : Record < `${typeof ONYXKEYS . COLLECTION . REPORT } ${string } `, NullishDeep < Report > > = { } ;
37- const cleanUpSetQueries : Record < `${typeof ONYXKEYS . COLLECTION . REPORT_DRAFT_COMMENT } ${string } ` | `${typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS_DRAFTS } ${string } `, null > = { } ;
38- policyReports . forEach ( ( policyReport ) => {
39- if ( ! policyReport ) {
40- return ;
41- }
42- const { reportID} = policyReport ;
43- cleanUpSetQueries [ `${ ONYXKEYS . COLLECTION . REPORT_DRAFT_COMMENT } ${ reportID } ` ] = null ;
44- cleanUpSetQueries [ `${ ONYXKEYS . COLLECTION . REPORT_ACTIONS_DRAFTS } ${ reportID } ` ] = null ;
45- } ) ;
46- Onyx . mergeCollection ( ONYXKEYS . COLLECTION . REPORT , cleanUpMergeQueries ) ;
47- Onyx . multiSet ( cleanUpSetQueries ) ;
48- delete allPolicies [ key ] ;
49- return ;
50- }
51-
52- allPolicies [ key ] = val ;
53- } ,
54- } ) ;
55-
5620type SubRateData = {
5721 pendingAction ?: PendingAction ;
5822 destination : string ;
@@ -67,7 +31,7 @@ type SubRateData = {
6731 * Returns a client generated 13 character hexadecimal value for a custom unit ID
6832 */
6933function generateCustomUnitID ( ) : string {
70- return NumberUtils . generateHexadecimalValue ( 13 ) ;
34+ return generateHexadecimalValue ( 13 ) ;
7135}
7236
7337function enablePerDiem ( policyID : string , enabled : boolean , customUnitID ?: string , shouldGoBack ?: boolean ) {
@@ -193,7 +157,7 @@ function downloadPerDiemCSV(policyID: string, onDownloadFailed: () => void) {
193157 formData . append ( key , String ( value ) ) ;
194158 } ) ;
195159
196- fileDownload ( ApiUtils . getCommandURL ( { command : WRITE_COMMANDS . EXPORT_PER_DIEM_CSV } ) , fileName , '' , false , formData , CONST . NETWORK . METHOD . POST , onDownloadFailed ) ;
160+ fileDownload ( getCommandURL ( { command : WRITE_COMMANDS . EXPORT_PER_DIEM_CSV } ) , fileName , '' , false , formData , CONST . NETWORK . METHOD . POST , onDownloadFailed ) ;
197161}
198162
199163function clearPolicyPerDiemRatesErrorFields ( policyID : string , customUnitID : string , updatedErrorFields : ErrorFields ) {
@@ -400,23 +364,6 @@ function editPerDiemRateCurrency(policyID: string, rateID: string, customUnit: C
400364 API . write ( WRITE_COMMANDS . UPDATE_WORKSPACE_CUSTOM_UNIT , parameters , onyxData ) ;
401365}
402366
403- let allRecentlyUsedDestinations : OnyxCollection < RecentlyUsedCategories > = { } ;
404- Onyx . connect ( {
405- key : ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_DESTINATIONS ,
406- waitForCollectionCallback : true ,
407- callback : ( val ) => ( allRecentlyUsedDestinations = val ) ,
408- } ) ;
409-
410- function buildOptimisticPolicyRecentlyUsedDestinations ( policyID : string | undefined , destination : string | undefined ) {
411- if ( ! policyID || ! destination ) {
412- return [ ] ;
413- }
414-
415- const policyRecentlyUsedDestinations = allRecentlyUsedDestinations ?. [ `${ ONYXKEYS . COLLECTION . POLICY_RECENTLY_USED_DESTINATIONS } ${ policyID } ` ] ?? [ ] ;
416-
417- return lodashUnion ( [ destination ] , policyRecentlyUsedDestinations ) ;
418- }
419-
420367export {
421368 generateCustomUnitID ,
422369 enablePerDiem ,
@@ -429,5 +376,4 @@ export {
429376 editPerDiemRateSubrate ,
430377 editPerDiemRateAmount ,
431378 editPerDiemRateCurrency ,
432- buildOptimisticPolicyRecentlyUsedDestinations ,
433379} ;
0 commit comments