|
@@ -5,10 +5,14 @@ import { Colors } from 'src/theme';
|
|
|
import { API_HOST } from 'src/constants';
|
|
|
import { getFontSize } from 'src/utils';
|
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
-import { ChatProps } from '../types';
|
|
|
+import { ChatProps, WarningProps } from '../types';
|
|
|
import { useNavigation } from '@react-navigation/native';
|
|
|
import { NAVIGATION_PAGES } from 'src/types';
|
|
|
-import { usePostSetBlockMutation, usePostSetMuteMutation } from '@api/chat';
|
|
|
+import {
|
|
|
+ usePostDeleteChatMutation,
|
|
|
+ usePostSetBlockMutation,
|
|
|
+ usePostSetMuteMutation
|
|
|
+} from '@api/chat';
|
|
|
import { useChatStore } from 'src/stores/chatStore';
|
|
|
import TrashIcon from 'assets/icons/travels-screens/trash-solid.svg';
|
|
|
import BanIcon from 'assets/icons/messages/ban.svg';
|
|
@@ -28,7 +32,9 @@ const MoreModal = () => {
|
|
|
>(null);
|
|
|
const { mutateAsync: muteUser } = usePostSetMuteMutation();
|
|
|
const { mutateAsync: blockUser } = usePostSetBlockMutation();
|
|
|
- const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState(false);
|
|
|
+ const { mutateAsync: deleteChat } = usePostDeleteChatMutation();
|
|
|
+
|
|
|
+ const [shouldOpenWarningModal, setShouldOpenWarningModal] = useState<WarningProps | null>(null);
|
|
|
|
|
|
const handleSheetOpen = (
|
|
|
payload:
|
|
@@ -60,19 +66,48 @@ const MoreModal = () => {
|
|
|
};
|
|
|
|
|
|
const handleBlock = async () => {
|
|
|
- // if (!chatData) return;
|
|
|
- // await blockUser({
|
|
|
- // value: chatData.blocked === 1 ? 0 : 1,
|
|
|
- // conversation_with_user: chatData.uid
|
|
|
- // });
|
|
|
+ if (!chatData) return;
|
|
|
+
|
|
|
+ setShouldOpenWarningModal({
|
|
|
+ title: 'Block user',
|
|
|
+ buttonTitle: 'Block',
|
|
|
+ message: `Are you sure you want to block ${chatData?.name}?\nThis user will be blocked and you will not be able to send or receive messages from him/her.`,
|
|
|
+ action: async () => {
|
|
|
+ await blockUser({
|
|
|
+ token: chatData.token,
|
|
|
+ value: 1,
|
|
|
+ conversation_with_user: chatData.uid
|
|
|
+ });
|
|
|
+
|
|
|
+ chatData.refetch();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ setTimeout(() => {
|
|
|
+ SheetManager.hide('more-modal');
|
|
|
+ setShouldOpenWarningModal(null);
|
|
|
+ }, 300);
|
|
|
};
|
|
|
|
|
|
const handleDelete = async () => {
|
|
|
- setShouldOpenWarningModal(true);
|
|
|
+ if (!chatData) return;
|
|
|
+
|
|
|
+ setShouldOpenWarningModal({
|
|
|
+ title: 'Delete conversation',
|
|
|
+ message: `Are you sure you want to delete conversation with ${chatData?.name}?\nThis conversation will be deleted for both sides.`,
|
|
|
+ action: async () => {
|
|
|
+ await deleteChat({
|
|
|
+ token: chatData.token,
|
|
|
+ conversation_with_user: chatData.uid
|
|
|
+ });
|
|
|
+
|
|
|
+ chatData.refetch();
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
setTimeout(() => {
|
|
|
SheetManager.hide('more-modal');
|
|
|
- setShouldOpenWarningModal(false);
|
|
|
+ setShouldOpenWarningModal(null);
|
|
|
}, 300);
|
|
|
};
|
|
|
|
|
@@ -86,7 +121,7 @@ const MoreModal = () => {
|
|
|
}}
|
|
|
onClose={() => {
|
|
|
if (shouldOpenWarningModal) {
|
|
|
- setIsWarningModalVisible(true);
|
|
|
+ setIsWarningModalVisible(shouldOpenWarningModal);
|
|
|
}
|
|
|
}}
|
|
|
containerStyle={styles.sheetContainer}
|
|
@@ -116,7 +151,7 @@ const MoreModal = () => {
|
|
|
</View>
|
|
|
|
|
|
<View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
|
|
|
- <TouchableOpacity style={[styles.option, styles.dangerOption]}>
|
|
|
+ <TouchableOpacity style={[styles.option, styles.dangerOption]} onPress={handleBlock}>
|
|
|
<Text style={[styles.optionText, styles.dangerText]}>Block {chatData.name}</Text>
|
|
|
<BanIcon fill={Colors.RED} />
|
|
|
</TouchableOpacity>
|