-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathBottomTabAvatar.tsx
86 lines (77 loc) · 3.1 KB
/
BottomTabAvatar.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import React, {useCallback} from 'react';
import {useOnyx} from 'react-native-onyx';
import {PressableWithFeedback} from '@components/Pressable';
import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import interceptAnonymousUser from '@libs/interceptAnonymousUser';
import Navigation from '@libs/Navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import AvatarWithDelegateAvatar from './AvatarWithDelegateAvatar';
import AvatarWithOptionalStatus from './AvatarWithOptionalStatus';
import ProfileAvatarWithIndicator from './ProfileAvatarWithIndicator';
type BottomTabAvatarProps = {
/** Whether the create menu is open or not */
isCreateMenuOpen?: boolean;
/** Whether the avatar is selected */
isSelected?: boolean;
};
function BottomTabAvatar({isCreateMenuOpen = false, isSelected = false}: BottomTabAvatarProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [account] = useOnyx(ONYXKEYS.ACCOUNT);
const delegateEmail = account?.delegatedAccess?.delegate ?? '';
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const emojiStatus = currentUserPersonalDetails?.status?.emojiCode ?? '';
const showSettingsPage = useCallback(() => {
if (isCreateMenuOpen) {
// Prevent opening Settings page when click profile avatar quickly after clicking FAB icon
return;
}
interceptAnonymousUser(() => Navigation.navigate(ROUTES.SETTINGS));
}, [isCreateMenuOpen]);
let children;
if (delegateEmail) {
children = (
<AvatarWithDelegateAvatar
delegateEmail={delegateEmail}
isSelected={isSelected}
containerStyle={styles.sidebarStatusAvatarWithEmojiContainer}
/>
);
} else if (emojiStatus) {
children = (
<AvatarWithOptionalStatus
emojiStatus={emojiStatus}
isSelected={isSelected}
containerStyle={styles.sidebarStatusAvatarWithEmojiContainer}
/>
);
} else {
children = (
<ProfileAvatarWithIndicator
isSelected={isSelected}
containerStyles={styles.tn0Half}
/>
);
}
return (
<PressableWithFeedback
onPress={showSettingsPage}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('sidebarScreen.buttonMySettings')}
wrapperStyle={styles.flex1}
style={[styles.bottomTabBarItem]}
>
{children}
<Text style={[styles.textSmall, styles.textAlignCenter, isSelected ? styles.textBold : styles.textSupporting, styles.mt0Half, styles.bottomTabBarLabel]}>
{translate('common.settings')}
</Text>
</PressableWithFeedback>
);
}
BottomTabAvatar.displayName = 'BottomTabAvatar';
export default BottomTabAvatar;