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

Remove invoice room invite message created optimistically #41887

Merged
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
43 changes: 0 additions & 43 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import type {
OriginalMessageCreated,
OriginalMessageReimbursementDequeued,
OriginalMessageRenamed,
OriginalMessageRoomChangeLog,
PaymentMethodType,
ReimbursementDeQueuedMessage,
} from '@src/types/onyx/OriginalMessage';
Expand Down Expand Up @@ -118,8 +117,6 @@ type SpendBreakdown = {

type ParticipantDetails = [number, string, UserUtils.AvatarSource, UserUtils.AvatarSource];

type OptimisticInviteReportAction = ReportActionBase & OriginalMessageRoomChangeLog;

type OptimisticAddCommentReportAction = Pick<
ReportAction,
| 'reportActionID'
Expand Down Expand Up @@ -3378,44 +3375,6 @@ function getPolicyDescriptionText(policy: OnyxEntry<Policy>): string {
return parser.htmlToText(policy.description);
}

/** Builds an optimistic reportAction for the invite message */
function buildOptimisticInviteReportAction(invitedUserDisplayName: string, invitedUserID: number): OptimisticInviteReportAction {
const text = `${Localize.translateLocal('workspace.invite.invited')} ${invitedUserDisplayName}`;
const commentText = getParsedComment(text);
const parser = new ExpensiMark();
const currentUser = allPersonalDetails?.[currentUserAccountID ?? -1];

return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM,
actorAccountID: currentUserAccountID,
person: [
{
style: 'strong',
text: currentUser?.displayName ?? currentUserEmail,
type: 'TEXT',
},
],
automatic: false,
avatar: currentUser?.avatar ?? UserUtils.getDefaultAvatarURL(currentUserAccountID),
created: DateUtils.getDBTime(),
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
html: commentText,
text: parser.htmlToText(commentText),
},
],
originalMessage: {
targetAccountIDs: [invitedUserID],
},
isFirstItem: false,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
shouldShow: true,
isOptimisticAction: true,
};
}

function buildOptimisticAddCommentReportAction(
text?: string,
file?: FileObject,
Expand Down Expand Up @@ -6764,7 +6723,6 @@ export {
updateReportPreview,
temporary_getMoneyRequestOptions,
buildOptimisticInvoiceReport,
buildOptimisticInviteReportAction,
getInvoiceChatByParticipants,
shouldShowMerchantColumn,
isCurrentUserInvoiceReceiver,
Expand All @@ -6783,6 +6741,5 @@ export type {
OptimisticTaskReportAction,
OptionData,
TransactionDetails,
OptimisticInviteReportAction,
ParsingDetails,
};
11 changes: 2 additions & 9 deletions src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import Permissions from '@libs/Permissions';
import * as PhoneNumber from '@libs/PhoneNumber';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticInviteReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils';
import type {OptimisticChatReport, OptimisticCreatedReportAction, OptimisticIOUReportAction, TransactionDetails} from '@libs/ReportUtils';
import * as ReportUtils from '@libs/ReportUtils';
import * as TransactionUtils from '@libs/TransactionUtils';
import * as UserUtils from '@libs/UserUtils';
Expand Down Expand Up @@ -816,7 +816,6 @@ function buildOnyxDataForInvoice(
isNewChatReport: boolean,
transactionThreadReport: OptimisticChatReport,
transactionThreadCreatedReportAction: OptimisticCreatedReportAction | EmptyObject,
inviteReportAction?: OptimisticInviteReportAction,
policy?: OnyxEntry<OnyxTypes.Policy>,
policyTagList?: OnyxEntry<OnyxTypes.PolicyTagList>,
policyCategories?: OnyxEntry<OnyxTypes.PolicyCategories>,
Expand All @@ -840,12 +839,11 @@ function buildOnyxDataForInvoice(
key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`,
value: transaction,
},
isNewChatReport && inviteReportAction
isNewChatReport
? {
onyxMethod: Onyx.METHOD.SET,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${chatReport?.reportID}`,
value: {
[inviteReportAction.reportActionID]: inviteReportAction as ReportAction,
[chatCreatedAction.reportActionID]: chatCreatedAction,
[reportPreviewAction.reportActionID]: reportPreviewAction,
},
Expand Down Expand Up @@ -1673,7 +1671,6 @@ function getSendInvoiceInformation(
}

// STEP 5: Build optimistic reportActions.
let inviteReportAction: OptimisticInviteReportAction | undefined;
const [optimisticCreatedActionForChat, optimisticCreatedActionForIOUReport, iouAction, optimisticTransactionThread, optimisticCreatedActionForTransactionThread] =
ReportUtils.buildOptimisticMoneyRequestEntities(
optimisticInvoiceReport,
Expand All @@ -1690,9 +1687,6 @@ function getSendInvoiceInformation(
receiptObject,
false,
);
if (isNewChatReport) {
inviteReportAction = ReportUtils.buildOptimisticInviteReportAction(receiver?.displayName ?? '', receiver.accountID ?? -1);
}
const reportPreviewAction = ReportUtils.buildOptimisticReportPreview(chatReport, optimisticInvoiceReport, trimmedComment, optimisticTransaction);

// STEP 6: Build Onyx Data
Expand All @@ -1710,7 +1704,6 @@ function getSendInvoiceInformation(
isNewChatReport,
optimisticTransactionThread,
optimisticCreatedActionForTransactionThread,
inviteReportAction,
policy,
policyTagList,
policyCategories,
Expand Down
Loading