be-components 1.3.0 → 1.3.2

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 (106) hide show
  1. package/lib/commonjs/Competition/api/index.js +1 -1
  2. package/lib/commonjs/Competition/api/index.js.map +1 -1
  3. package/lib/commonjs/Competition/components/CompetitionPlay.js +1 -1
  4. package/lib/commonjs/Competition/components/CompetitionPlay.js.map +1 -1
  5. package/lib/commonjs/Competition/components/MarketsCard.js.map +1 -1
  6. package/lib/commonjs/Competition/index.js +37 -2
  7. package/lib/commonjs/Competition/index.js.map +1 -1
  8. package/lib/commonjs/CompetitionManager/api/index.js +153 -35
  9. package/lib/commonjs/CompetitionManager/api/index.js.map +1 -1
  10. package/lib/commonjs/CompetitionManager/components/AthleteSelector.js +170 -0
  11. package/lib/commonjs/CompetitionManager/components/AthleteSelector.js.map +1 -0
  12. package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js +495 -423
  13. package/lib/commonjs/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
  14. package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js +134 -0
  15. package/lib/commonjs/CompetitionManager/components/CompetitionHeader.js.map +1 -0
  16. package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js +96 -73
  17. package/lib/commonjs/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
  18. package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js +147 -127
  19. package/lib/commonjs/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
  20. package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js +38 -127
  21. package/lib/commonjs/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
  22. package/lib/commonjs/CompetitionManager/components/ContestSelector.js +388 -0
  23. package/lib/commonjs/CompetitionManager/components/ContestSelector.js.map +1 -0
  24. package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js +436 -0
  25. package/lib/commonjs/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
  26. package/lib/commonjs/CompetitionManager/components/MarketSelector.js +36 -26
  27. package/lib/commonjs/CompetitionManager/components/MarketSelector.js.map +1 -1
  28. package/lib/commonjs/CompetitionManager/index.js +492 -19
  29. package/lib/commonjs/CompetitionManager/index.js.map +1 -1
  30. package/lib/commonjs/Components/SearchBox.js +82 -0
  31. package/lib/commonjs/Components/SearchBox.js.map +1 -0
  32. package/lib/module/Competition/api/index.js +1 -1
  33. package/lib/module/Competition/api/index.js.map +1 -1
  34. package/lib/module/Competition/components/CompetitionPlay.js +1 -1
  35. package/lib/module/Competition/components/CompetitionPlay.js.map +1 -1
  36. package/lib/module/Competition/components/MarketsCard.js.map +1 -1
  37. package/lib/module/Competition/index.js +37 -2
  38. package/lib/module/Competition/index.js.map +1 -1
  39. package/lib/module/CompetitionManager/api/index.js +153 -35
  40. package/lib/module/CompetitionManager/api/index.js.map +1 -1
  41. package/lib/module/CompetitionManager/components/AthleteSelector.js +161 -0
  42. package/lib/module/CompetitionManager/components/AthleteSelector.js.map +1 -0
  43. package/lib/module/CompetitionManager/components/CompetitionContestsForm.js +493 -425
  44. package/lib/module/CompetitionManager/components/CompetitionContestsForm.js.map +1 -1
  45. package/lib/module/CompetitionManager/components/CompetitionHeader.js +127 -0
  46. package/lib/module/CompetitionManager/components/CompetitionHeader.js.map +1 -0
  47. package/lib/module/CompetitionManager/components/CompetitionInfoForm.js +99 -76
  48. package/lib/module/CompetitionManager/components/CompetitionInfoForm.js.map +1 -1
  49. package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js +145 -127
  50. package/lib/module/CompetitionManager/components/CompetitionMatchMarketCard.js.map +1 -1
  51. package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js +39 -131
  52. package/lib/module/CompetitionManager/components/CompetitionSettingsForm.js.map +1 -1
  53. package/lib/module/CompetitionManager/components/ContestSelector.js +379 -0
  54. package/lib/module/CompetitionManager/components/ContestSelector.js.map +1 -0
  55. package/lib/module/CompetitionManager/components/ContestSettingsForm.js +428 -0
  56. package/lib/module/CompetitionManager/components/ContestSettingsForm.js.map +1 -0
  57. package/lib/module/CompetitionManager/components/MarketSelector.js +34 -26
  58. package/lib/module/CompetitionManager/components/MarketSelector.js.map +1 -1
  59. package/lib/module/CompetitionManager/index.js +493 -20
  60. package/lib/module/CompetitionManager/index.js.map +1 -1
  61. package/lib/module/Components/SearchBox.js +73 -0
  62. package/lib/module/Components/SearchBox.js.map +1 -0
  63. package/lib/typescript/src/Competition/index.d.ts +2 -1
  64. package/lib/typescript/src/Competition/index.d.ts.map +1 -1
  65. package/lib/typescript/src/CompetitionManager/api/index.d.ts +32 -3
  66. package/lib/typescript/src/CompetitionManager/api/index.d.ts.map +1 -1
  67. package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts +18 -0
  68. package/lib/typescript/src/CompetitionManager/components/AthleteSelector.d.ts.map +1 -0
  69. package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts +13 -1
  70. package/lib/typescript/src/CompetitionManager/components/CompetitionContestsForm.d.ts.map +1 -1
  71. package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts +20 -0
  72. package/lib/typescript/src/CompetitionManager/components/CompetitionHeader.d.ts.map +1 -0
  73. package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts +2 -1
  74. package/lib/typescript/src/CompetitionManager/components/CompetitionInfoForm.d.ts.map +1 -1
  75. package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts +1 -1
  76. package/lib/typescript/src/CompetitionManager/components/CompetitionMatchMarketCard.d.ts.map +1 -1
  77. package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts +3 -3
  78. package/lib/typescript/src/CompetitionManager/components/CompetitionSettingsForm.d.ts.map +1 -1
  79. package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts +16 -0
  80. package/lib/typescript/src/CompetitionManager/components/ContestSelector.d.ts.map +1 -0
  81. package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts +15 -0
  82. package/lib/typescript/src/CompetitionManager/components/ContestSettingsForm.d.ts.map +1 -0
  83. package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts +3 -2
  84. package/lib/typescript/src/CompetitionManager/components/MarketSelector.d.ts.map +1 -1
  85. package/lib/typescript/src/CompetitionManager/index.d.ts +2 -1
  86. package/lib/typescript/src/CompetitionManager/index.d.ts.map +1 -1
  87. package/lib/typescript/src/Components/SearchBox.d.ts +10 -0
  88. package/lib/typescript/src/Components/SearchBox.d.ts.map +1 -0
  89. package/package.json +2 -1
  90. package/src/Competition/api/index.ts +3 -3
  91. package/src/Competition/components/CompetitionPlay.tsx +1 -1
  92. package/src/Competition/components/MarketsCard.tsx +2 -2
  93. package/src/Competition/index.tsx +24 -4
  94. package/src/CompetitionManager/api/index.ts +71 -13
  95. package/src/CompetitionManager/components/AthleteSelector.tsx +127 -0
  96. package/src/CompetitionManager/components/CompetitionContestsForm.tsx +156 -261
  97. package/src/CompetitionManager/components/CompetitionHeader.tsx +101 -0
  98. package/src/CompetitionManager/components/CompetitionInfoForm.tsx +57 -45
  99. package/src/CompetitionManager/components/CompetitionMatchMarketCard.tsx +29 -70
  100. package/src/CompetitionManager/components/CompetitionSettingsForm.tsx +36 -103
  101. package/src/CompetitionManager/components/ContestSelector.tsx +269 -0
  102. package/src/CompetitionManager/components/ContestSettingsForm.tsx +281 -0
  103. package/src/CompetitionManager/components/MarketSelector.tsx +34 -23
  104. package/src/CompetitionManager/index.tsx +412 -16
  105. package/src/Components/SearchBox.tsx +54 -0
  106. package/src/types.d.ts +38 -4
@@ -12,20 +12,37 @@ var _colors = _interopRequireDefault(require("../constants/colors"));
12
12
  var _api = require("./api");
13
13
  var _CompetitionSettingsForm = _interopRequireDefault(require("./components/CompetitionSettingsForm"));
14
14
  var _CompetitionContestsForm = _interopRequireDefault(require("./components/CompetitionContestsForm"));
15
+ var _ContestSelector = _interopRequireDefault(require("./components/ContestSelector"));
16
+ var _MarketSelector = _interopRequireDefault(require("./components/MarketSelector"));
17
+ var _AthleteSelector = _interopRequireDefault(require("./components/AthleteSelector"));
18
+ var _ContestSettingsForm = _interopRequireDefault(require("./components/ContestSettingsForm"));
19
+ var _CompetitionHeader = _interopRequireDefault(require("./components/CompetitionHeader"));
20
+ var _Components = require("../Components");
15
21
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
22
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
23
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
24
  const CompetitionManager = ({
19
- competition_id
25
+ player_id,
26
+ competition_id,
27
+ onClose
20
28
  }) => {
21
29
  const [module_size, setModuleSize] = (0, _react.useState)({
22
30
  height: 0,
23
31
  width: 0
24
32
  });
33
+ const [action_loading, setActionLoading] = (0, _react.useState)(false);
34
+ const [show_athletes, setShowAthletes] = (0, _react.useState)({
35
+ filtered_positions: []
36
+ });
37
+ const [show_contests, setShowContests] = (0, _react.useState)({
38
+ visible: false
39
+ });
40
+ const [show_markets, setShowMarkets] = (0, _react.useState)({});
25
41
  const [competition_data, setCompetitionData] = (0, _react.useState)({
26
42
  loaded: false,
27
43
  loading: false,
28
44
  competition_result_types: [],
45
+ competition_summaries: [],
29
46
  competition_types: [],
30
47
  competition_matches: [],
31
48
  competition_payout_types: [],
@@ -33,15 +50,21 @@ const CompetitionManager = ({
33
50
  markets: [],
34
51
  leagues: [],
35
52
  events: [],
53
+ trades: [],
36
54
  tournaments: [],
37
55
  matches: [],
38
56
  teams: [],
39
57
  athletes: []
40
58
  });
59
+ const {
60
+ contest_id,
61
+ contest_type
62
+ } = show_markets;
41
63
  const {
42
64
  loaded,
43
65
  competition,
44
66
  competition_result_types,
67
+ trades,
45
68
  competition_types,
46
69
  draft_competition,
47
70
  competition_matches,
@@ -54,6 +77,44 @@ const CompetitionManager = ({
54
77
  teams,
55
78
  athletes
56
79
  } = competition_data;
80
+
81
+ //Market Selector Stuff
82
+ const showing_market_event = events.find(e => e.event_id == contest_id && contest_type == 'team');
83
+ const showing_market_event_matches = competition_matches.filter(cm => cm.event_type == 'team' && cm.event_id == contest_id);
84
+ const show_market_markets = competition_match_markets.filter(cmm => showing_market_event_matches.map(cm => cm.competition_match_id.toString()).includes(cmm.competition_match_id));
85
+ const show_market_id_overrides = showing_market_event_matches.filter(cm => cm.market_id_override).map(cm => cm.market_id_override ?? '0');
86
+
87
+ //AthleteSelectorStuff
88
+ const select_athlete_matches = competition_matches.filter(cm => cm.event_id == show_athletes.contest_id && cm.event_type == show_athletes.contest_type && cm.market_id_override == show_athletes.market_id);
89
+ const selected_athletes = select_athlete_matches.filter(m => m.side_type_override == 'athlete').map(m => m.side_id_override ?? '0');
90
+ const select_athlete_event = events.find(e => show_athletes.contest_type == 'team' && e.event_id == show_athletes.contest_id);
91
+ const select_athlete_positions = markets.find(m => m.market_id == show_athletes.market_id)?.supported_positions ?? [];
92
+ //Filter Athletes to those with trades
93
+ let trade_athletes = [...new Set(trades.filter(t => t.market_type == 'FOR_MONEY' && t.market_id == show_athletes.market_id && t.side_type == 'athlete').map(t => t.side_id))];
94
+
95
+ //Lets figure out if we can add / remove a primary market for all of them
96
+ let primary_markets = [];
97
+ events.map(e => {
98
+ if (!e.supported_markets) {
99
+ return;
100
+ }
101
+ e.supported_markets.map(sm => {
102
+ let market = markets.find(m => m.market_id == sm.market_id);
103
+ if (!market?.primary_market) {
104
+ return;
105
+ }
106
+ let exists = primary_markets.find(pm => pm.market.market_id == sm.market_id);
107
+ if (!exists) {
108
+ //check if this has been included or not!
109
+ let included = competition_match_markets.find(cmm => cmm.market_id == market.market_id) ? true : false;
110
+ primary_markets.push({
111
+ market,
112
+ included
113
+ });
114
+ }
115
+ });
116
+ });
117
+ const competition_valid = _api.ManageCompetitionHelpers.isCompetitionValid(competition_types, competition_result_types, competition_matches, competition_match_markets, events, competition);
57
118
  (0, _react.useEffect)(() => {
58
119
  if (!loaded) {
59
120
  _api.ManageCompetitionApi.setEnvironment();
@@ -66,6 +127,7 @@ const CompetitionManager = ({
66
127
  const options = await _api.ManageCompetitionApi.getCompetitionOptions();
67
128
  const lgs = await _api.ManageCompetitionApi.getLeagues();
68
129
  const mks = await _api.ManageCompetitionApi.getMarkets();
130
+ const summaries = await _api.ManageCompetitionApi.getCompetitionSummaries(id);
69
131
  //Get unique contests
70
132
  let event_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'team').map(cm => cm.event_id);
71
133
  let tournament_ids = cm_resp.competition_matches.filter(cm => cm.event_type == 'tournament').map(cm => cm.event_id);
@@ -77,14 +139,17 @@ const CompetitionManager = ({
77
139
  if (event_ids.length > 0) {
78
140
  c_events = await _api.ManageCompetitionMatchApi.getEventsByEventIds(event_ids);
79
141
  }
142
+ let e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(event_ids, 'team');
80
143
  let c_tournaments = [];
81
144
  if (tournament_ids.length > 0) {
82
145
  c_tournaments = await _api.ManageCompetitionMatchApi.getTournamentsByTournamentIds(tournament_ids);
83
146
  }
147
+ let t_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(tournament_ids, 'tournamet');
84
148
  let c_matches = [];
85
149
  if (match_ids.length > 0) {
86
150
  c_matches = await _api.ManageCompetitionMatchApi.getMatchesByMatchIds(match_ids);
87
151
  }
152
+ let m_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(match_ids, 'match');
88
153
  let c_teams = [];
89
154
  if (team_ids.length > 0) {
90
155
  c_teams = await _api.ManageCompetitionMatchApi.getTeamsByIds(team_ids);
@@ -98,6 +163,7 @@ const CompetitionManager = ({
98
163
  loading: false,
99
164
  competition: c,
100
165
  leagues: lgs,
166
+ competition_summaries: summaries,
101
167
  competition_types: options.competition_types,
102
168
  competition_payout_types: options.competition_payout_types,
103
169
  competition_result_types: options.competition_result_types,
@@ -106,13 +172,271 @@ const CompetitionManager = ({
106
172
  competition_match_markets: cm_resp.competition_match_markets,
107
173
  events: c_events,
108
174
  markets: mks,
175
+ trades: e_trades.concat(m_trades).concat(t_trades),
109
176
  tournaments: c_tournaments,
110
177
  matches: c_matches,
111
178
  teams: c_teams,
112
179
  athletes: c_athletes
113
180
  });
114
181
  };
115
- if (!competition || !draft_competition) {
182
+ const handleRemovePrimaryMarket = async market => {
183
+ setActionLoading(true);
184
+ //Grab all markets
185
+ let remove_markets = competition_match_markets.filter(cmm => cmm.market_id == market.market_id);
186
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(remove_markets.map(cmm => cmm.competition_match_market_id));
187
+ setCompetitionData({
188
+ ...competition_data,
189
+ competition_match_markets: competition_match_markets.filter(cmm => cmm.market_id != market.market_id)
190
+ });
191
+ setActionLoading(false);
192
+ };
193
+ const handleAddPrimaryMarket = async market => {
194
+ setActionLoading(true);
195
+ let market_cmms = [];
196
+ let primary_matches = competition_matches.filter(cm => !cm.market_id_override);
197
+ primary_matches.map(cm => {
198
+ let existing_markets = competition_match_markets.filter(cmm => cmm.competition_match_id == cm.competition_match_id && cmm.market_id == market.market_id);
199
+ if (existing_markets.length > 0) {
200
+ return;
201
+ } //Dont do anything on that one!
202
+ let market_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.event_id == cm.event_id && t.event_type == cm.event_type && t.market_id == market.market_id);
203
+ if (market_trades.length != 2) {
204
+ console.log(`no trades for event ${cm.event_id}`);
205
+ return;
206
+ } //This event doesnt have the trades
207
+ let new_cmms = [];
208
+ market_trades.map(t => {
209
+ new_cmms.push({
210
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
211
+ competition_match_id: cm.competition_match_id
212
+ });
213
+ });
214
+ market_cmms = market_cmms.concat(new_cmms);
215
+ });
216
+ market_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(market_cmms);
217
+ setCompetitionData({
218
+ ...competition_data,
219
+ competition_match_markets: competition_match_markets.filter(cmm => !market_cmms.find(ncmm => ncmm.competition_match_market_id == cmm.competition_match_market_id)).concat(market_cmms)
220
+ });
221
+ setActionLoading(false);
222
+ };
223
+ const handleSelectTeamEvents = async new_events => {
224
+ if (action_loading || !competition) {
225
+ return;
226
+ }
227
+ setActionLoading(true);
228
+ let added_matches = [];
229
+ const addEvents = new_events.map(async e => {
230
+ const cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, e.event_id, 'team', 'event', undefined, undefined, undefined);
231
+ added_matches.push(cm);
232
+ });
233
+ await Promise.all(addEvents);
234
+ const e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds(new_events.map(e => e.event_id), 'team');
235
+ setCompetitionData({
236
+ ...competition_data,
237
+ competition: {
238
+ ...competition,
239
+ scheduled_datetime: undefined
240
+ },
241
+ competition_matches: competition_matches.concat(added_matches),
242
+ events: events.filter(e => !new_events.find(ne => ne.event_id == e.event_id)).concat(new_events),
243
+ trades: trades.filter(t => !events.map(e => e.event_id.toString()).includes(t.event_id)).concat(e_trades)
244
+ });
245
+ setActionLoading(false);
246
+ };
247
+ const handleSelectTeamEvent = async event => {
248
+ if (action_loading || !competition) {
249
+ return;
250
+ }
251
+ setActionLoading(true);
252
+ const cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, event.event_id, 'team', 'event', undefined, undefined, undefined);
253
+ const e_trades = await _api.ManageCompetitionMarketApi.getLatestTradesByEventIds([event.event_id], 'team');
254
+ setCompetitionData({
255
+ ...competition_data,
256
+ competition: {
257
+ ...competition,
258
+ scheduled_datetime: undefined
259
+ },
260
+ competition_matches: competition_matches.concat(cm),
261
+ events: events.filter(e => e.event_id != event.event_id).concat(event),
262
+ trades: trades.filter(t => t.event_id != event.event_id).concat(e_trades)
263
+ });
264
+ setActionLoading(false);
265
+ };
266
+ const handleRemoveCompetitionMatch = async competition_match_id => {
267
+ if (action_loading) {
268
+ return;
269
+ }
270
+ setActionLoading(true);
271
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(competition_match_id);
272
+ setCompetitionData({
273
+ ...competition_data,
274
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != competition_match_id)
275
+ });
276
+ setActionLoading(false);
277
+ };
278
+ const handleRemoveCompetitionMatchMarkets = async cmms => {
279
+ if (action_loading) {
280
+ return;
281
+ }
282
+ setActionLoading(true);
283
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_market_id));
284
+ setCompetitionData({
285
+ ...competition_data,
286
+ competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
287
+ });
288
+ setActionLoading(false);
289
+ };
290
+ const handleDeselectTeamEvent = async event => {
291
+ const cms = competition_matches.filter(cm => cm.event_id == event.event_id && cm.event_type == 'team');
292
+ const deleteCMS = cms.map(async cm => {
293
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
294
+ });
295
+ await Promise.all(deleteCMS);
296
+ setCompetitionData({
297
+ ...competition_data,
298
+ competition_matches: competition_matches.filter(cm => !cms.find(dcm => dcm.competition_match_id == cm.competition_match_id))
299
+ });
300
+ };
301
+ const handleSelectAthlete = async athlete => {
302
+ if (!show_athletes?.contest_id || !show_athletes?.contest_type) {
303
+ return;
304
+ }
305
+ let athlete_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.side_type == 'athlete' && t.side_id == athlete.athlete_id && t.market_id == show_athletes.market_id);
306
+ if (athlete_trades.length != 2) {
307
+ return alert('Unable to add');
308
+ }
309
+ if (action_loading) {
310
+ return;
311
+ }
312
+ setActionLoading(true);
313
+ //First check if there is an existing market_id override without a side_id_override and add it!
314
+ let existing_cm = competition_matches.find(cm => cm.event_id == show_athletes.contest_id && cm.event_type == show_athletes.contest_type && cm.market_id_override == show_athletes.market_id && !cm.side_id_override);
315
+ if (existing_cm) {
316
+ existing_cm = await _api.ManageCompetitionMatchApi.updateCompetitionMatch({
317
+ ...existing_cm,
318
+ side_type_override: 'athlete',
319
+ side_id_override: athlete.athlete_id
320
+ });
321
+ } else {
322
+ existing_cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, show_athletes.contest_id, show_athletes.contest_type, 'athlete', show_athletes.market_id, 'athlete', athlete.athlete_id);
323
+ }
324
+ let new_cmms = [];
325
+ athlete_trades.map(t => {
326
+ new_cmms.push({
327
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
328
+ competition_match_id: existing_cm.competition_match_id
329
+ });
330
+ });
331
+ new_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(new_cmms);
332
+ setCompetitionData({
333
+ ...competition_data,
334
+ athletes: athletes.concat(athlete),
335
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != existing_cm.competition_match_id).concat(existing_cm),
336
+ competition_match_markets: competition_match_markets.filter(cmm => !new_cmms.find(ncmm => ncmm.competition_match_market_id == cmm.competition_match_market_id)).concat(new_cmms)
337
+ });
338
+ setActionLoading(false);
339
+ };
340
+ const handleDeselectAthlete = async athlete => {
341
+ if (!show_athletes?.contest_id || !show_athletes?.contest_type || !show_athletes?.market_id) {
342
+ return;
343
+ }
344
+ let athlete_cm = competition_matches.find(cm => cm.market_id_override == show_athletes.market_id && cm.side_id_override == athlete.athlete_id);
345
+ if (!athlete_cm) {
346
+ return alert('Unable to remove');
347
+ }
348
+ if (action_loading) {
349
+ return;
350
+ }
351
+ setActionLoading(true);
352
+ let cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == athlete_cm.competition_match_id);
353
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(athlete_cm.competition_match_id);
354
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(cmms.map(cmm => cmm.competition_match_id));
355
+ setCompetitionData({
356
+ ...competition_data,
357
+ competition_matches: competition_matches.filter(cm => cm.competition_match_id != athlete_cm.competition_match_id),
358
+ competition_match_markets: competition_match_markets.filter(cmm => !cmms.map(rmm => rmm.competition_match_market_id.toString()).includes(cmm.competition_match_market_id))
359
+ });
360
+ setActionLoading(false);
361
+ };
362
+ const handleRemoveMarket = async (contest_id, contest_type, market) => {
363
+ if (action_loading) {
364
+ return;
365
+ }
366
+ setActionLoading(true);
367
+ let relevant_matches = competition_matches.filter(cm => cm.event_id == contest_id && cm.event_type == contest_type);
368
+ //First remove all the non_primary if there are any
369
+ let non_primary_matches = relevant_matches.filter(cm => cm.market_id_override == market.market_id);
370
+ let matches_removed = [];
371
+ let markets_removed = [];
372
+ const rem_non_primary = non_primary_matches.map(async cm => {
373
+ const del_response = await _api.ManageCompetitionMatchApi.deleteCompetitionMatch(cm.competition_match_id);
374
+ matches_removed = matches_removed.concat(del_response.competition_match.competition_match_id);
375
+ markets_removed = markets_removed.concat(del_response.competition_match_markets.map(cmm => cmm.competition_match_market_id));
376
+ });
377
+ await Promise.all(rem_non_primary);
378
+
379
+ //Ok now lets looks for the primary market one
380
+ let primary_match = relevant_matches.find(cm => !cm.market_id_override);
381
+ if (primary_match) {
382
+ let primary_cmms = competition_match_markets.filter(cmm => cmm.competition_match_id == primary_match.competition_match_id && cmm.market_id == market.market_id);
383
+ await _api.ManageCompetitionMatchApi.deleteCompetitionMatchMarkets(primary_cmms.map(cmm => cmm.competition_match_market_id));
384
+ markets_removed = markets_removed.concat(primary_cmms.map(cmm => cmm.competition_match_market_id));
385
+ }
386
+ setCompetitionData({
387
+ ...competition_data,
388
+ competition_matches: competition_matches.filter(cm => !matches_removed.includes(cm.competition_match_id)),
389
+ competition_match_markets: competition_match_markets.filter(cmm => !markets_removed.includes(cmm.competition_match_market_id))
390
+ });
391
+ setActionLoading(false);
392
+ };
393
+ const handleAddMarket = async (contest_id, contest_type, market) => {
394
+ if (action_loading) {
395
+ return;
396
+ }
397
+ setActionLoading(true);
398
+ //First check if this is a primary market
399
+ if (market.primary_market) {
400
+ //Get the competition match that is available for it!
401
+ let primary_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && !cm.market_id_override);
402
+ if (!primary_match) {
403
+ setActionLoading(false);
404
+ return alert('Unable to add this market');
405
+ }
406
+ //Now lets get the trades!!
407
+ let market_trades = trades.filter(t => t.market_type == 'FOR_MONEY' && t.event_id == contest_id && t.event_type == contest_type && t.market_id == market.market_id);
408
+ let cmms = [];
409
+ market_trades.map(t => {
410
+ cmms.push({
411
+ ..._api.ManageCompetitionHelpers.createCompetitionMatchMarketFromTrade(t),
412
+ competition_match_id: primary_match.competition_match_id
413
+ });
414
+ });
415
+ if (cmms.length != 2) {
416
+ setActionLoading(false);
417
+ return alert('Unable to add this market');
418
+ }
419
+ const new_cmms = await _api.ManageCompetitionMatchApi.createCompetitionMatchMarkets(cmms);
420
+ setActionLoading(false);
421
+ return setCompetitionData({
422
+ ...competition_data,
423
+ competition_match_markets: competition_match_markets.filter(cmms => new_cmms.find(ncms => ncms.competition_match_market_id != cmms.competition_match_market_id)).concat(new_cmms)
424
+ });
425
+ }
426
+ //If this is not a primary market - we need to add a market_id override for the competition match!!
427
+ let existing_match = competition_matches.find(cm => cm.event_type == contest_type && cm.event_id == contest_id && cm.market_id_override == market.market_id);
428
+ if (existing_match) {
429
+ setActionLoading(false);
430
+ return alert('Already added this market!');
431
+ }
432
+ const new_cm = await _api.ManageCompetitionMatchApi.createCompetitionMatch(competition_id, contest_id, contest_type, market.level, market.market_id);
433
+ setCompetitionData({
434
+ ...competition_data,
435
+ competition_matches: competition_matches.concat(new_cm)
436
+ });
437
+ setActionLoading(false);
438
+ };
439
+ if (!competition || !draft_competition || player_id != competition.admin_id) {
116
440
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
117
441
  style: {
118
442
  flex: 1
@@ -126,7 +450,6 @@ const CompetitionManager = ({
126
450
  }
127
451
  }));
128
452
  }
129
- console.log(module_size);
130
453
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
131
454
  style: {
132
455
  flex: 1
@@ -149,40 +472,190 @@ const CompetitionManager = ({
149
472
  style: {
150
473
  ..._styles.view_styles.wrapper
151
474
  }
152
- }, /*#__PURE__*/_react.default.createElement(_CompetitionInfoForm.default, {
153
- competition: draft_competition,
475
+ }, /*#__PURE__*/_react.default.createElement(_CompetitionHeader.default, {
476
+ action_loading: action_loading,
477
+ width: module_size.width,
478
+ competition: competition,
479
+ competition_valid: competition_valid,
480
+ onActivate: async () => {
481
+ setActionLoading(true);
482
+ const new_c = await _api.ManageCompetitionApi.activateCompetition(competition_id);
483
+ setCompetitionData({
484
+ ...competition_data,
485
+ competition: new_c
486
+ });
487
+ setActionLoading(false);
488
+ },
489
+ onPause: async () => {
490
+ setActionLoading(true);
491
+ const new_c = await _api.ManageCompetitionApi.pauseCompetition(competition_id);
492
+ const new_summaries = await _api.ManageCompetitionApi.getCompetitionSummaries(competition_id);
493
+ setCompetitionData({
494
+ ...competition_data,
495
+ competition: new_c,
496
+ competition_summaries: new_summaries
497
+ });
498
+ setActionLoading(false);
499
+ },
500
+ onResume: async () => {
501
+ setActionLoading(true);
502
+ const new_c = await _api.ManageCompetitionApi.resumeCompetition(competition_id);
503
+ setCompetitionData({
504
+ ...competition_data,
505
+ competition: new_c
506
+ });
507
+ setActionLoading(false);
508
+ }
509
+ }), /*#__PURE__*/_react.default.createElement(_CompetitionInfoForm.default, {
510
+ is_valid: competition_valid.info,
511
+ competition: competition,
154
512
  width: module_size.width - 20,
155
- onCompetitionUpdate: comp => setCompetitionData({
156
- ...competition_data,
157
- draft_competition: comp
158
- })
513
+ onCompetitionUpdate: async comp => {
514
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(comp);
515
+ setCompetitionData({
516
+ ...competition_data,
517
+ competition: new_c
518
+ });
519
+ }
159
520
  }), /*#__PURE__*/_react.default.createElement(_CompetitionSettingsForm.default, {
160
- competition: draft_competition,
521
+ is_valid: competition_valid.settings,
522
+ competition: competition,
161
523
  width: module_size.width - 20,
162
524
  competition_result_types: competition_result_types,
163
- competition_types: competition_types,
164
- onCompetitionUpdate: comp => setCompetitionData({
165
- ...competition_data,
166
- draft_competition: comp
167
- })
525
+ onCompetitionUpdate: async comp => {
526
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(comp);
527
+ setCompetitionData({
528
+ ...competition_data,
529
+ competition: new_c
530
+ });
531
+ }
168
532
  }), /*#__PURE__*/_react.default.createElement(_CompetitionContestsForm.default, {
533
+ action_loading: action_loading,
534
+ is_valid: competition_valid.contests,
169
535
  width: module_size.width - 20,
170
- competition: draft_competition,
536
+ competition: competition,
171
537
  competition_matches: competition_matches,
172
538
  competition_match_markets: competition_match_markets,
173
539
  events: events,
540
+ primary_markets: primary_markets,
174
541
  teams: teams,
175
542
  athletes: athletes,
176
543
  tournaments: tournaments,
544
+ onAddPrimaryMarket: market => handleAddPrimaryMarket(market),
545
+ onRemovePrimaryMarket: market => handleRemovePrimaryMarket(market),
177
546
  matches: matches,
178
547
  leagues: leagues,
179
548
  markets: markets,
549
+ onDeleteMarket: (contest_id, contest_type, market) => handleRemoveMarket(contest_id, contest_type, market),
550
+ onShowAthletes: (contest_id, contest_type, market_id) => setShowAthletes({
551
+ contest_id,
552
+ contest_type,
553
+ market_id,
554
+ filtered_positions: []
555
+ }),
556
+ onShowMarkets: (contest_id, contest_type) => setShowMarkets({
557
+ contest_id,
558
+ contest_type
559
+ }),
560
+ onShowContests: () => setShowContests({
561
+ visible: true
562
+ }),
180
563
  onSaveCompetitionMatch: () => console.log('SAVE EVENT'),
181
- onDeleteCompetitionMatch: () => console.log('DELEVE'),
564
+ onDeleteCompetitionMatch: competition_match_id => handleRemoveCompetitionMatch(competition_match_id),
182
565
  onUpdateCompetitionMatch: () => console.log('UPDATE'),
183
566
  onSaveCompetitionMatchMarkets: smms => console.log(smms),
184
- onDeleteCompetitionMatchMarkets: cmms => console.log(cmms)
185
- }))));
567
+ onDeleteCompetitionMatchMarkets: cmms => handleRemoveCompetitionMatchMarkets(cmms)
568
+ }), /*#__PURE__*/_react.default.createElement(_ContestSettingsForm.default, {
569
+ is_valid: competition_valid.contest_settings,
570
+ width: module_size.width - 20,
571
+ competition: competition,
572
+ competition_matches: competition_matches,
573
+ competition_match_markets: competition_match_markets,
574
+ competition_types: competition_types,
575
+ events: events,
576
+ onCompetitionUpdate: async c => {
577
+ const new_c = await _api.ManageCompetitionApi.updateCompetition(c);
578
+ setCompetitionData({
579
+ ...competition_data,
580
+ competition: new_c
581
+ });
582
+ }
583
+ }))), show_contests.visible ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
584
+ style: {
585
+ position: 'absolute',
586
+ top: 0,
587
+ left: 0,
588
+ right: 0,
589
+ bottom: 0,
590
+ backgroundColor: _colors.default.shades.black_faded,
591
+ justifyContent: 'flex-end'
592
+ }
593
+ }, /*#__PURE__*/_react.default.createElement(_ContestSelector.default, {
594
+ action_loading: action_loading,
595
+ height: module_size.height,
596
+ width: module_size.width,
597
+ leagues: leagues,
598
+ onClose: () => setShowContests({
599
+ visible: false
600
+ }),
601
+ onSelectTeamEvent: event => handleSelectTeamEvent(event),
602
+ onSelectTeamEvents: events => handleSelectTeamEvents(events),
603
+ onDeselectTeamEvent: event => handleDeselectTeamEvent(event),
604
+ selected_team_events: events.filter(e => competition_matches.filter(cm => cm.event_type == 'team').map(cm => cm.event_id.toString()).includes(e.event_id.toString()))
605
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null), show_athletes.contest_id ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
606
+ style: {
607
+ position: 'absolute',
608
+ top: 0,
609
+ left: 0,
610
+ right: 0,
611
+ bottom: 0,
612
+ backgroundColor: _colors.default.shades.black_faded,
613
+ justifyContent: 'flex-end'
614
+ }
615
+ }, /*#__PURE__*/_react.default.createElement(_AthleteSelector.default, {
616
+ width: module_size.width,
617
+ height: module_size.height,
618
+ event: select_athlete_event,
619
+ selected_athletes: selected_athletes,
620
+ filtered_positions: select_athlete_positions,
621
+ filtered_athletes: trade_athletes,
622
+ onSelectAthlete: athlete => handleSelectAthlete(athlete),
623
+ onDeselectAthlete: athlete => handleDeselectAthlete(athlete),
624
+ onClose: () => setShowAthletes({
625
+ filtered_positions: []
626
+ })
627
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null), show_markets.contest_id && show_markets.contest_type && showing_market_event ? /*#__PURE__*/_react.default.createElement(_reactNative.View, {
628
+ style: {
629
+ position: 'absolute',
630
+ top: 0,
631
+ left: 0,
632
+ right: 0,
633
+ bottom: 0,
634
+ backgroundColor: _colors.default.shades.black_faded,
635
+ justifyContent: 'flex-end'
636
+ }
637
+ }, /*#__PURE__*/_react.default.createElement(_MarketSelector.default, {
638
+ height: module_size.height,
639
+ width: module_size.width,
640
+ markets: markets.filter(m => showing_market_event.supported_markets?.map(m => m.market_id.toString()).includes(m.market_id.toString())),
641
+ onClose: () => setShowMarkets({}),
642
+ onDeselectMarket: market => handleRemoveMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market),
643
+ onSelectMarket: market => handleAddMarket(show_markets.contest_id ?? '0', show_markets.contest_type ?? 'team', market),
644
+ selected_markets: [...new Set(show_market_markets.map(cmm => cmm.market_id).concat(show_market_id_overrides))]
645
+ })) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null), /*#__PURE__*/_react.default.createElement(_reactNative.View, {
646
+ style: {
647
+ ..._styles.view_styles.section_footer
648
+ }
649
+ }, /*#__PURE__*/_react.default.createElement(_Components.Button, {
650
+ title: "CLOSE",
651
+ style: {
652
+ flex: 1
653
+ },
654
+ title_color: _colors.default.shades.white,
655
+ backgroundColor: _colors.default.utility.error,
656
+ padding: 15,
657
+ onPress: () => onClose()
658
+ })));
186
659
  };
187
660
  var _default = exports.default = CompetitionManager;
188
661
  //# sourceMappingURL=index.js.map