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

[Held requests] break held message into separate system message + comment #38738

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ const CONST = {
EXPORTEDTOQUICKBOOKS: 'EXPORTEDTOQUICKBOOKS', // OldDot Action
FORWARDED: 'FORWARDED', // OldDot Action
HOLD: 'HOLD',
HOLDCOMMENT: 'HOLDCOMMENT',
IOU: 'IOU',
INTEGRATIONSMESSAGE: 'INTEGRATIONSMESSAGE', // OldDot Action
MANAGERATTACHRECEIPT: 'MANAGERATTACHRECEIPT', // OldDot Action
Expand Down
2 changes: 1 addition & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
FormattedMaxLengthParams,
GoBackMessageParams,
GoToRoomParams,
HeldRequestParams,

Check failure on line 29 in src/languages/en.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'HeldRequestParams' is defined but never used
InstantSummaryParams,
LocalTimeParams,
LoggedInAsParams,
Expand Down Expand Up @@ -691,7 +691,7 @@
hold: 'Hold',
holdRequest: 'Hold request',
unholdRequest: 'Unhold request',
heldRequest: ({comment}: HeldRequestParams) => `held this request with the comment: ${comment}`,
heldRequest: 'held this request with the comment:',
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
unheldRequest: 'unheld this request',
explainHold: "Explain why you're holding this request.",
reason: 'Reason',
Expand Down
2 changes: 1 addition & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
FormattedMaxLengthParams,
GoBackMessageParams,
GoToRoomParams,
HeldRequestParams,

Check failure on line 28 in src/languages/es.ts

View workflow job for this annotation

GitHub Actions / Run ESLint

'HeldRequestParams' is defined but never used
InstantSummaryParams,
LocalTimeParams,
LoggedInAsParams,
Expand Down Expand Up @@ -688,7 +688,7 @@
enableWallet: 'Habilitar Billetera',
holdRequest: 'Bloquear solicitud',
unholdRequest: 'Desbloquear solicitud',
heldRequest: ({comment}: HeldRequestParams) => `bloqueó esta solicitud con el comentario: ${comment}`,
heldRequest: 'bloqueó esta solicitud con el comentario:',
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
unheldRequest: 'desbloqueó esta solicitud',
explainHold: 'Explica la razón para bloquear esta solicitud.',
reason: 'Razón',
Expand Down
1 change: 1 addition & 0 deletions src/libs/API/parameters/HoldMoneyRequestParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ type HoldMoneyRequestParams = {
transactionID: string;
comment: string;
reportActionID: string;
commentReportActionID: string;
};

export default HoldMoneyRequestParams;
34 changes: 31 additions & 3 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3787,7 +3787,7 @@ function buildOptimisticRenamedRoomReportAction(newName: string, oldName: string
* Returns the necessary reportAction onyx data to indicate that the transaction has been put on hold optimistically
* @param [created] - Action created time
*/
function buildOptimisticHoldReportAction(comment: string, created = DateUtils.getDBTime()): OptimisticHoldReportAction {
function buildOptimisticHoldReportAction(created = DateUtils.getDBTime()): OptimisticHoldReportAction {
return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.HOLD,
Expand All @@ -3797,10 +3797,37 @@ function buildOptimisticHoldReportAction(comment: string, created = DateUtils.ge
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'normal',
text: Localize.translateLocal('iou.heldRequest', {comment}),
text: Localize.translateLocal('iou.heldRequest'),
},
],
person: [
{
type: CONST.REPORT.MESSAGE.TYPE.COMMENT,
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
style: 'strong',
text: getCurrentUserDisplayNameOrEmail(),
},
],
automatic: false,
avatar: getCurrentUserAvatarOrDefault(),
created,
shouldShow: true,
};
}

/**
* Returns the necessary reportAction onyx data to indicate that the transaction has been put on hold optimistically
* @param [created] - Action created time
*/
function buildOptimisticHoldReportActionComment(comment: string, created = DateUtils.getDBTime()): OptimisticHoldReportAction {
return {
reportActionID: NumberUtils.rand64(),
actionName: CONST.REPORT.ACTIONS.TYPE.HOLDCOMMENT,
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD,
actorAccountID: currentUserAccountID,
message: [
{
type: CONST.REPORT.MESSAGE.TYPE.TEXT,
Copy link
Contributor

@hoangzinh hoangzinh Jun 8, 2024

Choose a reason for hiding this comment

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

Comming from #40408, this message type should be CONST.REPORT.MESSAGE.TYPE.COMMENT. Otherwise, it causes inconsistency with BE and displaying style

style: 'normal',
text: comment,
},
],
Expand Down Expand Up @@ -5629,6 +5656,7 @@ export {
hasSmartscanError,
shouldAutoFocusOnKeyPress,
buildOptimisticHoldReportAction,
buildOptimisticHoldReportActionComment,
buildOptimisticUnHoldReportAction,
shouldDisplayThreadReplies,
shouldDisableThread,
Expand Down
5 changes: 4 additions & 1 deletion src/libs/actions/IOU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5032,14 +5032,16 @@ function getIOUReportID(iou?: OnyxTypes.IOU, route?: MoneyRequestRoute): string
* Put money request on HOLD
*/
function putOnHold(transactionID: string, comment: string, reportID: string) {
const createdReportAction = ReportUtils.buildOptimisticHoldReportAction(comment);
const createdReportAction = ReportUtils.buildOptimisticHoldReportAction();
const createdReportActionComment = ReportUtils.buildOptimisticHoldReportActionComment(comment);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have set the lastVisibleActionCreated to createdReportActionComment.created optimistically.
Fixed it in #54793


const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
value: {
[createdReportAction.reportActionID]: createdReportAction as ReportAction,
[createdReportActionComment.reportActionID]: createdReportActionComment as ReportAction,
},
},
{
Expand Down Expand Up @@ -5073,6 +5075,7 @@ function putOnHold(transactionID: string, comment: string, reportID: string) {
transactionID,
comment,
reportActionID: createdReportAction.reportActionID,
commentReportActionID: createdReportActionComment.reportActionID,
},
{optimisticData, successData, failureData},
);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ContextMenu/ContextMenuActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ const ContextMenuActions: ContextMenuAction[] = [
const mentionWhisperMessage = ReportActionsUtils.getActionableMentionWhisperMessage(reportAction);
setClipboardMessage(mentionWhisperMessage);
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
Clipboard.setString(Localize.translateLocal('iou.heldRequest', {comment: reportAction.message?.[1]?.text ?? ''}));
Clipboard.setString(Localize.translateLocal('iou.heldRequest'));
} else if (reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
Clipboard.setString(Localize.translateLocal('iou.unheldRequest'));
} else if (content) {
Expand Down
4 changes: 3 additions & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,9 @@ function ReportActionItem({
// This handles all historical actions from OldDot that we just want to display the message text
children = <ReportActionItemBasicMessage message={ReportActionsUtils.getMessageOfOldDotReportAction(action)} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLD) {
children = <ReportActionItemBasicMessage message={translate('iou.heldRequest', {comment: action.message?.[1].text ?? ''})} />;
children = <ReportActionItemBasicMessage message={translate('iou.heldRequest')} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.HOLDCOMMENT) {
children = <ReportActionItemBasicMessage message={action.message?.[0].text ?? ''} />;
} else if (action.actionName === CONST.REPORT.ACTIONS.TYPE.UNHOLD) {
children = <ReportActionItemBasicMessage message={translate('iou.unheldRequest')} />;
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/OriginalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type OriginalMessageHold = {
originalMessage: unknown;
};

type OriginalMessageHoldComment = {
actionName: typeof CONST.REPORT.ACTIONS.TYPE.HOLDCOMMENT;
originalMessage: unknown;
};

type OriginalMessageUnHold = {
actionName: typeof CONST.REPORT.ACTIONS.TYPE.UNHOLD;
originalMessage: unknown;
Expand Down Expand Up @@ -301,6 +306,7 @@ type OriginalMessage =
| OriginalMessageClosed
| OriginalMessageCreated
| OriginalMessageHold
| OriginalMessageHoldComment
| OriginalMessageUnHold
| OriginalMessageRenamed
| OriginalMessageChronosOOOList
Expand Down
Loading