Skip to content

Commit

Permalink
Merge pull request #19908 from akinwale/task-19460
Browse files Browse the repository at this point in the history
fix: set initial task title and description values from Onyx if present
  • Loading branch information
aldo-expensify authored Jun 5, 2023
2 parents 8ab9f36 + f3df108 commit dc398d1
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ function isTaskCanceled(taskReport) {
return taskReport.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && taskReport.statusNum === CONST.REPORT.STATUS.CLOSED;
}

/**
* Closes the current open task modal and clears out the task info from the store.
*/
function dismissModalAndClearOutTaskInfo() {
Navigation.dismissModal();
clearOutTaskInfo();
}

export {
createTaskAndNavigate,
editTaskAndNavigate,
Expand All @@ -605,4 +613,5 @@ export {
getShareDestination,
cancelTask,
isTaskCanceled,
dismissModalAndClearOutTaskInfo,
};
2 changes: 1 addition & 1 deletion src/pages/tasks/NewTaskDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const NewTaskDescriptionPage = (props) => {
>
<HeaderWithCloseButton
title={props.translate('newTaskPage.description')}
onCloseButtonPress={() => Navigation.dismissModal()}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
/>
Expand Down
28 changes: 24 additions & 4 deletions src/pages/tasks/NewTaskDetailsPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useRef} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
Expand All @@ -20,15 +20,29 @@ const propTypes = {
/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),

/** Task title and description data */
task: PropTypes.shape({
title: PropTypes.string,
description: PropTypes.string,
}),

...withLocalizePropTypes,
};

const defaultProps = {
betas: [],
task: {},
};

const NewTaskPage = (props) => {
const inputRef = useRef();
const [taskTitle, setTaskTitle] = useState(props.task.title);
const [taskDescription, setTaskDescription] = useState(props.task.description || '');

useEffect(() => {
setTaskTitle(props.task.title);
setTaskDescription(props.task.description || '');
}, [props.task]);

/**
* @param {Object} values - form input values passed by the Form component
Expand Down Expand Up @@ -63,9 +77,9 @@ const NewTaskPage = (props) => {
>
<HeaderWithCloseButton
title={props.translate('newTaskPage.assignTask')}
onCloseButtonPress={() => Navigation.dismissModal()}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
onBackButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
/>
<Form
formID={ONYXKEYS.FORMS.NEW_TASK_FORM}
Expand All @@ -80,13 +94,16 @@ const NewTaskPage = (props) => {
ref={(el) => (inputRef.current = el)}
inputID="taskTitle"
label={props.translate('newTaskPage.title')}
value={taskTitle}
onValueChange={(value) => setTaskTitle(value)}
/>
</View>
<View style={styles.mb5}>
<TextInput
inputID="taskDescription"
defaultValue=""
label={props.translate('newTaskPage.descriptionOptional')}
value={taskDescription}
onValueChange={(value) => setTaskDescription(value)}
/>
</View>
</Form>
Expand All @@ -103,6 +120,9 @@ export default compose(
betas: {
key: ONYXKEYS.BETAS,
},
task: {
key: ONYXKEYS.TASK,
},
}),
withLocalize,
)(NewTaskPage);
2 changes: 1 addition & 1 deletion src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const NewTaskPage = (props) => {
<ScreenWrapper>
<HeaderWithCloseButton
title={props.translate('newTaskPage.confirmTask')}
onCloseButtonPress={() => Navigation.dismissModal()}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/NewTaskTitlePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const NewTaskTitlePage = (props) => {
>
<HeaderWithCloseButton
title={props.translate('newTaskPage.title')}
onCloseButtonPress={() => Navigation.dismissModal()}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function TaskDescriptionPage(props) {
title={props.translate('newTaskPage.task')}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
onCloseButtonPress={() => Navigation.dismissModal(true)}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskTitlePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function TaskTitlePage(props) {
title={props.translate('newTaskPage.task')}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack()}
onCloseButtonPress={() => Navigation.dismissModal(true)}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
Expand Down

0 comments on commit dc398d1

Please sign in to comment.