From c4d9d12cde28367ec3b52b47dd33821637fa2911 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 26 Jan 2024 11:46:20 +0700 Subject: [PATCH 1/5] allow member to edit task --- .../ReportActionItem/TaskPreview.tsx | 28 ++----------------- src/components/ReportActionItem/TaskView.js | 21 +------------- src/components/TaskHeaderActionButton.tsx | 13 ++------- src/libs/actions/Task.ts | 13 ++------- src/pages/home/HeaderView.js | 16 +---------- src/pages/home/report/ReportActionItem.js | 1 - src/pages/tasks/TaskAssigneeSelectorModal.js | 19 +------------ src/pages/tasks/TaskDescriptionPage.js | 19 +------------ src/pages/tasks/TaskTitlePage.js | 16 +---------- 9 files changed, 12 insertions(+), 134 deletions(-) diff --git a/src/components/ReportActionItem/TaskPreview.tsx b/src/components/ReportActionItem/TaskPreview.tsx index cbd166d79d3a..9de95ca0cb3f 100644 --- a/src/components/ReportActionItem/TaskPreview.tsx +++ b/src/components/ReportActionItem/TaskPreview.tsx @@ -29,22 +29,14 @@ import * as Task from '@userActions/Task'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {Policy, Report, ReportAction} from '@src/types/onyx'; +import type {Report, ReportAction} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -type PolicyRole = { - /** The role of current user */ - role: Task.PolicyValue | undefined; -}; - type TaskPreviewOnyxProps = { /* Onyx Props */ /* current report of TaskPreview */ taskReport: OnyxEntry; - - /** The policy of root parent report */ - rootParentReportpolicy: OnyxEntry; }; type TaskPreviewProps = WithCurrentUserPersonalDetailsProps & @@ -71,17 +63,7 @@ type TaskPreviewProps = WithCurrentUserPersonalDetailsProps & checkIfContextMenuActive: () => void; }; -function TaskPreview({ - taskReport, - taskReportID, - action, - contextMenuAnchor, - chatReportID, - checkIfContextMenuActive, - currentUserPersonalDetails, - rootParentReportpolicy, - isHovered = false, -}: TaskPreviewProps) { +function TaskPreview({taskReport, taskReportID, action, contextMenuAnchor, chatReportID, checkIfContextMenuActive, currentUserPersonalDetails, isHovered = false}: TaskPreviewProps) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; @@ -124,7 +106,7 @@ function TaskPreview({ style={[styles.mr2]} containerStyle={[styles.taskCheckbox]} isChecked={isTaskCompleted} - disabled={!Task.canModifyTask(taskReport, currentUserPersonalDetails.accountID, rootParentReportpolicy?.role)} + disabled={!Task.canModifyTask(taskReport, currentUserPersonalDetails.accountID)} onPress={Session.checkIfActionIsAllowed(() => { if (isTaskCompleted) { Task.reopenTask(taskReport); @@ -152,9 +134,5 @@ export default withCurrentUserPersonalDetails( taskReport: { key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`, }, - rootParentReportpolicy: { - key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID ?? '0'}`, - selector: (policy: Policy | null) => ({role: policy?.role}), - }, })(TaskPreview), ); diff --git a/src/components/ReportActionItem/TaskView.js b/src/components/ReportActionItem/TaskView.js index 7f7b177136ed..bb8945495018 100644 --- a/src/components/ReportActionItem/TaskView.js +++ b/src/components/ReportActionItem/TaskView.js @@ -3,7 +3,6 @@ import PropTypes from 'prop-types'; import React, {useEffect} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; -import _ from 'underscore'; import Checkbox from '@components/Checkbox'; import Hoverable from '@components/Hoverable'; import Icon from '@components/Icon'; @@ -37,12 +36,6 @@ const propTypes = { /** The report currently being looked at */ report: reportPropTypes.isRequired, - /** The policy of root parent report */ - policy: PropTypes.shape({ - /** The role of current user */ - role: PropTypes.string, - }), - /** Whether we should display the horizontal rule below the component */ shouldShowHorizontalRule: PropTypes.bool.isRequired, @@ -51,10 +44,6 @@ const propTypes = { ...withCurrentUserPersonalDetailsPropTypes, }; -const defaultProps = { - policy: {}, -}; - function TaskView(props) { const styles = useThemeStyles(); const StyleUtils = useStyleUtils(); @@ -66,7 +55,7 @@ function TaskView(props) { const assigneeTooltipDetails = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs([props.report.managerID], props.personalDetails), false); const isCompleted = ReportUtils.isCompletedTaskReport(props.report); const isOpen = ReportUtils.isOpenTaskReport(props.report); - const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID, lodashGet(props.policy, 'role', '')); + const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID); const disableState = !canModifyTask; const isDisableInteractive = !canModifyTask || !isOpen; const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; @@ -199,7 +188,6 @@ function TaskView(props) { } TaskView.propTypes = propTypes; -TaskView.defaultProps = defaultProps; TaskView.displayName = 'TaskView'; export default compose( @@ -210,12 +198,5 @@ export default compose( personalDetails: { key: ONYXKEYS.PERSONAL_DETAILS_LIST, }, - policy: { - key: ({report}) => { - const rootParentReport = ReportUtils.getRootParentReport(report); - return `${ONYXKEYS.COLLECTION.POLICY}${rootParentReport ? rootParentReport.policyID : '0'}`; - }, - selector: (policy) => _.pick(policy, ['role']), - }, }), )(TaskView); diff --git a/src/components/TaskHeaderActionButton.tsx b/src/components/TaskHeaderActionButton.tsx index d39f03c5aad4..2d964f58c253 100644 --- a/src/components/TaskHeaderActionButton.tsx +++ b/src/components/TaskHeaderActionButton.tsx @@ -14,9 +14,6 @@ import Button from './Button'; type TaskHeaderActionButtonOnyxProps = { /** Current user session */ session: OnyxEntry; - - /** The policy of root parent report */ - policy: OnyxEntry; }; type TaskHeaderActionButtonProps = TaskHeaderActionButtonOnyxProps & { @@ -24,7 +21,7 @@ type TaskHeaderActionButtonProps = TaskHeaderActionButtonOnyxProps & { report: OnyxTypes.Report; }; -function TaskHeaderActionButton({report, session, policy}: TaskHeaderActionButtonProps) { +function TaskHeaderActionButton({report, session}: TaskHeaderActionButtonProps) { const {translate} = useLocalize(); const styles = useThemeStyles(); @@ -32,7 +29,7 @@ function TaskHeaderActionButton({report, session, policy}: TaskHeaderActionButto