Skip to content

Commit

Permalink
Merge pull request #29636 from salonikumawat28/issue_27704
Browse files Browse the repository at this point in the history
Fix for Not found page appearing for private notes list, view and edit pages in deep link
  • Loading branch information
MonilBhavsar authored Nov 6, 2023
2 parents d3edf53 + b131ffb commit b852d71
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 165 deletions.
1 change: 0 additions & 1 deletion src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ export default {
title: 'Private notes',
personalNoteMessage: 'Keep notes about this chat here. You are the only person who can add, edit or view these notes.',
sharedNoteMessage: 'Keep notes about this chat here. Expensify employees and other users on the team.expensify.com domain can view these notes.',
notesUnavailable: 'No notes found for the user',
composerLabel: 'Notes',
myNote: 'My note',
},
Expand Down
1 change: 0 additions & 1 deletion src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,6 @@ export default {
title: 'Notas privadas',
personalNoteMessage: 'Guarda notas sobre este chat aquí. Usted es la única persona que puede añadir, editar o ver estas notas.',
sharedNoteMessage: 'Guarda notas sobre este chat aquí. Los empleados de Expensify y otros usuarios del dominio team.expensify.com pueden ver estas notas.',
notesUnavailable: 'No se han encontrado notas para el usuario',
composerLabel: 'Notas',
myNote: 'Mi nota',
},
Expand Down
140 changes: 56 additions & 84 deletions src/pages/PrivateNotes/PrivateNotesEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, {useCallback, useMemo, useRef, useState} from 'react';
import {Keyboard} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FormProvider from '@components/Form/FormProvider';
import InputWrapper from '@components/Form/InputWrapper';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand All @@ -19,8 +18,8 @@ import withLocalize from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import updateMultilineInputRange from '@libs/UpdateMultilineInputRange';
import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import reportPropTypes from '@pages/reportPropTypes';
import styles from '@styles/styles';
Expand All @@ -43,23 +42,14 @@ const propTypes = {
accountID: PropTypes.string,
}),
}).isRequired,

/** Session of currently logged in user */
session: PropTypes.shape({
/** Currently logged in user accountID */
accountID: PropTypes.number,
}),
};

const defaultProps = {
report: {},
session: {
accountID: null,
},
personalDetailsList: {},
};

function PrivateNotesEditPage({route, personalDetailsList, session, report}) {
function PrivateNotesEditPage({route, personalDetailsList, report}) {
const {translate} = useLocalize();

// We need to edit the note in markdown format, but display it in HTML format
Expand All @@ -81,8 +71,6 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) {
[report.reportID],
);

const isCurrentUserNote = Number(session.accountID) === Number(route.params.accountID);

// To focus on the input field when the page loads
const privateNotesInput = useRef(null);
const focusTimeoutRef = useRef(null);
Expand Down Expand Up @@ -126,73 +114,62 @@ function PrivateNotesEditPage({route, personalDetailsList, session, report}) {
includeSafeAreaPaddingBottom={false}
testID={PrivateNotesEditPage.displayName}
>
<FullPageNotFoundView
shouldShow={
_.isEmpty(report) ||
_.isEmpty(report.privateNotes) ||
!_.has(report, ['privateNotes', route.params.accountID, 'note']) ||
!isCurrentUserNote ||
ReportUtils.isArchivedRoom(report)
}
subtitleKey="privateNotes.notesUnavailable"
<HeaderWithBackButton
title={translate('privateNotes.title')}
subtitle={translate('privateNotes.myNote')}
onBackButtonPress={() => Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID))}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<FormProvider
formID={ONYXKEYS.FORMS.PRIVATE_NOTES_FORM}
onSubmit={savePrivateNote}
style={[styles.flexGrow1, styles.ph5]}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
subtitle={translate('privateNotes.myNote')}
onBackButtonPress={() => Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID))}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<FormProvider
formID={ONYXKEYS.FORMS.PRIVATE_NOTES_FORM}
onSubmit={savePrivateNote}
style={[styles.flexGrow1, styles.ph5]}
submitButtonText={translate('common.save')}
enabledWhenOffline
<Text style={[styles.mb5]}>
{translate(
Str.extractEmailDomain(lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN
? 'privateNotes.sharedNoteMessage'
: 'privateNotes.personalNoteMessage',
)}
</Text>
<OfflineWithFeedback
errors={{
...lodashGet(report, ['privateNotes', route.params.accountID, 'errors'], ''),
}}
onClose={() => Report.clearPrivateNotesError(report.reportID, route.params.accountID)}
style={[styles.mb3]}
>
<Text style={[styles.mb5]}>
{translate(
Str.extractEmailDomain(lodashGet(personalDetailsList, [route.params.accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN
? 'privateNotes.sharedNoteMessage'
: 'privateNotes.personalNoteMessage',
)}
</Text>
<OfflineWithFeedback
errors={{
...lodashGet(report, ['privateNotes', route.params.accountID, 'errors'], ''),
<InputWrapper
InputComponent={TextInput}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="privateNotes"
label={translate('privateNotes.composerLabel')}
accessibilityLabel={translate('privateNotes.title')}
autoCompleteType="off"
maxLength={CONST.MAX_COMMENT_LENGTH}
autoCorrect={false}
autoGrowHeight
textAlignVertical="top"
containerStyles={[styles.autoGrowHeightMultilineInput]}
defaultValue={privateNote}
value={privateNote}
onChangeText={(text) => {
debouncedSavePrivateNote(text);
setPrivateNote(text);
}}
onClose={() => Report.clearPrivateNotesError(report.reportID, route.params.accountID)}
style={[styles.mb3]}
>
<InputWrapper
InputComponent={TextInput}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
inputID="privateNotes"
label={translate('privateNotes.composerLabel')}
accessibilityLabel={translate('privateNotes.title')}
autoCompleteType="off"
maxLength={CONST.MAX_COMMENT_LENGTH}
autoCorrect={false}
autoGrowHeight
textAlignVertical="top"
containerStyles={[styles.autoGrowHeightMultilineInput]}
defaultValue={privateNote}
value={privateNote}
onChangeText={(text) => {
debouncedSavePrivateNote(text);
setPrivateNote(text);
}}
ref={(el) => {
if (!el) {
return;
}
privateNotesInput.current = el;
updateMultilineInputRange(privateNotesInput.current);
}}
/>
</OfflineWithFeedback>
</FormProvider>
</FullPageNotFoundView>
ref={(el) => {
if (!el) {
return;
}
privateNotesInput.current = el;
updateMultilineInputRange(privateNotesInput.current);
}}
/>
</OfflineWithFeedback>
</FormProvider>
</ScreenWrapper>
);
}
Expand All @@ -203,13 +180,8 @@ PrivateNotesEditPage.defaultProps = defaultProps;

export default compose(
withLocalize,
withReportAndPrivateNotesOrNotFound,
withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID.toString()}`,
},
session: {
key: ONYXKEYS.SESSION,
},
personalDetailsList: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
Expand Down
53 changes: 10 additions & 43 deletions src/pages/PrivateNotes/PrivateNotesListPage.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useEffect, useMemo} from 'react';
import React, {useMemo} from 'react';
import {ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItem from '@components/MenuItem';
import networkPropTypes from '@components/networkPropTypes';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {withNetwork} from '@components/OnyxProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import * as UserUtils from '@libs/UserUtils';
import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import reportPropTypes from '@pages/reportPropTypes';
import styles from '@styles/styles';
import * as Report from '@userActions/Report';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand All @@ -47,8 +43,6 @@ const propTypes = {
/** All of the personal details for everyone */
personalDetailsList: PropTypes.objectOf(personalDetailsPropType),

/** Information about the network */
network: networkPropTypes.isRequired,
...withLocalizePropTypes,
};

Expand All @@ -60,17 +54,9 @@ const defaultProps = {
personalDetailsList: {},
};

function PrivateNotesListPage({report, personalDetailsList, network, session}) {
function PrivateNotesListPage({report, personalDetailsList, session}) {
const {translate} = useLocalize();

useEffect(() => {
if (network.isOffline && report.isLoadingPrivateNotes) {
return;
}
Report.getReportPrivateNote(report.reportID);
// eslint-disable-next-line react-hooks/exhaustive-deps -- do not add isLoadingPrivateNotes to dependencies
}, [report.reportID, network.isOffline]);

/**
* Gets the menu item for each workspace
*
Expand Down Expand Up @@ -124,26 +110,12 @@ function PrivateNotesListPage({report, personalDetailsList, network, session}) {
includeSafeAreaPaddingBottom={false}
testID={PrivateNotesListPage.displayName}
>
<FullPageNotFoundView
shouldShow={
_.isEmpty(report.reportID) ||
(!report.isLoadingPrivateNotes && network.isOffline && _.isEmpty(lodashGet(report, 'privateNotes', {}))) ||
ReportUtils.isArchivedRoom(report)
}
>
<HeaderWithBackButton
title={translate('privateNotes.title')}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<ScrollView contentContainerStyle={styles.flexGrow1}>
{report.isLoadingPrivateNotes && _.isEmpty(lodashGet(report, 'privateNotes', {})) ? (
<FullScreenLoadingIndicator style={[styles.flex1, styles.pRelative]} />
) : (
_.map(privateNotes, (item, index) => getMenuItem(item, index))
)}
</ScrollView>
</FullPageNotFoundView>
<HeaderWithBackButton
title={translate('privateNotes.title')}
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<ScrollView contentContainerStyle={styles.flexGrow1}>{_.map(privateNotes, (item, index) => getMenuItem(item, index))}</ScrollView>
</ScreenWrapper>
);
}
Expand All @@ -154,13 +126,8 @@ PrivateNotesListPage.displayName = 'PrivateNotesListPage';

export default compose(
withLocalize,
withReportAndPrivateNotesOrNotFound,
withOnyx({
report: {
key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${route.params.reportID.toString()}`,
},
session: {
key: ONYXKEYS.SESSION,
},
personalDetailsList: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
Expand Down
Loading

0 comments on commit b852d71

Please sign in to comment.