From 859b7b0d59831b004e2fbac5d232848b8dfb5a12 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 13 Jun 2023 18:33:30 +0700 Subject: [PATCH 01/13] Fix task assignee is empty in Task Header of Assignee side --- src/components/TaskHeader.js | 16 +++++++++------- src/libs/ReportActionsUtils.js | 2 +- src/libs/TaskUtils.js | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 src/libs/TaskUtils.js diff --git a/src/components/TaskHeader.js b/src/components/TaskHeader.js index 4c07e673a1c5..db48d6ff878c 100644 --- a/src/components/TaskHeader.js +++ b/src/components/TaskHeader.js @@ -20,7 +20,8 @@ import ROUTES from '../ROUTES'; import Icon from './Icon'; import MenuItemWithTopDescription from './MenuItemWithTopDescription'; import Button from './Button'; -import * as TaskUtils from '../libs/actions/Task'; +import * as Task from '../libs/actions/Task'; +import * as TaskUtils from '../libs/TaskUtils'; import * as UserUtils from '../libs/UserUtils'; import PressableWithFeedback from './Pressable/PressableWithFeedback'; @@ -36,13 +37,14 @@ const propTypes = { function TaskHeader(props) { const title = ReportUtils.getReportName(props.report); - const assigneeName = ReportUtils.getDisplayNameForParticipant(props.report.managerEmail); - const assigneeAvatar = UserUtils.getAvatar(lodashGet(props.personalDetails, [props.report.managerEmail, 'avatar']), props.report.managerEmail); + const assigneeEmail = TaskUtils.getTaskAssigneeEmail(props.report); + const assigneeName = ReportUtils.getDisplayNameForParticipant(assigneeEmail); + const assigneeAvatar = UserUtils.getAvatar(lodashGet(props.personalDetails, [assigneeEmail, 'avatar']), assigneeEmail); const isOpen = props.report.stateNum === CONST.REPORT.STATE_NUM.OPEN && props.report.statusNum === CONST.REPORT.STATUS.OPEN; const isCompleted = props.report.stateNum === CONST.REPORT.STATE_NUM.SUBMITTED && props.report.statusNum === CONST.REPORT.STATUS.APPROVED; useEffect(() => { - TaskUtils.setTaskReport(props.report); + Task.setTaskReport(props.report); }, [props.report]); return ( @@ -60,7 +62,7 @@ function TaskHeader(props) { > - {!_.isEmpty(props.report.managerEmail) && ( + {!_.isEmpty(assigneeEmail) && ( <> TaskUtils.completeTask(props.report.reportID, title)} + onPress={() => Task.completeTask(props.report.reportID, title)} /> )} diff --git a/src/libs/ReportActionsUtils.js b/src/libs/ReportActionsUtils.js index c255760f5d87..bcca65643b5c 100644 --- a/src/libs/ReportActionsUtils.js +++ b/src/libs/ReportActionsUtils.js @@ -65,7 +65,7 @@ function hasCommentThread(reportAction) { } /** - * Returns the parentReportAction if the given report is a thread. + * Returns the parentReportAction if the given report is a thread/task. * * @param {Object} report * @returns {Object} diff --git a/src/libs/TaskUtils.js b/src/libs/TaskUtils.js new file mode 100644 index 000000000000..accfd1c68d4f --- /dev/null +++ b/src/libs/TaskUtils.js @@ -0,0 +1,25 @@ +import lodashGet from 'lodash/get'; +import * as ReportActionsUtils from './ReportActionsUtils'; + +/** + * Returns the parentReportAction if the given report is a thread/task. + * + * @param {Object} taskReport + * @returns {String|null} + */ +const getTaskAssigneeEmail = (taskReport) => { + if (!taskReport) { + return null; + } + + if (taskReport.managerEmail) { + return taskReport.managerEmail + } + + const reportAction = ReportActionsUtils.getParentReportAction(taskReport); + return lodashGet(reportAction, 'childManagerEmail', null); +} + +export { + getTaskAssigneeEmail, +}; From 1372cae93f0c01f900c4febbf900ea3136444b97 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 13 Jun 2023 22:22:03 +0700 Subject: [PATCH 02/13] Disable Mark as done button when current user is not neither assignee or owner --- src/components/TaskHeader.js | 26 ++++++++++++++++++++++++-- src/libs/TaskUtils.js | 21 ++++++++++++++++++++- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/components/TaskHeader.js b/src/components/TaskHeader.js index db48d6ff878c..da462f505d84 100644 --- a/src/components/TaskHeader.js +++ b/src/components/TaskHeader.js @@ -3,6 +3,7 @@ import {View} from 'react-native'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import _ from 'underscore'; +import {withOnyx} from 'react-native-onyx'; import reportPropTypes from '../pages/reportPropTypes'; import withLocalize, {withLocalizePropTypes} from './withLocalize'; import * as ReportUtils from '../libs/ReportUtils'; @@ -24,6 +25,7 @@ import * as Task from '../libs/actions/Task'; import * as TaskUtils from '../libs/TaskUtils'; import * as UserUtils from '../libs/UserUtils'; import PressableWithFeedback from './Pressable/PressableWithFeedback'; +import ONYXKEYS from '../ONYXKEYS'; const propTypes = { /** The report currently being looked at */ @@ -32,9 +34,20 @@ const propTypes = { /** Personal details so we can get the ones for the report participants */ personalDetails: PropTypes.objectOf(participantPropTypes).isRequired, + /** Current user session */ + session: PropTypes.shape({ + email: PropTypes.string.isRequired, + }), + ...withLocalizePropTypes, }; +const defaultProps = { + session: { + email: null, + }, +}; + function TaskHeader(props) { const title = ReportUtils.getReportName(props.report); const assigneeEmail = TaskUtils.getTaskAssigneeEmail(props.report); @@ -95,7 +108,7 @@ function TaskHeader(props) { ) : (