@@ -83,6 +83,7 @@ import {buildTaskData} from '@userActions/Task';
8383import { getOnboardingMessages } from '@userActions/Welcome/OnboardingFlow' ;
8484import type { OnboardingCompanySize , OnboardingPurpose } from '@userActions/Welcome/OnboardingFlow' ;
8585import CONST from '@src/CONST' ;
86+ import type { OnboardingAccounting } from '@src/CONST' ;
8687import ONYXKEYS from '@src/ONYXKEYS' ;
8788import type {
8889 IntroSelected ,
@@ -136,6 +137,20 @@ type WorkspaceFromIOUCreationData = {
136137 adminsChatReportID : string ;
137138} ;
138139
140+ type BuildPolicyDataOptions = {
141+ policyOwnerEmail ?: string ;
142+ makeMeAdmin ?: boolean ;
143+ policyName ?: string ;
144+ policyID ?: string ;
145+ expenseReportId ?: string ;
146+ engagementChoice ?: OnboardingPurpose ;
147+ currency ?: string ;
148+ file ?: File ;
149+ shouldAddOnboardingTasks ?: boolean ;
150+ companySize ?: OnboardingCompanySize ;
151+ userReportedIntegration ?: OnboardingAccounting ;
152+ } ;
153+
139154const allPolicies : OnyxCollection < Policy > = { } ;
140155Onyx . connect ( {
141156 key : ONYXKEYS . COLLECTION . POLICY ,
@@ -1842,18 +1857,20 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol
18421857 * @param [file] Optional, avatar file for workspace
18431858 * @param [shouldAddOnboardingTasks] whether to add onboarding tasks to the workspace
18441859 */
1845- function buildPolicyData (
1846- policyOwnerEmail = '' ,
1847- makeMeAdmin = false ,
1848- policyName = '' ,
1849- policyID = generatePolicyID ( ) ,
1850- expenseReportId ?: string ,
1851- engagementChoice ?: OnboardingPurpose ,
1852- currency = '' ,
1853- file ?: File ,
1854- shouldAddOnboardingTasks = true ,
1855- companySize ?: OnboardingCompanySize ,
1856- ) {
1860+ function buildPolicyData ( options : BuildPolicyDataOptions = { } ) {
1861+ const {
1862+ policyOwnerEmail = '' ,
1863+ makeMeAdmin = false ,
1864+ policyName = '' ,
1865+ policyID = generatePolicyID ( ) ,
1866+ expenseReportId,
1867+ engagementChoice,
1868+ currency = '' ,
1869+ file,
1870+ shouldAddOnboardingTasks = true ,
1871+ companySize,
1872+ userReportedIntegration,
1873+ } = options ;
18571874 const workspaceName = policyName || generateDefaultWorkspaceName ( policyOwnerEmail ) ;
18581875
18591876 const { customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticDistanceRateCustomUnits ( currency ) ;
@@ -1881,14 +1898,18 @@ function buildPolicyData(
18811898 engagementChoice === CONST . ONBOARDING_CHOICES . TRACK_WORKSPACE ;
18821899 const shouldSetCreatedWorkspaceAsActivePolicy = ! ! activePolicyID && allPolicies ?. [ `${ ONYXKEYS . COLLECTION . POLICY } ${ activePolicyID } ` ] ?. type === CONST . POLICY . TYPE . PERSONAL ;
18831900
1901+ // Determine workspace type based on user reported integration
1902+ const workspaceType =
1903+ userReportedIntegration && ( CONST . POLICY . CONNECTIONS . CORPORATE as readonly string [ ] ) . includes ( userReportedIntegration ) ? CONST . POLICY . TYPE . CORPORATE : CONST . POLICY . TYPE . TEAM ;
1904+
18841905 // WARNING: The data below should be kept in sync with the API so we create the policy with the correct configuration.
18851906 const optimisticData : OnyxUpdate [ ] = [
18861907 {
18871908 onyxMethod : Onyx . METHOD . SET ,
18881909 key : `${ ONYXKEYS . COLLECTION . POLICY } ${ policyID } ` ,
18891910 value : {
18901911 id : policyID ,
1891- type : CONST . POLICY . TYPE . TEAM ,
1912+ type : workspaceType ,
18921913 name : workspaceName ,
18931914 role : CONST . POLICY . ROLE . ADMIN ,
18941915 owner : sessionEmail ,
@@ -2162,7 +2183,7 @@ function buildPolicyData(
21622183 ownerEmail : policyOwnerEmail ,
21632184 makeMeAdmin,
21642185 policyName : workspaceName ,
2165- type : CONST . POLICY . TYPE . TEAM ,
2186+ type : workspaceType ,
21662187 adminsCreatedReportActionID,
21672188 expenseCreatedReportActionID,
21682189 customUnitID,
@@ -2171,6 +2192,7 @@ function buildPolicyData(
21712192 currency : outputCurrency ,
21722193 file : clonedFile ,
21732194 companySize,
2195+ userReportedIntegration : userReportedIntegration ?? undefined ,
21742196 } ;
21752197
21762198 if (
@@ -2221,19 +2243,20 @@ function createWorkspace(
22212243 file ?: File ,
22222244 shouldAddOnboardingTasks = true ,
22232245 companySize ?: OnboardingCompanySize ,
2246+ userReportedIntegration ?: OnboardingAccounting ,
22242247) : CreateWorkspaceParams {
2225- const { optimisticData, failureData, successData, params} = buildPolicyData (
2248+ const { optimisticData, failureData, successData, params} = buildPolicyData ( {
22262249 policyOwnerEmail,
22272250 makeMeAdmin,
22282251 policyName,
22292252 policyID,
2230- undefined ,
22312253 engagementChoice,
22322254 currency,
22332255 file,
22342256 shouldAddOnboardingTasks,
22352257 companySize,
2236- ) ;
2258+ userReportedIntegration,
2259+ } ) ;
22372260
22382261 API . write ( WRITE_COMMANDS . CREATE_WORKSPACE , params , { optimisticData, successData, failureData} ) ;
22392262
0 commit comments