|
@@ -9,34 +9,65 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
import { ChatProps } 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';
|
|
|
|
|
|
const MoreModal = () => {
|
|
|
const insets = useSafeAreaInsets();
|
|
|
const navigation = useNavigation();
|
|
|
|
|
|
- const [chatData, setChatData] = useState<ChatProps | null>(null);
|
|
|
+ const [chatData, setChatData] = useState<
|
|
|
+ (ChatProps & { token: string; refetch: () => void }) | null
|
|
|
+ >(null);
|
|
|
const { mutateAsync: muteUser } = usePostSetMuteMutation();
|
|
|
const { mutateAsync: blockUser } = usePostSetBlockMutation();
|
|
|
+ const { mutateAsync: deleteChat } = usePostDeleteChatMutation();
|
|
|
|
|
|
- const handleSheetOpen = (payload: ChatProps | null) => {
|
|
|
+ const handleSheetOpen = (
|
|
|
+ payload: (ChatProps & { token: string; refetch: () => void }) | null
|
|
|
+ ) => {
|
|
|
setChatData(payload);
|
|
|
};
|
|
|
|
|
|
const handleMute = async () => {
|
|
|
- // await muteUser({
|
|
|
- // value: chatData.muted === 1 ? 0 : 1,
|
|
|
- // conversation_with_user: chatData.id
|
|
|
- // });
|
|
|
+ if (!chatData) return;
|
|
|
+
|
|
|
+ await muteUser(
|
|
|
+ {
|
|
|
+ token: chatData.token,
|
|
|
+ value: chatData.muted === 1 ? 0 : 1,
|
|
|
+ conversation_with_user: chatData.id
|
|
|
+ },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ setChatData({ ...chatData, muted: chatData.muted === 1 ? 0 : 1 });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ chatData.refetch();
|
|
|
};
|
|
|
|
|
|
const handleBlock = async () => {
|
|
|
+ // if (!chatData) return;
|
|
|
+
|
|
|
// await blockUser({
|
|
|
// value: chatData.blocked === 1 ? 0 : 1,
|
|
|
// conversation_with_user: chatData.id
|
|
|
// });
|
|
|
};
|
|
|
|
|
|
+ const handleDelete = async () => {
|
|
|
+ if (!chatData) return;
|
|
|
+
|
|
|
+ await deleteChat({
|
|
|
+ token: chatData.token,
|
|
|
+ conversation_with_user: chatData.id
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<ActionSheet
|
|
|
id="more-modal"
|
|
@@ -64,8 +95,8 @@ const MoreModal = () => {
|
|
|
</TouchableOpacity>
|
|
|
|
|
|
<View style={styles.optionsContainer}>
|
|
|
- <TouchableOpacity style={styles.option}>
|
|
|
- <Text style={styles.optionText}>Mute</Text>
|
|
|
+ <TouchableOpacity style={styles.option} onPress={handleMute}>
|
|
|
+ <Text style={styles.optionText}>{chatData.muted === 1 ? 'Unmute' : 'Mute'}</Text>
|
|
|
<Ionicons name="notifications-off-outline" size={18} color={Colors.DARK_BLUE} />
|
|
|
</TouchableOpacity>
|
|
|
</View>
|