be-components 1.9.5 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,52 +1,207 @@
1
1
  import React, { useEffect, useState } from "react"
2
- import { View, FlatList, TouchableOpacity, Image, ActivityIndicator } from "react-native"
3
- import { ManageCompetitionApi } from "../api"
2
+ import { View, FlatList, TouchableOpacity, Image, ActivityIndicator, ScrollView } from "react-native"
3
+ import { ManageCompetitionApi, ManageCompetitionHelpers } from "../api"
4
4
  import Colors from "../../constants/colors"
5
5
  import { view_styles } from "../../constants/styles"
6
6
  import { Button, Icons, Text } from "../../Components"
7
- import type { CompetitionProps } from "../../types"
7
+ import type { BracketCompetitionProps, CompetitionPlayerBracketProps, CompetitionPlayerProps, CompetitionProps, CompetitionRecordProps, CompetitionResultProps, CompetitionSeasonPlayerProps, CompetitionSeasonProps, CompetitionSeasonResultProps, PlayerBracketProps, SquaresCompetitionProps } from "../../types"
8
8
 
9
9
  type AdminCompetitionListProps = {
10
10
  width:number,
11
- max_height?:number,
11
+ height?:number,
12
12
  onSelectCompetition:(competition:CompetitionProps) => void,
13
+ onSelectSquaresCompetition:(squares_competition:SquaresCompetitionProps) => void,
14
+ onSelectBracketCompetition:(bracket_competition:BracketCompetitionProps) => void,
13
15
  onClose: () => void,
14
- onCreateNew: () => void
16
+ onCreateNew: (engagement_type:'competitions'|'brackets'|'squares') => void
15
17
  }
16
18
 
17
- const AdminCompetitionList = ({ width, max_height, onClose, onCreateNew, onSelectCompetition }:AdminCompetitionListProps) => {
19
+ const AdminCompetitionList = ({ width, height, onClose, onCreateNew, onSelectCompetition, onSelectBracketCompetition, onSelectSquaresCompetition }:AdminCompetitionListProps) => {
18
20
  const [ list_data, setData ] = useState<{
19
21
  loading: boolean,
22
+ active_engagement: 'competitions'|'squares'|'brackets'
20
23
  active_tab:'active'|'closed',
21
24
  offset:number,
22
- competitions:CompetitionProps[]
25
+ admin_competitions:CompetitionProps[],
26
+ competitions:CompetitionProps[],
27
+ competition_players:CompetitionPlayerProps[],
28
+ competition_records:CompetitionRecordProps[],
29
+ competition_results:CompetitionResultProps[],
30
+ competition_seasons:CompetitionSeasonProps[],
31
+ competition_season_players:CompetitionSeasonPlayerProps[],
32
+ competition_season_results:CompetitionSeasonResultProps[],
33
+ bracket_competitions:BracketCompetitionProps[],
34
+ competition_player_brackets:CompetitionPlayerBracketProps[],
35
+ player_brackets:PlayerBracketProps[],
36
+ squares_competitions:SquaresCompetitionProps[]
23
37
  }>({
24
38
  loading:false,
25
39
  offset:0,
40
+ active_engagement: 'competitions',
26
41
  active_tab: 'active',
27
- competitions: []
42
+ competitions: [],
43
+ competition_players:[],
44
+ competition_records:[],
45
+ competition_results:[],
46
+ admin_competitions:[],
47
+ competition_seasons: [],
48
+ competition_season_players:[],
49
+ competition_season_results:[],
50
+ bracket_competitions: [],
51
+ competition_player_brackets:[],
52
+ player_brackets: [],
53
+ squares_competitions: []
28
54
  })
29
- const { offset, active_tab, loading, competitions } = list_data;
55
+ const { offset, active_tab, active_engagement, loading, competitions, admin_competitions, competition_results, bracket_competitions, squares_competitions, competition_player_brackets } = list_data;
30
56
 
31
57
  useEffect(() => {
32
58
  ManageCompetitionApi.setEnvironment();
33
59
  getDataFromServer(0)
34
- },[active_tab])
60
+ },[])
61
+
62
+ useEffect(() => {
63
+ getDataFromServer(0)
64
+ },[active_engagement, active_tab])
35
65
 
36
66
  const getDataFromServer = async(offset:number) => {
37
67
  setData({ ...list_data, loading:true });
38
- const comps = await ManageCompetitionApi.getMyAdminCompetition(offset, active_tab);
39
- setData({
40
- ...list_data,
41
- loading: false,
42
- competitions: comps,
43
- offset
44
- })
68
+ switch(active_engagement){
69
+ case 'competitions':
70
+ const comps = await ManageCompetitionApi.getMyAdminCompetition(offset, active_tab);
71
+ if(active_tab == 'active'){
72
+ const c_resp = await ManageCompetitionApi.getMyActiveCompetitions();
73
+ setData({
74
+ ...list_data,
75
+ loading: false,
76
+ admin_competitions: comps,
77
+ competitions: c_resp.competitions,
78
+ competition_players: c_resp.competition_players,
79
+ competition_records: c_resp.competition_records,
80
+ competition_results: c_resp.competition_results,
81
+ offset
82
+ })
83
+ } else {
84
+ const c_resp = await ManageCompetitionApi.getMyHistoryCompetitions(offset);
85
+ setData({
86
+ ...list_data,
87
+ loading: false,
88
+ admin_competitions: comps,
89
+ competitions: c_resp.competitions,
90
+ competition_players: c_resp.competition_players,
91
+ competition_records: c_resp.competition_records,
92
+ competition_results: c_resp.competition_results,
93
+ offset
94
+ })
95
+ }
96
+ return
97
+ case 'brackets':
98
+ if(active_tab == 'active'){
99
+ const b_resp = await ManageCompetitionApi.getMyActiveBracketCompetitions();
100
+ setData({
101
+ ...list_data,
102
+ loading:false,
103
+ bracket_competitions: b_resp.bracket_competitions,
104
+ player_brackets: b_resp.player_brackets,
105
+ competition_player_brackets: b_resp.competition_player_brackets,
106
+ offset
107
+ })
108
+ } else {
109
+ const b_resp = await ManageCompetitionApi.getMyHistoryBracketCompetitions(offset);
110
+ setData({
111
+ ...list_data,
112
+ loading:false,
113
+ bracket_competitions: b_resp.bracket_competitions,
114
+ player_brackets: b_resp.player_brackets,
115
+ competition_player_brackets: b_resp.competition_player_brackets,
116
+ offset
117
+ })
118
+ }
119
+ return
120
+ case 'squares':
121
+ if(active_tab == 'active'){
122
+ const s_resp = await ManageCompetitionApi.getMyActiveSquaresCompetitions();
123
+ setData({
124
+ ...list_data,
125
+ loading:false,
126
+ offset,
127
+ squares_competitions: s_resp.squares_competitions
128
+ })
129
+ } else {
130
+ const s_resp = await ManageCompetitionApi.getMyHistorySquaresCompetitions(offset);
131
+ setData({
132
+ ...list_data,
133
+ loading:false,
134
+ offset,
135
+ squares_competitions: s_resp.squares_competitions
136
+ })
137
+ }
138
+ return
139
+ default: return
140
+ }
45
141
  }
46
142
 
47
143
  const renderCompetitions = (data: { item:CompetitionProps, index:number }) => {
144
+ const competition_result = competition_results.find(cr => cr.competition_id == data.item.competition_id);
145
+ const cl = data.item.market_type == 'FOR_MONEY' ? '$' : 'E'
146
+ return (
147
+ <TouchableOpacity style={{ ...view_styles.body_row, padding:15, borderBottomWidth:1, borderColor:Colors.shades.shade600 }} onPress={() => onSelectCompetition(data.item)}>
148
+ <Image
149
+ source={{ uri: data.item.image?.url }}
150
+ style={{ height:30, width:30, borderRadius:4 }}
151
+ resizeMode="cover"
152
+ />
153
+ <View style={{ flex:1, marginLeft:10 }}>
154
+ <Text theme="header_2">{data.item.competition_name}</Text>
155
+ <Text style={{ marginTop:3 }} theme="body">{data.item.competition_description}</Text>
156
+ </View>
157
+ {competition_result ?
158
+ <View style={{ marginRight:10, marginLeft:10, justifyContent:'center' }}>
159
+ <Text size={12} color={Colors.brand.midnight} weight="bold" textAlign="center">{ManageCompetitionHelpers.formatPlace(competition_result.place)}</Text>
160
+ <Text size={12} color={Colors.brand.midnight} textAlign="center" style={{ marginTop:3 }}>{cl}{competition_result.winnings.toFixed(2)}</Text>
161
+ </View>
162
+ :<></>}
163
+ <Icons.ChevronIcon direction='right' size={8} color={Colors.brand.midnight}/>
164
+ </TouchableOpacity>
165
+ )
166
+ }
167
+
168
+ const renderAdminCompetitions = (data: { item:CompetitionProps, index:number }) => {
169
+ return (
170
+ <TouchableOpacity style={{ borderRadius:8, backgroundColor:Colors.shades.white, width: width / 3, borderWidth:1, borderColor:Colors.shades.shade600 }} onPress={() => onSelectCompetition(data.item)}>
171
+ <Image
172
+ source={{ uri: data.item.image?.url }}
173
+ style={{ height:width/3*0.5, width:width/3, borderRadius:4, borderBottomRightRadius:0, borderBottomLeftRadius:0 }}
174
+ resizeMode="cover"
175
+ />
176
+ <View style={{ marginTop:5, padding:10 }}>
177
+ <Text size={14} textAlign="center" weight='bold'>{data.item.competition_name}</Text>
178
+ </View>
179
+ </TouchableOpacity>
180
+ )
181
+ }
182
+
183
+ const renderSquares = (data: { item:SquaresCompetitionProps, index:number }) => {
184
+ return (
185
+ <TouchableOpacity style={{ ...view_styles.body_row, padding:10, borderBottomWidth:1, borderColor:Colors.shades.shade600 }} onPress={() => onSelectSquaresCompetition(data.item)}>
186
+ <Image
187
+ source={{ uri: data.item.image?.url }}
188
+ style={{ height:30, width:30, borderRadius:4 }}
189
+ resizeMode="cover"
190
+ />
191
+ <View style={{ flex:1, marginLeft:10 }}>
192
+ <Text theme="header_2">{data.item.sq_comp_name}</Text>
193
+ <Text style={{ marginTop:3 }} theme="body">{data.item.sq_comp_description}</Text>
194
+ </View>
195
+ <Icons.ChevronIcon direction='right' size={8} color={Colors.brand.midnight}/>
196
+ </TouchableOpacity>
197
+ )
198
+ }
199
+
200
+ const renderBrackets = (data: { item:BracketCompetitionProps, index:number }) => {
201
+ const competition_player_bracket = competition_player_brackets.find(cpb => cpb.bracket_competition_id == data.item.bracket_competition_id);
202
+ const cl = data.item.market_type == 'FOR_MONEY' ? '$' : 'E'
48
203
  return (
49
- <TouchableOpacity style={{ ...view_styles.body_row, padding:10, borderBottomWidth:1, borderColor:Colors.shades.shade600 }} onPress={() => onSelectCompetition(data.item)}>
204
+ <TouchableOpacity style={{ ...view_styles.body_row, padding:10, borderBottomWidth:1, borderColor:Colors.shades.shade600 }} onPress={() => onSelectBracketCompetition(data.item)}>
50
205
  <Image
51
206
  source={{ uri: data.item.image?.url }}
52
207
  style={{ height:30, width:30, borderRadius:4 }}
@@ -56,81 +211,162 @@ const AdminCompetitionList = ({ width, max_height, onClose, onCreateNew, onSelec
56
211
  <Text theme="header_2">{data.item.competition_name}</Text>
57
212
  <Text style={{ marginTop:3 }} theme="body">{data.item.competition_description}</Text>
58
213
  </View>
214
+ {competition_player_bracket ?
215
+ <View style={{ marginRight:10, marginLeft:10, justifyContent:'center' }}>
216
+ <Text size={12} color={Colors.brand.midnight} weight="bold" textAlign="center">{ManageCompetitionHelpers.formatPlace(competition_player_bracket.place)}</Text>
217
+ <Text size={12} color={Colors.brand.midnight} textAlign="center" style={{ marginTop:3 }}>{cl}{competition_player_bracket.winnings.toFixed(2)}</Text>
218
+ </View>
219
+ :<></>}
59
220
  <Icons.ChevronIcon direction='right' size={8} color={Colors.brand.midnight}/>
60
221
  </TouchableOpacity>
61
222
  )
62
223
  }
63
224
 
64
225
  return (
65
- <View style={{ maxWidth:width, minWidth:300, maxHeight:max_height ?? 700, backgroundColor:Colors.shades.white }}>
226
+ <View style={{ maxWidth:width, minWidth:300, minHeight:400, height:height, backgroundColor:Colors.shades.white }}>
66
227
  <View style={{ ...view_styles.section_header }}>
67
228
  <View style={{ flex:1 }}>
68
- <Text theme='header'>MY COMPETITIONS</Text>
69
- <Text style={{ marginTop:3 }} theme="body">Below is a list of the competitions you have created</Text>
229
+ <Text theme='header'>MY ENGAGEMENTS</Text>
230
+ <Text style={{ marginTop:3 }} theme="body">Use the buttons below to see your active and past engagements (competitions, brackets, squares, etc)</Text>
70
231
  </View>
232
+ </View>
233
+ <View style={{ flexDirection:'row', margin:10, borderRadius:22, borderWidth:4, borderColor:Colors.shades.shade100 }}>
71
234
  <Button
72
- title="CREATE"
73
- backgroundColor={Colors.utility.success}
74
- title_color={Colors.shades.white}
75
- onPress={() => onCreateNew()}
235
+ title="COMPETITIONS"
236
+ title_color={active_engagement == 'competitions' ? Colors.shades.white : Colors.brand.midnight}
237
+ backgroundColor={active_engagement == 'competitions' ? Colors.brand.midnight: Colors.shades.white}
238
+ title_weight={active_engagement == 'competitions' ? 'bold' : 'regular'}
239
+ borderRadius={0}
240
+ padding={10}
241
+ style={{ flex:1, borderTopLeftRadius:22, borderBottomLeftRadius:22 }}
242
+ onPress={() => setData({ ...list_data, active_engagement: 'competitions' })}
76
243
  />
77
- </View>
78
- <View style={{ flexDirection:'row' }}>
79
244
  <Button
80
- title="ACTIVE"
81
- title_color={active_tab == 'active' ? Colors.shades.white : Colors.brand.midnight}
82
- backgroundColor={active_tab == 'active' ? Colors.brand.midnight: Colors.shades.white}
83
- title_weight={active_tab == 'active' ? 'bold' : 'regular'}
245
+ title="SQUARES"
246
+ title_color={active_engagement == 'squares' ? Colors.shades.white : Colors.brand.midnight}
247
+ backgroundColor={active_engagement == 'squares' ? Colors.brand.midnight: Colors.shades.white}
248
+ title_weight={active_engagement == 'squares' ? 'bold' : 'regular'}
84
249
  borderRadius={0}
85
- padding={15}
250
+ padding={10}
86
251
  style={{ flex:1 }}
87
- onPress={() => setData({ ...list_data, active_tab: 'active' })}
252
+ onPress={() => setData({ ...list_data, active_engagement: 'squares' })}
88
253
  />
89
254
  <Button
90
- title="CLOSED"
91
- title_color={active_tab == 'closed' ? Colors.shades.white : Colors.brand.midnight}
92
- backgroundColor={active_tab == 'closed' ? Colors.brand.midnight: Colors.shades.white}
93
- title_weight={active_tab == 'closed' ? 'bold' : 'regular'}
255
+ title="BRACKETS"
256
+ title_color={active_engagement == 'brackets' ? Colors.shades.white : Colors.brand.midnight}
257
+ backgroundColor={active_engagement == 'brackets' ? Colors.brand.midnight: Colors.shades.white}
258
+ title_weight={active_engagement == 'brackets' ? 'bold' : 'regular'}
94
259
  borderRadius={0}
95
- padding={15}
96
- style={{ flex:1 }}
97
- onPress={() => setData({ ...list_data, active_tab: 'closed' })}
260
+ padding={10}
261
+ style={{ flex:1, borderTopRightRadius:22, borderBottomRightRadius:22 }}
262
+ onPress={() => setData({ ...list_data, active_engagement: 'brackets' })}
98
263
  />
99
264
  </View>
100
- <View style={{ ...view_styles.section_body }}>
265
+ <ScrollView style={{ ...view_styles.section_body, padding:0 }}>
266
+
267
+ <View style={{ ...view_styles.section_header, backgroundColor:Colors.shades.shade100 }}>
268
+ <View style={{ flex:1, marginRight:10 }}>
269
+ <Text theme="header">Showing {active_tab} {active_engagement}</Text>
270
+ <Text style={{ marginTop: 3}} theme="body">Use the toggle to the right to see active / closed engagements</Text>
271
+ </View>
272
+ <View style={{ flexDirection:'row' }}>
273
+ <Button
274
+ title="ACTIVE"
275
+ title_color={active_tab == 'active' ? Colors.shades.white : Colors.brand.midnight}
276
+ backgroundColor={active_tab == 'active' ? Colors.utility.success: Colors.shades.white}
277
+ title_weight={active_tab == 'active' ? 'bold' : 'regular'}
278
+ borderRadius={0}
279
+ style={{ borderTopLeftRadius:22, borderBottomLeftRadius:22 }}
280
+ padding={10}
281
+ onPress={() => setData({ ...list_data, active_tab: 'active' })}
282
+ />
283
+ <Button
284
+ title="CLOSED"
285
+ title_color={active_tab == 'closed' ? Colors.shades.white : Colors.brand.midnight}
286
+ backgroundColor={active_tab == 'closed' ? Colors.utility.error: Colors.shades.white}
287
+ title_weight={active_tab == 'closed' ? 'bold' : 'regular'}
288
+ borderRadius={0}
289
+ padding={10}
290
+ style={{ borderTopRightRadius:22, borderBottomRightRadius:22 }}
291
+ onPress={() => setData({ ...list_data, active_tab: 'closed' })}
292
+ />
293
+ </View>
294
+ </View>
295
+ {active_tab == 'closed' ?
296
+ <View style={{ ...view_styles.section_footer }}>
297
+ {offset > 0 ?
298
+ <Button
299
+ title='PREV'
300
+ title_color={Colors.brand.electric}
301
+ backgroundColor='transparent'
302
+ onPress={() => getDataFromServer(offset - 1)}
303
+ />
304
+ :<View/>}
305
+ <View style={{ flex:1 }} />
306
+ <Button
307
+ title='NEXT'
308
+ title_color={Colors.brand.electric}
309
+ backgroundColor='transparent'
310
+ onPress={() => getDataFromServer(offset + 1)}
311
+ />
312
+ </View>
313
+ :<></>}
101
314
  {loading ?
102
315
  <ActivityIndicator style={{ padding:20, alignSelf:'center' }} size='large' color={Colors.brand.midnight} />
103
316
  :<></>}
317
+ {active_engagement == 'competitions' ?
318
+ <View>
319
+ {admin_competitions.length > 0 ?
320
+ <View style={{ padding:10, backgroundColor:Colors.incentive.gold_faded }}>
321
+ <View style={{ padding:10 }}>
322
+ <Text theme="header_2">Admin Competitions</Text>
323
+ <Text style={{ marginTop:4 }} theme="body">These are the competitions you are an admin of</Text>
324
+ </View>
325
+ <FlatList
326
+ key='admin_competition'
327
+ data={admin_competitions}
328
+ horizontal
329
+ renderItem={renderAdminCompetitions}
330
+ keyExtractor={(item) => item.competition_id.toString()}
331
+ />
332
+ </View>
333
+ :<></>}
334
+ <FlatList
335
+ key={'my_competitions'}
336
+ data={competitions}
337
+ renderItem={renderCompetitions}
338
+ keyExtractor={(item) => item.competition_id.toString()}
339
+ />
340
+ </View>
341
+ :active_engagement == 'brackets' ?
104
342
  <FlatList
105
- data={competitions}
106
- renderItem={renderCompetitions}
107
- keyExtractor={(item) => item.competition_id.toString()}
343
+ data={bracket_competitions}
344
+ renderItem={renderBrackets}
345
+ keyExtractor={(item) => item.bracket_competition_id.toString()}
108
346
  />
109
- </View>
110
- {active_tab == 'closed' ?
111
- <View style={{ ...view_styles.section_footer }}>
112
- {offset > 0 ?
113
- <Button
114
- title='PREV'
115
- title_color={Colors.brand.electric}
116
- backgroundColor='transparent'
117
- onPress={() => getDataFromServer(offset - 1)}
347
+ :active_engagement == 'squares' ?
348
+ <FlatList
349
+ data={squares_competitions}
350
+ renderItem={renderSquares}
351
+ keyExtractor={(item) => item.sq_comp_id.toString()}
118
352
  />
119
- :<View/>}
120
- <View style={{ flex:1 }} />
353
+ :<></>}
354
+ </ScrollView>
355
+
356
+
357
+ <View style={{ ...view_styles.section_footer }}>
121
358
  <Button
122
- title='NEXT'
123
- title_color={Colors.brand.electric}
124
- backgroundColor='transparent'
125
- onPress={() => getDataFromServer(offset + 1)}
359
+ title="CREATE NEW"
360
+ style={{ flex:1, marginRight:5 }}
361
+ title_color={Colors.shades.white}
362
+ backgroundColor={Colors.utility.success}
363
+ padding={15}
364
+ onPress={() => onCreateNew(active_engagement)}
126
365
  />
127
- </View>
128
- :<></>}
129
- <View style={{ ...view_styles.section_footer }}>
130
366
  <Button
131
367
  title="CLOSE"
132
368
  title_color={Colors.shades.white}
133
- style={{ flex:1, marginRight:8 }}
369
+ style={{ flex:2, marginRight:8 }}
134
370
  padding={15}
135
371
  backgroundColor={Colors.utility.error}
136
372
  onPress={() => onClose()}