Skip to content

Commit

Permalink
Merge pull request #26634 from BhuvaneshPatil/22451-disallow-changing…
Browse files Browse the repository at this point in the history
…-title-for-completed-task
  • Loading branch information
thienlnam authored Sep 13, 2023
2 parents 07c28d6 + ee095a7 commit 2435680
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 51 deletions.
13 changes: 10 additions & 3 deletions src/pages/tasks/TaskAssigneeSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize
import compose from '../../libs/compose';
import personalDetailsPropType from '../personalDetailsPropType';
import reportPropTypes from '../reportPropTypes';
import ROUTES from '../../ROUTES';
import * as ReportUtils from '../../libs/ReportUtils';
import ROUTES from '../../ROUTES';
import * as Task from '../../libs/actions/Task';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails';

const propTypes = {
/** Beta features list */
Expand Down Expand Up @@ -194,10 +196,14 @@ function TaskAssigneeSelectorModal(props) {
}
};

const isOpen = ReportUtils.isOpenTaskReport(props.task.report);
const canModifyTask = Task.canModifyTask(props.task.report, props.currentUserPersonalDetails.accountID);
const isTaskNonEditable = report && ReportUtils.isTaskReport(props.task.report) && (!canModifyTask || !isOpen);

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
{({didScreenTransitionEnd, safeAreaPaddingBottomStyle}) => (
<>
<FullPageNotFoundView shouldShow={isTaskNonEditable}>
<HeaderWithBackButton
title={props.translate('task.assignee')}
onBackButtonPress={() => (lodashGet(props.route.params, 'reportID') ? Navigation.dismissModal() : Navigation.goBack(ROUTES.NEW_TASK))}
Expand All @@ -215,7 +221,7 @@ function TaskAssigneeSelectorModal(props) {
safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle}
/>
</View>
</>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
Expand All @@ -227,6 +233,7 @@ TaskAssigneeSelectorModal.defaultProps = defaultProps;

export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withOnyx({
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
Expand Down
74 changes: 48 additions & 26 deletions src/pages/tasks/TaskDescriptionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import reportPropTypes from '../reportPropTypes';
import styles from '../../styles/styles';
import compose from '../../libs/compose';
import * as Task from '../../libs/actions/Task';
import * as ReportUtils from '../../libs/ReportUtils';
import CONST from '../../CONST';
import focusAndUpdateMultilineInputRange from '../../libs/focusAndUpdateMultilineInputRange';
import * as Browser from '../../libs/Browser';
import * as ReportUtils from '../../libs/ReportUtils';
import Navigation from '../../libs/Navigation/Navigation';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails';
import withReportOrNotFound from '../home/report/withReportOrNotFound';

const propTypes = {
/** Current user session */
Expand Down Expand Up @@ -55,37 +58,54 @@ function TaskDescriptionPage(props) {
}
const inputRef = useRef(null);

const isOpen = ReportUtils.isOpenTaskReport(props.report);
const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID);
const isTaskNonEditable = ReportUtils.isTaskReport(props.report) && (!canModifyTask || !isOpen);

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
onEntryTransitionEnd={() => focusAndUpdateMultilineInputRange(inputRef.current)}
shouldEnableMaxHeight
>
<HeaderWithBackButton title={props.translate('task.task')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.EDIT_TASK_FORM}
validate={validate}
onSubmit={submit}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<View style={[styles.mb4]}>
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="description"
name="description"
label={props.translate('newTaskPage.descriptionOptional')}
accessibilityLabel={props.translate('newTaskPage.descriptionOptional')}
defaultValue={(props.report && props.report.description) || ''}
ref={(el) => (inputRef.current = el)}
autoGrowHeight
submitOnEnter={!Browser.isMobile()}
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
/>
</View>
</Form>
{({didScreenTransitionEnd}) => (
<FullPageNotFoundView shouldShow={isTaskNonEditable}>
<HeaderWithBackButton title={props.translate('task.task')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.EDIT_TASK_FORM}
validate={validate}
onSubmit={submit}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<View style={[styles.mb4]}>
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="description"
name="description"
label={props.translate('newTaskPage.descriptionOptional')}
accessibilityLabel={props.translate('newTaskPage.descriptionOptional')}
defaultValue={(props.report && props.report.description) || ''}
ref={(el) => {
// if we wrap the page with FullPageNotFoundView we need to explicitly handle focusing on text input
if (!el) {
return;
}
if (!inputRef.current && didScreenTransitionEnd) {
focusAndUpdateMultilineInputRange(el);
}
inputRef.current = el;
}}
autoGrowHeight
submitOnEnter={!Browser.isMobile()}
containerStyles={[styles.autoGrowHeightMultilineInput]}
textAlignVertical="top"
/>
</View>
</Form>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
Expand All @@ -95,6 +115,8 @@ TaskDescriptionPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withReportOrNotFound,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
Expand Down
62 changes: 40 additions & 22 deletions src/pages/tasks/TaskTitlePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import styles from '../../styles/styles';
import reportPropTypes from '../reportPropTypes';
import compose from '../../libs/compose';
import * as Task from '../../libs/actions/Task';
import CONST from '../../CONST';
import * as ReportUtils from '../../libs/ReportUtils';
import CONST from '../../CONST';
import Navigation from '../../libs/Navigation/Navigation';
import FullPageNotFoundView from '../../components/BlockingViews/FullPageNotFoundView';
import withCurrentUserPersonalDetails from '../../components/withCurrentUserPersonalDetails';
import withReportOrNotFound from '../home/report/withReportOrNotFound';

const propTypes = {
/** The report currently being looked at */
Expand Down Expand Up @@ -67,34 +70,47 @@ function TaskTitlePage(props) {
}

const inputRef = useRef(null);
const isOpen = ReportUtils.isOpenTaskReport(props.report);
const canModifyTask = Task.canModifyTask(props.report, props.currentUserPersonalDetails.accountID);
const isTaskNonEditable = ReportUtils.isTaskReport(props.report) && (!canModifyTask || !isOpen);

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
onEntryTransitionEnd={() => inputRef.current && inputRef.current.focus()}
shouldEnableMaxHeight
>
<HeaderWithBackButton title={props.translate('task.task')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.EDIT_TASK_FORM}
validate={validate}
onSubmit={submit}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<View style={[styles.mb4]}>
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="title"
name="title"
label={props.translate('task.title')}
accessibilityLabel={props.translate('task.title')}
defaultValue={(props.report && props.report.reportName) || ''}
ref={(el) => (inputRef.current = el)}
/>
</View>
</Form>
{({didScreenTransitionEnd}) => (
<FullPageNotFoundView shouldShow={isTaskNonEditable}>
<HeaderWithBackButton title={props.translate('task.task')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.EDIT_TASK_FORM}
validate={validate}
onSubmit={submit}
submitButtonText={props.translate('common.save')}
enabledWhenOffline
>
<View style={[styles.mb4]}>
<TextInput
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="title"
name="title"
label={props.translate('task.title')}
accessibilityLabel={props.translate('task.title')}
defaultValue={(props.report && props.report.reportName) || ''}
ref={(el) => {
if (!el) return;
if (!inputRef.current && didScreenTransitionEnd) {
el.focus();
}
inputRef.current = el;
}}
/>
</View>
</Form>
</FullPageNotFoundView>
)}
</ScreenWrapper>
);
}
Expand All @@ -104,6 +120,8 @@ TaskTitlePage.defaultProps = defaultProps;

export default compose(
withLocalize,
withCurrentUserPersonalDetails,
withReportOrNotFound,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
Expand Down

0 comments on commit 2435680

Please sign in to comment.