|
@@ -1,6 +1,7 @@
|
|
|
-import React, { FC, useCallback, useEffect } from 'react';
|
|
|
+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';
|
|
|
|
|
@@ -61,8 +62,12 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
true
|
|
|
);
|
|
|
const { mutateAsync: updateFriendStatus } = usePostUpdateFriendStatusMutation();
|
|
|
- const [isModalVisible, setIsModalVisible] = React.useState(false);
|
|
|
const [isFriend, setIsFriend] = React.useState<0 | 1>(0);
|
|
|
+ const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState(false);
|
|
|
+ const [modalState, setModalState] = useState({
|
|
|
+ isModalVisible: false,
|
|
|
+ isWarningVisible: false
|
|
|
+ });
|
|
|
|
|
|
useFocusEffect(
|
|
|
useCallback(() => {
|
|
@@ -102,6 +107,14 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ 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)',
|
|
@@ -199,6 +212,14 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
/>
|
|
|
)}
|
|
|
{data.scores.rank_tbt && data.scores.rank_tbt >= 1 ? <TBRanking /> : null}
|
|
|
+ {isFriend === 1 && token && data.own_profile === 0 ? (
|
|
|
+ <TouchableOpacity style={styles.friend} onPress={() => openModal('isModalVisible')}>
|
|
|
+ <Text style={styles.friendText}>Friend</Text>
|
|
|
+ <View style={{ transform: 'rotate(180deg)' }}>
|
|
|
+ <ChevronIcon fill={Colors.WHITE} height={8} />
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
+ ) : null}
|
|
|
</View>
|
|
|
<View style={{ gap: 5, flex: 1 }}>
|
|
|
<View style={{ height: 34 }}></View>
|
|
@@ -206,14 +227,6 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
<Text style={[styles.headerText, { fontSize: getFontSize(18) }]}>
|
|
|
{data.user_data.first_name} {data.user_data.last_name}
|
|
|
</Text>
|
|
|
- {isFriend === 1 && token && data.own_profile === 0 ? (
|
|
|
- <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}>
|
|
@@ -300,7 +313,8 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
friendRequestSent: data.friend_request_sent,
|
|
|
friendRequestReceived: data.friend_request_received,
|
|
|
isFriend,
|
|
|
- friendDbId: data.friend_db_id
|
|
|
+ friendDbId: data.friend_db_id,
|
|
|
+ ownProfile: data.own_profile
|
|
|
}}
|
|
|
updates={lastUpdates.data.updates}
|
|
|
userId={isPublicView ? route.params?.userId : +currentUserId}
|
|
@@ -310,12 +324,40 @@ const ProfileScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
/>
|
|
|
</ScrollView>
|
|
|
|
|
|
+ <ReactModal
|
|
|
+ isVisible={modalState.isModalVisible}
|
|
|
+ onBackdropPress={() => closeModal('isModalVisible')}
|
|
|
+ style={styles.modal}
|
|
|
+ statusBarTranslucent={true}
|
|
|
+ presentationStyle="overFullScreen"
|
|
|
+ onModalHide={() => {
|
|
|
+ if (shouldOpenWarningModal) {
|
|
|
+ openModal('isWarningVisible');
|
|
|
+ setShouldOpenWarningModal(false);
|
|
|
+ }
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View style={styles.wrapper}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={styles.btnModalEdit}
|
|
|
+ onPress={() => {
|
|
|
+ closeModal('isModalVisible');
|
|
|
+ setShouldOpenWarningModal(true);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <Text style={styles.btnModalEditText}>Unfriend</Text>
|
|
|
+ <View style={{ transform: 'rotate(180deg)' }}>
|
|
|
+ <ChevronIcon fill={Colors.DARK_BLUE} height={11} />
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
+ </ReactModal>
|
|
|
<WarningModal
|
|
|
type={'confirm'}
|
|
|
- isVisible={isModalVisible}
|
|
|
+ isVisible={modalState.isWarningVisible}
|
|
|
message={`Are you sure you want to unfriend ${data.user_data.first_name} ${data.user_data.last_name}?`}
|
|
|
action={handleUpdateFriendStatus}
|
|
|
- onClose={() => setIsModalVisible(false)}
|
|
|
+ onClose={() => closeModal('isWarningVisible')}
|
|
|
title=""
|
|
|
/>
|
|
|
</PageWrapper>
|