11import React , { memo } from 'react' ;
22import { View } from 'react-native' ;
3+ import type { OnyxEntry } from 'react-native-onyx' ;
34import useStyleUtils from '@hooks/useStyleUtils' ;
45import useThemeStyles from '@hooks/useThemeStyles' ;
6+ import { clearAvatarErrors , getCurrentUserAccountID , updatePolicyRoomAvatar } from '@libs/actions/Report' ;
57import Navigation from '@libs/Navigation/Navigation' ;
8+ import { isUserCreatedPolicyRoom } from '@libs/ReportUtils' ;
9+ import { isDefaultAvatar } from '@libs/UserUtils' ;
610import CONST from '@src/CONST' ;
711import ROUTES from '@src/ROUTES' ;
12+ import type { Policy , Report } from '@src/types/onyx' ;
813import type { Icon } from '@src/types/onyx/OnyxCommon' ;
914import Avatar from './Avatar' ;
15+ import AvatarWithImagePicker from './AvatarWithImagePicker' ;
1016import * as Expensicons from './Icon/Expensicons' ;
1117import PressableWithoutFocus from './Pressable/PressableWithoutFocus' ;
1218import Text from './Text' ;
1319
1420type RoomHeaderAvatarsProps = {
1521 icons : Icon [ ] ;
16- reportID : string ;
22+ report : Report ;
23+ policy : OnyxEntry < Policy > ;
24+ participants : number [ ] ;
1725} ;
1826
19- function RoomHeaderAvatars ( { icons, reportID } : RoomHeaderAvatarsProps ) {
27+ function RoomHeaderAvatars ( { icons, report , policy , participants } : RoomHeaderAvatarsProps ) {
2028 const navigateToAvatarPage = ( icon : Icon ) => {
2129 if ( icon . type === CONST . ICON_TYPE_WORKSPACE && icon . id ) {
22- Navigation . navigate ( ROUTES . REPORT_AVATAR . getRoute ( reportID , icon . id . toString ( ) ) ) ;
30+ Navigation . navigate ( ROUTES . REPORT_AVATAR . getRoute ( report ?. reportID , icon . id . toString ( ) ) ) ;
2331 return ;
2432 }
2533
@@ -30,6 +38,8 @@ function RoomHeaderAvatars({icons, reportID}: RoomHeaderAvatarsProps) {
3038
3139 const styles = useThemeStyles ( ) ;
3240 const StyleUtils = useStyleUtils ( ) ;
41+ const currentUserAccountID = getCurrentUserAccountID ( ) ;
42+ const canEditRoomAvatar = isUserCreatedPolicyRoom ( report ) && participants . includes ( currentUserAccountID ) && ! ! policy && policy . role !== CONST . POLICY . ROLE . AUDITOR ;
3343
3444 if ( ! icons . length ) {
3545 return null ;
@@ -42,6 +52,31 @@ function RoomHeaderAvatars({icons, reportID}: RoomHeaderAvatarsProps) {
4252 return ;
4353 }
4454
55+ if ( canEditRoomAvatar ) {
56+ return (
57+ < AvatarWithImagePicker
58+ source = { icon . source || report . avatarUrl }
59+ avatarID = { icon . id }
60+ isUsingDefaultAvatar = { ! report . avatarUrl || isDefaultAvatar ( icon . source ) }
61+ size = { CONST . AVATAR_SIZE . X_LARGE }
62+ avatarStyle = { [ styles . avatarXLarge , styles . alignSelfCenter ] }
63+ onViewPhotoPress = { ( ) => Navigation . navigate ( ROUTES . REPORT_AVATAR . getRoute ( report . reportID ) ) }
64+ onImageRemoved = { ( ) => updatePolicyRoomAvatar ( report . reportID ) }
65+ onImageSelected = { ( file ) => updatePolicyRoomAvatar ( report . reportID , file ) }
66+ editIcon = { Expensicons . Camera }
67+ editIconStyle = { styles . smallEditIconAccount }
68+ pendingAction = { report . pendingFields ?. avatar }
69+ errors = { report . errorFields ?. avatar ?? null }
70+ errorRowStyles = { styles . mt6 }
71+ onErrorClose = { ( ) => clearAvatarErrors ( report . reportID ) }
72+ style = { [ styles . w100 , styles . mb3 , styles . alignItemsStart , styles . sectionMenuItemTopDescription ] }
73+ type = { icon . type }
74+ editorMaskImage = { Expensicons . ImageCropSquareMask }
75+ name = { icon . name }
76+ />
77+ ) ;
78+ }
79+
4580 return (
4681 < PressableWithoutFocus
4782 style = { styles . noOutline }
0 commit comments