@@ -13,7 +13,6 @@ import type {
13
13
SetPolicyCategoryMaxAmountParams ,
14
14
SetPolicyCategoryReceiptsRequiredParams ,
15
15
SetPolicyCategoryTaxParams ,
16
- SetPolicyDistanceRatesDefaultCategoryParams ,
17
16
SetWorkspaceCategoryDescriptionHintParams ,
18
17
UpdatePolicyCategoryGLCodeParams ,
19
18
} from '@libs/API/parameters' ;
@@ -28,13 +27,13 @@ import {translateLocal} from '@libs/Localize';
28
27
import Log from '@libs/Log' ;
29
28
import enhanceParameters from '@libs/Network/enhanceParameters' ;
30
29
import * as OptionsListUtils from '@libs/OptionsListUtils' ;
31
- import { navigateWhenEnableFeature , removePendingFieldsFromCustomUnit } from '@libs/PolicyUtils' ;
30
+ import { navigateWhenEnableFeature } from '@libs/PolicyUtils' ;
32
31
import * as PolicyUtils from '@libs/PolicyUtils' ;
33
32
import * as ReportUtils from '@libs/ReportUtils' ;
34
33
import CONST from '@src/CONST' ;
35
34
import ONYXKEYS from '@src/ONYXKEYS' ;
36
35
import type { Policy , PolicyCategories , PolicyCategory , RecentlyUsedCategories , Report } from '@src/types/onyx' ;
37
- import type { ApprovalRule , CustomUnit , ExpenseRule } from '@src/types/onyx/Policy' ;
36
+ import type { ApprovalRule , ExpenseRule } from '@src/types/onyx/Policy' ;
38
37
import type { PolicyCategoryExpenseLimitType } from '@src/types/onyx/PolicyCategory' ;
39
38
import type { OnyxData } from '@src/types/onyx/Request' ;
40
39
@@ -1015,15 +1014,15 @@ function enablePolicyCategories(policyID: string, enabled: boolean) {
1015
1014
}
1016
1015
}
1017
1016
1018
- function setPolicyDistanceRatesDefaultCategory ( policyID : string , currentCustomUnit : CustomUnit , newCustomUnit : CustomUnit ) {
1017
+ function setPolicyCustomUnitDefaultCategory ( policyID : string , customUnitID : string , oldCategory : string | undefined , category : string ) {
1019
1018
const optimisticData : OnyxUpdate [ ] = [
1020
1019
{
1021
1020
onyxMethod : Onyx . METHOD . MERGE ,
1022
1021
key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1023
1022
value : {
1024
1023
customUnits : {
1025
- [ newCustomUnit . customUnitID ] : {
1026
- ... newCustomUnit ,
1024
+ [ customUnitID ] : {
1025
+ defaultCategory : category ,
1027
1026
pendingFields : { defaultCategory : CONST . RED_BRICK_ROAD_PENDING_ACTION . UPDATE } ,
1028
1027
} ,
1029
1028
} ,
@@ -1037,7 +1036,7 @@ function setPolicyDistanceRatesDefaultCategory(policyID: string, currentCustomUn
1037
1036
key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1038
1037
value : {
1039
1038
customUnits : {
1040
- [ newCustomUnit . customUnitID ] : {
1039
+ [ customUnitID ] : {
1041
1040
pendingFields : { defaultCategory : null } ,
1042
1041
} ,
1043
1042
} ,
@@ -1051,8 +1050,8 @@ function setPolicyDistanceRatesDefaultCategory(policyID: string, currentCustomUn
1051
1050
key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
1052
1051
value : {
1053
1052
customUnits : {
1054
- [ currentCustomUnit . customUnitID ] : {
1055
- ... currentCustomUnit ,
1053
+ [ customUnitID ] : {
1054
+ defaultCategory : oldCategory ,
1056
1055
errorFields : { defaultCategory : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'common.genericErrorMessage' ) } ,
1057
1056
pendingFields : { defaultCategory : null } ,
1058
1057
} ,
@@ -1061,12 +1060,13 @@ function setPolicyDistanceRatesDefaultCategory(policyID: string, currentCustomUn
1061
1060
} ,
1062
1061
] ;
1063
1062
1064
- const params : SetPolicyDistanceRatesDefaultCategoryParams = {
1063
+ const params = {
1065
1064
policyID,
1066
- customUnit : JSON . stringify ( removePendingFieldsFromCustomUnit ( newCustomUnit ) ) ,
1065
+ customUnitID,
1066
+ category,
1067
1067
} ;
1068
1068
1069
- API . write ( WRITE_COMMANDS . SET_POLICY_DISTANCE_RATES_DEFAULT_CATEGORY , params , { optimisticData, successData, failureData} ) ;
1069
+ API . write ( WRITE_COMMANDS . SET_CUSTOM_UNIT_DEFAULT_CATEGORY , params , { optimisticData, successData, failureData} ) ;
1070
1070
}
1071
1071
1072
1072
function downloadCategoriesCSV ( policyID : string , onDownloadFailed : ( ) => void ) {
@@ -1364,7 +1364,7 @@ export {
1364
1364
setPolicyCategoryGLCode ,
1365
1365
clearCategoryErrors ,
1366
1366
enablePolicyCategories ,
1367
- setPolicyDistanceRatesDefaultCategory ,
1367
+ setPolicyCustomUnitDefaultCategory ,
1368
1368
deleteWorkspaceCategories ,
1369
1369
buildOptimisticPolicyCategories ,
1370
1370
setPolicyCategoryReceiptsRequired ,
0 commit comments