@@ -134,6 +134,7 @@ import type {
134134 CustomUnit ,
135135 NetSuiteCustomList ,
136136 NetSuiteCustomSegment ,
137+ PolicyReportField ,
137138 ProhibitedExpenses ,
138139 Rate ,
139140 TaxRate ,
@@ -313,17 +314,6 @@ function isCurrencySupportedForGlobalReimbursement(currency: TupleToUnion<typeof
313314 return CONST . DIRECT_REIMBURSEMENT_CURRENCIES . includes ( currency ) ;
314315}
315316
316- /**
317- * Returns the policy of the report
318- * @deprecated Get the data straight from Onyx - This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
319- */
320- function getPolicy ( policyID : string | undefined ) : OnyxEntry < Policy > {
321- if ( ! deprecatedAllPolicies || ! policyID ) {
322- return undefined ;
323- }
324- return deprecatedAllPolicies [ `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ] ;
325- }
326-
327317/** Check if the policy has invoicing company details */
328318function hasInvoicingDetails ( policy : OnyxEntry < Policy > ) : boolean {
329319 return ! ! policy ?. invoice ?. companyName && ! ! policy ?. invoice ?. companyWebsite ;
@@ -3838,14 +3828,10 @@ function requestExpensifyCardLimitIncrease(settlementBankAccountID?: number) {
38383828 API . write ( WRITE_COMMANDS . REQUEST_EXPENSIFY_CARD_LIMIT_INCREASE , params ) ;
38393829}
38403830
3841- function updateMemberCustomField ( policyID : string , login : string , customFieldType : CustomFieldType , value : string ) {
3831+ function updateMemberCustomField ( policyID : string , login : string , customFieldType : CustomFieldType , value : string , currentValue : string | undefined ) {
38423832 const customFieldKey = CONST . CUSTOM_FIELD_KEYS [ customFieldType ] ;
3843- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
3844- // eslint-disable-next-line @typescript-eslint/no-deprecated
3845- const policy = getPolicy ( policyID ) ;
3846- const previousValue = policy ?. employeeList ?. [ login ] ?. [ customFieldKey ] ;
38473833
3848- if ( value === ( previousValue ?? '' ) ) {
3834+ if ( value === ( currentValue ?? '' ) ) {
38493835 return ;
38503836 }
38513837
@@ -3872,7 +3858,7 @@ function updateMemberCustomField(policyID: string, login: string, customFieldTyp
38723858 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
38733859 onyxMethod : Onyx . METHOD . MERGE ,
38743860 value : {
3875- employeeList : { [ login ] : { [ customFieldKey ] : previousValue , pendingFields : { [ customFieldKey ] : null } } } ,
3861+ employeeList : { [ login ] : { [ customFieldKey ] : currentValue , pendingFields : { [ customFieldKey ] : null } } } ,
38763862 } ,
38773863 } ,
38783864 ] ;
@@ -5428,16 +5414,7 @@ function downgradeToTeam(policyID: string, currentType: Policy['type'], currentI
54285414 API . write ( WRITE_COMMANDS . DOWNGRADE_TO_TEAM , parameters , { optimisticData, successData, failureData} ) ;
54295415}
54305416
5431- function setWorkspaceDefaultSpendCategory ( policyID : string , groupID : string , category : string ) {
5432- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
5433- // eslint-disable-next-line @typescript-eslint/no-deprecated
5434- const policy = getPolicy ( policyID ) ;
5435- if ( ! policy ) {
5436- return ;
5437- }
5438-
5439- const { mccGroup} = policy ;
5440-
5417+ function setWorkspaceDefaultSpendCategory ( policyID : string , groupID : string , category : string , mccGroup : Policy [ 'mccGroup' ] ) {
54415418 const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = mccGroup
54425419 ? [
54435420 {
@@ -5771,13 +5748,9 @@ function setPolicyMaxExpenseAge(policyID: string, maxExpenseAge: string, current
57715748 * @param policyID - id of the policy to set the max expense age
57725749 * @param customRules - the custom rules description in natural language
57735750 */
5774- function updateCustomRules ( policyID : string , customRules : string ) {
5775- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
5776- // eslint-disable-next-line @typescript-eslint/no-deprecated
5777- const policy = getPolicy ( policyID ) ;
5778- const originalCustomRules = policy ?. customRules ;
5751+ function updateCustomRules ( policyID : string , customRules : string , currentCustomRules : string | undefined ) {
57795752 const parsedCustomRules = ReportUtils . getParsedComment ( customRules ) ;
5780- if ( parsedCustomRules === originalCustomRules ) {
5753+ if ( parsedCustomRules === currentCustomRules ) {
57815754 return ;
57825755 }
57835756
@@ -5812,7 +5785,7 @@ function updateCustomRules(policyID: string, customRules: string) {
58125785 onyxMethod : Onyx . METHOD . MERGE ,
58135786 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
58145787 value : {
5815- customRules : originalCustomRules ,
5788+ customRules : currentCustomRules ,
58165789 pendingFields : { customRules : null } ,
58175790 errorFields : { customRules : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'common.genericErrorMessage' ) } ,
58185791 // TODO
@@ -5991,11 +5964,6 @@ function setPolicyReimbursableMode(
59915964 * @param policyID - id of the policy to enable or disable the billable mode
59925965 */
59935966function disableWorkspaceBillableExpenses ( policyID : string ) {
5994- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
5995- // eslint-disable-next-line @typescript-eslint/no-deprecated
5996- const policy = getPolicy ( policyID ) ;
5997- const originalDefaultBillableDisabled = policy ?. disabledFields ?. defaultBillable ;
5998-
59995967 const onyxData : OnyxData < typeof ONYXKEYS . COLLECTION . POLICY > = {
60005968 optimisticData : [
60015969 {
@@ -6028,7 +5996,7 @@ function disableWorkspaceBillableExpenses(policyID: string) {
60285996 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
60295997 value : {
60305998 pendingFields : { disabledFields : null } ,
6031- disabledFields : { defaultBillable : originalDefaultBillableDisabled } ,
5999+ disabledFields : { defaultBillable : false } ,
60326000 } ,
60336001 } ,
60346002 ] ,
@@ -6200,17 +6168,11 @@ function getAdminPolicies(): Policy[] {
62006168 * @param policyID - id of the policy to apply the naming pattern to
62016169 * @param customName - name pattern to be used for the reports
62026170 */
6203- function setPolicyDefaultReportTitle ( policyID : string , customName : string ) {
6204- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
6205- // eslint-disable-next-line @typescript-eslint/no-deprecated
6206- const policy = getPolicy ( policyID ) ;
6207-
6208- if ( customName === policy ?. fieldList ?. [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] ?. defaultValue ) {
6171+ function setPolicyDefaultReportTitle ( policyID : string , customName : string , currentReportTitleField : PolicyReportField | undefined ) {
6172+ if ( customName === currentReportTitleField ?. defaultValue ) {
62096173 return ;
62106174 }
62116175
6212- const previousReportTitleField = policy ?. fieldList ?. [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] ?? { } ;
6213-
62146176 const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
62156177 {
62166178 onyxMethod : Onyx . METHOD . MERGE ,
@@ -6245,7 +6207,7 @@ function setPolicyDefaultReportTitle(policyID: string, customName: string) {
62456207 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
62466208 value : {
62476209 fieldList : {
6248- [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...previousReportTitleField , pendingFields : { defaultValue : null } } ,
6210+ [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...currentReportTitleField , pendingFields : { defaultValue : null } } ,
62496211 } ,
62506212 errorFields : {
62516213 fieldList : {
@@ -6275,26 +6237,20 @@ function setPolicyDefaultReportTitle(policyID: string, customName: string) {
62756237 * @param policyID - id of the policy to apply the naming pattern to
62766238 * @param enforced - flag whether to enforce policy name
62776239 */
6278- function setPolicyPreventMemberCreatedTitle ( policyID : string , enforced : boolean ) {
6279- // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850
6280- // eslint-disable-next-line @typescript-eslint/no-deprecated
6281- const policy = getPolicy ( policyID ) ;
6282-
6240+ function setPolicyPreventMemberCreatedTitle ( policyID : string , enforced : boolean , currentReportTitleField : PolicyReportField | undefined ) {
62836241 // When fieldList is empty, deletable is undefined. We treat undefined as true (not enforced) to match OldDot's fallback behavior.
6284- const currentDeletable = policy ?. fieldList ?. [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] ?. deletable ?? true ;
6242+ const currentDeletable = currentReportTitleField ?. deletable ?? true ;
62856243 if ( ! enforced === currentDeletable ) {
62866244 return ;
62876245 }
62886246
6289- const previousReportTitleField = policy ?. fieldList ?. [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] ?? { } ;
6290-
62916247 const optimisticData : Array < OnyxUpdate < typeof ONYXKEYS . COLLECTION . POLICY > > = [
62926248 {
62936249 onyxMethod : Onyx . METHOD . MERGE ,
62946250 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
62956251 value : {
62966252 fieldList : {
6297- [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...previousReportTitleField , deletable : ! enforced , pendingFields : { deletable : CONST . RED_BRICK_ROAD_PENDING_ACTION . UPDATE } } ,
6253+ [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...currentReportTitleField , deletable : ! enforced , pendingFields : { deletable : CONST . RED_BRICK_ROAD_PENDING_ACTION . UPDATE } } ,
62986254 } ,
62996255 } ,
63006256 } ,
@@ -6319,7 +6275,7 @@ function setPolicyPreventMemberCreatedTitle(policyID: string, enforced: boolean)
63196275 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
63206276 value : {
63216277 fieldList : {
6322- [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...previousReportTitleField , pendingFields : { deletable : null } } ,
6278+ [ CONST . POLICY . FIELDS . FIELD_LIST_TITLE ] : { ...currentReportTitleField , pendingFields : { deletable : null } } ,
63236279 } ,
63246280 errorFields : {
63256281 fieldList : ErrorUtils . getMicroSecondOnyxErrorWithTranslationKey ( 'common.genericErrorMessage' ) ,
0 commit comments