Skip to content

Commit

Permalink
Merge pull request #26692 from shubham1206agra/fix-25689
Browse files Browse the repository at this point in the history
fixed race condition in task creation and onyx
  • Loading branch information
cristipaval authored Sep 12, 2023
2 parents 73627ae + 89e8dbc commit 6246232
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ function createTaskAndNavigate(parentReportID, title, description, assigneeEmail
value: {[optimisticAddCommentReport.reportAction.reportActionID]: {pendingAction: null}},
});

clearOutTaskInfo();

API.write(
'CreateTask',
{
Expand Down
38 changes: 19 additions & 19 deletions src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useMemo} from 'react';
import React, {useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand Down Expand Up @@ -63,11 +63,12 @@ const defaultProps = {
};

function NewTaskPage(props) {
const [assignee, setAssignee] = React.useState({});
const [shareDestination, setShareDestination] = React.useState({});
const [errorMessage, setErrorMessage] = React.useState('');
const [parentReport, setParentReport] = React.useState({});
const shouldClearOutTaskInfoOnUnmount = React.useRef(false);
const [assignee, setAssignee] = useState({});
const [shareDestination, setShareDestination] = useState({});
const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const [parentReport, setParentReport] = useState({});

const isAllowedToCreateTask = useMemo(() => _.isEmpty(parentReport) || ReportUtils.isAllowedToComment(parentReport), [parentReport]);

Expand Down Expand Up @@ -95,17 +96,17 @@ function NewTaskPage(props) {
const displayDetails = Task.getShareDestination(props.task.shareDestination, props.reports, props.personalDetails);
setShareDestination(displayDetails);
}
}, [props]);

useEffect(
() => () => {
if (!shouldClearOutTaskInfoOnUnmount.current) {
return;
}
Task.clearOutTaskInfo();
},
[],
);
// If we have a title, we want to set the title
if (!_.isUndefined(props.task.title)) {
setTitle(props.task.title);
}

// If we have a description, we want to set the description
if (!_.isUndefined(props.task.description)) {
setDescription(props.task.description);
}
}, [props]);

// On submit, we want to call the createTask function and wait to validate
// the response
Expand All @@ -125,7 +126,6 @@ function NewTaskPage(props) {
return;
}

shouldClearOutTaskInfoOnUnmount.current = true;
Task.createTaskAndNavigate(parentReport.reportID, props.task.title, props.task.description, props.task.assignee, props.task.assigneeAccountID, props.task.assigneeChatReport);
}

Expand Down Expand Up @@ -153,13 +153,13 @@ function NewTaskPage(props) {
<View style={styles.mb5}>
<MenuItemWithTopDescription
description={props.translate('task.title')}
title={props.task.title || ''}
title={title}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_TITLE)}
shouldShowRightIcon
/>
<MenuItemWithTopDescription
description={props.translate('task.description')}
title={props.task.description || ''}
title={description}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_DESCRIPTION)}
shouldShowRightIcon
numberOfLinesTitle={2}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function TaskAssigneeSelectorModal(props) {
const assigneeChatReport = Task.setAssigneeValue(option.login, option.accountID, props.route.params.reportID, OptionsListUtils.isCurrentUser(option));

// Pass through the selected assignee
Task.editTaskAssigneeAndNavigate(props.task.report, props.session.accountID, option.login, option.accountID, assigneeChatReport);
Task.editTaskAssigneeAndNavigate(report, props.session.accountID, option.login, option.accountID, assigneeChatReport);
}
};

Expand Down

0 comments on commit 6246232

Please sign in to comment.