|
@@ -1,7 +1,7 @@
|
|
|
import React, { FC, useEffect, useState } from 'react';
|
|
|
import { View, StyleSheet } from 'react-native';
|
|
|
import { NavigationProp } from '@react-navigation/native';
|
|
|
-import { PageWrapper, Header, Input } from 'src/components';
|
|
|
+import { PageWrapper, Header, Input, WarningModal } from 'src/components';
|
|
|
import { FlashList } from '@shopify/flash-list';
|
|
|
|
|
|
import SearchIcon from 'assets/icons/search.svg';
|
|
@@ -10,6 +10,9 @@ import { RankingDropdown } from '../../TravellersScreen/utils/types';
|
|
|
import { Profile } from '../../MapScreen/UsersListScreen/Profile';
|
|
|
import { FilterButton, FilterModal } from '../../TravellersScreen/Components/FilterModal';
|
|
|
import { usePostGetCountriesRanking } from '@api/ranking';
|
|
|
+import OptionsModal from '../Components/OptionsModal';
|
|
|
+import { SheetManager } from 'react-native-actions-sheet';
|
|
|
+import { storage, StoreType } from 'src/storage';
|
|
|
|
|
|
type Props = {
|
|
|
navigation: NavigationProp<any>;
|
|
@@ -17,24 +20,33 @@ type Props = {
|
|
|
};
|
|
|
|
|
|
const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
- const { participants } = route.params;
|
|
|
+ const { participants, eventId, isHost } = route.params;
|
|
|
+ const token = storage.get('token', StoreType.STRING);
|
|
|
const { data: masterCountries } = usePostGetCountriesRanking();
|
|
|
|
|
|
+ const [allParticipants, setAllParticipants] = useState(participants);
|
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
|
const [filteredData, setFilteredData] = useState<any[]>([]);
|
|
|
const [confirmedValueRanking, setConfirmedValueRanking] = useState<RankingDropdown | null>();
|
|
|
const [isModalVisible, setModalVisible] = useState(false);
|
|
|
+ const [modalState, setModalState] = useState({
|
|
|
+ isWarningVisible: false,
|
|
|
+ title: '',
|
|
|
+ buttonTitle: '',
|
|
|
+ message: '',
|
|
|
+ action: () => {}
|
|
|
+ });
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (participants) {
|
|
|
- setFilteredData(participants);
|
|
|
+ if (allParticipants) {
|
|
|
+ setFilteredData(allParticipants);
|
|
|
}
|
|
|
- }, [participants]);
|
|
|
+ }, [allParticipants]);
|
|
|
|
|
|
const handleSearch = (text: string) => {
|
|
|
- if (text && participants) {
|
|
|
+ if (text && allParticipants) {
|
|
|
const searchData =
|
|
|
- participants?.filter((item: any) => {
|
|
|
+ allParticipants?.filter((item: any) => {
|
|
|
const itemData = item.first_name
|
|
|
? item.first_name.toLowerCase() + ' ' + item.last_name?.toLowerCase()
|
|
|
: ''.toLowerCase();
|
|
@@ -44,11 +56,28 @@ const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
setFilteredData(searchData);
|
|
|
setSearchQuery(text);
|
|
|
} else {
|
|
|
- setFilteredData(participants ?? []);
|
|
|
+ setFilteredData(allParticipants ?? []);
|
|
|
setSearchQuery(text);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ const handleFilterParticipants = (userId: number) => {
|
|
|
+ setAllParticipants(allParticipants.filter((p: any) => p.user_id !== userId));
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleOptionPress = (user: any) => {
|
|
|
+ SheetManager.show('host-options-modal', {
|
|
|
+ payload: {
|
|
|
+ eventId,
|
|
|
+ userId: user.user_id,
|
|
|
+ name: user.first_name + ' ' + user.last_name,
|
|
|
+ token,
|
|
|
+ filterParticipants: () => handleFilterParticipants(user.user_id),
|
|
|
+ setIsWarningVisible: setModalState
|
|
|
+ } as any
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
return (
|
|
|
<PageWrapper>
|
|
|
<Header
|
|
@@ -73,6 +102,8 @@ const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
data={filteredData || []}
|
|
|
renderItem={({ item, index }) => (
|
|
|
<Profile
|
|
|
+ withMenu={isHost}
|
|
|
+ onPressOption={() => handleOptionPress(item)}
|
|
|
userId={item.user_id}
|
|
|
key={index}
|
|
|
index={index}
|
|
@@ -124,7 +155,7 @@ const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
setConfirmedValueRanking(filterRanking);
|
|
|
setFilteredData(
|
|
|
applyModalSort(
|
|
|
- participants ?? [],
|
|
|
+ allParticipants ?? [],
|
|
|
filterAge,
|
|
|
filterRanking ?? dataRanking[0],
|
|
|
filterCountry
|
|
@@ -134,6 +165,16 @@ const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
|
|
|
}}
|
|
|
countriesData={masterCountries ? masterCountries.data : []}
|
|
|
/>
|
|
|
+ <OptionsModal />
|
|
|
+ <WarningModal
|
|
|
+ type={'delete'}
|
|
|
+ isVisible={modalState.isWarningVisible}
|
|
|
+ buttonTitle={modalState.buttonTitle}
|
|
|
+ message={modalState.message}
|
|
|
+ action={modalState.action}
|
|
|
+ onClose={() => setModalState({ ...modalState, isWarningVisible: false })}
|
|
|
+ title={modalState.title}
|
|
|
+ />
|
|
|
</PageWrapper>
|
|
|
);
|
|
|
};
|