Skip to content

Commit

Permalink
fix: post tasks in admin room
Browse files Browse the repository at this point in the history
  • Loading branch information
ishpaul777 committed Jan 19, 2025
1 parent b315040 commit bb02e14
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
12 changes: 10 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1699,7 +1699,15 @@ Onyx.connect({
* @param [engagementChoice] the engagement choice for the workspace
* @param [shouldAddOnboardingTasks] whether to add onboarding tasks to the workspace
*/
function buildPolicyData(policyOwnerEmail = '', makeMeAdmin = false, policyName = '', policyID = generatePolicyID(), expenseReportId?: string, engagementChoice?: OnboardingPurpose, shouldAddOnboardingTasks = true) {
function buildPolicyData(
policyOwnerEmail = '',
makeMeAdmin = false,
policyName = '',
policyID = generatePolicyID(),
expenseReportId?: string,
engagementChoice?: OnboardingPurpose,
shouldAddOnboardingTasks = true,
) {
const workspaceName = policyName || generateDefaultWorkspaceName(policyOwnerEmail);

const {customUnits, customUnitID, customUnitRateID, outputCurrency} = buildOptimisticDistanceRateCustomUnits();
Expand Down Expand Up @@ -1963,7 +1971,7 @@ Onyx.connect({
customUnitRateID,
};

if (!introSelected?.createWorkspace && engagementChoice && shouldAddOnboardingTasks) {
if (engagementChoice && shouldAddOnboardingTasks) {
const {
guidedSetupData,
optimisticData: taskOptimisticData,
Expand Down
34 changes: 20 additions & 14 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3618,12 +3618,14 @@ function prepareOnboardingOnyxData(
!currentUserEmail?.includes('+');
const integrationName = userReportedIntegration ? CONST.ONBOARDING_ACCOUNTING_MAPPING[userReportedIntegration] : '';
const adminsChatReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${adminsChatReportID}`];
const targetChatReport = shouldPostTasksInAdminsRoom ? adminsChatReport : getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, currentUserAccountID]);
const targetChatReport = shouldPostTasksInAdminsRoom
? adminsChatReport ?? {reportID: adminsChatReportID, policyID: onboardingPolicyID}
: getChatByParticipants([CONST.ACCOUNT_ID.CONCIERGE, currentUserAccountID]);
const {reportID: targetChatReportID = '', policyID: targetChatPolicyID = ''} = targetChatReport ?? {};
const assignedGuideEmail = getPolicy(targetChatPolicyID)?.assignedGuide?.email ?? 'Setup Specialist';
const assignedGuidePersonalDetail = Object.values(allPersonalDetails ?? {}).find((personalDetail) => personalDetail?.login === assignedGuideEmail);
let assignedGuideAccountID: number;
if (assignedGuidePersonalDetail) {
if (assignedGuidePersonalDetail && assignedGuidePersonalDetail.accountID) {
assignedGuideAccountID = assignedGuidePersonalDetail.accountID;
} else {
assignedGuideAccountID = generateAccountID(assignedGuideEmail);
Expand Down Expand Up @@ -3669,9 +3671,13 @@ function prepareOnboardingOnyxData(
type SkipViewTourOnboardingChoices = 'newDotSubmit' | 'newDotSplitChat' | 'newDotPersonalSpend' | 'newDotEmployer';
if (
task.type === 'viewTour' &&
[CONST.ONBOARDING_CHOICES.EMPLOYER, CONST.ONBOARDING_CHOICES.PERSONAL_SPEND, CONST.ONBOARDING_CHOICES.SUBMIT, CONST.ONBOARDING_CHOICES.CHAT_SPLIT].includes(
introSelected?.choice as SkipViewTourOnboardingChoices,
) &&
[
CONST.ONBOARDING_CHOICES.EMPLOYER,
CONST.ONBOARDING_CHOICES.PERSONAL_SPEND,
CONST.ONBOARDING_CHOICES.SUBMIT,
CONST.ONBOARDING_CHOICES.CHAT_SPLIT,
CONST.ONBOARDING_CHOICES.MANAGE_TEAM,
].includes(introSelected?.choice as SkipViewTourOnboardingChoices) &&
engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM
) {
return false;
Expand Down Expand Up @@ -3916,8 +3922,8 @@ function prepareOnboardingOnyxData(
},
);

// If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom) {
// If we post tasks in the #admins room and introSelected?.choice does not exist, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom || !!introSelected?.choice) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
Expand All @@ -3937,8 +3943,8 @@ function prepareOnboardingOnyxData(

const successData: OnyxUpdate[] = [...tasksForSuccessData];

// If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom) {
// If we post tasks in the #admins room and introSelected?.choice does not exist, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom || !!introSelected?.choice) {
successData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
Expand Down Expand Up @@ -3984,8 +3990,8 @@ function prepareOnboardingOnyxData(
},
},
);
// If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom) {
// If we post tasks in the #admins room and introSelected?.choice does not exist, it means that a guide is assigned and all messages except tasks are handled by the backend
if (!shouldPostTasksInAdminsRoom || !!introSelected?.choice) {
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
Expand Down Expand Up @@ -4037,10 +4043,10 @@ function prepareOnboardingOnyxData(
});
}

// If we post tasks in the #admins room, it means that a guide is assigned and all messages except tasks are handled by the backend
const guidedSetupData: GuidedSetupData = shouldPostTasksInAdminsRoom ? [] : [{type: 'message', ...textMessage}];
// If we post tasks in the #admins room and introSelected?.choice does not exist, it means that a guide is assigned and all messages except tasks are handled by the backend
const guidedSetupData: GuidedSetupData = shouldPostTasksInAdminsRoom && !!introSelected?.choice ? [] : [{type: 'message', ...textMessage}];

if (!shouldPostTasksInAdminsRoom && 'video' in data && data.video && videoCommentAction && videoMessage) {
if ((!shouldPostTasksInAdminsRoom || !!introSelected?.choice) && 'video' in data && data.video && videoCommentAction && videoMessage) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`,
Expand Down

0 comments on commit bb02e14

Please sign in to comment.