|
@@ -0,0 +1,295 @@
|
|
|
+import React, { FC, useCallback, useEffect, useState } from 'react';
|
|
|
+import { ScrollView, Text, TouchableOpacity, View, Image, StyleSheet } from 'react-native';
|
|
|
+import { NavigationProp, useFocusEffect } from '@react-navigation/native';
|
|
|
+import ImageView from 'react-native-image-viewing';
|
|
|
+import { storage, StoreType } from 'src/storage';
|
|
|
+import { PageWrapper, Header, Loading, Input, AvatarWithInitials } from 'src/components';
|
|
|
+import { usePostGetGroupMembersQuery, usePostGetGroupSettingsQuery } from '@api/chat';
|
|
|
+import { Colors } from 'src/theme';
|
|
|
+import { API_HOST } from 'src/constants';
|
|
|
+import GroupIcon from 'assets/icons/messages/group-chat.svg';
|
|
|
+import { getFontSize } from 'src/utils';
|
|
|
+import MegaphoneIcon from 'assets/icons/messages/megaphone.svg';
|
|
|
+import ExitIcon from 'assets/icons/messages/exit.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 { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
|
+
|
|
|
+type Props = {
|
|
|
+ navigation: NavigationProp<any>;
|
|
|
+ route: any;
|
|
|
+};
|
|
|
+
|
|
|
+const GroupSettingScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
+ const token = storage.get('token', StoreType.STRING) as string;
|
|
|
+ const groupToken = route.params.groupToken;
|
|
|
+ const insets = useSafeAreaInsets();
|
|
|
+ const [canSeeMembers, setCanSeeMembers] = useState(false);
|
|
|
+ const { data } = usePostGetGroupSettingsQuery(token, groupToken, true);
|
|
|
+ const { data: members } = usePostGetGroupMembersQuery(token, groupToken, canSeeMembers);
|
|
|
+
|
|
|
+ const [fullSizeImageVisible, setFullSizeImageVisible] = useState(false);
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (data && data.settings) {
|
|
|
+ setCanSeeMembers(data.settings.members_can_see_members === 1);
|
|
|
+ }
|
|
|
+ }, [data]);
|
|
|
+
|
|
|
+ if (!data) return <Loading />;
|
|
|
+
|
|
|
+ return (
|
|
|
+ <PageWrapper>
|
|
|
+ <Header
|
|
|
+ label={data.settings.name}
|
|
|
+ rightElement={
|
|
|
+ data.settings.members_can_edit_settings === 1 ? (
|
|
|
+ <TouchableOpacity
|
|
|
+ style={{ width: 30, height: 30, backgroundColor: 'green' }}
|
|
|
+ ></TouchableOpacity>
|
|
|
+ ) : null
|
|
|
+ }
|
|
|
+ />
|
|
|
+ <ScrollView
|
|
|
+ showsVerticalScrollIndicator={false}
|
|
|
+ style={{ flex: 1 }}
|
|
|
+ contentContainerStyle={{
|
|
|
+ paddingBottom: insets.bottom,
|
|
|
+ justifyContent: 'space-between',
|
|
|
+ flex: 1
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View style={{ gap: 16 }}>
|
|
|
+ <View style={styles.photoContainer}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={styles.photoContainer}
|
|
|
+ onPress={() => setFullSizeImageVisible(true)}
|
|
|
+ disabled={!data.settings.avatar}
|
|
|
+ >
|
|
|
+ {!data.settings.avatar ? (
|
|
|
+ <GroupIcon width={80} height={80} fill={Colors.LIGHT_GRAY} />
|
|
|
+ ) : (
|
|
|
+ <Image
|
|
|
+ source={{ uri: API_HOST + data.settings.avatar }}
|
|
|
+ style={{
|
|
|
+ width: 80,
|
|
|
+ height: 80,
|
|
|
+ borderRadius: 40,
|
|
|
+ borderWidth: 1,
|
|
|
+ borderColor: Colors.FILL_LIGHT
|
|
|
+ }}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </TouchableOpacity>
|
|
|
+ <Text style={styles.bigText}>{data.settings.name}</Text>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ {data.settings.description && (
|
|
|
+ <Input
|
|
|
+ editable={false}
|
|
|
+ value={data.settings.description}
|
|
|
+ header="Description"
|
|
|
+ multiline
|
|
|
+ height={58}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+
|
|
|
+ {canSeeMembers && members ? (
|
|
|
+ <View style={{ gap: 8, marginBottom: 16 }}>
|
|
|
+ <View
|
|
|
+ style={{
|
|
|
+ flexDirection: 'row',
|
|
|
+ justifyContent: 'space-between',
|
|
|
+ alignItems: 'center'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <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>
|
|
|
+ ) : null}
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View style={{ gap: 6 }}>
|
|
|
+ {(members.settings.length > 4
|
|
|
+ ? members.settings.slice(0, 4)
|
|
|
+ : members.settings
|
|
|
+ ).map((member, index) => (
|
|
|
+ <TouchableOpacity key={index} style={styles.userItem} onPress={() => {}}>
|
|
|
+ {member.avatar ? (
|
|
|
+ <Image source={{ uri: API_HOST + member.avatar }} style={styles.avatar} />
|
|
|
+ ) : (
|
|
|
+ <AvatarWithInitials
|
|
|
+ text={`${member.name?.split(' ')[0][0]}${member.name?.split(' ')[1][0]}`}
|
|
|
+ flag={''}
|
|
|
+ size={36}
|
|
|
+ fontSize={16}
|
|
|
+ borderColor={Colors.LIGHT_GRAY}
|
|
|
+ borderWidth={1}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ <View style={{ flex: 1 }}>
|
|
|
+ <Text style={styles.userName}>{member.name}</Text>
|
|
|
+ </View>
|
|
|
+ <View style={{ justifyContent: 'center', alignItems: 'center' }}>
|
|
|
+ {member.admin === 1 && (
|
|
|
+ <Text
|
|
|
+ style={{
|
|
|
+ fontSize: getFontSize(10),
|
|
|
+ fontWeight: '600',
|
|
|
+ color: Colors.LIGHT_GRAY
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ Admin
|
|
|
+ </Text>
|
|
|
+ )}
|
|
|
+ </View>
|
|
|
+ </TouchableOpacity>
|
|
|
+ ))}
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ ) : null}
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View style={{ gap: 16 }}>
|
|
|
+ <View style={styles.optionsContainer}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={styles.option}
|
|
|
+ // onPress={handleMute}
|
|
|
+ >
|
|
|
+ <Text style={styles.optionText}>{false ? 'Unmute' : 'Mute'}</Text>
|
|
|
+ <BellSlashIcon fill={Colors.DARK_BLUE} />
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
+
|
|
|
+ <View style={[styles.optionsContainer, { paddingVertical: 0, gap: 0 }]}>
|
|
|
+ <TouchableOpacity
|
|
|
+ style={[styles.option, styles.dangerOption]}
|
|
|
+ // onPress={handleLeaveGroup}
|
|
|
+ >
|
|
|
+ <Text style={[styles.optionText, styles.dangerText]}>Leave group</Text>
|
|
|
+ <ExitIcon fill={Colors.RED} width={16} />
|
|
|
+ </TouchableOpacity>
|
|
|
+
|
|
|
+ <TouchableOpacity
|
|
|
+ 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}
|
|
|
+ >
|
|
|
+ <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>
|
|
|
+ <TrashIcon fill={Colors.RED} width={18} height={18} />
|
|
|
+ </TouchableOpacity>
|
|
|
+ </View>
|
|
|
+ </View>
|
|
|
+ </ScrollView>
|
|
|
+
|
|
|
+ {/* <WarningModal
|
|
|
+ type={'confirm'}
|
|
|
+ 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=""
|
|
|
+ /> */}
|
|
|
+ <ImageView
|
|
|
+ images={[{ uri: API_HOST + data.settings.avatar_full }]}
|
|
|
+ keyExtractor={(imageSrc, index) => index.toString()}
|
|
|
+ imageIndex={0}
|
|
|
+ visible={fullSizeImageVisible}
|
|
|
+ onRequestClose={() => setFullSizeImageVisible(false)}
|
|
|
+ swipeToCloseEnabled={false}
|
|
|
+ backgroundColor={Colors.DARK_BLUE}
|
|
|
+ doubleTapToZoomEnabled={true}
|
|
|
+ />
|
|
|
+ </PageWrapper>
|
|
|
+ );
|
|
|
+};
|
|
|
+
|
|
|
+const styles = StyleSheet.create({
|
|
|
+ photoContainer: {
|
|
|
+ alignItems: 'center',
|
|
|
+ gap: 8
|
|
|
+ },
|
|
|
+ groupPhoto: {
|
|
|
+ width: 80,
|
|
|
+ height: 80,
|
|
|
+ borderRadius: 40,
|
|
|
+ alignItems: 'center',
|
|
|
+ justifyContent: 'center'
|
|
|
+ },
|
|
|
+ bigText: {
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(18),
|
|
|
+ fontFamily: 'montserrat-700'
|
|
|
+ },
|
|
|
+ userItem: {
|
|
|
+ flexDirection: 'row',
|
|
|
+ alignItems: 'center',
|
|
|
+ paddingVertical: 8,
|
|
|
+ paddingHorizontal: 12,
|
|
|
+ backgroundColor: Colors.FILL_LIGHT,
|
|
|
+ gap: 8,
|
|
|
+ borderRadius: 8
|
|
|
+ },
|
|
|
+ avatar: {
|
|
|
+ width: 36,
|
|
|
+ height: 36,
|
|
|
+ borderRadius: 18,
|
|
|
+ borderWidth: 1,
|
|
|
+ borderColor: Colors.LIGHT_GRAY
|
|
|
+ },
|
|
|
+ userName: {
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(14),
|
|
|
+ fontFamily: 'montserrat-700'
|
|
|
+ },
|
|
|
+ title: {
|
|
|
+ color: Colors.DARK_BLUE,
|
|
|
+ fontSize: getFontSize(14),
|
|
|
+ fontFamily: 'redhat-700'
|
|
|
+ },
|
|
|
+ optionsContainer: {
|
|
|
+ paddingVertical: 10,
|
|
|
+ paddingHorizontal: 8,
|
|
|
+ gap: 16,
|
|
|
+ borderRadius: 8,
|
|
|
+ backgroundColor: Colors.FILL_LIGHT
|
|
|
+ },
|
|
|
+ option: {
|
|
|
+ flexDirection: 'row',
|
|
|
+ alignItems: 'center',
|
|
|
+ justifyContent: 'space-between'
|
|
|
+ },
|
|
|
+ optionText: {
|
|
|
+ fontSize: getFontSize(12),
|
|
|
+ fontWeight: '600',
|
|
|
+ color: Colors.DARK_BLUE
|
|
|
+ },
|
|
|
+ dangerOption: {
|
|
|
+ paddingVertical: 10,
|
|
|
+ borderBottomWidth: 1,
|
|
|
+ borderBlockColor: Colors.WHITE
|
|
|
+ },
|
|
|
+ dangerText: {
|
|
|
+ color: Colors.RED
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+export default GroupSettingScreen;
|