Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: The title field is cleared when the Confirm task button is pressed #23342

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,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();
},
[],
);
Comment on lines +105 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On lower end devices this caused race condition with the loading of next screen


// 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 @@ -71,7 +68,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 @@ -93,8 +90,8 @@ export default compose(
session: {
key: ONYXKEYS.SESSION,
},
task: {
key: ONYXKEYS.TASK,
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID}`,
},
}),
)(TaskDescriptionPage);
Loading