Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/27634: Improve private notes flow #31344

Merged
merged 16 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/pages/PrivateNotes/PrivateNotesEditPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) {
Keyboard.dismiss();

// Take user back to the PrivateNotesView page
Navigation.goBack(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, route.params.accountID));

Navigation.goBack();
};

return (
Expand All @@ -116,7 +117,6 @@ function PrivateNotesEditPage({route, personalDetailsList, report}) {
>
<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()}
Expand Down
38 changes: 25 additions & 13 deletions src/pages/PrivateNotes/PrivateNotesListPage.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import {some} from 'lodash';
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useMemo} from 'react';
import React, {useEffect, useMemo} from 'react';
import {ScrollView} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import {withNetwork} from '@components/OnyxProvider';
import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useLocalize from '@hooks/useLocalize';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as UserUtils from '@libs/UserUtils';
import withReportAndPrivateNotesOrNotFound from '@pages/home/report/withReportAndPrivateNotesOrNotFound';
import personalDetailsPropType from '@pages/personalDetailsPropType';
import reportPropTypes from '@pages/reportPropTypes';
Expand Down Expand Up @@ -66,7 +67,6 @@ function PrivateNotesListPage({report, personalDetailsList, session}) {
*/
function getMenuItem(item, index) {
const keyTitle = item.translationKey ? translate(item.translationKey) : item.title;

return (
<OfflineWithFeedback
key={`${keyTitle}_${index}`}
Expand All @@ -75,14 +75,16 @@ function PrivateNotesListPage({report, personalDetailsList, session}) {
onClose={item.dismissError}
errors={item.errors}
>
<MenuItem
title={keyTitle}
icon={item.icon}
iconType={CONST.ICON_TYPE_WORKSPACE}
<MenuItemWithTopDescription
description={item.title}
title={item.note}
onPress={item.action}
shouldShowRightIcon
fallbackIcon={item.fallbackIcon}
shouldShowRightIcon={!item.disabled}
numberOfLinesTitle={0}
shouldRenderAsHTML
brickRoadIndicator={item.brickRoadIndicator}
disabled={item.disabled}
shouldGreyOutWhenDisabled={false}
/>
</OfflineWithFeedback>
);
Expand All @@ -97,14 +99,20 @@ function PrivateNotesListPage({report, personalDetailsList, session}) {
return _.chain(lodashGet(report, 'privateNotes', {}))
.map((privateNote, accountID) => ({
title: Number(lodashGet(session, 'accountID', null)) === Number(accountID) ? translate('privateNotes.myNote') : lodashGet(personalDetailsList, [accountID, 'login'], ''),
icon: UserUtils.getAvatar(lodashGet(personalDetailsList, [accountID, 'avatar'], UserUtils.getDefaultAvatar(accountID)), accountID),
iconType: CONST.ICON_TYPE_AVATAR,
action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_VIEW.getRoute(report.reportID, accountID)),
action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, accountID)),
brickRoadIndicator: privateNoteBrickRoadIndicator(accountID),
note: lodashGet(privateNote, 'note', ''),
disabled: Number(session.accountID) !== Number(accountID),
}))
.value();
}, [report, personalDetailsList, session, translate]);

useEffect(() => {
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
if (some(privateNotes, (item) => item.note)) {
DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
return;
}
Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID));
}, [privateNotes, report.reportID, session.accountID]);
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand All @@ -115,6 +123,7 @@ function PrivateNotesListPage({report, personalDetailsList, session}) {
shouldShowBackButton
onCloseButtonPress={() => Navigation.dismissModal()}
/>
<Text style={[styles.mb5, styles.ph5]}>{translate('privateNotes.personalNoteMessage')}</Text>
<ScrollView contentContainerStyle={styles.flexGrow1}>{_.map(privateNotes, (item, index) => getMenuItem(item, index))}</ScrollView>
</ScreenWrapper>
);
Expand All @@ -131,6 +140,9 @@ export default compose(
personalDetailsList: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
withNetwork(),
)(PrivateNotesListPage);
16 changes: 14 additions & 2 deletions src/pages/ReportDetailsPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {isEmpty} from 'lodash';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useMemo} from 'react';
Expand Down Expand Up @@ -139,7 +140,15 @@ function ReportDetailsPage(props) {
translationKey: 'privateNotes.title',
icon: Expensicons.Pencil,
isAnonymousAction: false,
action: () => Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID)),
action: () => {
const currentUserPrivateNote = lodashGet(props.report, ['privateNotes', props.session.accountID, 'note'], '');
if (isEmpty(currentUserPrivateNote)) {
Report.getReportPrivateNote(props.report.reportID);
Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(props.report.reportID, props.session.accountID));
return;
}
Navigation.navigate(ROUTES.PRIVATE_NOTES_LIST.getRoute(props.report.reportID));
},
brickRoadIndicator: Report.hasErrorInPrivateNotes(props.report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : '',
});
}
Expand All @@ -156,7 +165,7 @@ function ReportDetailsPage(props) {
}

return items;
}, [props.report, isMoneyRequestReport, participants.length, isArchivedRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat, isPolicyMember]);
}, [props.report, isMoneyRequestReport, participants.length, isArchivedRoom, isThread, isUserCreatedPolicyRoom, canLeaveRoom, isGroupDMChat, isPolicyMember, props.session.accountID]);

const displayNamesWithTooltips = useMemo(() => {
const hasMultipleParticipants = participants.length > 1;
Expand Down Expand Up @@ -271,5 +280,8 @@ export default compose(
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
session: {
key: ONYXKEYS.SESSION,
},
}),
)(ReportDetailsPage);
Loading