|
@@ -1,10 +1,16 @@
|
|
|
-import React, { FC, useCallback } from 'react';
|
|
|
+import React, { FC, useCallback, useEffect } from 'react';
|
|
|
import { Linking, ScrollView, Text, TouchableOpacity, View, Image, Platform } from 'react-native';
|
|
|
import { CommonActions, NavigationProp, useFocusEffect } from '@react-navigation/native';
|
|
|
|
|
|
import { usePostGetProfileInfoDataQuery, usePostGetProfileUpdatesQuery } from '@api/user';
|
|
|
|
|
|
-import { PageWrapper, Loading, AvatarWithInitials, Header } from '../../../components';
|
|
|
+import {
|
|
|
+ PageWrapper,
|
|
|
+ Loading,
|
|
|
+ AvatarWithInitials,
|
|
|
+ Header,
|
|
|
+ WarningModal
|
|
|
+} from '../../../components';
|
|
|
import { adaptiveStyle, Colors } from '../../../theme';
|
|
|
import { styles } from './styles';
|
|
|
|
|
@@ -24,10 +30,12 @@ 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 ChevronIcon from '../../../../assets/icons/chevron-left.svg';
|
|
|
|
|
|
import { ProfileStyles, ScoreStyles, TBTStyles } from '../TravellersScreen/Components/styles';
|
|
|
import UnauthenticatedProfileScreen from './UnauthenticatedProfileScreen';
|
|
|
import { PersonalInfo } from './Components/PersonalInfo';
|
|
|
+import { usePostUpdateFriendStatusMutation } from '@api/friends';
|
|
|
|
|
|
type Props = {
|
|
|
navigation: NavigationProp<any>;
|
|
@@ -52,6 +60,9 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
isPublicView ? route.params?.userId : +currentUserId,
|
|
|
true
|
|
|
);
|
|
|
+ const { mutateAsync: updateFriendStatus } = usePostUpdateFriendStatusMutation();
|
|
|
+ const [isModalVisible, setIsModalVisible] = React.useState(false);
|
|
|
+ const [isFriend, setIsFriend] = React.useState<0 | 1>(0);
|
|
|
|
|
|
useFocusEffect(
|
|
|
useCallback(() => {
|
|
@@ -71,6 +82,10 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
}, [navigation])
|
|
|
);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ setIsFriend(userData?.data?.is_friend ?? 0);
|
|
|
+ }, [userData]);
|
|
|
+
|
|
|
if (!userData?.data || !lastUpdates?.data || isFetching) return <Loading />;
|
|
|
|
|
|
const data = userData.data;
|
|
@@ -138,6 +153,17 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ const handleUpdateFriendStatus = async () => {
|
|
|
+ await updateFriendStatus(
|
|
|
+ { token: token as string, id: data.friend_db_id, status: -1 },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ setIsFriend(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<PageWrapper>
|
|
|
{isPublicView && <Header label="Profile" />}
|
|
@@ -176,9 +202,19 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
</View>
|
|
|
<View style={{ gap: 5, flex: 1 }}>
|
|
|
<View style={{ height: 34 }}></View>
|
|
|
- <Text style={[styles.headerText, { fontSize: getFontSize(18), flex: 0 }]}>
|
|
|
- {data.user_data.first_name} {data.user_data.last_name}
|
|
|
- </Text>
|
|
|
+ <View style={styles.nameRow}>
|
|
|
+ <Text style={[styles.headerText, { fontSize: getFontSize(18), flex: 0 }]}>
|
|
|
+ {data.user_data.first_name} {data.user_data.last_name}
|
|
|
+ </Text>
|
|
|
+ {isFriend === 1 && token ? (
|
|
|
+ <TouchableOpacity style={styles.friend} onPress={() => setIsModalVisible(true)}>
|
|
|
+ <Text style={styles.friendText}>Friend</Text>
|
|
|
+ <View style={{ transform: 'rotate(180deg)' }}>
|
|
|
+ <ChevronIcon fill={Colors.WHITE} height={8} />
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
+ ) : null}
|
|
|
+ </View>
|
|
|
|
|
|
<View style={styles.userInfoContainer}>
|
|
|
<View style={styles.userInfo}>
|
|
@@ -263,7 +299,7 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
lastName: data.user_data.last_name,
|
|
|
friendRequestSent: data.friend_request_sent,
|
|
|
friendRequestReceived: data.friend_request_received,
|
|
|
- isFriend: data.is_friend,
|
|
|
+ isFriend,
|
|
|
friendDbId: data.friend_db_id
|
|
|
}}
|
|
|
updates={lastUpdates.data.updates}
|
|
@@ -273,6 +309,15 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
token={token ? token : null}
|
|
|
/>
|
|
|
</ScrollView>
|
|
|
+
|
|
|
+ <WarningModal
|
|
|
+ type={'confirm'}
|
|
|
+ isVisible={isModalVisible}
|
|
|
+ message={`Are you sure you want to unfriend ${data.user_data.first_name} ${data.user_data.last_name}?`}
|
|
|
+ action={handleUpdateFriendStatus}
|
|
|
+ onClose={() => setIsModalVisible(false)}
|
|
|
+ title=""
|
|
|
+ />
|
|
|
</PageWrapper>
|
|
|
);
|
|
|
};
|