import React, { FC, useCallback, useEffect, useState } from 'react'; import { Linking, ScrollView, Text, TouchableOpacity, View, Image, Platform } from 'react-native'; import { CommonActions, NavigationProp, useFocusEffect } from '@react-navigation/native'; import ReactModal from 'react-native-modal'; import { usePostGetProfileInfoDataQuery, usePostGetProfileUpdatesQuery } from '@api/user'; import { PageWrapper, Loading, AvatarWithInitials, Header, WarningModal } from '../../../components'; import { adaptiveStyle, Colors } from '../../../theme'; import { styles } from './styles'; import { API_HOST } from '../../../constants'; import { NAVIGATION_PAGES } from '../../../types'; import { storage, StoreType } from '../../../storage'; import { getFontSize } from '../../../utils'; import IconFacebook from '../../../../assets/icons/facebook.svg'; import IconInstagram from '../../../../assets/icons/instagram.svg'; import IconTwitter from '../../../../assets/icons/x(twitter).svg'; import IconYouTube from '../../../../assets/icons/youtube.svg'; import IconGlobe from '../../../../assets/icons/bottom-navigation/globe.svg'; import IconLink from '../../../../assets/icons/link.svg'; import GearIcon from '../../../../assets/icons/gear.svg'; import TBTIcon from '../../../../assets/icons/tbt.svg'; import TickIcon from '../../../../assets/icons/tick.svg'; import UNIcon from '../../../../assets/icons/un_icon.svg'; import NMIcon from '../../../../assets/icons/nm_icon.svg'; import UN50Icon from '../../../../assets/icons/un-50.svg'; import UN100Icon from '../../../../assets/icons/un-100.svg'; import UN150Icon from '../../../../assets/icons/un-150.svg'; import ChevronIcon from '../../../../assets/icons/chevron-left.svg'; import ShareIcon from '../../../../assets/icons/share.svg'; import UnverifiedIcon from '../../../../assets/icons/unverified.svg'; import { ProfileStyles, ScoreStyles, TBTStyles } from '../TravellersScreen/Components/styles'; import UnauthenticatedProfileScreen from './UnauthenticatedProfileScreen'; import { PersonalInfo } from './Components/PersonalInfo'; import { usePostUpdateFriendStatusMutation } from '@api/friends'; import Tooltip from 'react-native-walkthrough-tooltip'; type Props = { navigation: NavigationProp; route: any; }; const ProfileScreen: FC = ({ navigation, route }) => { const isPublicView = route.name === NAVIGATION_PAGES.PUBLIC_PROFILE_VIEW; const token = storage.get('token', StoreType.STRING) as string; const currentUserId = storage.get('uid', StoreType.STRING) as string; if (!token) return ; const { data: userData, isFetching } = usePostGetProfileInfoDataQuery( token, isPublicView ? route.params?.userId : +currentUserId, true ); const { data: lastUpdates } = usePostGetProfileUpdatesQuery( token, isPublicView ? route.params?.userId : +currentUserId, true ); const { mutateAsync: updateFriendStatus } = usePostUpdateFriendStatusMutation(); const [isFriend, setIsFriend] = React.useState<0 | 1>(0); const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState(false); const [modalState, setModalState] = useState({ isModalVisible: false, isWarningVisible: false }); const [tooltipVisible, setTooltipVisible] = useState(false); useFocusEffect( useCallback(() => { if (!route.params?.hideTabBar) { navigation.getParent()?.setOptions({ tabBarStyle: { display: 'flex', ...Platform.select({ android: { height: 58 } }) } }); } }, [navigation]) ); useEffect(() => { setIsFriend(userData?.data?.is_friend ?? 0); if (userData && userData?.data?.own_profile === 1) { const userInfo = { avatar: userData?.data?.user_data.avatar ?? '', first_name: userData?.data?.user_data.first_name, last_name: userData?.data?.user_data.last_name, homebase_flag: userData?.data?.user_data.flag1 }; storage.set('currentUserData', JSON.stringify(userInfo)); } }, [userData]); if (!userData?.data || !lastUpdates || isFetching) return ; const data = userData.data; const links = JSON.parse(data.user_data.links_json); const handleGoToMap = () => { data.own_profile === 0 ? navigation.navigate(NAVIGATION_PAGES.USERS_MAP, { userId: route.params?.userId, data }) : navigation.dispatch( CommonActions.reset({ index: 1, routes: [{ name: NAVIGATION_PAGES.IN_APP_MAP_TAB }] }) ); }; const closeModal = (modalName: string) => { setModalState((prevState) => ({ ...prevState, [modalName]: false })); }; const openModal = (modalName: string) => { setModalState((prevState) => ({ ...prevState, [modalName]: true })); }; const TBRanking = () => { const colors = [ 'rgba(237, 147, 52, 1)', 'rgba(128, 128, 128, 1)', 'rgba(211, 211, 211, 1)', 'rgba(187, 95, 5, 1)', '#808080' ]; const Rank = ({ color }: { color: string }) => ( ); return ( {data.user_data.badge_tbt && data.scores.rank_tbt ? ( ) : null} {data.scores.rank_tbt && data.scores.rank_tbt >= 1 ? ( TBT # {data.scores.rank_tbt} ) : ( )} ); }; const handleOpenUrl = (url: string | undefined) => { url && Linking.openURL(url); }; const hasActiveLinks = () => { return ( (links?.f?.link && links?.f?.active !== 0) || (links?.i?.link && links?.i?.active !== 0) || (links?.t?.link && links?.t?.active !== 0) || (links?.y?.link && links?.y?.active !== 0) || (links?.www?.link && links?.www?.active !== 0) || (links?.other?.link && links?.other?.active !== 0) ); }; const handleUpdateFriendStatus = async () => { await updateFriendStatus( { token: token as string, id: data.friend_db_id, status: -1 }, { onSuccess: () => { setIsFriend(0); } } ); }; return (
{data.user_data.avatar ? ( ) : ( )} {data.scores.rank_tbt && data.scores.rank_tbt >= 1 ? : null} {isFriend === 1 && token && data.own_profile === 0 ? ( openModal('isModalVisible')}> Friend ) : null} {data.user_data.first_name} {data.user_data.last_name} Age: {data.user_data.age} {data.user_data.flag2 && data.user_data.flag2 !== data.user_data.flag1 ? ( ) : null} {data.user_data.auth ? : null} {data.user_data.badge_un ? : null} {data.user_data.badge_nm ? : null} {data.user_data.badge_un_150 ? : null} {data.user_data.badge_un_100 ? : null} {data.user_data.badge_un_50 ? : null} {data.user_data.badge_ghost ? ( setTooltipVisible(false)} content={Unverified User} contentStyle={{ backgroundColor: Colors.WHITE }} backgroundColor="transparent" allowChildInteraction={false} placement="top" > setTooltipVisible(true)}> ) : null} {data.own_profile === 1 ? ( <> navigation.navigate(NAVIGATION_PAGES.SHARE_PROFILE, { data: { avatar: data.user_data.avatar, first_name: data.user_data.first_name, last_name: data.user_data.last_name, flag1: data.user_data.flag1, flag2: data.user_data.flag2, id: +currentUserId, auth: data.user_data.auth, badge_un: data.user_data.badge_un, badge_nm: data.user_data.badge_nm, badge_un_50: data.user_data.badge_un_50, badge_un_100: data.user_data.badge_un_100, badge_un_150: data.user_data.badge_un_150, scores: data.scores } }) } > navigation.navigate(NAVIGATION_PAGES.EDIT_PERSONAL_INFO)} > ) : null} {hasActiveLinks() && ( {links?.f?.link && links?.f?.active !== 0 ? ( handleOpenUrl(links?.f?.link)}> ) : null} {links?.i?.link && links?.i?.active !== 0 ? ( handleOpenUrl(links?.i?.link)}> ) : null} {links?.t?.link && links?.t?.active !== 0 ? ( handleOpenUrl(links?.t?.link)}> ) : null} {links?.y?.link && links?.y?.active !== 0 ? ( handleOpenUrl(links?.y?.link)}> ) : null} {links?.www?.link && links?.www?.active !== 0 ? ( handleOpenUrl(links?.www?.link)}> ) : null} {links?.other?.link && links?.other?.active !== 0 ? ( handleOpenUrl(links?.other?.link)}> ) : null} )} closeModal('isModalVisible')} style={styles.modal} statusBarTranslucent={true} presentationStyle="overFullScreen" onModalHide={() => { if (shouldOpenWarningModal) { openModal('isWarningVisible'); setShouldOpenWarningModal(false); } }} > { closeModal('isModalVisible'); setShouldOpenWarningModal(true); }} > Unfriend closeModal('isWarningVisible')} title="" /> ); }; export default ProfileScreen;