diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 53700e30e153..fd4f3e13dac8 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1162,11 +1162,12 @@ function editReportComment(reportID, originalReportAction, textForNewComment) { * Saves the draft for a comment report action. This will put the comment into "edit mode" * * @param {String} reportID - * @param {Number} reportActionID + * @param {Object} reportAction * @param {String} draftMessage */ -function saveReportActionDraft(reportID, reportActionID, draftMessage) { - Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${reportID}_${reportActionID}`, draftMessage); +function saveReportActionDraft(reportID, reportAction, draftMessage) { + const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${reportAction.reportActionID}`, draftMessage); } /** diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 440cc46d6230..e66c61b1122f 100644 --- a/src/pages/home/report/ContextMenu/ContextMenuActions.js +++ b/src/pages/home/report/ContextMenu/ContextMenuActions.js @@ -279,7 +279,7 @@ export default [ shouldShow: (type, reportAction, isArchivedRoom, betas, menuTarget, isChronosReport) => type === CONTEXT_MENU_TYPES.REPORT_ACTION && ReportUtils.canEditReportAction(reportAction) && !isArchivedRoom && !isChronosReport, onPress: (closePopover, {reportID, reportAction, draftMessage}) => { - const editAction = () => Report.saveReportActionDraft(reportID, reportAction.reportActionID, _.isEmpty(draftMessage) ? getActionText(reportAction) : ''); + const editAction = () => Report.saveReportActionDraft(reportID, reportAction, _.isEmpty(draftMessage) ? getActionText(reportAction) : ''); if (closePopover) { // Hide popover, then call editAction diff --git a/src/pages/home/report/ReportActionCompose.js b/src/pages/home/report/ReportActionCompose.js index 244bac35001e..9b1f604c46be 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -884,7 +884,7 @@ class ReportActionCompose extends React.Component { const lastReportAction = _.find([...this.props.reportActions, parentReportAction], (action) => ReportUtils.canEditReportAction(action)); if (lastReportAction !== -1 && lastReportAction) { - Report.saveReportActionDraft(this.props.reportID, lastReportAction.reportActionID, _.last(lastReportAction.message).html); + Report.saveReportActionDraft(this.props.reportID, lastReportAction, _.last(lastReportAction.message).html); } } } diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 00e4f3f19883..8700327a168a 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -607,7 +607,8 @@ export default compose( withReportActionsDrafts({ propName: 'draftMessage', transformValue: (drafts, props) => { - const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${props.report.reportID}_${props.action.reportActionID}`; + const originalReportID = ReportUtils.getOriginalReportID(props.report.reportID, props.action); + const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${props.action.reportActionID}`; return lodashGet(drafts, draftKey, ''); }, }), diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index 8a6d957ad167..0ceffc716e34 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -111,6 +111,13 @@ function ReportActionItemMessageEdit(props) { const isFocusedRef = useRef(false); const insertedEmojis = useRef([]); + useEffect(() => { + if (props.draftMessage === props.action.message[0].html) { + return; + } + setDraft(Str.htmlDecode(props.draftMessage)); + }, [props.draftMessage, props.action.message]); + useEffect(() => { // required for keeping last state of isFocused variable isFocusedRef.current = isFocused; @@ -149,9 +156,9 @@ function ReportActionItemMessageEdit(props) { const debouncedSaveDraft = useMemo( () => _.debounce((newDraft) => { - Report.saveReportActionDraft(props.reportID, props.action.reportActionID, newDraft); + Report.saveReportActionDraft(props.reportID, props.action, newDraft); }, 1000), - [props.reportID, props.action.reportActionID], + [props.reportID, props.action], ); /** @@ -210,7 +217,7 @@ function ReportActionItemMessageEdit(props) { */ const deleteDraft = useCallback(() => { debouncedSaveDraft.cancel(); - Report.saveReportActionDraft(props.reportID, props.action.reportActionID, ''); + Report.saveReportActionDraft(props.reportID, props.action, ''); ComposerActions.setShouldShowComposeInput(true); ReportActionComposeFocusManager.focus(); @@ -221,7 +228,7 @@ function ReportActionItemMessageEdit(props) { keyboardDidHideListener.remove(); }); } - }, [props.action.reportActionID, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]); + }, [props.action, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]); /** * Save the draft of the comment to be the new comment message. This will take the comment out of "edit mode" with