Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: only pin the selfDM if the onboarding purpose is newDotPersonalSpend #54098

Merged
merged 9 commits into from
Jan 2, 2025
Merged
2 changes: 2 additions & 0 deletions src/libs/API/parameters/CompleteGuidedSetupParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type CompleteGuidedSetupParams = {
companySize?: OnboardingCompanySize;
userReportedIntegration?: OnboardingAccounting;
policyID?: string;
selfDMReportID?: string;
selfDMCreatedReportActionID?: string;
};

export default CompleteGuidedSetupParams;
26 changes: 26 additions & 0 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4594,6 +4594,31 @@ function buildOptimisticTaskCommentReportAction(
return reportAction;
}

function buildOptimisticSelfDMReport(created: string): Report {
return {
reportID: generateReportID(),
participants: {
[currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID]: {
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.MUTE,
},
},
type: CONST.REPORT.TYPE.CHAT,
chatType: CONST.REPORT.CHAT_TYPE.SELF_DM,
isOwnPolicyExpenseChat: false,
isPinned: true,
lastActorAccountID: 0,
lastMessageHtml: '',
lastMessageText: undefined,
lastReadTime: created,
lastVisibleActionCreated: created,
ownerAccountID: currentUserAccountID,
reportName: '',
stateNum: 0,
statusNum: 0,
writeCapability: CONST.REPORT.WRITE_CAPABILITIES.ALL,
};
}

/**
* Builds an optimistic IOU report with a randomly generated reportID
*
Expand Down Expand Up @@ -8901,6 +8926,7 @@ export {
getAllReportActionsErrorsAndReportActionThatRequiresAttention,
hasInvoiceReports,
getReportMetadata,
buildOptimisticSelfDMReport,
isHiddenForCurrentUser,
};

Expand Down
92 changes: 74 additions & 18 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4012,24 +4012,78 @@ function prepareOnboardingOptimisticData(
guidedSetupData.push({type: 'video', ...data.video, ...videoMessage});
}

if (engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM) {
type SelfDMParameters = {
reportID?: string;
createdReportActionID?: string;
};

let selfDMParameters: SelfDMParameters = {};
if (engagementChoice === CONST.ONBOARDING_CHOICES.PERSONAL_SPEND) {
const selfDMReportID = ReportUtils.findSelfDMReportID();
const selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
isPinned: false,
},
});
let selfDMReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`];
let createdAction: ReportAction;
if (!selfDMReport) {
MonilBhavsar marked this conversation as resolved.
Show resolved Hide resolved
const currentTime = DateUtils.getDBTime();
selfDMReport = ReportUtils.buildOptimisticSelfDMReport(currentTime);
createdAction = ReportUtils.buildOptimisticCreatedReportAction(currentUserEmail ?? '', currentTime);
selfDMParameters = {reportID: selfDMReport.reportID, createdReportActionID: createdAction.reportActionID};
optimisticData.push(
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`,
value: {
...selfDMReport,
pendingFields: {
createChat: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
},
},
},
{
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`,
value: {
[createdAction.reportActionID]: createdAction,
},
},
);

failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
isPinned: selfDMReport?.isPinned,
},
});
successData.push(
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReport.reportID}`,
value: {
pendingFields: {
createChat: null,
},
},
},
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${selfDMReport.reportID}`,
value: {
[createdAction.reportActionID]: {
pendingAction: null,
},
},
},
);
} else {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
isPinned: true,
},
});

failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${selfDMReportID}`,
value: {
isPinned: selfDMReport?.isPinned,
},
});
}
}

optimisticData.push({
Expand Down Expand Up @@ -4060,7 +4114,7 @@ function prepareOnboardingOptimisticData(

guidedSetupData.push(...tasksForParameters, {type: 'message', ...welcomeSignOffMessage});

return {optimisticData, successData, failureData, guidedSetupData, actorAccountID};
return {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters};
}

function completeOnboarding(
Expand All @@ -4075,7 +4129,7 @@ function completeOnboarding(
userReportedIntegration?: OnboardingAccounting,
wasInvited?: boolean,
) {
const {optimisticData, successData, failureData, guidedSetupData, actorAccountID} = prepareOnboardingOptimisticData(
const {optimisticData, successData, failureData, guidedSetupData, actorAccountID, selfDMParameters} = prepareOnboardingOptimisticData(
engagementChoice,
data,
adminsChatReportID,
Expand All @@ -4094,6 +4148,8 @@ function completeOnboarding(
companySize,
userReportedIntegration,
policyID: onboardingPolicyID,
selfDMReportID: selfDMParameters.reportID,
selfDMCreatedReportActionID: selfDMParameters.createdReportActionID,
};

API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData, failureData});
Expand Down
Loading