be-components 7.0.2 → 7.0.4

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.
Files changed (50) hide show
  1. package/lib/commonjs/Competition/index.js +1 -7
  2. package/lib/commonjs/Competition/index.js.map +1 -1
  3. package/lib/commonjs/Squares/api/index.js +10 -2
  4. package/lib/commonjs/Squares/api/index.js.map +1 -1
  5. package/lib/commonjs/Squares/index.js +75 -2
  6. package/lib/commonjs/Squares/index.js.map +1 -1
  7. package/lib/commonjs/SquaresManager/api/index.js +10 -0
  8. package/lib/commonjs/SquaresManager/api/index.js.map +1 -1
  9. package/lib/commonjs/SquaresManager/index.js +111 -13
  10. package/lib/commonjs/SquaresManager/index.js.map +1 -1
  11. package/lib/module/Competition/index.js +1 -7
  12. package/lib/module/Competition/index.js.map +1 -1
  13. package/lib/module/Squares/api/index.js +10 -2
  14. package/lib/module/Squares/api/index.js.map +1 -1
  15. package/lib/module/Squares/index.js +75 -2
  16. package/lib/module/Squares/index.js.map +1 -1
  17. package/lib/module/SquaresManager/api/index.js +10 -0
  18. package/lib/module/SquaresManager/api/index.js.map +1 -1
  19. package/lib/module/SquaresManager/index.js +111 -13
  20. package/lib/module/SquaresManager/index.js.map +1 -1
  21. package/lib/typescript/lib/commonjs/Competition/index.d.ts.map +1 -1
  22. package/lib/typescript/lib/commonjs/Squares/api/index.d.ts +1 -0
  23. package/lib/typescript/lib/commonjs/Squares/api/index.d.ts.map +1 -1
  24. package/lib/typescript/lib/commonjs/Squares/index.d.ts.map +1 -1
  25. package/lib/typescript/lib/commonjs/SquaresManager/api/index.d.ts +1 -0
  26. package/lib/typescript/lib/commonjs/SquaresManager/api/index.d.ts.map +1 -1
  27. package/lib/typescript/lib/commonjs/SquaresManager/index.d.ts +2 -1
  28. package/lib/typescript/lib/commonjs/SquaresManager/index.d.ts.map +1 -1
  29. package/lib/typescript/lib/module/Competition/index.d.ts.map +1 -1
  30. package/lib/typescript/lib/module/Squares/api/index.d.ts +1 -0
  31. package/lib/typescript/lib/module/Squares/api/index.d.ts.map +1 -1
  32. package/lib/typescript/lib/module/Squares/index.d.ts.map +1 -1
  33. package/lib/typescript/lib/module/SquaresManager/api/index.d.ts +1 -0
  34. package/lib/typescript/lib/module/SquaresManager/api/index.d.ts.map +1 -1
  35. package/lib/typescript/lib/module/SquaresManager/index.d.ts +2 -1
  36. package/lib/typescript/lib/module/SquaresManager/index.d.ts.map +1 -1
  37. package/lib/typescript/src/Competition/index.d.ts.map +1 -1
  38. package/lib/typescript/src/Squares/api/index.d.ts +7 -0
  39. package/lib/typescript/src/Squares/api/index.d.ts.map +1 -1
  40. package/lib/typescript/src/Squares/index.d.ts.map +1 -1
  41. package/lib/typescript/src/SquaresManager/api/index.d.ts +1 -0
  42. package/lib/typescript/src/SquaresManager/api/index.d.ts.map +1 -1
  43. package/lib/typescript/src/SquaresManager/index.d.ts +2 -1
  44. package/lib/typescript/src/SquaresManager/index.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/Competition/index.tsx +1 -7
  47. package/src/Squares/api/index.ts +8 -2
  48. package/src/Squares/index.tsx +46 -2
  49. package/src/SquaresManager/api/index.ts +8 -0
  50. package/src/SquaresManager/index.tsx +78 -17
@@ -34,7 +34,7 @@ type SquaresModuleProps = {
34
34
  onEvent:(ev:BEEventProps) => void
35
35
  }
36
36
 
37
- const squares_sections = ['header', 'offers', 'toggle', 'event', 'board', 'board_stats', 'my_stats', 'results', 'my_squares', 'winners','hidden_prizes','details', 'owners']
37
+ const squares_sections = ['header', 'activate', 'offers', 'toggle', 'event', 'board', 'board_stats', 'my_stats', 'results', 'my_squares', 'winners','hidden_prizes','details', 'owners']
38
38
 
39
39
  const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id, distinct_id, onManageSquares, onRequestAuthenticate, onShareCompetition, onPlayerSelect }:SquaresModuleProps) => {
40
40
  const C = useColors();
@@ -334,6 +334,23 @@ const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id,
334
334
  })
335
335
  }
336
336
 
337
+ const handleActivate = async() => {
338
+ if(!squares_competition || loading){ return }
339
+ if(squares_competition.status != 'pending'){ return }
340
+ setModuleData({ ...module_data, loading: true });
341
+ const activate_resp = await SquaresApi.activateSquares(squares_competition.sq_comp_id);
342
+ if(!activate_resp){ return alert('Unable to activate competition') }
343
+ setModuleData({
344
+ ...module_data,
345
+ squares_competition: activate_resp.squares_competition,
346
+ player_squares: activate_resp.player_squares,
347
+ squares: activate_resp.squares,
348
+ squares_type: activate_resp.squares_type,
349
+ squares_payout_type: activate_resp.squares_payout_type,
350
+ loading: true
351
+ });
352
+ }
353
+
337
354
  const handleUpdateBoardFromBuy = (data:BuySquaresResponseProps) => {
338
355
  //First remove squares
339
356
  //Now update squares
@@ -378,6 +395,25 @@ const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id,
378
395
  </Button>
379
396
  </View>
380
397
  )
398
+ case 'activate':
399
+ if(squares_competition?.status != 'pending'){ return <></> }
400
+ if(player_id != squares_competition?.admin_id){ return <></> }
401
+ return (
402
+ <View type='row' style={{ padding:10 }}>
403
+ <View style={{ flex:1 }}>
404
+ <Text theme="h2">Squares competition is pending.</Text>
405
+ <Text theme="description" style={{ marginTop:3 }}>Press Activate to allow others to join!</Text>
406
+ </View>
407
+ <Button
408
+ disabled={loading ? true : false}
409
+ style={{ marginLeft:5, padding:10 }}
410
+ loading={loading}
411
+ title="ACTIVATE!"
412
+ type='success'
413
+ onPress={() => handleActivate()}
414
+ />
415
+ </View>
416
+ )
381
417
  case 'event':
382
418
  if(!event){ return <></> }
383
419
  return (
@@ -512,6 +548,7 @@ const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id,
512
548
  )
513
549
  case 'board':
514
550
  if(!squares_competition){ return <></> }
551
+ if(squares_competition.status == 'pending'){ return <></> }
515
552
  return (
516
553
  <View style={{ alignItems:view_mode == 'desktop' ? 'center': undefined }}>
517
554
  <SquaresBoard
@@ -597,10 +634,17 @@ const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id,
597
634
  if(ev.action == 'buy'){ setUpdatedFromBid(data as BuySquaresResponseProps) }
598
635
  if(ev.action == 'offer')[ setUpdatedFromOffer(data as OfferResponseProps) ]
599
636
  break;
637
+ case 'ACTIVATE_SQUARES':
638
+ //When activated - we should just reload the modules
639
+ let socket_comp = ev.squares_competition as SquaresCompetitionProps
640
+ if(!socket_comp){return}
641
+ if(socket_comp.sq_comp_id != sq_comp_id){ return } //Dont do anything here
642
+ getDataFromServer(sq_comp_id, {});
643
+ break;
600
644
  default: break;
601
645
  }
602
646
  }}
603
- subscribed_events={['V1_UPDATE_SQUARE_DETAILS']}
647
+ subscribed_events={['V1_UPDATE_SQUARE_DETAILS', 'ACTIVATE_SQUARES']}
604
648
  />
605
649
  <Modal
606
650
  transparent
@@ -27,6 +27,14 @@ const SquaresManagerApi = {
27
27
  return []
28
28
  }
29
29
  },
30
+ deleteCompetition: async(sq_comp_id:string):Promise<SquaresCompetitionProps|undefined> => {
31
+ try {
32
+ const resp = await axios.post(`${TP_SVC_API}/v1/squares/competition/delete`, { sq_comp_id });
33
+ return resp.data.squares_competition
34
+ } catch (e) {
35
+ return undefined
36
+ }
37
+ },
30
38
  getEventsByEventIds: async(event_ids:string[]):Promise<EventProps[]> => {
31
39
  try {
32
40
  if(event_ids.length == 0){ return [] }
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"
2
2
  import { SquaresManagerApi, SquaresManagerHelpers } from "./api";
3
3
  import { Button, Text, TextInput, View } from "../Components/Themed";
4
4
  import { FlatList, Image, type ViewStyle } from "react-native";
5
- import type { CompanyProps, EventProps, FocusPositionProps, GroupProps, LeagueProps, MyPlayerProps, SquaresCompetitionProps } from "../types";
5
+ import type { CompanyProps, EventProps, FocusPositionProps, GroupProps, LeagueProps, MyPlayerProps, PlayerSquareProps, SquaresCompetitionProps } from "../types";
6
6
  import { useColors } from "../constants/useColors";
7
7
  import LeagueSchedule from "../MarketComponents/components/LeagueSchedule";
8
8
  import { Icons, Switch, Toggle } from "../Components";
@@ -10,6 +10,7 @@ import moment from "moment-mini";
10
10
  import ImageUploader from "../Components/ImageUploader";
11
11
  import GroupSelector from "../CompetitionManager/components/GroupSelector";
12
12
  import CompanySelector from "../CompetitionManager/components/CompanySelector";
13
+ import { showConfirmAlert } from "../Components/ConfirmAlert";
13
14
 
14
15
  type SquaresManagerProps = {
15
16
  sq_comp_id:string,
@@ -17,12 +18,13 @@ type SquaresManagerProps = {
17
18
  float?:boolean,
18
19
  player?:MyPlayerProps,
19
20
  onActivate:(sq:SquaresCompetitionProps) => void,
21
+ onDelete:(sq:SquaresCompetitionProps) => void,
20
22
  onClose:() => void,
21
23
  header_style?:ViewStyle,
22
24
  footer_style?:ViewStyle
23
25
  }
24
- const sections = ['header','toggle','info','event']
25
- const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPosition, footer_style, onClose, onActivate }:SquaresManagerProps) => {
26
+ const sections = ['header','activate','toggle','info','event','delete']
27
+ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPosition, footer_style, onDelete, onClose, onActivate }:SquaresManagerProps) => {
26
28
  const Colors = useColors();
27
29
  const [ my_data, setMyData ] = useState<{
28
30
  groups:GroupProps[],
@@ -34,10 +36,11 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
34
36
  const { groups, companies } = my_data;
35
37
  const [ sq_state, setState ] = useState<{
36
38
  loading: boolean,
37
- active_tab: 'info'|'event',
39
+ active_tab: 'info'|'event'|'danger',
38
40
  leagues_visible?:boolean,
39
41
  active_event?:EventProps,
40
42
  active_league?:LeagueProps,
43
+ player_squares:PlayerSquareProps[],
41
44
  min_square_price:string,
42
45
  guaranteed_payout:string,
43
46
  leagues:LeagueProps[],
@@ -50,13 +53,13 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
50
53
  leagues_visible:false,
51
54
  leagues:[],
52
55
  min_square_price: '0',
56
+ player_squares:[],
53
57
  guaranteed_payout: '0',
54
58
  league_schedule: false
55
59
  });
56
- const { loading, squares_competition, min_square_price, guaranteed_payout, active_tab, leagues, league_schedule, draft_competition, leagues_visible, active_event, active_league } = sq_state
60
+ const { loading, squares_competition, min_square_price, player_squares, guaranteed_payout, active_tab, leagues, league_schedule, draft_competition, leagues_visible, active_event, active_league } = sq_state
57
61
  const active_group = groups.find(g => g.group_id == draft_competition?.group_id)
58
62
  const active_company = companies.find(c => c.company_id == draft_competition?.company_id);
59
-
60
63
  useEffect(() => {
61
64
  SquaresManagerApi.setEnvironment();
62
65
  getData(sq_comp_id)
@@ -93,6 +96,7 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
93
96
  loading: false,
94
97
  leagues: lgs.filter(l => l.sport == 'Football'),
95
98
  active_event: active_ev,
99
+ player_squares: sq_data.player_squares,
96
100
  min_square_price: sq_data.squares_competition.minimum_square_price.toFixed(2),
97
101
  active_league: active_league,
98
102
  draft_competition: sq_data.squares_competition,
@@ -114,6 +118,27 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
114
118
  onActivate(activate_resp.squares_competition)
115
119
  }
116
120
 
121
+ const handleDelete = async() => {
122
+ setState({ ...sq_state, loading:true });
123
+ const deleted_comp = await SquaresManagerApi.deleteCompetition(sq_comp_id);
124
+ if(!deleted_comp){ return alert('Unable to delete competition. If any bids are active, you cannot delete this competition') }
125
+ setState({
126
+ ...sq_state,
127
+ squares_competition: deleted_comp,
128
+ draft_competition: deleted_comp,
129
+ loading:true
130
+ });
131
+ onDelete(deleted_comp)
132
+ }
133
+
134
+ const handleConfirmDelete = () => {
135
+ if(player_squares.length > 0){ return alert('Unable to delete competition with active bids') }
136
+ showConfirmAlert('Are you sure?', 'Once this is deleted you can no longer access it',
137
+ () => handleDelete(),
138
+ () => console.log('')
139
+ )
140
+ }
141
+
117
142
  const updateCompetition = async(sq_comp:SquaresCompetitionProps) => {
118
143
  if(errors.length > 0){ return alert(errors.map(e => e)) }
119
144
  if(loading){ return }//No mashy
@@ -189,6 +214,24 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
189
214
  />
190
215
  </View>
191
216
  )
217
+ case 'activate':
218
+ if(squares_competition?.status != 'pending'){ return <></> }
219
+ return (
220
+ <View type='row' style={{ padding:10 }}>
221
+ <View style={{ flex:1 }}>
222
+ <Text theme="h2">Squares competition is pending.</Text>
223
+ <Text theme="description" style={{ marginTop:3 }}>Press Activate to allow others to join!</Text>
224
+ </View>
225
+ <Button
226
+ disabled={errors.length > 0 || loading ? true : false}
227
+ style={{ marginLeft:5, padding:10, opacity: errors.length > 0 ? 0.5: 1 }}
228
+ loading={loading}
229
+ title="ACTIVATE!"
230
+ type='success'
231
+ onPress={() => handleActivate()}
232
+ />
233
+ </View>
234
+ )
192
235
  case 'toggle':
193
236
  return (
194
237
  <View transparent>
@@ -199,9 +242,10 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
199
242
  options={[
200
243
  { key: 'info', label: 'Info', icon: <Icons.MenuIcon size={14} color={Colors.text.warning} /> },
201
244
  { key: 'event', label: 'Event', icon: <Icons.ActivityIcon size={14} color={Colors.text.warning} /> },
245
+ { key: 'danger', label: 'Danger', icon: <Icons.AlertIcon size={14} color={Colors.text.error} /> },
202
246
  ]}
203
247
  selected_option={active_tab}
204
- onSelectOption={(key) => setState({ ...sq_state, active_tab: key as 'info'|'event'})}
248
+ onSelectOption={(key) => setState({ ...sq_state, active_tab: key as 'info'|'event'|'danger'})}
205
249
  title_renderer={(option) => {
206
250
  const selected = option.key == active_tab ? true : false
207
251
  return (
@@ -216,6 +260,33 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
216
260
  />
217
261
  </View>
218
262
  )
263
+ case 'delete':
264
+ if(active_tab != 'danger'){ return <></> }
265
+ return (
266
+ <View>
267
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10 }}>
268
+ <View transparent style={{ flex:1 }}>
269
+ <Text theme="h1">DELETE COMPETITION</Text>
270
+ <Text theme="description" style={{ marginTop:3 }}>Archive this competition</Text>
271
+ </View>
272
+ </View>
273
+ <View style={{ padding:10 }}>
274
+ {player_squares.length > 0 ?
275
+ <Text theme="warning">This competition cannot be archived as there are active bids on squares.</Text>
276
+ :
277
+ <Text theme="warning">Once archived you will no longer be able to edit or see this competition</Text>
278
+ }
279
+ <Button
280
+ title="DELETE"
281
+ disabled={player_squares.length > 0 ? true: false}
282
+ loading={loading}
283
+ onPress={() => handleConfirmDelete()}
284
+ type='error'
285
+ style={{ marginTop:10, opacity: player_squares.length > 0 || loading ? 0.5:1 }}
286
+ />
287
+ </View>
288
+ </View>
289
+ )
219
290
  case 'info':
220
291
  if(!draft_competition){ return <></> }
221
292
  if(active_tab != 'info'){ return <></> }
@@ -392,16 +463,6 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
392
463
  type='action'
393
464
  onPress={() => draft_competition ? updateCompetition(draft_competition) : console.log('')}
394
465
  />
395
- {squares_competition?.status == 'pending' ?
396
- <Button
397
- disabled={errors.length > 0 || loading ? true : false}
398
- style={{ flex:2, marginLeft:10, opacity: errors.length > 0 ? 0.5: 1 }}
399
- loading={loading}
400
- title="ACTIVATE!"
401
- type='success'
402
- onPress={() => handleActivate()}
403
- />
404
- :<></>}
405
466
  </View>
406
467
  </View>
407
468
  )