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
5 changes: 3 additions & 2 deletions src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import type {InvitedEmailsToAccountIDs, PersonalDetailsList, Policy, PolicyEmplo
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
import type {JoinWorkspaceResolution} from '@src/types/onyx/OriginalMessage';
import type {ApprovalRule} from '@src/types/onyx/Policy';
import type {Participant} from '@src/types/onyx/Report';
import type {NotificationPreference, Participant} from '@src/types/onyx/Report';
import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {createPolicyExpenseChats} from './Policy';
Expand Down Expand Up @@ -880,6 +880,7 @@ function buildAddMembersToWorkspaceOnyxData(
policyMemberAccountIDs: number[],
role: string,
formatPhoneNumber: LocaleContextProps['formatPhoneNumber'],
policyExpenseChatNotificationPreference?: NotificationPreference,
) {
const logins = Object.keys(invitedEmailsToAccountIDs).map((memberLogin) => PhoneNumber.addSMSDomainIfPhoneNumber(memberLogin));
const accountIDs = Object.values(invitedEmailsToAccountIDs);
Expand All @@ -899,7 +900,7 @@ function buildAddMembersToWorkspaceOnyxData(
const announceRoomChat = optimisticAnnounceChat.announceChatData;

// create onyx data for policy expense chats for each new member
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs);
const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs, undefined, policyExpenseChatNotificationPreference);

const optimisticMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
const successMembersState: OnyxCollectionInputValue<PolicyEmployee> = {};
Expand Down
10 changes: 8 additions & 2 deletions src/libs/actions/Policy/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import type {
import type {Errors} from '@src/types/onyx/OnyxCommon';
import type {Attributes, CompanyAddress, CustomUnit, NetSuiteCustomList, NetSuiteCustomSegment, ProhibitedExpenses, Rate, TaxRate} from '@src/types/onyx/Policy';
import type {CustomFieldType} from '@src/types/onyx/PolicyEmployee';
import type {NotificationPreference} from '@src/types/onyx/Report';
import type {OnyxData} from '@src/types/onyx/Request';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {buildOptimisticMccGroup, buildOptimisticPolicyCategories} from './Category';
Expand Down Expand Up @@ -1158,7 +1159,12 @@ function verifySetupIntentAndRequestPolicyOwnerChange(policyID: string) {
*
* @returns - object with onyxSuccessData, onyxOptimisticData, and optimisticReportIDs (map login to reportID)
*/
function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs, hasOutstandingChildRequest = false): WorkspaceMembersChats {
function createPolicyExpenseChats(
policyID: string,
invitedEmailsToAccountIDs: InvitedEmailsToAccountIDs,
hasOutstandingChildRequest = false,
notificationPreference: NotificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
): WorkspaceMembersChats {
const workspaceMembersChats: WorkspaceMembersChats = {
onyxSuccessData: [],
onyxOptimisticData: [],
Expand Down Expand Up @@ -1221,7 +1227,7 @@ function createPolicyExpenseChats(policyID: string, invitedEmailsToAccountIDs: I
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
policyID,
ownerAccountID: cleanAccountID,
notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN,
notificationPreference,
});

// Set correct notification preferences: visible for the submitter, hidden for others until there's activity
Expand Down
7 changes: 4 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5523,7 +5523,7 @@ function navigateToTrainingModal(dismissedProductTrainingNVP: OnyxEntry<Dismisse
Navigation.navigate(ROUTES.CHANGE_POLICY_EDUCATIONAL.getRoute(ROUTES.REPORT_WITH_ID.getRoute(reportID)));
}

function buildOptimisticChangePolicyData(report: Report, policyID: string, reportNextStep?: ReportNextStep) {
function buildOptimisticChangePolicyData(report: Report, policyID: string, reportNextStep?: ReportNextStep, optimisticPolicyExpenseChatReport?: Report) {
const optimisticData: OnyxUpdate[] = [];
const successData: OnyxUpdate[] = [];
const failureData: OnyxUpdate[] = [];
Expand Down Expand Up @@ -5651,7 +5651,7 @@ function buildOptimisticChangePolicyData(report: Report, policyID: string, repor

// 3. Optimistically create a new REPORT_PREVIEW reportAction with the newReportPreviewActionID
// and set it as a parent of the moved report
const policyExpenseChat = getPolicyExpenseChat(currentUserAccountID, policyID);
const policyExpenseChat = optimisticPolicyExpenseChatReport ?? getPolicyExpenseChat(report.ownerAccountID, policyID);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@truph01 Could you please provide a test step in case optimisticPolicyExpenseChatReport is valuable

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump @truph01

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DylanDylann The optimisticPolicyExpenseChatReport is valuable when we call changeReportPolicyAndInviteSubmitter, so this scenario is already covered by the test case mentioned in the Tests section of the PR author checklist.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@truph01 Then please add a test in case we don't need to create optimistic chat

const optimisticReportPreviewAction = buildOptimisticReportPreview(policyExpenseChat, report);

const newPolicyExpenseChatReportID = policyExpenseChat?.reportID;
Expand Down Expand Up @@ -5790,6 +5790,7 @@ function changeReportPolicyAndInviteSubmitter(report: Report, policyID: string,
policyMemberAccountIDs,
CONST.POLICY.ROLE.USER,
formatPhoneNumber,
CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS,
);
const optimisticPolicyExpenseChatReportID = membersChats.reportCreationData[submitterEmail].reportID;
const optimisticPolicyExpenseChatCreatedReportActionID = membersChats.reportCreationData[submitterEmail].reportActionID;
Expand All @@ -5804,7 +5805,7 @@ function changeReportPolicyAndInviteSubmitter(report: Report, policyID: string,
failureData: failureChangePolicyData,
optimisticReportPreviewAction,
optimisticMovedReportAction,
} = buildOptimisticChangePolicyData(report, policyID);
} = buildOptimisticChangePolicyData(report, policyID, undefined, membersChats.reportCreationData[submitterEmail]);
optimisticData.push(...optimisticChangePolicyData);
successData.push(...successChangePolicyData);
failureData.push(...failureChangePolicyData);
Expand Down