Skip to content

Commit 28a6d10

Browse files
authored
Merge pull request Expensify#65462 from Expensify/chirag-create-control-workspace
[No QA] Create control workspace for specific accounting options
2 parents 9c6f6b3 + 743b59f commit 28a6d10

5 files changed

Lines changed: 56 additions & 20 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,6 +2934,7 @@ const CONST = {
29342934
microsoftDynamics: 'Microsoft Dynamics',
29352935
other: 'Other',
29362936
},
2937+
CORPORATE: ['quickbooksDesktop', 'netsuite', 'intacct', 'oracle', 'sap', 'microsoftDynamics', 'other'],
29372938
AUTH_HELP_LINKS: {
29382939
intacct:
29392940
"https://help.expensify.com/articles/expensify-classic/connections/sage-intacct/Sage-Intacct-Troubleshooting#:~:text=First%20make%20sure%20that%20you,your%20company's%20Web%20Services%20authorizations.",

src/libs/API/parameters/CreateWorkspaceParams.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CreateWorkspaceParams = {
1515
currency: string;
1616
file?: File;
1717
companySize?: string;
18+
userReportedIntegration?: string;
1819
};
1920

2021
export default CreateWorkspaceParams;

src/libs/actions/IOU.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3784,7 +3784,14 @@ function getTrackExpenseInformation(params: GetTrackExpenseInformationParams): T
37843784
let createdWorkspaceParams: CreateWorkspaceParams | undefined;
37853785

37863786
if (isDraftReportLocal) {
3787-
const workspaceData = buildPolicyData(undefined, policy?.makeMeAdmin, policy?.name, policy?.id, chatReport?.reportID, CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE);
3787+
const workspaceData = buildPolicyData({
3788+
policyOwnerEmail: undefined,
3789+
makeMeAdmin: policy?.makeMeAdmin,
3790+
policyName: policy?.name,
3791+
policyID: policy?.id,
3792+
expenseReportId: chatReport?.reportID,
3793+
engagementChoice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE,
3794+
});
37883795
createdWorkspaceParams = workspaceData.params;
37893796
optimisticData.push(...workspaceData.optimisticData);
37903797
successData.push(...workspaceData.successData);
@@ -8806,7 +8813,11 @@ function getPayMoneyRequestParams(
88068813
failureData: policyFailureData,
88078814
successData: policySuccessData,
88088815
params,
8809-
} = buildPolicyData(currentUserEmail, true, undefined, payerPolicyID);
8816+
} = buildPolicyData({
8817+
policyOwnerEmail: currentUserEmail,
8818+
makeMeAdmin: true,
8819+
policyID: payerPolicyID,
8820+
});
88108821
const {adminsChatReportID, adminsCreatedReportActionID, expenseChatReportID, expenseCreatedReportActionID, customUnitRateID, customUnitID, ownerEmail, policyName} = params;
88118822

88128823
policyParams = {

src/libs/actions/Policy/Policy.ts

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {buildTaskData} from '@userActions/Task';
8383
import {getOnboardingMessages} from '@userActions/Welcome/OnboardingFlow';
8484
import type {OnboardingCompanySize, OnboardingPurpose} from '@userActions/Welcome/OnboardingFlow';
8585
import CONST from '@src/CONST';
86+
import type {OnboardingAccounting} from '@src/CONST';
8687
import ONYXKEYS from '@src/ONYXKEYS';
8788
import 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+
139154
const allPolicies: OnyxCollection<Policy> = {};
140155
Onyx.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

src/pages/OnboardingAccounting/BaseOnboardingAccounting.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount
211211
// We need `adminsChatReportID` for `completeOnboarding`, but at the same time, we don't want to call `createWorkspace` more than once.
212212
// If we have already created a workspace, we want to reuse the `onboardingAdminsChatReportID` and `onboardingPolicyID`.
213213
const {adminsChatReportID, policyID} = shouldCreateWorkspace
214-
? createWorkspace(undefined, true, '', generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM, '', undefined, false, onboardingCompanySize)
214+
? createWorkspace(undefined, true, '', generatePolicyID(), CONST.ONBOARDING_CHOICES.MANAGE_TEAM, '', undefined, false, onboardingCompanySize, userReportedIntegration)
215215
: {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID};
216216

217217
if (shouldCreateWorkspace) {

0 commit comments

Comments
 (0)