index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import React, { FC, useEffect, useState } from 'react';
  2. import { View, StyleSheet } from 'react-native';
  3. import { NavigationProp } from '@react-navigation/native';
  4. import { PageWrapper, Header, Input, WarningModal } from 'src/components';
  5. import { FlashList } from '@shopify/flash-list';
  6. import SearchIcon from 'assets/icons/search.svg';
  7. import { applyModalSort, dataRanking } from '../../TravellersScreen/utils';
  8. import { RankingDropdown } from '../../TravellersScreen/utils/types';
  9. import { Profile } from '../../MapScreen/UsersListScreen/Profile';
  10. import { FilterButton, FilterModal } from '../../TravellersScreen/Components/FilterModal';
  11. import { usePostGetCountriesRanking } from '@api/ranking';
  12. import OptionsModal from '../Components/OptionsModal';
  13. import { SheetManager } from 'react-native-actions-sheet';
  14. import { storage, StoreType } from 'src/storage';
  15. type Props = {
  16. navigation: NavigationProp<any>;
  17. route: any;
  18. };
  19. const ParticipantsListScreen: FC<Props> = ({ navigation, route }) => {
  20. const { participants, eventId, isHost } = route.params;
  21. const token = storage.get('token', StoreType.STRING);
  22. const { data: masterCountries } = usePostGetCountriesRanking();
  23. const [allParticipants, setAllParticipants] = useState(participants);
  24. const [searchQuery, setSearchQuery] = useState('');
  25. const [filteredData, setFilteredData] = useState<any[]>([]);
  26. const [confirmedValueRanking, setConfirmedValueRanking] = useState<RankingDropdown | null>();
  27. const [isModalVisible, setModalVisible] = useState(false);
  28. const [modalState, setModalState] = useState({
  29. isWarningVisible: false,
  30. title: '',
  31. buttonTitle: '',
  32. message: '',
  33. action: () => {}
  34. });
  35. useEffect(() => {
  36. if (allParticipants) {
  37. setFilteredData(allParticipants);
  38. }
  39. }, [allParticipants]);
  40. const handleSearch = (text: string) => {
  41. if (text && allParticipants) {
  42. const searchData =
  43. allParticipants?.filter((item: any) => {
  44. const itemData = item.first_name
  45. ? item.first_name.toLowerCase() + ' ' + item.last_name?.toLowerCase()
  46. : ''.toLowerCase();
  47. const textData = text.toLowerCase();
  48. return itemData.indexOf(textData) > -1;
  49. }) ?? [];
  50. setFilteredData(searchData);
  51. setSearchQuery(text);
  52. } else {
  53. setFilteredData(allParticipants ?? []);
  54. setSearchQuery(text);
  55. }
  56. };
  57. const handleFilterParticipants = (userId: number) => {
  58. setAllParticipants(allParticipants.filter((p: any) => p.user_id !== userId));
  59. };
  60. const handleOptionPress = (user: any) => {
  61. SheetManager.show('host-options-modal', {
  62. payload: {
  63. eventId,
  64. userId: user.user_id,
  65. name: user.first_name + ' ' + user.last_name,
  66. token,
  67. filterParticipants: () => handleFilterParticipants(user.user_id),
  68. setIsWarningVisible: setModalState
  69. } as any
  70. });
  71. };
  72. return (
  73. <PageWrapper>
  74. <Header
  75. label="Participants"
  76. rightElement={<FilterButton onPress={() => setModalVisible(!isModalVisible)} />}
  77. />
  78. <View style={styles.container}>
  79. <Input
  80. inputMode={'search'}
  81. placeholder={'Search nomads'}
  82. onChange={handleSearch}
  83. value={searchQuery}
  84. icon={<SearchIcon fill={'#C8C8C8'} width={14} height={14} />}
  85. />
  86. <FlashList
  87. viewabilityConfig={{
  88. waitForInteraction: true,
  89. itemVisiblePercentThreshold: 50,
  90. minimumViewTime: 1000
  91. }}
  92. estimatedItemSize={50}
  93. data={filteredData || []}
  94. renderItem={({ item, index }) => (
  95. <Profile
  96. withMenu={isHost}
  97. onPressOption={() => handleOptionPress(item)}
  98. userId={item.user_id}
  99. key={index}
  100. index={index}
  101. first_name={item.first_name}
  102. last_name={item.last_name}
  103. avatar={item.avatar ? '/img/avatars/' + item.avatar : null}
  104. date_of_birth={item.age}
  105. homebase_flag={'/img/flags_new/' + item.flag1}
  106. homebase2_flag={item.flag2 ? '/img/flags_new/' + item.flag2 : null}
  107. score={[
  108. item.score_nm,
  109. item.score_un,
  110. item.score_unp,
  111. item.score_dare,
  112. item.score_tcc,
  113. item.score_deep,
  114. item.score_slow,
  115. item.score_yes,
  116. item.score_kye,
  117. item.score_whs,
  118. item.score_tbt
  119. ]}
  120. active_score={
  121. confirmedValueRanking ? confirmedValueRanking.value - 1 : dataRanking[0].value - 1
  122. }
  123. tbt_score={item.score_tbt}
  124. tbt_rank={item.rank_tbt}
  125. badge_tbt={item.badge_tbt}
  126. badge_1281={item.badge_1281}
  127. badge_un={item.badge_un}
  128. badge_un_25={item.badge_un_25}
  129. badge_un_50={item.badge_un_50}
  130. badge_un_75={item.badge_un_75}
  131. badge_un_100={item.badge_un_100}
  132. badge_un_150={item.badge_un_150}
  133. badge_premium={item.badge_premium}
  134. auth={item.auth}
  135. />
  136. )}
  137. keyExtractor={(item) => item.user_id.toString()}
  138. contentContainerStyle={{ paddingBottom: 16, paddingTop: 8 }}
  139. showsVerticalScrollIndicator={false}
  140. />
  141. </View>
  142. <FilterModal
  143. isModalVisible={isModalVisible}
  144. setModalVisible={(value) => setModalVisible(value)}
  145. applyFilter={(filterAge, filterRanking, filterCountry) => {
  146. setConfirmedValueRanking(filterRanking);
  147. setFilteredData(
  148. applyModalSort(
  149. allParticipants ?? [],
  150. filterAge,
  151. filterRanking ?? dataRanking[0],
  152. filterCountry
  153. )
  154. );
  155. setModalVisible(false);
  156. }}
  157. countriesData={masterCountries ? masterCountries.data : []}
  158. />
  159. <OptionsModal />
  160. <WarningModal
  161. type={'delete'}
  162. isVisible={modalState.isWarningVisible}
  163. buttonTitle={modalState.buttonTitle}
  164. message={modalState.message}
  165. action={modalState.action}
  166. onClose={() => setModalState({ ...modalState, isWarningVisible: false })}
  167. title={modalState.title}
  168. />
  169. </PageWrapper>
  170. );
  171. };
  172. const styles = StyleSheet.create({
  173. container: {
  174. backgroundColor: 'white',
  175. gap: 16,
  176. flex: 1
  177. }
  178. });
  179. export default ParticipantsListScreen;