fix the profile update through all the app

This commit is contained in:
Reinaldo Neto 2022-12-12 14:47:12 -03:00
parent a283f41022
commit a478f1ff52
11 changed files with 59 additions and 20 deletions

View File

@ -18,11 +18,19 @@ const IconOrAvatar = ({
teamMain, teamMain,
showLastMessage, showLastMessage,
displayMode, displayMode,
sourceType sourceType,
isUserProfile
}: IIconOrAvatar): React.ReactElement | null => { }: IIconOrAvatar): React.ReactElement | null => {
if (showAvatar) { if (showAvatar) {
return ( return (
<Avatar text={avatar} size={displayMode === DisplayMode.Condensed ? 36 : 48} type={type} style={styles.avatar} rid={rid} /> <Avatar
isUserProfile={isUserProfile}
text={avatar}
size={displayMode === DisplayMode.Condensed ? 36 : 48}
type={type}
style={styles.avatar}
rid={rid}
/>
); );
} }

View File

@ -52,7 +52,8 @@ const RoomItem = ({
showAvatar, showAvatar,
displayMode, displayMode,
sourceType, sourceType,
hideMentionStatus hideMentionStatus,
isUserProfile
}: IRoomItemProps) => ( }: IRoomItemProps) => (
<Touchable <Touchable
onPress={onPress} onPress={onPress}
@ -83,6 +84,7 @@ const RoomItem = ({
showAvatar={showAvatar} showAvatar={showAvatar}
showLastMessage={!!showLastMessage} showLastMessage={!!showLastMessage}
sourceType={sourceType} sourceType={sourceType}
isUserProfile={isUserProfile}
> >
{showLastMessage && displayMode === DisplayMode.Expanded ? ( {showLastMessage && displayMode === DisplayMode.Expanded ? (
<> <>

View File

@ -34,7 +34,8 @@ const RoomItemContainer = React.memo(
getRoomTitle = () => 'title', getRoomTitle = () => 'title',
getRoomAvatar = () => '', getRoomAvatar = () => '',
getIsRead = () => false, getIsRead = () => false,
swipeEnabled = true swipeEnabled = true,
isUserProfile
}: IRoomItemContainerProps) => { }: IRoomItemContainerProps) => {
const name = getRoomTitle(item); const name = getRoomTitle(item);
const testID = `rooms-list-view-item-${name}`; const testID = `rooms-list-view-item-${name}`;
@ -127,6 +128,7 @@ const RoomItemContainer = React.memo(
showAvatar={showAvatar} showAvatar={showAvatar}
displayMode={displayMode} displayMode={displayMode}
sourceType={item.source} sourceType={item.source}
isUserProfile={isUserProfile}
/> />
); );
}, },

View File

@ -47,6 +47,7 @@ export interface IWrapperProps {
teamMain: boolean; teamMain: boolean;
showAvatar: boolean; showAvatar: boolean;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
isUserProfile: boolean;
} }
export interface ITypeIconProps { export interface ITypeIconProps {
@ -116,6 +117,7 @@ export interface IRoomItemProps extends IBaseRoomItem {
size?: number; size?: number;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
hideMentionStatus?: boolean; hideMentionStatus?: boolean;
isUserProfile: boolean;
} }
export interface ILastMessageProps { export interface ILastMessageProps {
@ -152,4 +154,5 @@ export interface IIconOrAvatar {
teamMain: boolean; teamMain: boolean;
showLastMessage: boolean; showLastMessage: boolean;
sourceType: IOmnichannelSource; sourceType: IOmnichannelSource;
isUserProfile: boolean;
} }

View File

@ -1,6 +1,8 @@
import React from 'react'; import React from 'react';
import { Pressable, StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native'; import { Pressable, StyleProp, StyleSheet, Text, View, ViewStyle } from 'react-native';
import { useAppSelector } from '../lib/hooks';
import { getUserSelector } from '../selectors/login';
import Avatar from './Avatar'; import Avatar from './Avatar';
import { CustomIcon, TIconsName } from './CustomIcon'; import { CustomIcon, TIconsName } from './CustomIcon';
import sharedStyles from '../views/Styles'; import sharedStyles from '../views/Styles';
@ -43,10 +45,12 @@ interface IUserItem {
style?: StyleProp<ViewStyle>; style?: StyleProp<ViewStyle>;
icon?: TIconsName | null; icon?: TIconsName | null;
iconColor?: string; iconColor?: string;
id?: string;
} }
const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, iconColor }: IUserItem) => { const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, iconColor, id }: IUserItem) => {
const { colors } = useTheme(); const { colors } = useTheme();
const { userId } = useAppSelector(state => ({ userId: getUserSelector(state).id }));
return ( return (
<Pressable <Pressable
@ -61,7 +65,7 @@ const UserItem = ({ name, username, onPress, testID, onLongPress, style, icon, i
})} })}
> >
<View style={[styles.container, styles.button, style]}> <View style={[styles.container, styles.button, style]}>
<Avatar text={username} size={30} style={styles.avatar} /> <Avatar text={username} size={30} style={styles.avatar} isUserProfile={userId === id} />
<View style={styles.textContainer}> <View style={styles.textContainer}>
<Text style={[styles.name, { color: colors.bodyText }]} numberOfLines={1}> <Text style={[styles.name, { color: colors.bodyText }]} numberOfLines={1}>
{name} {name}

View File

@ -20,6 +20,7 @@ const MessageAvatar = React.memo(({ isHeader, avatar, author, small, navToRoomIn
size={small ? 20 : 36} size={small ? 20 : 36}
borderRadius={small ? 2 : 4} borderRadius={small ? 2 : 4}
onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)} onPress={author._id === user.id ? undefined : () => navToRoomInfo(navParam)}
isUserProfile={author._id === user.id}
getCustomEmoji={getCustomEmoji} getCustomEmoji={getCustomEmoji}
avatar={avatar} avatar={avatar}
emoji={emoji} emoji={emoji}

View File

@ -93,6 +93,7 @@ const NewMessageView = () => {
return ( return (
<UserItem <UserItem
id={item._id}
name={useRealName && itemSearch.fname ? itemSearch.fname : itemModel.name} name={useRealName && itemSearch.fname ? itemSearch.fname : itemModel.name}
username={itemSearch.search ? itemSearch.username : itemModel.name} username={itemSearch.search ? itemSearch.username : itemModel.name}
onPress={() => goRoom(itemModel)} onPress={() => goRoom(itemModel)}

View File

@ -183,17 +183,17 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'), title: t === SubscriptionType.DIRECT ? I18n.t('User_Info') : I18n.t('Room_Info'),
headerRight: showEdit headerRight: showEdit
? () => ( ? () => (
<HeaderButton.Container> <HeaderButton.Container>
<HeaderButton.Item <HeaderButton.Item
iconName='edit' iconName='edit'
onPress={() => { onPress={() => {
const isLivechat = t === SubscriptionType.OMNICHANNEL; const isLivechat = t === SubscriptionType.OMNICHANNEL;
logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]); logEvent(events[`RI_GO_${isLivechat ? 'LIVECHAT' : 'RI'}_EDIT`]);
navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser }); navigation.navigate(isLivechat ? 'LivechatEditView' : 'RoomInfoEditView', { rid, room, roomUser });
}} }}
testID='room-info-view-edit-button' testID='room-info-view-edit-button'
/> />
</HeaderButton.Container> </HeaderButton.Container>
) )
: undefined : undefined
}); });
@ -399,11 +399,26 @@ class RoomInfoView extends React.Component<IRoomInfoViewProps, IRoomInfoViewStat
log(e); log(e);
} }
}; };
handleEditAvatar = () => {
const {navigation} = this.props
navigation.navigate("ChangeAvatarView",{titleHeader:I18n.t('Room_Info')})
}
renderAvatar = (room: ISubscription, roomUser: IUserParsed) => { renderAvatar = (room: ISubscription, roomUser: IUserParsed) => {
const { theme } = this.props; const { theme } = this.props;
const { showEdit } = this.state;
const showAvatarEdit = showEdit && this.t !== SubscriptionType.OMNICHANNEL;
return ( return (
<Avatar text={room.name || roomUser.username} style={styles.avatar} type={this.t} size={100} rid={room?.rid}> <Avatar
text={room.name || roomUser.username}
style={styles.avatar}
type={this.t}
size={100}
rid={room?.rid}
handleEdit={showAvatarEdit ? this.handleEditAvatar : undefined}
>
{this.t === SubscriptionType.DIRECT && roomUser._id ? ( {this.t === SubscriptionType.DIRECT && roomUser._id ? (
<View style={[sharedStyles.status, { backgroundColor: themes[theme].auxiliaryBackground }]}> <View style={[sharedStyles.status, { backgroundColor: themes[theme].auxiliaryBackground }]}>
<Status size={20} id={roomUser._id} /> <Status size={20} id={roomUser._id} />

View File

@ -27,7 +27,7 @@ export default StyleSheet.create({
marginHorizontal: 10 marginHorizontal: 10
}, },
roomTitleContainer: { roomTitleContainer: {
paddingTop: 20, paddingTop: 32,
marginHorizontal: 16, marginHorizontal: 16,
alignItems: 'center' alignItems: 'center'
}, },

View File

@ -935,7 +935,7 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
const { item: currentItem } = this.state; const { item: currentItem } = this.state;
const { const {
user: { username }, user: { username, id: userId },
StoreLastMessage, StoreLastMessage,
useRealName, useRealName,
isMasterDetail, isMasterDetail,
@ -945,6 +945,7 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
} = this.props; } = this.props;
const id = getUidDirectMessage(item); const id = getUidDirectMessage(item);
const swipeEnabled = this.isSwipeEnabled(item); const swipeEnabled = this.isSwipeEnabled(item);
const isUserProfile = id === userId;
return ( return (
<RoomItem <RoomItem
@ -965,6 +966,7 @@ class RoomsListView extends React.Component<IRoomsListViewProps, IRoomsListViewS
swipeEnabled={swipeEnabled} swipeEnabled={swipeEnabled}
showAvatar={showAvatar} showAvatar={showAvatar}
displayMode={displayMode} displayMode={displayMode}
isUserProfile={isUserProfile}
/> />
); );
}; };

View File

@ -155,6 +155,7 @@ const SelectedUsersView = () => {
const username = item.search ? (item.username as string) : item.name; const username = item.search ? (item.username as string) : item.name;
return ( return (
<UserItem <UserItem
id={item._id}
name={name} name={name}
username={username} username={username}
onPress={() => _onPressItem(item)} onPress={() => _onPressItem(item)}