index.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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, interested, isTrip } = 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. interested: interested,
  70. isTrip: isTrip
  71. } as any
  72. });
  73. };
  74. return (
  75. <PageWrapper>
  76. <Header
  77. label={interested ? 'Interested' : 'Joined'}
  78. rightElement={<FilterButton onPress={() => setModalVisible(!isModalVisible)} />}
  79. />
  80. <View style={styles.container}>
  81. <Input
  82. inputMode={'search'}
  83. placeholder={'Search nomads'}
  84. onChange={handleSearch}
  85. value={searchQuery}
  86. icon={<SearchIcon fill={'#C8C8C8'} width={14} height={14} />}
  87. />
  88. <FlashList
  89. viewabilityConfig={{
  90. waitForInteraction: true,
  91. itemVisiblePercentThreshold: 50,
  92. minimumViewTime: 1000
  93. }}
  94. estimatedItemSize={50}
  95. data={filteredData || []}
  96. renderItem={({ item, index }) => (
  97. <Profile
  98. withMenu={isHost}
  99. onPressOption={() => handleOptionPress(item)}
  100. userId={item.user_id}
  101. key={index}
  102. index={index}
  103. first_name={item.first_name}
  104. last_name={item.last_name}
  105. avatar={item.avatar ? '/img/avatars/' + item.avatar : null}
  106. date_of_birth={item.age}
  107. homebase_flag={'/img/flags_new/' + item.flag1}
  108. homebase2_flag={item.flag2 ? '/img/flags_new/' + item.flag2 : null}
  109. score={[
  110. item.score_nm,
  111. item.score_un,
  112. item.score_unp,
  113. item.score_dare,
  114. item.score_tcc,
  115. item.score_deep,
  116. item.score_slow,
  117. item.score_yes,
  118. item.score_kye,
  119. item.score_whs,
  120. item.score_tbt
  121. ]}
  122. active_score={
  123. confirmedValueRanking ? confirmedValueRanking.value - 1 : dataRanking[0].value - 1
  124. }
  125. tbt_score={item.score_tbt}
  126. tbt_rank={item.rank_tbt}
  127. badge_tbt={item.badge_tbt}
  128. badge_1281={item.badge_1281}
  129. badge_un={item.badge_un}
  130. badge_un_25={item.badge_un_25}
  131. badge_un_50={item.badge_un_50}
  132. badge_un_75={item.badge_un_75}
  133. badge_un_100={item.badge_un_100}
  134. badge_un_150={item.badge_un_150}
  135. badge_premium={item.badge_premium}
  136. auth={item.auth}
  137. />
  138. )}
  139. keyExtractor={(item) => item.user_id.toString()}
  140. contentContainerStyle={{ paddingBottom: 16, paddingTop: 8 }}
  141. showsVerticalScrollIndicator={false}
  142. />
  143. </View>
  144. <FilterModal
  145. isModalVisible={isModalVisible}
  146. setModalVisible={(value) => setModalVisible(value)}
  147. applyFilter={(filterAge, filterRanking, filterCountry) => {
  148. setConfirmedValueRanking(filterRanking);
  149. setFilteredData(
  150. applyModalSort(
  151. allParticipants ?? [],
  152. filterAge,
  153. filterRanking ?? dataRanking[0],
  154. filterCountry
  155. )
  156. );
  157. setModalVisible(false);
  158. }}
  159. countriesData={masterCountries ? masterCountries.data : []}
  160. />
  161. <OptionsModal />
  162. <WarningModal
  163. type={'delete'}
  164. isVisible={modalState.isWarningVisible}
  165. buttonTitle={modalState.buttonTitle}
  166. message={modalState.message}
  167. action={modalState.action}
  168. onClose={() => setModalState({ ...modalState, isWarningVisible: false })}
  169. title={modalState.title}
  170. />
  171. </PageWrapper>
  172. );
  173. };
  174. const styles = StyleSheet.create({
  175. container: {
  176. backgroundColor: 'white',
  177. gap: 16,
  178. flex: 1
  179. }
  180. });
  181. export default ParticipantsListScreen;