@@ -39,6 +39,40 @@ import type {ApprovalRule, ExpenseRule, MccGroup} from '@src/types/onyx/Policy';
3939import type { PolicyCategoryExpenseLimitType } from '@src/types/onyx/PolicyCategory' ;
4040import type { OnyxData } from '@src/types/onyx/Request' ;
4141
42+ type CreatePolicyCategoryParams = {
43+ policyID : string ;
44+ categoryName : string ;
45+ isSetupCategoriesTaskParentReportArchived : boolean ;
46+ setupCategoryTaskReport : OnyxEntry < Report > ;
47+ setupCategoryTaskParentReport : OnyxEntry < Report > ;
48+ currentUserAccountID : number ;
49+ hasOutstandingChildTask : boolean ;
50+ parentReportAction : OnyxEntry < ReportAction > ;
51+ setupCategoriesAndTagsTaskReport ?: OnyxEntry < Report > ;
52+ setupCategoriesAndTagsTaskParentReport ?: OnyxEntry < Report > ;
53+ isSetupCategoriesAndTagsTaskParentReportArchived ?: boolean ;
54+ setupCategoriesAndTagsHasOutstandingChildTask ?: boolean ;
55+ setupCategoriesAndTagsParentReportAction ?: OnyxEntry < ReportAction > ;
56+ policyHasTags ?: boolean ;
57+ } ;
58+
59+ type SetWorkspaceCategoryEnabledParams = {
60+ policyData : PolicyData ;
61+ categoriesToUpdate : Record < string , { name : string ; enabled : boolean } > ;
62+ isSetupCategoriesTaskParentReportArchived : boolean ;
63+ setupCategoryTaskReport : OnyxEntry < Report > ;
64+ setupCategoryTaskParentReport : OnyxEntry < Report > ;
65+ currentUserAccountID : number ;
66+ hasOutstandingChildTask : boolean ;
67+ parentReportAction : OnyxEntry < ReportAction > | undefined ;
68+ setupCategoriesAndTagsTaskReport ?: OnyxEntry < Report > ;
69+ setupCategoriesAndTagsTaskParentReport ?: OnyxEntry < Report > ;
70+ isSetupCategoriesAndTagsTaskParentReportArchived ?: boolean ;
71+ setupCategoriesAndTagsHasOutstandingChildTask ?: boolean ;
72+ setupCategoriesAndTagsParentReportAction ?: OnyxEntry < ReportAction > ;
73+ policyHasTags ?: boolean ;
74+ } ;
75+
4276function appendSetupCategoriesOnboardingData (
4377 onyxData : OnyxData <
4478 typeof ONYXKEYS . COLLECTION . POLICY_CATEGORIES | typeof ONYXKEYS . COLLECTION . POLICY_CATEGORIES_DRAFT | typeof ONYXKEYS . COLLECTION . REPORT | typeof ONYXKEYS . COLLECTION . REPORT_ACTIONS
@@ -328,16 +362,22 @@ function getPolicyCategories(policyID: string) {
328362 API . read ( READ_COMMANDS . GET_POLICY_CATEGORIES , params ) ;
329363}
330364
331- function setWorkspaceCategoryEnabled (
332- policyData : PolicyData ,
333- categoriesToUpdate : Record < string , { name : string ; enabled : boolean } > ,
334- isSetupCategoriesTaskParentReportArchived : boolean ,
335- setupCategoryTaskReport : OnyxEntry < Report > ,
336- setupCategoryTaskParentReport : OnyxEntry < Report > ,
337- currentUserAccountID : number ,
338- hasOutstandingChildTask : boolean ,
339- parentReportAction : OnyxEntry < ReportAction > | undefined ,
340- ) {
365+ function setWorkspaceCategoryEnabled ( {
366+ policyData,
367+ categoriesToUpdate,
368+ isSetupCategoriesTaskParentReportArchived,
369+ setupCategoryTaskReport,
370+ setupCategoryTaskParentReport,
371+ currentUserAccountID,
372+ hasOutstandingChildTask,
373+ parentReportAction,
374+ setupCategoriesAndTagsTaskReport,
375+ setupCategoriesAndTagsTaskParentReport,
376+ isSetupCategoriesAndTagsTaskParentReportArchived,
377+ setupCategoriesAndTagsHasOutstandingChildTask,
378+ setupCategoriesAndTagsParentReportAction,
379+ policyHasTags,
380+ } : SetWorkspaceCategoryEnabledParams ) {
341381 const policyID = policyData . policy ?. id ;
342382 const policyCategoriesOptimisticData = {
343383 ...Object . keys ( categoriesToUpdate ) . reduce < PolicyCategories > ( ( acc , key ) => {
@@ -414,6 +454,18 @@ function setWorkspaceCategoryEnabled(
414454 parentReportAction ,
415455 ) ;
416456
457+ if ( setupCategoriesAndTagsTaskReport && policyHasTags ) {
458+ appendSetupCategoriesOnboardingData (
459+ onyxData ,
460+ setupCategoriesAndTagsTaskReport ,
461+ setupCategoriesAndTagsTaskParentReport ,
462+ isSetupCategoriesAndTagsTaskParentReportArchived ?? false ,
463+ currentUserAccountID ,
464+ setupCategoriesAndTagsHasOutstandingChildTask ?? false ,
465+ setupCategoriesAndTagsParentReportAction ,
466+ ) ;
467+ }
468+
417469 const parameters = {
418470 policyID,
419471 categories : JSON . stringify ( Object . keys ( categoriesToUpdate ) . map ( ( key ) => categoriesToUpdate [ key ] ) ) ,
@@ -620,16 +672,22 @@ function removePolicyCategoryReceiptsRequired(policyData: PolicyData, categoryNa
620672 API . write ( WRITE_COMMANDS . REMOVE_POLICY_CATEGORY_RECEIPTS_REQUIRED , parameters , onyxData ) ;
621673}
622674
623- function createPolicyCategory (
624- policyID : string ,
625- categoryName : string ,
626- isSetupCategoriesTaskParentReportArchived : boolean ,
627- setupCategoryTaskReport : OnyxEntry < Report > ,
628- setupCategoryTaskParentReport : OnyxEntry < Report > ,
629- currentUserAccountID : number ,
630- hasOutstandingChildTask : boolean ,
631- parentReportAction : OnyxEntry < ReportAction > ,
632- ) {
675+ function createPolicyCategory ( {
676+ policyID,
677+ categoryName,
678+ isSetupCategoriesTaskParentReportArchived,
679+ setupCategoryTaskReport,
680+ setupCategoryTaskParentReport,
681+ currentUserAccountID,
682+ hasOutstandingChildTask,
683+ parentReportAction,
684+ setupCategoriesAndTagsTaskReport,
685+ setupCategoriesAndTagsTaskParentReport,
686+ isSetupCategoriesAndTagsTaskParentReportArchived,
687+ setupCategoriesAndTagsHasOutstandingChildTask,
688+ setupCategoriesAndTagsParentReportAction,
689+ policyHasTags,
690+ } : CreatePolicyCategoryParams ) {
633691 const onyxData = buildOptimisticPolicyCategories ( policyID , [ categoryName ] ) ;
634692 appendSetupCategoriesOnboardingData (
635693 onyxData ,
@@ -640,6 +698,18 @@ function createPolicyCategory(
640698 hasOutstandingChildTask ,
641699 parentReportAction ,
642700 ) ;
701+ // Complete the combined "Set up categories and tags" task only if tags already exist
702+ if ( setupCategoriesAndTagsTaskReport && policyHasTags ) {
703+ appendSetupCategoriesOnboardingData (
704+ onyxData ,
705+ setupCategoriesAndTagsTaskReport ,
706+ setupCategoriesAndTagsTaskParentReport ,
707+ isSetupCategoriesAndTagsTaskParentReportArchived ?? false ,
708+ currentUserAccountID ,
709+ setupCategoriesAndTagsHasOutstandingChildTask ?? false ,
710+ setupCategoriesAndTagsParentReportAction ,
711+ ) ;
712+ }
643713 const parameters = {
644714 policyID,
645715 categories : JSON . stringify ( [ { name : categoryName } ] ) ,
0 commit comments