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

feat: update ProfilePage #42188

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
17 changes: 16 additions & 1 deletion src/components/PromotedActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import {View} from 'react-native';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as HeaderUtils from '@libs/HeaderUtils';
import * as Localize from '@libs/Localize';
import * as ReportActions from '@userActions/Report';
import type OnyxReport from '@src/types/onyx/Report';
import Button from './Button';
import type {ThreeDotsMenuItem} from './HeaderWithBackButton/types';
import * as Expensicons from './Icon/Expensicons';

type PromotedAction = {
key: string;
} & ThreeDotsMenuItem;

type PromotedActionsType = Record<'pin' | 'share', (report: OnyxReport) => PromotedAction>;
type PromotedActionsType = Record<'pin' | 'share', (report: OnyxReport) => PromotedAction> & {
message: (accountID: number) => PromotedAction;
};

const PromotedActions = {
pin: (report) => ({
Expand All @@ -23,6 +28,12 @@ const PromotedActions = {
key: 'share',
...HeaderUtils.getShareMenuItem(report),
}),
message: (accountID) => ({
key: 'message',
icon: Expensicons.CommentBubbles,
text: Localize.translateLocal('common.message'),
onSelected: () => ReportActions.navigateToAndOpenReportWithAccountIDs([accountID]),
}),
} satisfies PromotedActionsType;

type PromotedActionsBarProps = {
Expand All @@ -41,6 +52,10 @@ function PromotedActionsBar({promotedActions, containerStyle}: PromotedActionsBa
return null;
}

if (promotedActions.length === 0) {
return null;
}

Comment on lines 52 to +58
Copy link
Contributor

Choose a reason for hiding this comment

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

@kosmydel Any specific reason why the additional identical early return is needed here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it must have been added by mistake.

return (
<View style={[styles.flexRow, styles.ph5, styles.mb5, styles.gap2, styles.mw100, styles.w100, styles.justifyContentCenter, containerStyle]}>
{promotedActions.map(({key, onSelected, ...props}) => (
Expand Down
37 changes: 22 additions & 15 deletions src/pages/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import MenuItem from '@components/MenuItem';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import PressableWithoutFocus from '@components/Pressable/PressableWithoutFocus';
import type {PromotedAction} from '@components/PromotedActionsBar';
import PromotedActionsBar, {PromotedActions} from '@components/PromotedActionsBar';
import ScreenWrapper from '@components/ScreenWrapper';
import ScrollView from '@components/ScrollView';
import Text from '@components/Text';
Expand Down Expand Up @@ -137,6 +139,18 @@ function ProfilePage({route}: ProfilePageProps) {
}
}, [accountID]);

const promotedActions = useMemo(() => {
const result: PromotedAction[] = [];
if (report) {
result.push(PromotedActions.pin(report));
}

if (!isCurrentUser && !SessionActions.isAnonymousUser()) {
result.push(PromotedActions.message(accountID));
}
return result;
}, [accountID, isCurrentUser, report]);

return (
<ScreenWrapper testID={ProfilePage.displayName}>
<FullPageNotFoundView shouldShow={CONST.RESTRICTED_ACCOUNT_IDS.includes(accountID)}>
Expand All @@ -146,17 +160,17 @@ function ProfilePage({route}: ProfilePageProps) {
/>
<View style={[styles.containerWithSpaceBetween, styles.pointerEventsBoxNone]}>
<ScrollView>
<View style={styles.avatarSectionWrapper}>
<View style={[styles.avatarSectionWrapper, styles.pb0]}>
<PressableWithoutFocus
style={[styles.noOutline]}
style={[styles.noOutline, styles.mb4]}
onPress={() => Navigation.navigate(ROUTES.PROFILE_AVATAR.getRoute(String(accountID)))}
accessibilityLabel={translate('common.profile')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON}
disabled={!hasAvatar}
>
<OfflineWithFeedback pendingAction={details?.pendingFields?.avatar}>
<Avatar
containerStyles={[styles.avatarXLarge, styles.mb3]}
containerStyles={[styles.avatarXLarge]}
imageStyles={[styles.avatarXLarge]}
source={details.avatar}
avatarID={accountID}
Expand All @@ -167,12 +181,16 @@ function ProfilePage({route}: ProfilePageProps) {
</PressableWithoutFocus>
{Boolean(displayName) && (
<Text
style={[styles.textHeadline, styles.pre, styles.mb6, styles.w100, styles.textAlignCenter]}
style={[styles.textHeadline, styles.pre, styles.mb8, styles.w100, styles.textAlignCenter]}
numberOfLines={1}
>
{displayName}
</Text>
)}
<PromotedActionsBar
promotedActions={promotedActions}
containerStyle={[styles.ph0, styles.mb8]}
/>
{hasStatus && (
<View style={[styles.mb6, styles.detailsPageSectionContainer, styles.mw100]}>
<Text
Expand Down Expand Up @@ -220,17 +238,6 @@ function ProfilePage({route}: ProfilePageProps) {
title={notificationPreference}
description={translate('notificationPreferencesPage.label')}
onPress={() => Navigation.navigate(ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES.getRoute(report.reportID))}
wrapperStyle={[styles.mtn6, styles.mb5]}
/>
)}
{!isCurrentUser && !SessionActions.isAnonymousUser() && (
<MenuItem
title={`${translate('common.message')}${displayName}`}
titleStyle={styles.flex1}
icon={Expensicons.ChatBubble}
onPress={() => ReportActions.navigateToAndOpenReportWithAccountIDs([accountID])}
wrapperStyle={styles.breakAll}
shouldShowRightIcon
/>
)}
{!isEmptyObject(report) && report.reportID && !isCurrentUser && (
Expand Down
Loading