Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@
const parsedReportActionMessageCache: Record<string, string> = {};

let conciergeReportID: OnyxEntry<string>;
Onyx.connect({

Check warning on line 963 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.CONCIERGE_REPORT_ID,
callback: (value) => {
conciergeReportID = value;
Expand All @@ -968,7 +968,7 @@
});

const defaultAvatarBuildingIconTestID = 'SvgDefaultAvatarBuilding Icon';
Onyx.connect({

Check warning on line 971 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
// When signed out, val is undefined
Expand All @@ -986,7 +986,7 @@
let allPersonalDetails: OnyxEntry<PersonalDetailsList>;
let allPersonalDetailLogins: string[];
let currentUserPersonalDetails: OnyxEntry<PersonalDetails>;
Onyx.connect({

Check warning on line 989 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
if (currentUserAccountID) {
Expand All @@ -998,14 +998,14 @@
});

let allReportsDraft: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 1001 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_DRAFT,
waitForCollectionCallback: true,
callback: (value) => (allReportsDraft = value),
});

let allPolicies: OnyxCollection<Policy>;
Onyx.connect({

Check warning on line 1008 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => (allPolicies = value),
Expand All @@ -1020,7 +1020,7 @@

let allReports: OnyxCollection<Report>;
let reportsByPolicyID: ReportByPolicyMap;
Onyx.connect({

Check warning on line 1023 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -1058,14 +1058,14 @@
});

let allBetas: OnyxEntry<Beta[]>;
Onyx.connect({

Check warning on line 1061 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.BETAS,
callback: (value) => (allBetas = value),
});

let allTransactions: OnyxCollection<Transaction> = {};
let reportsTransactions: Record<string, Transaction[]> = {};
Onyx.connect({

Check warning on line 1068 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -1091,7 +1091,7 @@
});

let allReportActions: OnyxCollection<ReportActions>;
Onyx.connect({

Check warning on line 1094 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand All @@ -1104,7 +1104,7 @@

let allReportMetadata: OnyxCollection<ReportMetadata>;
const allReportMetadataKeyValue: Record<string, ReportMetadata> = {};
Onyx.connect({

Check warning on line 1107 in src/libs/ReportUtils.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_METADATA,
waitForCollectionCallback: true,
callback: (value) => {
Expand Down Expand Up @@ -11196,18 +11196,33 @@
return isChatRoom(report) && !isInvoiceRoom(report) && !isThread(report);
}

function prepareOnboardingOnyxData(
introSelected: OnyxEntry<IntroSelected>,
engagementChoice: OnboardingPurpose,
onboardingMessage: OnboardingMessage,
adminsChatReportID?: string,
onboardingPolicyID?: string,
userReportedIntegration?: OnboardingAccounting,
wasInvited?: boolean,
companySize?: OnboardingCompanySize,
selectedInterestedFeatures: string[] = [],
isInvitedAccountant?: boolean,
) {
type PrepareOnboardingOnyxDataParams = {
introSelected: OnyxEntry<IntroSelected>;
engagementChoice: OnboardingPurpose;
onboardingMessage: OnboardingMessage;
adminsChatReportID?: string;
onboardingPolicyID?: string;
userReportedIntegration?: OnboardingAccounting;
wasInvited?: boolean;
companySize?: OnboardingCompanySize;
selectedInterestedFeatures?: string[];
isInvitedAccountant?: boolean;
onboardingPurposeSelected?: OnboardingPurpose;
};

function prepareOnboardingOnyxData({
introSelected,
engagementChoice,
onboardingMessage,
adminsChatReportID,
onboardingPolicyID,
userReportedIntegration,
wasInvited,
companySize,
selectedInterestedFeatures = [],
isInvitedAccountant,
onboardingPurposeSelected,
}: PrepareOnboardingOnyxDataParams) {
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) {
// eslint-disable-next-line no-param-reassign
onboardingMessage = getOnboardingMessages().onboardingMessages[CONST.ONBOARDING_CHOICES.PERSONAL_SPEND];
Expand Down Expand Up @@ -11697,7 +11712,10 @@
guidedSetupData.push({type: 'message', ...textMessage});

let selfDMParameters: SelfDMParameters = {};
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND || engagementChoice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE) {
if (
engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND ||
(engagementChoice === CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE && (!onboardingPurposeSelected || onboardingPurposeSelected === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND))
) {
const selfDMReportID = findSelfDMReportID();
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
let createdAction: ReportAction;
Expand Down Expand Up @@ -13085,5 +13103,6 @@
ParsingDetails,
MissingPaymentMethod,
OptimisticNewReport,
PrepareOnboardingOnyxDataParams,
SelfDMParameters,
};
10 changes: 5 additions & 5 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6149,11 +6149,11 @@ function requestMoney(requestMoneyInformation: RequestMoneyInformation): {iouRep
default: {
// This is only required when inviting admins to test drive the app
const guidedSetupData: GuidedSetupData | undefined = isTestDrive
? prepareOnboardingOnyxData(
{choice: CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER},
CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER,
getOnboardingMessages().onboardingMessages[CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER],
)?.guidedSetupData
? prepareOnboardingOnyxData({
introSelected: {choice: CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER},
engagementChoice: CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER,
onboardingMessage: getOnboardingMessages().onboardingMessages[CONST.ONBOARDING_CHOICES.TEST_DRIVE_RECEIVER],
})?.guidedSetupData
: undefined;

const parameters: RequestMoneyParams = {
Expand Down
11 changes: 10 additions & 1 deletion src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ type BuildPolicyDataOptions = {
lastUsedPaymentMethod?: LastPaymentMethodType;
adminParticipant?: Participant;
hasOutstandingChildRequest?: boolean;
onboardingPurposeSelected?: OnboardingPurpose;
shouldAddGuideWelcomeMessage?: boolean;
};

Expand Down Expand Up @@ -2044,6 +2045,7 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
adminParticipant,
hasOutstandingChildRequest = true,
shouldAddGuideWelcomeMessage = true,
onboardingPurposeSelected,
} = options;
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);

Expand Down Expand Up @@ -2428,7 +2430,14 @@ function buildPolicyData(options: BuildPolicyDataOptions = {}) {
shouldAddOnboardingTasks
) {
const {onboardingMessages} = getOnboardingMessages();
const onboardingData = ReportUtils.prepareOnboardingOnyxData(deprecatedIntroSelected, engagementChoice, onboardingMessages[engagementChoice], adminsChatReportID, policyID);
const onboardingData = ReportUtils.prepareOnboardingOnyxData({
introSelected: deprecatedIntroSelected,
engagementChoice,
onboardingMessage: onboardingMessages[engagementChoice],
adminsChatReportID,
onboardingPolicyID: policyID,
onboardingPurposeSelected,
});
if (!onboardingData) {
return {successData, optimisticData, failureData, params};
}
Expand Down
13 changes: 10 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,11 @@ function openReport(
onboardingMessage.tasks = updatedTasks;
}

const onboardingData = prepareOnboardingOnyxData(introSelected, choice, onboardingMessage);
const onboardingData = prepareOnboardingOnyxData({
introSelected,
engagementChoice: choice,
onboardingMessage,
});

if (onboardingData) {
optimisticData.push(...onboardingData.optimisticData, {
Expand Down Expand Up @@ -4272,6 +4276,7 @@ function completeOnboarding({
selectedInterestedFeatures = [],
shouldSkipTestDriveModal,
isInvitedAccountant,
onboardingPurposeSelected,
}: {
engagementChoice: OnboardingPurpose;
onboardingMessage: OnboardingMessage;
Expand All @@ -4286,8 +4291,9 @@ function completeOnboarding({
selectedInterestedFeatures?: string[];
shouldSkipTestDriveModal?: boolean;
isInvitedAccountant?: boolean;
onboardingPurposeSelected?: OnboardingPurpose;
}) {
const onboardingData = prepareOnboardingOnyxData(
const onboardingData = prepareOnboardingOnyxData({
introSelected,
engagementChoice,
onboardingMessage,
Expand All @@ -4298,7 +4304,8 @@ function completeOnboarding({
companySize,
selectedInterestedFeatures,
isInvitedAccountant,
);
onboardingPurposeSelected,
});
if (!onboardingData) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function BaseOnboardingWorkspaceConfirmation({shouldUseNativeStyles}: BaseOnboar
file: undefined,
shouldAddOnboardingTasks: false,
shouldAddGuideWelcomeMessage: false,
onboardingPurposeSelected,
})
: {adminsChatReportID: onboardingAdminsChatReportID, policyID: onboardingPolicyID};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
const {translate, formatPhoneNumber} = useLocalize();
const [onboardingPolicyID] = useOnyx(ONYXKEYS.ONBOARDING_POLICY_ID, {canBeMissing: true});
const [onboardingAdminsChatReportID] = useOnyx(ONYXKEYS.ONBOARDING_ADMINS_CHAT_REPORT_ID, {canBeMissing: true});
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});
const policy = usePolicy(onboardingPolicyID);
const {onboardingMessages} = useOnboardingMessages();
// We need to use isSmallScreenWidth, see navigateAfterOnboarding function comment
Expand Down Expand Up @@ -137,6 +138,7 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
onboardingPolicyID,
shouldSkipTestDriveModal: !!onboardingPolicyID && !onboardingAdminsChatReportID,
isInvitedAccountant,
onboardingPurposeSelected,
Comment thread
gijoe0295 marked this conversation as resolved.
});

setOnboardingAdminsChatReportID();
Expand All @@ -158,6 +160,7 @@ function BaseOnboardingWorkspaceInvite({shouldUseNativeStyles}: BaseOnboardingWo
currentUserPersonalDetails.lastName,
onboardingAdminsChatReportID,
onboardingPolicyID,
onboardingPurposeSelected,
isSmallScreenWidth,
isBetaEnabled,
session?.email,
Expand Down
5 changes: 4 additions & 1 deletion src/pages/iou/request/step/IOURequestStepUpgrade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function IOURequestStepUpgrade({
const personalDetails = usePersonalDetails();

const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transactionID}`, {canBeMissing: true});
const [onboardingPurposeSelected] = useOnyx(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, {canBeMissing: true});

const [isUpgraded, setIsUpgraded] = useState(false);
const [showConfirmationForm, setShowConfirmationForm] = useState(false);
Expand Down Expand Up @@ -142,10 +143,11 @@ function IOURequestStepUpgrade({
],
adminParticipant,
hasOutstandingChildRequest: false,
onboardingPurposeSelected,
});
setIsUpgraded(true);
policyDataRef.current = policyData;
}, [isCategorizing, isReporting, currentUserPersonalDetails?.localCurrencyCode, isDistanceRateUpgrade, adminParticipant]);
}, [isCategorizing, isReporting, currentUserPersonalDetails?.localCurrencyCode, isDistanceRateUpgrade, adminParticipant, onboardingPurposeSelected]);

const [session] = useOnyx(ONYXKEYS.SESSION, {canBeMissing: false});

Expand All @@ -158,6 +160,7 @@ function IOURequestStepUpgrade({
currency: params.currency,
file: params.avatarFile as File,
engagementChoice: CONST.ONBOARDING_CHOICES.TRACK_WORKSPACE,
onboardingPurposeSelected,
});
policyDataRef.current = policyData;
setCreatedPolicyName(params.name);
Expand Down
54 changes: 25 additions & 29 deletions tests/unit/ReportUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ describe('ReportUtils', () => {
it('provides test drive url to task title', () => {
const title = jest.fn();

prepareOnboardingOnyxData(
undefined,
CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
{
prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [
{
Expand All @@ -423,8 +423,8 @@ describe('ReportUtils', () => {
},
],
},
'1',
);
adminsChatReportID: '1',
});

expect(title).toHaveBeenCalledWith(
expect.objectContaining<OnboardingTaskLinks>({
Expand All @@ -437,10 +437,10 @@ describe('ReportUtils', () => {
it('provides test drive url to task description', () => {
const description = jest.fn();

prepareOnboardingOnyxData(
undefined,
CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
{
prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [
{
Expand All @@ -452,8 +452,8 @@ describe('ReportUtils', () => {
},
],
},
'1',
);
adminsChatReportID: '1',
});

expect(description).toHaveBeenCalledWith(
expect.objectContaining<OnboardingTaskLinks>({
Expand All @@ -464,36 +464,32 @@ describe('ReportUtils', () => {
});

it('should not create tasks if the task feature is not in the selected interested features', () => {
const result = prepareOnboardingOnyxData(
undefined,
CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
{
const result = prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [{type: CONST.ONBOARDING_TASK_TYPE.CONNECT_CORPORATE_CARD, title: () => '', description: () => '', autoCompleted: false, mediaAttributes: {}}],
},
'1',
undefined,
undefined,
undefined,
undefined,
['categories', 'accounting', 'tags'],
);
adminsChatReportID: '1',
selectedInterestedFeatures: ['categories', 'accounting', 'tags'],
});

expect(result?.guidedSetupData.filter((data) => data.type === 'task')).toHaveLength(0);
});

it('includes avatar in optimistic Setup Specialist personal detail', () => {
const mergeSpy = jest.spyOn(Onyx, 'merge');

prepareOnboardingOnyxData(
undefined,
CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
{
prepareOnboardingOnyxData({
introSelected: undefined,
engagementChoice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
onboardingMessage: {
message: 'This is a test',
tasks: [],
},
'1',
);
adminsChatReportID: '1',
});

const personalDetailsCall = mergeSpy.mock.calls.find((call) => call[0] === ONYXKEYS.PERSONAL_DETAILS_LIST);
const personalDetailsData = personalDetailsCall?.[1] as Record<string, {avatar?: string; login?: string; displayName?: string}>;
Expand Down
Loading