Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/components/ReportActionItem/TaskPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import compose from '../../libs/compose';
import styles from '../../styles/styles';
import ONYXKEYS from '../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../withCurrentUserPersonalDetails';
import Icon from '../Icon';
import CONST from '../../CONST';
import * as Expensicons from '../Icon/Expensicons';
Expand Down Expand Up @@ -52,9 +53,12 @@ const propTypes = {
}),

...withLocalizePropTypes,

...withCurrentUserPersonalDetailsPropTypes,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to use withCurrentUserPersonalDetailsDefaultProps.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in commit d2b8d08

};

const defaultProps = {
...withCurrentUserPersonalDetailsDefaultProps,
personalDetailsList: {},
taskReport: {},
isHovered: false,
Expand Down Expand Up @@ -92,7 +96,7 @@ function TaskPreview(props) {
style={[styles.mr2]}
containerStyle={[styles.taskCheckbox]}
isChecked={isTaskCompleted}
disabled={ReportUtils.isCanceledTaskReport(props.taskReport)}
disabled={!Task.canModifyTask(props.taskReport, props.currentUserPersonalDetails.accountID)}
onPress={Session.checkIfActionIsAllowed(() => {
if (isTaskCompleted) {
Task.reopenTask(props.taskReport);
Expand All @@ -119,6 +123,7 @@ TaskPreview.displayName = 'TaskPreview';

export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withOnyx({
taskReport: {
key: ({taskReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${taskReportID}`,
Expand Down
5 changes: 2 additions & 3 deletions src/components/ReportActionItem/TaskView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ function TaskView(props) {
const taskTitle = convertToLTR(props.report.reportName || '');
const isCompleted = ReportUtils.isCompletedTaskReport(props.report);
const isOpen = ReportUtils.isOpenTaskReport(props.report);
const isCanceled = ReportUtils.isCanceledTaskReport(props.report);
const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID);
const disableState = !canModifyTask || isCanceled;
const disableState = !canModifyTask;
const isDisableInteractive = !canModifyTask || !isOpen;
return (
<View>
Expand Down Expand Up @@ -102,7 +101,7 @@ function TaskView(props) {
containerBorderRadius={8}
caretSize={16}
accessibilityLabel={taskTitle || props.translate('task.task')}
disabled={isCanceled || !canModifyTask}
disabled={!canModifyTask}
/>
<View style={[styles.flexRow, styles.flex1]}>
<Text
Expand Down
2 changes: 1 addition & 1 deletion src/components/TaskHeaderActionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function TaskHeaderActionButton(props) {
<View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentEnd]}>
<Button
success
isDisabled={ReportUtils.isCanceledTaskReport(props.report) || !Task.canModifyTask(props.report, props.session.accountID)}
isDisabled={!Task.canModifyTask(props.report, props.session.accountID)}
medium
text={props.translate(ReportUtils.isCompletedTaskReport(props.report) ? 'task.markAsIncomplete' : 'task.markAsComplete')}
onPress={() => (ReportUtils.isCompletedTaskReport(props.report) ? Task.reopenTask(props.report) : Task.completeTask(props.report))}
Expand Down
4 changes: 4 additions & 0 deletions src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,10 @@ function getTaskOwnerAccountID(taskReport) {
* @returns {Boolean}
*/
function canModifyTask(taskReport, sessionAccountID) {
if (ReportUtils.isCanceledTaskReport(taskReport)) {
return false;
}

if (sessionAccountID === getTaskOwnerAccountID(taskReport) || sessionAccountID === getTaskAssigneeAccountID(taskReport)) {
return true;
}
Expand Down