From 95ced480daaafc75045040f91cfeb73a3a404bb7 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 21 Jul 2023 14:32:38 +0700 Subject: [PATCH 1/2] using report field instead of task.report field --- src/libs/actions/Task.js | 2 -- src/pages/tasks/NewTaskPage.js | 12 ++++++++++++ src/pages/tasks/TaskDescriptionPage.js | 20 +++++++++----------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index b3dd76a38d78..760d99568752 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -203,8 +203,6 @@ function createTaskAndNavigate(parentReportID, title, description, assignee, ass {optimisticData, successData, failureData}, ); - clearOutTaskInfo(); - Navigation.dismissModal(optimisticTaskReport.reportID); } diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 01a9e2e94dc1..3e9cbb4dfdeb 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -68,6 +68,7 @@ function NewTaskPage(props) { const [shareDestination, setShareDestination] = React.useState({}); const [errorMessage, setErrorMessage] = React.useState(''); const [parentReport, setParentReport] = React.useState({}); + const shouldClearOutTaskInfoOnUnmount = React.useRef(false); const isAllowedToCreateTask = useMemo(() => _.isEmpty(parentReport) || ReportUtils.isAllowedToComment(parentReport), [parentReport]); @@ -101,6 +102,16 @@ function NewTaskPage(props) { } }, [props]); + useEffect( + () => () => { + if (!shouldClearOutTaskInfoOnUnmount.current) { + return; + } + Task.clearOutTaskInfo(); + }, + [], + ); + // On submit, we want to call the createTask function and wait to validate // the response function onSubmit() { @@ -119,6 +130,7 @@ function NewTaskPage(props) { return; } + shouldClearOutTaskInfoOnUnmount.current = true; Task.createTaskAndNavigate(parentReport.reportID, props.task.title, props.task.description, props.task.assignee, props.task.assigneeAccountID); } diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index a6ebbc7fb258..59e970cd22c6 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -8,9 +8,9 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize import Form from '../../components/Form'; import ONYXKEYS from '../../ONYXKEYS'; import TextInput from '../../components/TextInput'; +import reportPropTypes from '../reportPropTypes'; import styles from '../../styles/styles'; import compose from '../../libs/compose'; -import reportPropTypes from '../reportPropTypes'; import * as Task from '../../libs/actions/Task'; import CONST from '../../CONST'; import focusAndUpdateMultilineInputRange from '../../libs/focusAndUpdateMultilineInputRange'; @@ -21,11 +21,8 @@ const propTypes = { email: PropTypes.string.isRequired, }), - /** Task Report Info */ - task: PropTypes.shape({ - /** Title of the Task */ - report: reportPropTypes, - }), + /** The report currently being looked at */ + report: reportPropTypes, /* Onyx Props */ ...withLocalizePropTypes, @@ -33,7 +30,8 @@ const propTypes = { const defaultProps = { session: {}, - task: {}, + report: {}, + }; function TaskDescriptionPage(props) { @@ -43,7 +41,7 @@ function TaskDescriptionPage(props) { (values) => { // Set the description of the report in the store and then call Task.editTaskReport // to update the description of the report on the server - Task.editTaskAndNavigate(props.task.report, props.session.accountID, {description: values.description}); + Task.editTaskAndNavigate(props.report, props.session.accountID, {description: values.description}); }, [props], ); @@ -71,7 +69,7 @@ function TaskDescriptionPage(props) { name="description" label={props.translate('newTaskPage.descriptionOptional')} accessibilityLabel={props.translate('newTaskPage.descriptionOptional')} - defaultValue={(props.task.report && props.task.report.description) || ''} + defaultValue={(props.report && props.report.description) || ''} ref={(el) => (inputRef.current = el)} autoGrowHeight submitOnEnter @@ -93,8 +91,8 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, - task: { - key: ONYXKEYS.TASK, + report: { + key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`, }, }), )(TaskDescriptionPage); From dea5c96e0ced36cf8ffbf8c23073ec3cbd142871 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 21 Jul 2023 17:08:05 +0700 Subject: [PATCH 2/2] fix: lint issue --- src/pages/tasks/TaskDescriptionPage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index 59e970cd22c6..42280eb54ec1 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -31,7 +31,6 @@ const propTypes = { const defaultProps = { session: {}, report: {}, - }; function TaskDescriptionPage(props) {