From 79a42c64a7263a83159036729ae7cd7c54dbe0db Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 17 Jul 2023 11:44:21 +0700 Subject: [PATCH 1/2] fix: The title field is cleared when the Confirm task button is pressed --- src/libs/actions/Task.js | 2 -- src/pages/tasks/NewTaskPage.js | 17 ++++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 6d2da2716eee..ab27428c7ff8 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -187,8 +187,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..2da9165cf5f1 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); } @@ -141,7 +153,10 @@ function NewTaskPage(props) { Navigation.goBack(ROUTES.NEW_TASK_DETAILS); }} /> - + Date: Mon, 17 Jul 2023 17:01:10 +0700 Subject: [PATCH 2/2] fix: remove redundant ref --- src/pages/tasks/NewTaskPage.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index 2da9165cf5f1..3e9cbb4dfdeb 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -153,10 +153,7 @@ function NewTaskPage(props) { Navigation.goBack(ROUTES.NEW_TASK_DETAILS); }} /> - +