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
101 changes: 56 additions & 45 deletions src/pages/tasks/NewTaskPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect} from 'react';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
Expand All @@ -18,7 +18,9 @@ import MenuItem from '../../components/MenuItem';
import reportPropTypes from '../reportPropTypes';
import * as TaskUtils from '../../libs/actions/Task';
import * as OptionsListUtils from '../../libs/OptionsListUtils';
import * as ReportUtils from '../../libs/ReportUtils';
import FormAlertWithSubmitButton from '../../components/FormAlertWithSubmitButton';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';

const propTypes = {
/** Task Creation Data */
Expand Down Expand Up @@ -72,6 +74,8 @@ function NewTaskPage(props) {
const [errorMessage, setErrorMessage] = React.useState('');
const [parentReport, setParentReport] = React.useState({});

const isAllowedToCreateTask = useMemo(() => _.isEmpty(parentReport) || ReportUtils.isAllowedToComment(parentReport), [parentReport]);

useEffect(() => {
setErrorMessage('');

Expand Down Expand Up @@ -138,52 +142,59 @@ function NewTaskPage(props) {

return (
<ScreenWrapper>
<HeaderWithBackButton
title={props.translate('newTaskPage.confirmTask')}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => Navigation.goBack(ROUTES.NEW_TASK_DETAILS)}
/>
<View style={[styles.containerWithSpaceBetween]}>
<View style={styles.mb5}>
<MenuItemWithTopDescription
description={props.translate('newTaskPage.title')}
title={props.task.title || ''}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_TITLE)}
shouldShowRightIcon
/>
<MenuItemWithTopDescription
description={props.translate('newTaskPage.description')}
title={props.task.description || ''}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_DESCRIPTION)}
shouldShowRightIcon
/>
<MenuItem
label={assignee.displayName ? props.translate('newTaskPage.assignee') : ''}
title={assignee.displayName || ''}
description={assignee.displayName ? assignee.subtitle : props.translate('newTaskPage.assignee')}
icon={assignee.icons}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_ASSIGNEE)}
shouldShowRightIcon
/>
<MenuItem
label={shareDestination.displayName ? props.translate('newTaskPage.shareSomewhere') : ''}
title={shareDestination.displayName || ''}
description={shareDestination.displayName ? shareDestination.subtitle : props.translate('newTaskPage.shareSomewhere')}
icon={shareDestination.icons}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_SHARE_DESTINATION)}
shouldShowRightIcon
<FullPageNotFoundView
shouldShow={!isAllowedToCreateTask}
onBackButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
>
<HeaderWithBackButton
title={props.translate('newTaskPage.confirmTask')}
onCloseButtonPress={() => TaskUtils.dismissModalAndClearOutTaskInfo()}
shouldShowBackButton
onBackButtonPress={() => {
Navigation.goBack(ROUTES.NEW_TASK_DETAILS);
}}
/>
<View style={[styles.containerWithSpaceBetween]}>
<View style={styles.mb5}>
<MenuItemWithTopDescription
description={props.translate('newTaskPage.title')}
title={props.task.title || ''}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_TITLE)}
shouldShowRightIcon
/>
<MenuItemWithTopDescription
description={props.translate('newTaskPage.description')}
title={props.task.description || ''}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_DESCRIPTION)}
shouldShowRightIcon
/>
<MenuItem
label={assignee.displayName ? props.translate('newTaskPage.assignee') : ''}
title={assignee.displayName || ''}
description={assignee.displayName ? assignee.subtitle : props.translate('newTaskPage.assignee')}
icon={assignee.icons}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_ASSIGNEE)}
shouldShowRightIcon
/>
<MenuItem
label={shareDestination.displayName ? props.translate('newTaskPage.shareSomewhere') : ''}
title={shareDestination.displayName || ''}
description={shareDestination.displayName ? shareDestination.subtitle : props.translate('newTaskPage.shareSomewhere')}
icon={shareDestination.icons}
onPress={() => Navigation.navigate(ROUTES.NEW_TASK_SHARE_DESTINATION)}
shouldShowRightIcon
/>
</View>
<FormAlertWithSubmitButton
isAlertVisible={!_.isEmpty(errorMessage)}
message={errorMessage}
onSubmit={() => onSubmit()}
enabledWhenOffline
buttonText={props.translate('newTaskPage.confirmTask')}
containerStyles={[styles.mh0, styles.mt5, styles.flex1, styles.ph5]}
/>
</View>
<FormAlertWithSubmitButton
isAlertVisible={!_.isEmpty(errorMessage)}
message={errorMessage}
onSubmit={() => onSubmit()}
enabledWhenOffline
buttonText={props.translate('newTaskPage.confirmTask')}
containerStyles={[styles.mh0, styles.mt5, styles.flex1, styles.ph5]}
/>
</View>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
Expand Down
24 changes: 19 additions & 5 deletions src/pages/tasks/TaskShareDestinationSelectorModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable es/no-optional-chaining */
import React, {useState, useEffect} from 'react';
import React, {useState, useEffect, useMemo} from 'react';
import _ from 'underscore';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
Expand All @@ -16,6 +17,7 @@ import compose from '../../libs/compose';
import personalDetailsPropType from '../personalDetailsPropType';
import reportPropTypes from '../reportPropTypes';
import * as TaskUtils from '../../libs/actions/Task';
import * as ReportUtils from '../../libs/ReportUtils';
import ROUTES from '../../ROUTES';

const propTypes = {
Expand Down Expand Up @@ -46,17 +48,29 @@ function TaskShareDestinationSelectorModal(props) {
const [filteredPersonalDetails, setFilteredPersonalDetails] = useState([]);
const [filteredUserToInvite, setFilteredUserToInvite] = useState(null);

// Filter out all the reports where user is not allowed to create task
const filteredReports = useMemo(() => {
const reports = {};
_.keys(props.reports).forEach((reportKey) => {
if (!ReportUtils.isAllowedToComment(props.reports[reportKey])) {
return;
}
reports[reportKey] = props.reports[reportKey];
});
return reports;
}, [props.reports]);

useEffect(() => {
const results = OptionsListUtils.getShareDestinationOptions(props.reports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, true);
const results = OptionsListUtils.getShareDestinationOptions(filteredReports, props.personalDetails, props.betas, '', [], CONST.EXPENSIFY_EMAILS, true);

setFilteredUserToInvite(results.userToInvite);
setFilteredRecentReports(results.recentReports);
setFilteredPersonalDetails(results.personalDetails);
}, [props]);
}, [props, filteredReports]);

useEffect(() => {
const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getShareDestinationOptions(
props.reports,
filteredReports,
props.personalDetails,
props.betas,
searchValue.trim(),
Expand All @@ -70,7 +84,7 @@ function TaskShareDestinationSelectorModal(props) {
setFilteredUserToInvite(userToInvite);
setFilteredRecentReports(recentReports);
setFilteredPersonalDetails(personalDetails);
}, [props, searchValue]);
}, [props, searchValue, filteredReports]);

const onChangeText = (newSearchTerm = '') => {
setSearchValue(newSearchTerm);
Expand Down