diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 3bc4ea966b23..ade3791fc0c7 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1188,12 +1188,11 @@ 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 {Object} reportAction + * @param {Number} reportActionID * @param {String} draftMessage */ -function saveReportActionDraft(reportID, reportAction, draftMessage) { - const originalReportID = ReportUtils.getOriginalReportID(reportID, reportAction); - Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${reportAction.reportActionID}`, draftMessage); +function saveReportActionDraft(reportID, reportActionID, draftMessage) { + Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${reportID}_${reportActionID}`, draftMessage); } /** diff --git a/src/pages/home/report/ContextMenu/ContextMenuActions.js b/src/pages/home/report/ContextMenu/ContextMenuActions.js index 374539a3ea74..936f482cca17 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, _.isEmpty(draftMessage) ? getActionText(reportAction) : ''); + const editAction = () => Report.saveReportActionDraft(reportID, reportAction.reportActionID, _.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 8f9e43cfdbab..e9f4b4ea930e 100644 --- a/src/pages/home/report/ReportActionCompose.js +++ b/src/pages/home/report/ReportActionCompose.js @@ -897,7 +897,7 @@ function ReportActionCompose({ const lastReportAction = _.find([...reportActions, parentReportAction], (action) => ReportUtils.canEditReportAction(action)); if (lastReportAction !== -1 && lastReportAction) { - Report.saveReportActionDraft(reportID, lastReportAction, _.last(lastReportAction.message).html); + Report.saveReportActionDraft(reportID, lastReportAction.reportActionID, _.last(lastReportAction.message).html); } } }, diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index 9f0c2d8cda47..ea9d20b04500 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -617,8 +617,7 @@ export default compose( withReportActionsDrafts({ propName: 'draftMessage', transformValue: (drafts, props) => { - const originalReportID = ReportUtils.getOriginalReportID(props.report.reportID, props.action); - const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${originalReportID}_${props.action.reportActionID}`; + const draftKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS_DRAFTS}${props.report.reportID}_${props.action.reportActionID}`; return lodashGet(drafts, draftKey, ''); }, }), diff --git a/src/pages/home/report/ReportActionItemMessageEdit.js b/src/pages/home/report/ReportActionItemMessageEdit.js index d6a734080019..2d8bd5f35655 100644 --- a/src/pages/home/report/ReportActionItemMessageEdit.js +++ b/src/pages/home/report/ReportActionItemMessageEdit.js @@ -111,13 +111,6 @@ 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; @@ -156,9 +149,9 @@ function ReportActionItemMessageEdit(props) { const debouncedSaveDraft = useMemo( () => _.debounce((newDraft) => { - Report.saveReportActionDraft(props.reportID, props.action, newDraft); + Report.saveReportActionDraft(props.reportID, props.action.reportActionID, newDraft); }, 1000), - [props.reportID, props.action], + [props.reportID, props.action.reportActionID], ); /** @@ -217,7 +210,7 @@ function ReportActionItemMessageEdit(props) { */ const deleteDraft = useCallback(() => { debouncedSaveDraft.cancel(); - Report.saveReportActionDraft(props.reportID, props.action, ''); + Report.saveReportActionDraft(props.reportID, props.action.reportActionID, ''); ComposerActions.setShouldShowComposeInput(true); ReportActionComposeFocusManager.clear(); ReportActionComposeFocusManager.focus(); @@ -229,7 +222,7 @@ function ReportActionItemMessageEdit(props) { keyboardDidHideListener.remove(); }); } - }, [props.action, debouncedSaveDraft, props.index, props.reportID, reportScrollManager]); + }, [props.action.reportActionID, 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