|
@@ -1,20 +1,36 @@
|
|
-import React, { FC, useCallback, useEffect, useState } from 'react';
|
|
|
|
|
|
+import React, { FC, useEffect, useState } from 'react';
|
|
import { ScrollView, Text, TouchableOpacity, View, Image, StyleSheet } from 'react-native';
|
|
import { ScrollView, Text, TouchableOpacity, View, Image, StyleSheet } from 'react-native';
|
|
-import { NavigationProp, useFocusEffect } from '@react-navigation/native';
|
|
|
|
|
|
+import { NavigationProp } from '@react-navigation/native';
|
|
import ImageView from 'react-native-image-viewing';
|
|
import ImageView from 'react-native-image-viewing';
|
|
import { storage, StoreType } from 'src/storage';
|
|
import { storage, StoreType } from 'src/storage';
|
|
-import { PageWrapper, Header, Loading, Input, AvatarWithInitials } from 'src/components';
|
|
|
|
-import { usePostGetGroupMembersQuery, usePostGetGroupSettingsQuery } from '@api/chat';
|
|
|
|
|
|
+import {
|
|
|
|
+ PageWrapper,
|
|
|
|
+ Header,
|
|
|
|
+ Loading,
|
|
|
|
+ Input,
|
|
|
|
+ AvatarWithInitials,
|
|
|
|
+ WarningModal
|
|
|
|
+} from 'src/components';
|
|
|
|
+import {
|
|
|
|
+ usePostGetGroupMembersQuery,
|
|
|
|
+ usePostGetGroupSettingsQuery,
|
|
|
|
+ usePostLeaveGroupMutation,
|
|
|
|
+ usePostRemoveGroupFromListMutation,
|
|
|
|
+ usePostSetMuteForGroupMutation
|
|
|
|
+} from '@api/chat';
|
|
import { Colors } from 'src/theme';
|
|
import { Colors } from 'src/theme';
|
|
import { API_HOST } from 'src/constants';
|
|
import { API_HOST } from 'src/constants';
|
|
import GroupIcon from 'assets/icons/messages/group-chat.svg';
|
|
import GroupIcon from 'assets/icons/messages/group-chat.svg';
|
|
import { getFontSize } from 'src/utils';
|
|
import { getFontSize } from 'src/utils';
|
|
-import MegaphoneIcon from 'assets/icons/messages/megaphone.svg';
|
|
|
|
import ExitIcon from 'assets/icons/messages/exit.svg';
|
|
import ExitIcon from 'assets/icons/messages/exit.svg';
|
|
import TrashIcon from 'assets/icons/travels-screens/trash-solid.svg';
|
|
import TrashIcon from 'assets/icons/travels-screens/trash-solid.svg';
|
|
-import BanIcon from 'assets/icons/messages/ban.svg';
|
|
|
|
import BellSlashIcon from 'assets/icons/messages/bell-slash.svg';
|
|
import BellSlashIcon from 'assets/icons/messages/bell-slash.svg';
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
|
+import EditIcon from 'assets/icons/travels-screens/pen-to-square.svg';
|
|
|
|
+import UserPlusIcon from 'assets/icons/user-plus.svg';
|
|
|
|
+import { NAVIGATION_PAGES } from 'src/types';
|
|
|
|
+import { SheetManager } from 'react-native-actions-sheet';
|
|
|
|
+import EditGroupModal from '../Components/EditGroupModal';
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
navigation: NavigationProp<any>;
|
|
navigation: NavigationProp<any>;
|
|
@@ -26,17 +42,111 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
const groupToken = route.params.groupToken;
|
|
const groupToken = route.params.groupToken;
|
|
const insets = useSafeAreaInsets();
|
|
const insets = useSafeAreaInsets();
|
|
const [canSeeMembers, setCanSeeMembers] = useState(false);
|
|
const [canSeeMembers, setCanSeeMembers] = useState(false);
|
|
- const { data } = usePostGetGroupSettingsQuery(token, groupToken, true);
|
|
|
|
- const { data: members } = usePostGetGroupMembersQuery(token, groupToken, canSeeMembers);
|
|
|
|
|
|
+ const { data, refetch } = usePostGetGroupSettingsQuery(token, groupToken, true);
|
|
|
|
+ const { data: members, refetch: refetchMembers } = usePostGetGroupMembersQuery(
|
|
|
|
+ token,
|
|
|
|
+ groupToken,
|
|
|
|
+ canSeeMembers
|
|
|
|
+ );
|
|
|
|
|
|
const [fullSizeImageVisible, setFullSizeImageVisible] = useState(false);
|
|
const [fullSizeImageVisible, setFullSizeImageVisible] = useState(false);
|
|
|
|
+ const [muted, setMuted] = useState(false);
|
|
|
|
+ const [modalState, setModalState] = useState({
|
|
|
|
+ isWarningVisible: false,
|
|
|
|
+ title: '',
|
|
|
|
+ buttonTitle: '',
|
|
|
|
+ message: '',
|
|
|
|
+ action: () => {}
|
|
|
|
+ });
|
|
|
|
+ const { mutateAsync: muteGroup } = usePostSetMuteForGroupMutation();
|
|
|
|
+ const { mutateAsync: leaveGroup } = usePostLeaveGroupMutation();
|
|
|
|
+ const { mutateAsync: removeGroupFromList } = usePostRemoveGroupFromListMutation();
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (data && data.settings) {
|
|
if (data && data.settings) {
|
|
- setCanSeeMembers(data.settings.members_can_see_members === 1);
|
|
|
|
|
|
+ setCanSeeMembers(data.settings.members_can_see_members === 1 || data.settings.admin === 1);
|
|
|
|
+ setMuted(data.settings.muted === 1);
|
|
}
|
|
}
|
|
}, [data]);
|
|
}, [data]);
|
|
|
|
|
|
|
|
+ const handleMute = async () => {
|
|
|
|
+ await muteGroup(
|
|
|
|
+ {
|
|
|
|
+ token,
|
|
|
|
+ value: muted ? 0 : 1,
|
|
|
|
+ group_token: groupToken
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ onSuccess: () => {
|
|
|
|
+ setMuted(!muted);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const handleLeaveGroup = async () => {
|
|
|
|
+ if (!data) return;
|
|
|
|
+
|
|
|
|
+ setModalState({
|
|
|
|
+ isWarningVisible: true,
|
|
|
|
+ title: `Leave group ${data.settings.name}`,
|
|
|
|
+ buttonTitle: 'Leave',
|
|
|
|
+ message: `Are you sure you want to leave ${data.settings.name}?`,
|
|
|
|
+ action: async () => {
|
|
|
|
+ await leaveGroup(
|
|
|
|
+ {
|
|
|
|
+ token,
|
|
|
|
+ group_token: groupToken
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ onSuccess: () => {
|
|
|
|
+ navigation.navigate(NAVIGATION_PAGES.CHATS_LIST);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const handleDeleteGroup = async () => {
|
|
|
|
+ if (!data) return;
|
|
|
|
+
|
|
|
|
+ setModalState({
|
|
|
|
+ isWarningVisible: true,
|
|
|
|
+ title: `Delete ${data.settings.name}`,
|
|
|
|
+ buttonTitle: 'Delete',
|
|
|
|
+ message: `Are you sure you want to delete this group chat?\nThis action will remove the chat from your history, but it won't affect other participants.`,
|
|
|
|
+ action: async () => {
|
|
|
|
+ await removeGroupFromList(
|
|
|
|
+ {
|
|
|
|
+ token,
|
|
|
|
+ group_token: groupToken
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ onSuccess: () => {
|
|
|
|
+ navigation.navigate(NAVIGATION_PAGES.CHATS_LIST);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const openEditModal = () => {
|
|
|
|
+ if (!data) return;
|
|
|
|
+
|
|
|
|
+ SheetManager.show('edit-group-modal', {
|
|
|
|
+ payload: {
|
|
|
|
+ settings: data.settings,
|
|
|
|
+ members: data.settings.admin === 1 ? members?.settings : [],
|
|
|
|
+ token,
|
|
|
|
+ groupToken,
|
|
|
|
+ refetch,
|
|
|
|
+ refetchMembers
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+
|
|
if (!data) return <Loading />;
|
|
if (!data) return <Loading />;
|
|
|
|
|
|
return (
|
|
return (
|
|
@@ -44,10 +154,10 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
<Header
|
|
<Header
|
|
label={data.settings.name}
|
|
label={data.settings.name}
|
|
rightElement={
|
|
rightElement={
|
|
- data.settings.members_can_edit_settings === 1 ? (
|
|
|
|
- <TouchableOpacity
|
|
|
|
- style={{ width: 30, height: 30, backgroundColor: 'green' }}
|
|
|
|
- ></TouchableOpacity>
|
|
|
|
|
|
+ data.settings.members_can_edit_settings === 1 || data.settings.admin === 1 ? (
|
|
|
|
+ <TouchableOpacity style={{ padding: 6 }} onPress={openEditModal}>
|
|
|
|
+ <EditIcon fill={Colors.DARK_BLUE} width={18} height={18} />
|
|
|
|
+ </TouchableOpacity>
|
|
) : null
|
|
) : null
|
|
}
|
|
}
|
|
/>
|
|
/>
|
|
@@ -83,6 +193,9 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
)}
|
|
)}
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
<Text style={styles.bigText}>{data.settings.name}</Text>
|
|
<Text style={styles.bigText}>{data.settings.name}</Text>
|
|
|
|
+ <Text style={{ fontSize: getFontSize(12), fontWeight: '600', color: Colors.DARK_BLUE }}>
|
|
|
|
+ {data.settings.member_count} nomads
|
|
|
|
+ </Text>
|
|
</View>
|
|
</View>
|
|
|
|
|
|
{data.settings.description && (
|
|
{data.settings.description && (
|
|
@@ -105,15 +218,15 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
<Text style={styles.title}>{members.settings.length} nomads</Text>
|
|
<Text style={styles.title}>{members.settings.length} nomads</Text>
|
|
- {data.settings.members_can_add_new_members === 1 ? (
|
|
|
|
- <TouchableOpacity
|
|
|
|
- style={{ width: 30, height: 30, backgroundColor: 'green' }}
|
|
|
|
- ></TouchableOpacity>
|
|
|
|
|
|
+ {data.settings.members_can_add_new_members === 1 || data.settings.admin === 1 ? (
|
|
|
|
+ <TouchableOpacity style={{ padding: 6, paddingRight: 0 }}>
|
|
|
|
+ <UserPlusIcon fill={Colors.ORANGE} height={18} width={23} />
|
|
|
|
+ </TouchableOpacity>
|
|
) : null}
|
|
) : null}
|
|
</View>
|
|
</View>
|
|
|
|
|
|
<View style={{ gap: 6 }}>
|
|
<View style={{ gap: 6 }}>
|
|
- {(members.settings.length > 4
|
|
|
|
|
|
+ {(data.settings.member_count > 4
|
|
? members.settings.slice(0, 4)
|
|
? members.settings.slice(0, 4)
|
|
: members.settings
|
|
: members.settings
|
|
).map((member, index) => (
|
|
).map((member, index) => (
|
|
@@ -123,7 +236,7 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
) : (
|
|
) : (
|
|
<AvatarWithInitials
|
|
<AvatarWithInitials
|
|
text={`${member.name?.split(' ')[0][0]}${member.name?.split(' ')[1][0]}`}
|
|
text={`${member.name?.split(' ')[0][0]}${member.name?.split(' ')[1][0]}`}
|
|
- flag={''}
|
|
|
|
|
|
+ flag={API_HOST + member?.flag}
|
|
size={36}
|
|
size={36}
|
|
fontSize={16}
|
|
fontSize={16}
|
|
borderColor={Colors.LIGHT_GRAY}
|
|
borderColor={Colors.LIGHT_GRAY}
|
|
@@ -148,6 +261,19 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
</View>
|
|
</View>
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
))}
|
|
))}
|
|
|
|
+ {data.settings.member_count > 4 ? (
|
|
|
|
+ <TouchableOpacity style={{ padding: 8, alignItems: 'center' }}>
|
|
|
|
+ <Text
|
|
|
|
+ style={{
|
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
|
+ fontSize: getFontSize(12),
|
|
|
|
+ fontWeight: '700'
|
|
|
|
+ }}
|
|
|
|
+ >
|
|
|
|
+ All nomads...
|
|
|
|
+ </Text>
|
|
|
|
+ </TouchableOpacity>
|
|
|
|
+ ) : null}
|
|
</View>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
) : null}
|
|
) : null}
|
|
@@ -155,11 +281,8 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
|
|
|
<View style={{ gap: 16 }}>
|
|
<View style={{ gap: 16 }}>
|
|
<View style={styles.optionsContainer}>
|
|
<View style={styles.optionsContainer}>
|
|
- <TouchableOpacity
|
|
|
|
- style={styles.option}
|
|
|
|
- // onPress={handleMute}
|
|
|
|
- >
|
|
|
|
- <Text style={styles.optionText}>{false ? 'Unmute' : 'Mute'}</Text>
|
|
|
|
|
|
+ <TouchableOpacity style={styles.option} onPress={handleMute}>
|
|
|
|
+ <Text style={styles.optionText}>{muted ? 'Unmute' : 'Mute'}</Text>
|
|
<BellSlashIcon fill={Colors.DARK_BLUE} />
|
|
<BellSlashIcon fill={Colors.DARK_BLUE} />
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
@@ -167,47 +290,32 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
<View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
|
|
<View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
|
|
<TouchableOpacity
|
|
<TouchableOpacity
|
|
style={[styles.option, styles.dangerOption]}
|
|
style={[styles.option, styles.dangerOption]}
|
|
- // onPress={handleLeaveGroup}
|
|
|
|
|
|
+ onPress={handleLeaveGroup}
|
|
>
|
|
>
|
|
- <Text style={[styles.optionText, styles.dangerText]}>Leave group</Text>
|
|
|
|
|
|
+ <Text style={[styles.optionText, styles.dangerText]}>Leave group chat</Text>
|
|
<ExitIcon fill={Colors.RED} width={16} />
|
|
<ExitIcon fill={Colors.RED} width={16} />
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
|
|
|
|
<TouchableOpacity
|
|
<TouchableOpacity
|
|
style={[styles.option, styles.dangerOption]}
|
|
style={[styles.option, styles.dangerOption]}
|
|
- // onPress={handleReport}
|
|
|
|
- >
|
|
|
|
- <Text style={[styles.optionText, styles.dangerText]}>Report</Text>
|
|
|
|
- <MegaphoneIcon fill={Colors.RED} />
|
|
|
|
- </TouchableOpacity>
|
|
|
|
-
|
|
|
|
- <TouchableOpacity
|
|
|
|
- style={[styles.option, styles.dangerOption]}
|
|
|
|
- // onPress={handleBlock}
|
|
|
|
|
|
+ onPress={handleDeleteGroup}
|
|
>
|
|
>
|
|
- <Text style={[styles.optionText, styles.dangerText]}>Block</Text>
|
|
|
|
- <BanIcon fill={Colors.RED} />
|
|
|
|
- </TouchableOpacity>
|
|
|
|
-
|
|
|
|
- <TouchableOpacity
|
|
|
|
- style={[styles.option, styles.dangerOption]}
|
|
|
|
- // onPress={handleDelete}
|
|
|
|
- >
|
|
|
|
- <Text style={[styles.optionText, styles.dangerText]}>Delete chat</Text>
|
|
|
|
|
|
+ <Text style={[styles.optionText, styles.dangerText]}>Delete group chat</Text>
|
|
<TrashIcon fill={Colors.RED} width={18} height={18} />
|
|
<TrashIcon fill={Colors.RED} width={18} height={18} />
|
|
</TouchableOpacity>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
</View>
|
|
</ScrollView>
|
|
</ScrollView>
|
|
|
|
|
|
- {/* <WarningModal
|
|
|
|
- type={'confirm'}
|
|
|
|
|
|
+ <WarningModal
|
|
|
|
+ type={'delete'}
|
|
isVisible={modalState.isWarningVisible}
|
|
isVisible={modalState.isWarningVisible}
|
|
- message={`Are you sure you want to unfriend ${data.user_data.first_name} ${data.user_data.last_name}?`}
|
|
|
|
- action={handleUpdateFriendStatus}
|
|
|
|
- onClose={() => closeModal('isWarningVisible')}
|
|
|
|
- title=""
|
|
|
|
- /> */}
|
|
|
|
|
|
+ buttonTitle={modalState.buttonTitle}
|
|
|
|
+ message={modalState.message}
|
|
|
|
+ action={modalState.action}
|
|
|
|
+ onClose={() => setModalState({ ...modalState, isWarningVisible: false })}
|
|
|
|
+ title={modalState.title}
|
|
|
|
+ />
|
|
<ImageView
|
|
<ImageView
|
|
images={[{ uri: API_HOST + data.settings.avatar_full }]}
|
|
images={[{ uri: API_HOST + data.settings.avatar_full }]}
|
|
keyExtractor={(imageSrc, index) => index.toString()}
|
|
keyExtractor={(imageSrc, index) => index.toString()}
|
|
@@ -218,6 +326,7 @@ const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
backgroundColor={Colors.DARK_BLUE}
|
|
backgroundColor={Colors.DARK_BLUE}
|
|
doubleTapToZoomEnabled={true}
|
|
doubleTapToZoomEnabled={true}
|
|
/>
|
|
/>
|
|
|
|
+ <EditGroupModal />
|
|
</PageWrapper>
|
|
</PageWrapper>
|
|
);
|
|
);
|
|
};
|
|
};
|