From 93970c0e768ea888f3853591e6364fa70f5c3339 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Fri, 5 May 2023 09:02:44 -0400 Subject: [PATCH 01/33] Started setting up the editTask method --- src/libs/actions/Task.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index d55d6b910c83..4877b03df871 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -151,6 +151,26 @@ function createTaskAndNavigate(currentUserEmail, parentReportID, title, descript Navigation.navigate(ROUTES.getReportRoute(optimisticTaskReport.reportID)); } +/** + * @function editTask + * @param {string} taskId + * @param {string} title + * @param {string} description + * @param {string} assignee + * @returns {object} action + * + */ + +function editTaskAndNavigate(taskId, title, description, assignee) { + API.write('EditTask', { + taskID: taskId, + title, + description, + assignee, + }); + Navigation.navigate(ROUTES.getTaskDetailsRoute(taskId)); +} + /** * Sets the title and description values for the task * @param {string} title @@ -233,4 +253,14 @@ function clearOutTaskInfoAndNavigate(reportID) { Navigation.navigate(ROUTES.NEW_TASK_DETAILS); } -export {createTaskAndNavigate, setTitleValue, setDescriptionValue, setDetailsValue, setAssigneeValue, setShareDestinationValue, clearOutTaskInfo, clearOutTaskInfoAndNavigate}; +export { + createTaskAndNavigate, + editTaskAndNavigate, + setTitleValue, + setDescriptionValue, + setDetailsValue, + setAssigneeValue, + setShareDestinationValue, + clearOutTaskInfo, + clearOutTaskInfoAndNavigate, +}; From 27ef942055aaaa3533d78e7c9d6ec130254f0119 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 8 May 2023 13:43:49 -0400 Subject: [PATCH 02/33] added some comments --- src/libs/actions/Task.js | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Task.js b/src/libs/actions/Task.js index 4877b03df871..ca816d6bd2f4 100644 --- a/src/libs/actions/Task.js +++ b/src/libs/actions/Task.js @@ -151,9 +151,11 @@ function createTaskAndNavigate(currentUserEmail, parentReportID, title, descript Navigation.navigate(ROUTES.getReportRoute(optimisticTaskReport.reportID)); } +// import ReportUtils from '../ReportUtils'; + /** * @function editTask - * @param {string} taskId + * @param {object} report * @param {string} title * @param {string} description * @param {string} assignee @@ -161,14 +163,40 @@ function createTaskAndNavigate(currentUserEmail, parentReportID, title, descript * */ -function editTaskAndNavigate(taskId, title, description, assignee) { +function editTaskAndNavigate(report, title, description, assignee) { + /** + * Anything about a task can be edited, except where the task is 'shared in'. + * + * The EditTask action will live in src/libs/actions/Task.js + * The action is the only action that exists purely on the task report itself. + * This is because we don't need to notify the parent chat report that the task was edited. + * The previous EditTask reportAction details will be stored on the task report itself as a way to audit previous changes. + * Each edit will create a new EditTaskReportAction instead of having an array that is updated to contain each edit. + * + * The message of the reportAction would look like this: + * {"title":"Previous Task Title","description":"Previous description", "assignee": 31231313} + * + * The action will call the 'EditTask' API endpoint and + * Optimistically: Add the EditTask reportAction on the task report, and make those edits on the task report + * Success: None + * Failure: Remove the EditTask reportAction on the task report, and remove the edits on the task report + * + * When updating the assignee, similar to when the task is created we need to create an ADD_COMMENT reportAction in the DM between the assignee and the task creator + */ + // Create report action on the Task Report to store the previous details of the task + // Not sure if we need to generate a new reportAction for each edit. + // const editTaskReportAction = ReportUtils.buildOptimisticReportAction(report, 'EditTask', { + + const optimisticData = []; + const successData = []; + const failureData = []; API.write('EditTask', { - taskID: taskId, + taskID: report.taskReportID, title, description, assignee, - }); - Navigation.navigate(ROUTES.getTaskDetailsRoute(taskId)); + }, [optimisticData, successData, failureData]); + Navigation.navigate(ROUTES.getTaskDetailsRoute(report.taskReportID)); } /** From 5b5dd58ebffba003529215186580986170f72579 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 8 May 2023 16:18:24 -0400 Subject: [PATCH 03/33] Added buildOptimisticEditedTaskReportActions --- src/libs/ReportUtils.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bf891ec11ecf..270992cd8ec8 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1455,6 +1455,45 @@ function buildOptimisticCreatedReportAction(ownerEmail) { }; } +/** + * Returns the necessary reportAction onyx data to indicate that a task report has been edited + * + * @param {String} ownerEmail + * @returns {Object} + */ + +function buildOptimisticEditedTaskReportAction(ownerEmail) { + return { + reportActionID: NumberUtils.rand64(), + actionName: CONST.REPORT.ACTIONS.TYPE.EDITED, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + actorAccountID: ownerEmail, + message: [ + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'strong', + text: lodashGet(allPersonalDetails, [ownerEmail, 'displayName'], ownerEmail), + }, + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'normal', + text: ' edited this task', + }, + ], + person: [ + { + type: CONST.REPORT.MESSAGE.TYPE.TEXT, + style: 'strong', + text: lodashGet(allPersonalDetails, [ownerEmail, 'displayName'], ownerEmail), + }, + ], + automatic: false, + avatar: lodashGet(allPersonalDetails, [ownerEmail, 'avatar'], getDefaultAvatar(ownerEmail)), + created: DateUtils.getDBTime(), + shouldShow: true, + }; +} + /** * Returns the necessary reportAction onyx data to indicate that a chat has been archived * @@ -2068,6 +2107,7 @@ export { buildOptimisticChatReport, buildOptimisticClosedReportAction, buildOptimisticCreatedReportAction, + buildOptimisticEditedTaskReportAction, buildOptimisticIOUReport, buildOptimisticExpenseReport, buildOptimisticIOUReportAction, From d32f51f99e0c6517eb9c2d8c318432b410bc4baa Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 8 May 2023 16:18:47 -0400 Subject: [PATCH 04/33] Added necessary new CONSTs --- src/CONST.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CONST.js b/src/CONST.js index 8cd797fefda2..40c41a0ecfb2 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -407,6 +407,7 @@ const CONST = { ADDCOMMENT: 'ADDCOMMENT', CLOSED: 'CLOSED', CREATED: 'CREATED', + EDITED: 'EDITED', IOU: 'IOU', RENAMED: 'RENAMED', CHRONOSOOOLIST: 'CHRONOSOOOLIST', From 07444cdc3698e316adf592adc82df6218253d857 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 9 May 2023 11:25:24 -0400 Subject: [PATCH 05/33] Some updates to screens and logic --- src/ROUTES.js | 6 ++-- .../AppNavigator/ModalStackNavigators.js | 7 +++++ src/libs/Navigation/linkingConfig.js | 1 + src/libs/ReportUtils.js | 8 ++--- src/pages/tasks/TaskDescriptionPage.js | 30 +++++++++++++++---- src/pages/tasks/TaskTitlePage.js | 30 +++++++++++++++---- 6 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/ROUTES.js b/src/ROUTES.js index d0e16820772c..c8bf2880d885 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -95,8 +95,10 @@ export default { NEW_TASK_WITH_REPORT_ID: `${NEW_TASK}/:reportID?`, TASK_TITLE: 'r/:reportID/title', TASK_DESCRIPTION: 'r/:reportID/description', - getTaskReportTitleRoute: (reportID) => `r/${reportID}/title`, - getTaskReportDescriptionRoute: (reportID) => `r/${reportID}/description`, + TASK_ASSIGNEE: 'r/:reportID/assignee', + getTaskReportTitleRoute: reportID => `r/${reportID}/title`, + getTaskReportDescriptionRoute: reportID => `r/${reportID}/description`, + getTaskReportAssigneeRoute: reportID => `r/${reportID}/assignee`, NEW_TASK_ASSIGNEE: `${NEW_TASK}/assignee`, NEW_TASK_SHARE_DESTINATION: `${NEW_TASK}/share-destination`, NEW_TASK_DETAILS: `${NEW_TASK}/details`, diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js index 7946c0b30ea7..1dbc85a3e5a6 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js @@ -177,6 +177,13 @@ const TaskModalStackNavigator = createModalStackNavigator([ }, name: 'Task_Description', }, + { + getComponent: () => { + const TaskAssigneeSelectorPage = require('../../../pages/tasks/TaskAssigneeSelectorModal').default; + return TaskAssigneeSelectorPage; + }, + name: 'Task_Assignee_Selector', + }, ]); const ReportSettingsModalStackNavigator = createModalStackNavigator([ diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index 92a24c01ca0b..92b4414b99ae 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -263,6 +263,7 @@ export default { screens: { Task_Title: ROUTES.TASK_TITLE, Task_Description: ROUTES.TASK_DESCRIPTION, + Task_Assignee: ROUTES.TASK_ASSIGNEE, }, }, AddPersonalBankAccount: { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 270992cd8ec8..9c395bbe3f48 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -1467,12 +1467,12 @@ function buildOptimisticEditedTaskReportAction(ownerEmail) { reportActionID: NumberUtils.rand64(), actionName: CONST.REPORT.ACTIONS.TYPE.EDITED, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, - actorAccountID: ownerEmail, + actorAccountID: currentUserEmail, message: [ { type: CONST.REPORT.MESSAGE.TYPE.TEXT, style: 'strong', - text: lodashGet(allPersonalDetails, [ownerEmail, 'displayName'], ownerEmail), + text: ownerEmail === currentUserEmail ? 'You' : ownerEmail, }, { type: CONST.REPORT.MESSAGE.TYPE.TEXT, @@ -1484,11 +1484,11 @@ function buildOptimisticEditedTaskReportAction(ownerEmail) { { type: CONST.REPORT.MESSAGE.TYPE.TEXT, style: 'strong', - text: lodashGet(allPersonalDetails, [ownerEmail, 'displayName'], ownerEmail), + text: lodashGet(allPersonalDetails, [currentUserEmail, 'displayName'], currentUserEmail), }, ], automatic: false, - avatar: lodashGet(allPersonalDetails, [ownerEmail, 'avatar'], getDefaultAvatar(ownerEmail)), + avatar: lodashGet(allPersonalDetails, [currentUserEmail, 'avatar'], getDefaultAvatar(currentUserEmail)), created: DateUtils.getDBTime(), shouldShow: true, }; diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index 22a51fb114ff..1712b1bf139a 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -2,6 +2,7 @@ import _ from 'underscore'; import React, {useCallback, useRef} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; import ScreenWrapper from '../../components/ScreenWrapper'; import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; @@ -13,6 +14,7 @@ import Navigation from '../../libs/Navigation/Navigation'; import reportPropTypes from '../reportPropTypes'; import compose from '../../libs/compose'; import withReportOrNotFound from '../home/report/withReportOrNotFound'; +import * as TaskUtils from '../../libs/actions/Task'; const propTypes = { /** URL Route params */ @@ -27,11 +29,18 @@ const propTypes = { /** The report currently being looked at */ report: reportPropTypes.isRequired, + /** Current user session */ + session: PropTypes.shape({ + email: PropTypes.string.isRequired, + }), + /* Onyx Props */ ...withLocalizePropTypes, }; -const defaultProps = {}; +const defaultProps = { + session: {}, +}; function TaskDescriptionPage(props) { /** @@ -52,9 +61,11 @@ function TaskDescriptionPage(props) { [props], ); - const submit = useCallback(() => { - // Functionality will be implemented in https://github.com/Expensify/App/issues/16856 - }, []); + const submit = useCallback((values) => { + // Set the description of the report in the store and then call TaskUtils.editTaskReport + // to update the description of the report on the server + TaskUtils.editTaskAndNavigate(props.report, props.session.email, '', values.description, ''); + }, [props]); const inputRef = useRef(null); @@ -94,4 +105,13 @@ function TaskDescriptionPage(props) { TaskDescriptionPage.propTypes = propTypes; TaskDescriptionPage.defaultProps = defaultProps; -export default compose(withLocalize, withReportOrNotFound)(TaskDescriptionPage); +export default compose( + withLocalize, + withReportOrNotFound, + withOnyx({ + session: + { + key: ONYXKEYS.SESSION, + }, + }), +)(TaskDescriptionPage); diff --git a/src/pages/tasks/TaskTitlePage.js b/src/pages/tasks/TaskTitlePage.js index ae86f18bb775..4a928744bab7 100644 --- a/src/pages/tasks/TaskTitlePage.js +++ b/src/pages/tasks/TaskTitlePage.js @@ -2,6 +2,7 @@ import _ from 'underscore'; import React, {useCallback, useRef} from 'react'; import PropTypes from 'prop-types'; import {View} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; import ScreenWrapper from '../../components/ScreenWrapper'; import HeaderWithCloseButton from '../../components/HeaderWithCloseButton'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; @@ -13,6 +14,7 @@ import Navigation from '../../libs/Navigation/Navigation'; import reportPropTypes from '../reportPropTypes'; import compose from '../../libs/compose'; import withReportOrNotFound from '../home/report/withReportOrNotFound'; +import * as TaskUtils from '../../libs/actions/Task'; const propTypes = { /** URL Route params */ @@ -27,11 +29,18 @@ const propTypes = { /** The report currently being looked at */ report: reportPropTypes.isRequired, + /** Current user session */ + session: PropTypes.shape({ + email: PropTypes.string.isRequired, + }), + /* Onyx Props */ ...withLocalizePropTypes, }; -const defaultProps = {}; +const defaultProps = { + session: {}, +}; function TaskTitlePage(props) { /** @@ -52,9 +61,12 @@ function TaskTitlePage(props) { [props], ); - const submit = useCallback(() => { - // Functionality will be implemented in https://github.com/Expensify/App/issues/16856 - }, []); + const submit = useCallback((values) => { + // Set the description of the report in the store and then call TaskUtils.editTaskReport + // to update the description of the report on the server + + TaskUtils.editTaskAndNavigate(props.report, props.session.email, values.title, '', ''); + }, [props]); const inputRef = useRef(null); @@ -94,4 +106,12 @@ function TaskTitlePage(props) { TaskTitlePage.propTypes = propTypes; TaskTitlePage.defaultProps = defaultProps; -export default compose(withLocalize, withReportOrNotFound)(TaskTitlePage); +export default compose( + withLocalize, + withReportOrNotFound, + withOnyx({ + session: { + key: ONYXKEYS.SESSION, + }, + }), +)(TaskTitlePage); From 17ceb69f1fd6246ca8d8c00b4be2be213ff1fb49 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 9 May 2023 15:29:36 -0400 Subject: [PATCH 06/33] Added new translation props --- src/languages/en.js | 3 +++ src/languages/es.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/languages/en.js b/src/languages/en.js index 22ac07e014f6..223cd2b3c35b 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -1189,6 +1189,9 @@ export default { pleaseEnterTaskAssignee: 'Please select an assignee', pleaseEnterTaskDestination: 'Please select a share destination', }, + taskReport: { + to: 'To', + }, statementPage: { generatingPDF: "We're generating your PDF right now. Please come back later!", }, diff --git a/src/languages/es.js b/src/languages/es.js index 003192a3c8cc..1c33fbdbda70 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -1194,6 +1194,9 @@ export default { pleaseEnterTaskAssignee: 'Por favor, asigna una persona a esta tarea', pleaseEnterTaskDestination: 'Por favor, selecciona un destino de tarea', }, + taskReport: { + to: 'A', + }, statementPage: { generatingPDF: 'Estamos generando tu PDF ahora mismo. ¡Por favor, vuelve más tarde!', }, From bfdbe81fb0a64072e71e7831eb7e103ed221e908 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 9 May 2023 15:31:25 -0400 Subject: [PATCH 07/33] Updated routes and the TaskSelectorLink to reuse --- src/components/TaskSelectorLink.js | 6 +- .../AppNavigator/ModalStackNavigators.js | 2 +- src/libs/actions/Task.js | 116 +++++++++++++----- src/styles/styles.js | 1 - 4 files changed, 94 insertions(+), 31 deletions(-) diff --git a/src/components/TaskSelectorLink.js b/src/components/TaskSelectorLink.js index 82a80223a567..5b156a023add 100644 --- a/src/components/TaskSelectorLink.js +++ b/src/components/TaskSelectorLink.js @@ -36,6 +36,9 @@ const propTypes = { /** Whether the Touchable should be disabled */ disabled: PropTypes.bool, + /** Whether we're creating a new task or editing */ + isNewTask: PropTypes.bool, + ...withLocalizePropTypes, }; @@ -45,6 +48,7 @@ const defaultProps = { alternateText: '', isShareDestination: false, disabled: false, + isNewTask: true, }; const TaskSelectorLink = (props) => { @@ -93,7 +97,7 @@ const TaskSelectorLink = (props) => { ) : ( {props.translate(props.label)} )} - {props.disabled ? null : ( + {props.disabled || !props.isNewTask ? null : ( Date: Tue, 9 May 2023 15:34:09 -0400 Subject: [PATCH 08/33] Updated TaskTitle and TaskDescription Pages --- src/pages/tasks/TaskDescriptionPage.js | 4 ++-- src/pages/tasks/TaskTitlePage.js | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/pages/tasks/TaskDescriptionPage.js b/src/pages/tasks/TaskDescriptionPage.js index 1712b1bf139a..9bd4590ecae2 100644 --- a/src/pages/tasks/TaskDescriptionPage.js +++ b/src/pages/tasks/TaskDescriptionPage.js @@ -93,8 +93,8 @@ function TaskDescriptionPage(props) { inputID="description" name="description" label={props.translate('newTaskPage.description')} - defaultValue={props.report.description || ''} - ref={(el) => (inputRef.current = el)} + defaultValue={props.task.report.description || ''} + ref={el => inputRef.current = el} /> diff --git a/src/pages/tasks/TaskTitlePage.js b/src/pages/tasks/TaskTitlePage.js index 4a928744bab7..ef4d5453d7aa 100644 --- a/src/pages/tasks/TaskTitlePage.js +++ b/src/pages/tasks/TaskTitlePage.js @@ -13,21 +13,14 @@ import styles from '../../styles/styles'; import Navigation from '../../libs/Navigation/Navigation'; import reportPropTypes from '../reportPropTypes'; import compose from '../../libs/compose'; -import withReportOrNotFound from '../home/report/withReportOrNotFound'; import * as TaskUtils from '../../libs/actions/Task'; const propTypes = { - /** URL Route params */ - route: PropTypes.shape({ - /** Params from the URL path */ - params: PropTypes.shape({ - /** taskReportID passed via route: /r/:taskReportID/title */ - taskReportID: PropTypes.string, - }), - }).isRequired, - - /** The report currently being looked at */ - report: reportPropTypes.isRequired, + /** Task Report Info */ + task: PropTypes.shape({ + /** Title of the Task */ + report: reportPropTypes.isRequired, + }), /** Current user session */ session: PropTypes.shape({ @@ -40,6 +33,7 @@ const propTypes = { const defaultProps = { session: {}, + task: {}, }; function TaskTitlePage(props) { @@ -94,8 +88,8 @@ function TaskTitlePage(props) { inputID="title" name="title" label={props.translate('newTaskPage.title')} - defaultValue={props.report.reportName || ''} - ref={(el) => (inputRef.current = el)} + defaultValue={props.task.report.reportName || ''} + ref={el => inputRef.current = el} /> @@ -108,10 +102,12 @@ TaskTitlePage.defaultProps = defaultProps; export default compose( withLocalize, - withReportOrNotFound, withOnyx({ session: { key: ONYXKEYS.SESSION, }, + task: { + key: ONYXKEYS.TASK, + }, }), )(TaskTitlePage); From 531590a580d73c4a43636f33c46cf66ec93b6fa3 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 9 May 2023 15:34:28 -0400 Subject: [PATCH 09/33] Moved some functions to Task file --- src/pages/tasks/NewTaskPage.js | 40 +++++----------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/src/pages/tasks/NewTaskPage.js b/src/pages/tasks/NewTaskPage.js index e9859f8c058d..2a66729449ca 100644 --- a/src/pages/tasks/NewTaskPage.js +++ b/src/pages/tasks/NewTaskPage.js @@ -14,7 +14,6 @@ import Permissions from '../../libs/Permissions'; import ROUTES from '../../ROUTES'; import TaskSelectorLink from '../../components/TaskSelectorLink'; import reportPropTypes from '../reportPropTypes'; -import * as ReportUtils from '../../libs/ReportUtils'; import * as TaskUtils from '../../libs/actions/Task'; import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButton'; @@ -64,37 +63,6 @@ const defaultProps = { session: {}, }; -/** - * Get the assignee data - * - * @param {Object} details - * @returns {Object} - */ -function constructAssignee(details) { - const source = ReportUtils.getAvatar(lodashGet(details, 'avatar', ''), lodashGet(details, 'login', '')); - return { - icons: [{source, type: 'avatar', name: details.login}], - displayName: details.displayName, - subtitle: details.login, - }; -} - -/** - * Get the share destination data - * @param {Object} reportID - * @param {Object} reports - * @param {Object} personalDetails - * @returns {Object} - * */ -function constructShareDestination(reportID, reports, personalDetails) { - const report = lodashGet(reports, `report_${reportID}`, {}); - return { - icons: ReportUtils.getIcons(report, personalDetails), - displayName: ReportUtils.getReportName(report), - subtitle: ReportUtils.getChatRoomSubtitle(report), - }; -} - const NewTaskPage = (props) => { const [assignee, setAssignee] = React.useState({}); const [shareDestination, setShareDestination] = React.useState({}); @@ -113,7 +81,7 @@ const NewTaskPage = (props) => { setSubmitError(true); return setErrorMessage(props.translate('newTaskPage.assigneeError')); } - const displayDetails = constructAssignee(assigneeDetails); + const displayDetails = TaskUtils.constructAssignee(assigneeDetails); setAssignee(displayDetails); } @@ -128,7 +96,11 @@ const NewTaskPage = (props) => { // the share destination data if (props.task.shareDestination) { setParentReport(lodashGet(props.reports, `report_${props.task.shareDestination}`, {})); - const displayDetails = constructShareDestination(props.task.shareDestination, props.reports, props.personalDetails); + const displayDetails = TaskUtils.constructShareDestination( + props.task.shareDestination, + props.reports, + props.personalDetails, + ); setShareDestination(displayDetails); } }, [props]); From 0f289abde681e5c439da58a941ffcee93170383e Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 9 May 2023 15:35:40 -0400 Subject: [PATCH 10/33] Added Assignee to TaskHeader and Updated the TaskAssigneeSelectorModal to be reusable for editing --- src/pages/home/TaskHeaderView.js | 84 +++++++++++++++++++- src/pages/tasks/TaskAssigneeSelectorModal.js | 33 ++++++++ 2 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/pages/home/TaskHeaderView.js b/src/pages/home/TaskHeaderView.js index 9f00fe5e4f9c..efe2dff1f528 100644 --- a/src/pages/home/TaskHeaderView.js +++ b/src/pages/home/TaskHeaderView.js @@ -1,34 +1,110 @@ -import React from 'react'; +import React, {useEffect, useState} from 'react'; +import {View} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; import lodashGet from 'lodash/get'; +import PropTypes from 'prop-types'; +import compose from '../../libs/compose'; +import styles from '../../styles/styles'; import reportPropTypes from '../reportPropTypes'; import MenuItemWithTopDescription from '../../components/MenuItemWithTopDescription'; +import TaskSelectorLink from '../../components/TaskSelectorLink'; import Navigation from '../../libs/Navigation/Navigation'; import ROUTES from '../../ROUTES'; +import * as TaskUtils from '../../libs/actions/Task'; +import ONYXKEYS from '../../ONYXKEYS'; +import withLocalize from '../../components/withLocalize'; +import Button from '../../components/Button'; const propTypes = { /** The report currently being looked at */ report: reportPropTypes.isRequired, + + /** All of the personal details for everyone */ + personalDetails: PropTypes.objectOf( + PropTypes.shape({ + /** Display name of the person */ + displayName: PropTypes.string, + + /** Avatar URL of the person */ + avatar: PropTypes.string, + + /** Login of the person */ + login: PropTypes.string, + }), + ), +}; + +const defaultProps = { + personalDetails: {}, }; function TaskHeaderView(props) { + const [assignee, setAssignee] = useState(''); + + useEffect(() => { + if (!props.report.assignee) { + return; + } + if (props.report.assignee) { + const assigneeDetails = lodashGet(props.personalDetails, props.report.assignee); + const displayDetails = TaskUtils.constructAssignee(assigneeDetails); + setAssignee(displayDetails); + } + }, [props]); + // eslint-disable-next-line no-console + console.log('TaskHeaderView.js props', props); return ( <> + + { + props.report.assignee + + && ( + { + TaskUtils.beginEditingTask(props.report); + Navigation.navigate(ROUTES.getTaskReportAssigneeRoute(props.report.reportID)); + }} + label="taskReport.to" + isNewTask={false} + /> + ) + } +