Skip to content

Commit

Permalink
Merge pull request #23342 from dukenv0307/fix/22078-after
Browse files Browse the repository at this point in the history
Fix: The title field is cleared when the Confirm task button is pressed
  • Loading branch information
robertjchen authored Jul 25, 2023
2 parents a426cca + dea5c96 commit ecf0ec2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
2 changes: 0 additions & 2 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,6 @@ function createTaskAndNavigate(parentReportID, title, description, assignee, ass
{optimisticData, successData, failureData},
);

clearOutTaskInfo();

Navigation.dismissModal(optimisticTaskReport.reportID);
}

Expand Down
12 changes: 12 additions & 0 deletions src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}

Expand Down
19 changes: 8 additions & 11 deletions src/pages/tasks/TaskDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -21,19 +21,16 @@ 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,
};

const defaultProps = {
session: {},
task: {},
report: {},
};

function TaskDescriptionPage(props) {
Expand All @@ -43,7 +40,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],
);
Expand Down Expand Up @@ -72,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
Expand All @@ -94,8 +91,8 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
task: {
key: ONYXKEYS.TASK,
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
},
}),
)(TaskDescriptionPage);

0 comments on commit ecf0ec2

Please sign in to comment.