be-components 7.2.1 → 7.2.3

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 (67) hide show
  1. package/lib/commonjs/PartnerPortal/api/index.js +134 -1
  2. package/lib/commonjs/PartnerPortal/api/index.js.map +1 -1
  3. package/lib/commonjs/PartnerPortal/components/EmbedManager.js +214 -3
  4. package/lib/commonjs/PartnerPortal/components/EmbedManager.js.map +1 -1
  5. package/lib/commonjs/PartnerPortal/components/PromoSelector.js +100 -0
  6. package/lib/commonjs/PartnerPortal/components/PromoSelector.js.map +1 -0
  7. package/lib/commonjs/PartnerPortal/components/ReferralCodeManager.js +498 -0
  8. package/lib/commonjs/PartnerPortal/components/ReferralCodeManager.js.map +1 -0
  9. package/lib/commonjs/PartnerPortal/index.js +337 -3
  10. package/lib/commonjs/PartnerPortal/index.js.map +1 -1
  11. package/lib/commonjs/index.js +7 -0
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/types.d.js.map +1 -1
  14. package/lib/module/PartnerPortal/api/index.js +133 -0
  15. package/lib/module/PartnerPortal/api/index.js.map +1 -1
  16. package/lib/module/PartnerPortal/components/EmbedManager.js +214 -3
  17. package/lib/module/PartnerPortal/components/EmbedManager.js.map +1 -1
  18. package/lib/module/PartnerPortal/components/PromoSelector.js +93 -0
  19. package/lib/module/PartnerPortal/components/PromoSelector.js.map +1 -0
  20. package/lib/module/PartnerPortal/components/ReferralCodeManager.js +490 -0
  21. package/lib/module/PartnerPortal/components/ReferralCodeManager.js.map +1 -0
  22. package/lib/module/PartnerPortal/index.js +339 -5
  23. package/lib/module/PartnerPortal/index.js.map +1 -1
  24. package/lib/module/index.js +2 -1
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/types.d.js.map +1 -1
  27. package/lib/typescript/lib/commonjs/PartnerPortal/api/index.d.ts +23 -0
  28. package/lib/typescript/lib/commonjs/PartnerPortal/api/index.d.ts.map +1 -1
  29. package/lib/typescript/lib/commonjs/PartnerPortal/components/EmbedManager.d.ts.map +1 -1
  30. package/lib/typescript/lib/commonjs/PartnerPortal/components/PromoSelector.d.ts +10 -0
  31. package/lib/typescript/lib/commonjs/PartnerPortal/components/PromoSelector.d.ts.map +1 -0
  32. package/lib/typescript/lib/commonjs/PartnerPortal/components/ReferralCodeManager.d.ts +12 -0
  33. package/lib/typescript/lib/commonjs/PartnerPortal/components/ReferralCodeManager.d.ts.map +1 -0
  34. package/lib/typescript/lib/commonjs/PartnerPortal/index.d.ts +3 -1
  35. package/lib/typescript/lib/commonjs/PartnerPortal/index.d.ts.map +1 -1
  36. package/lib/typescript/lib/commonjs/index.d.ts +1 -0
  37. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
  38. package/lib/typescript/lib/module/PartnerPortal/api/index.d.ts +23 -0
  39. package/lib/typescript/lib/module/PartnerPortal/api/index.d.ts.map +1 -1
  40. package/lib/typescript/lib/module/PartnerPortal/components/EmbedManager.d.ts.map +1 -1
  41. package/lib/typescript/lib/module/PartnerPortal/components/PromoSelector.d.ts +10 -0
  42. package/lib/typescript/lib/module/PartnerPortal/components/PromoSelector.d.ts.map +1 -0
  43. package/lib/typescript/lib/module/PartnerPortal/components/ReferralCodeManager.d.ts +12 -0
  44. package/lib/typescript/lib/module/PartnerPortal/components/ReferralCodeManager.d.ts.map +1 -0
  45. package/lib/typescript/lib/module/PartnerPortal/index.d.ts +3 -1
  46. package/lib/typescript/lib/module/PartnerPortal/index.d.ts.map +1 -1
  47. package/lib/typescript/lib/module/index.d.ts +2 -1
  48. package/lib/typescript/lib/module/index.d.ts.map +1 -1
  49. package/lib/typescript/src/PartnerPortal/api/index.d.ts +19 -1
  50. package/lib/typescript/src/PartnerPortal/api/index.d.ts.map +1 -1
  51. package/lib/typescript/src/PartnerPortal/components/EmbedManager.d.ts.map +1 -1
  52. package/lib/typescript/src/PartnerPortal/components/PromoSelector.d.ts +12 -0
  53. package/lib/typescript/src/PartnerPortal/components/PromoSelector.d.ts.map +1 -0
  54. package/lib/typescript/src/PartnerPortal/components/ReferralCodeManager.d.ts +15 -0
  55. package/lib/typescript/src/PartnerPortal/components/ReferralCodeManager.d.ts.map +1 -0
  56. package/lib/typescript/src/PartnerPortal/index.d.ts +4 -2
  57. package/lib/typescript/src/PartnerPortal/index.d.ts.map +1 -1
  58. package/lib/typescript/src/index.d.ts +2 -1
  59. package/lib/typescript/src/index.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/PartnerPortal/api/index.ts +119 -1
  62. package/src/PartnerPortal/components/EmbedManager.tsx +127 -1
  63. package/src/PartnerPortal/components/PromoSelector.tsx +61 -0
  64. package/src/PartnerPortal/components/ReferralCodeManager.tsx +303 -0
  65. package/src/PartnerPortal/index.tsx +166 -9
  66. package/src/index.tsx +2 -0
  67. package/src/types.d.ts +22 -0
@@ -22,7 +22,7 @@ type EmbedManagerProps = {
22
22
  company_id:string,
23
23
  onClose: () => void
24
24
  }
25
- const sections = ['header','embed','toggle','loading','name','properties','identifer','code']
25
+ const sections = ['header','embed','action','toggle','loading','name','properties','identifer','code']
26
26
  const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition, onClose, header_style, footer_style }:EmbedManagerProps) => {
27
27
  const Colors = useColors();
28
28
  const [ size, setSize ] = useState({ height:0, width:0 });
@@ -45,6 +45,22 @@ const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition
45
45
  });
46
46
  const { loading, promos, player_referrals, embed, company_embed, embed_properties, draft_company_embed } = embed_data;
47
47
 
48
+
49
+
50
+ const isValid = () => {
51
+ if(!company_embed){ return }
52
+ if(!company_embed.name){ return }
53
+ let valid = true
54
+ let props = company_embed.properties
55
+ embed_properties.map(p => {
56
+ if(!p.required){ return }
57
+ let exists = props[p.property]
58
+ if(!exists){ valid = false }
59
+ });
60
+ return valid
61
+ }
62
+ const is_valid = isValid();
63
+
48
64
  useEffect(() => {
49
65
  PartnerPortalApi.setEnvironment();
50
66
  getEmbedData(company_embed_id);
@@ -81,6 +97,48 @@ const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition
81
97
  setActionLoading(false);
82
98
  }
83
99
 
100
+ const activate = async() => {
101
+ if(!company_embed){ return }
102
+ if(!is_valid){ return alert('Please complete all properties before activating') }
103
+ setActionLoading(true);
104
+ const new_embed = await PartnerPortalApi.CompanyEmbedApi.activateCompanyEmbed(company_embed.company_embed_id);
105
+ if(!new_embed){ setActionLoading(false); return alert('Unable to activate at this time. Please try again later') }
106
+ setEmbedData({
107
+ ...embed_data,
108
+ company_embed: new_embed,
109
+ draft_company_embed: new_embed
110
+ })
111
+ setActionLoading(false);
112
+ }
113
+
114
+ const archive = async() => {
115
+ if(!company_embed){ return }
116
+ setActionLoading(true);
117
+ const new_embed = await PartnerPortalApi.CompanyEmbedApi.archiveCompanyEmbed(company_embed.company_embed_id);
118
+ if(!new_embed){ setActionLoading(false); return alert('Unable to archive at this time. Please try again later') }
119
+ setEmbedData({
120
+ ...embed_data,
121
+ company_embed: new_embed,
122
+ draft_company_embed: new_embed
123
+ })
124
+ setActionLoading(false);
125
+ }
126
+
127
+
128
+ const deactivate = async() => {
129
+ if(!company_embed){ return }
130
+ setActionLoading(true);
131
+ const new_embed = await PartnerPortalApi.CompanyEmbedApi.deActivateCompanyEmbed(company_embed.company_embed_id);
132
+ if(!new_embed){ setActionLoading(false); return alert('Unable to deactivate at this time. Please try again later') }
133
+ setEmbedData({
134
+ ...embed_data,
135
+ company_embed: new_embed,
136
+ draft_company_embed: new_embed
137
+ })
138
+ setActionLoading(false);
139
+ }
140
+
141
+
84
142
  const renderProperties = (data:{ item:EmbedPropertyProps, index:number }) => {
85
143
  if(!company_embed || !draft_company_embed){ return <></> }
86
144
  const value:string | undefined = draft_company_embed.properties[data.item.property]
@@ -232,6 +290,66 @@ const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition
232
290
  </View>
233
291
  </ImageBackground>
234
292
  )
293
+ case 'action':
294
+ if(!draft_company_embed){ return <></> }
295
+ switch(draft_company_embed.status){
296
+ case 'pending':
297
+ return (
298
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10, borderTopRightRadius:8, borderTopLeftRadius:8 }}>
299
+ <View transparent style={{ flex:1, marginRight:5 }}>
300
+ <Text theme='h1'>Pending</Text>
301
+ <Text theme='description' style={{ marginTop:3 }}>Once ready - press activate for the embed to become usable</Text>
302
+ </View>
303
+ <Button
304
+ title='ACTIVATE'
305
+ type='success'
306
+ loading={action_loading}
307
+ style={{ padding:10, opacity: is_valid ? 1 : 0.5 }}
308
+ onPress={() => activate()}
309
+ />
310
+ </View>
311
+ )
312
+ case 'inactive':
313
+ return (
314
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10, borderTopRightRadius:8, borderTopLeftRadius:8 }}>
315
+ <View transparent style={{ flex:1, marginRight:5 }}>
316
+ <Text theme='h1'>Inactive</Text>
317
+ <Text theme='description' style={{ marginTop:3 }}>Press activate to reactive it or archive it</Text>
318
+ </View>
319
+ <Button
320
+ title='ACTIVATE'
321
+ type='success'
322
+ loading={action_loading}
323
+ style={{ padding:10, marginRight:5 }}
324
+ onPress={() => activate()}
325
+ />
326
+ <Button
327
+ title='ARCHIVE'
328
+ type='error'
329
+ loading={action_loading}
330
+ style={{ padding:10 }}
331
+ onPress={() => archive()}
332
+ />
333
+ </View>
334
+ )
335
+ case 'active':
336
+ return (
337
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10, borderTopRightRadius:8, borderTopLeftRadius:8 }}>
338
+ <View transparent style={{ flex:1, marginRight:5 }}>
339
+ <Text theme='h1'>Deactive</Text>
340
+ <Text theme='description' style={{ marginTop:3 }}>Your embed is active! Press deactivate to stop it</Text>
341
+ </View>
342
+ <Button
343
+ title='DEACTIVATE'
344
+ type='error'
345
+ loading={action_loading}
346
+ style={{ padding:10 }}
347
+ onPress={() => deactivate()}
348
+ />
349
+ </View>
350
+ )
351
+ default: return <></>
352
+ }
235
353
  case 'toggle':
236
354
  return (
237
355
  <View style={{ padding:10, paddingBottom:0 }}>
@@ -339,6 +457,13 @@ const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition
339
457
  keyExtractor={item => item}
340
458
  renderItem={renderSections}
341
459
  />
460
+ {company_embed?.status == 'archived' ?
461
+ <View type='blur' style={{ position:'absolute', top:0, left:0, right:0, bottom:0, justifyContent:'center', alignItems:'center' }}>
462
+ <View float style={{ height:200, width:200, justifyContent:'center', alignItems:'center' }}>
463
+ <Text theme='h1' textAlign='center'>EMBED HAS BEEN ARCHIVED</Text>
464
+ </View>
465
+ </View>
466
+ :<></>}
342
467
  {draft_company_embed ?
343
468
  <View type='footer' style={{ flexDirection:'row', alignItems:'center', padding:10, ...footer_style }}>
344
469
  <Button
@@ -347,6 +472,7 @@ const EmbedManager = ({ float, me, company_id, company_embed_id, onFocusPosition
347
472
  style={{ flex:1 }}
348
473
  onPress={() => onClose()}
349
474
  />
475
+ {is_changed}
350
476
  <Button
351
477
  title='SAVE'
352
478
  type='success'
@@ -0,0 +1,61 @@
1
+ import React, { useState } from "react";
2
+ import type { PromoProps } from "../../types";
3
+ import { useColors } from "../../constants/useColors";
4
+ import { Button, Text, View } from "../../Components/Themed";
5
+ import { FlatList } from "react-native";
6
+ import { Icons } from "../../Components";
7
+ import { PartnerPortalHelpers } from "../api";
8
+
9
+ type PromoSelectorProps = {
10
+ promos:PromoProps[],
11
+ active_promo?:PromoProps,
12
+ max_value:number,
13
+ limited_type?:string,
14
+ onSelectPromo:(promo:PromoProps) => void
15
+ }
16
+ const PromoSelector = ({ active_promo, limited_type, max_value, promos, onSelectPromo}:PromoSelectorProps) => {
17
+ const Colors = useColors();
18
+ const [ visible, setVisible ] = useState(false);
19
+ let available_promos = promos.filter(p => p.amount <= max_value);
20
+ if(limited_type){ available_promos = available_promos.filter(p => p.type == limited_type) }
21
+ const renderPromos = (data:{ item:PromoProps, index:number }) => {
22
+ return (
23
+ <Button
24
+ transparent
25
+ style={{ flexDirection:'row', alignItems:'center', padding:10, borderRadius:0, borderBottomWidth:1, borderColor:Colors.borders.light }}
26
+ onPress={() => { setVisible(false); onSelectPromo(data.item) }}
27
+ >
28
+ <View transparent style={{ flex:1, marginLeft:10 }}>
29
+ <Text theme='h1'>{PartnerPortalHelpers.prettyKey(data.item.type)}</Text>
30
+ <Text theme='description' style={{ marginTop:3 }}>{data.item.description}</Text>
31
+ </View>
32
+ </Button>
33
+ )
34
+ }
35
+
36
+ return (
37
+ <View style={{ padding:15 }} float>
38
+ <Button transparent style={{ padding:0, flexDirection:'row', alignItems:'center' }} onPress={() => setVisible(!visible) }>
39
+ <View transparent style={{ flex:1, marginRight:10 }}>
40
+ <Text theme='h1'>{active_promo? PartnerPortalHelpers.prettyKey(active_promo.type) : 'Select Referral'}</Text>
41
+ {active_promo ?
42
+ <Text theme="description" style={{ marginTop:3 }}>{active_promo.description}</Text>
43
+ :<></>}
44
+ </View>
45
+ <Icons.ChevronIcon direction={visible?'up':'down'} color={Colors.text.h1} size={8} />
46
+ </Button>
47
+ {visible ?
48
+ <View transparent style={{ marginTop:20 }}>
49
+ <FlatList
50
+ data={available_promos.sort((a,b) => a.amount - b.amount)}
51
+ key={'promo_selector'}
52
+ keyExtractor={item => item.promo_id.toString()}
53
+ renderItem={renderPromos}
54
+ />
55
+ </View>
56
+ :<></>}
57
+ </View>
58
+ )
59
+ }
60
+
61
+ export default PromoSelector
@@ -0,0 +1,303 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Button, Text, TextInput, View } from "../../Components/Themed";
3
+ import type { FocusPositionProps, PlayerReferralProps, PromoProps } from '../../types';
4
+ import { PartnerPortalApi, PartnerPortalHelpers } from '../api';
5
+ import { FlatList, ImageBackground, type ViewStyle } from 'react-native';
6
+ import PromoSelector from './PromoSelector';
7
+ import { useColors } from '../../constants/useColors';
8
+ import { showConfirmAlert } from '../../Components/ConfirmAlert';
9
+
10
+ type ReferralCodeManagerProps = {
11
+ player_referral_id?:string,
12
+ company_id?:string,
13
+ onFocusPosition?:(pos:FocusPositionProps) => void,
14
+ float?:boolean,
15
+ onClose: () => void,
16
+ header_style?:ViewStyle,
17
+ footer_style?:ViewStyle
18
+ }
19
+ const sections = ['header','info','code','promo','inactivate','activate','delete']
20
+ const ReferralCodeManager = ({ float, player_referral_id, company_id, header_style, footer_style, onFocusPosition, onClose }:ReferralCodeManagerProps) => {
21
+ const Colors = useColors();
22
+ const [ action_loading, setActionLoading ] = useState(false);
23
+ const [ size, setSize ] = useState({ height:0, width:0 });
24
+ const [ state, setState ] = useState<{
25
+ checked:boolean,
26
+ available:boolean,
27
+ promos:PromoProps[],
28
+ player_referral?:PlayerReferralProps,
29
+ draft_referral?:PlayerReferralProps
30
+ }>({
31
+ draft_referral: undefined,
32
+ player_referral:undefined,
33
+ promos:[],
34
+ checked:false,
35
+ available:false
36
+ });
37
+ const { draft_referral, promos, player_referral, checked, available } = state;
38
+ const active_promo = promos.find(p => p.promo_id == draft_referral?.promo_id);
39
+ useEffect(() => {
40
+ PartnerPortalApi.setEnvironment();
41
+ getData(player_referral_id);
42
+ },[player_referral_id]);
43
+
44
+ const getData = async(id?:string) => {
45
+ const s_promos = await PartnerPortalApi.CompanyApi.getPromos();
46
+ let s_refer:PlayerReferralProps | undefined
47
+ if(id){
48
+ s_refer = await PartnerPortalApi.CompanyApi.getReferralById(id);
49
+ if(!s_refer){ return alert('Unable to get referral. Please try again') }
50
+ } else {
51
+ s_refer = PartnerPortalHelpers.CompanyHelpers.generateNewReferral()
52
+ }
53
+ setState({
54
+ checked:id ? true : false,
55
+ available: id ? true : false,
56
+ promos:s_promos,
57
+ draft_referral: s_refer,
58
+ player_referral: id ? s_refer : undefined
59
+ })
60
+ }
61
+
62
+ const isValid = () => {
63
+ let errors:string[] = []
64
+ if(!draft_referral){ return ['Please complete this form'] }
65
+ if(!draft_referral.referral_code){ errors.push('Please enter a valid code') }
66
+ if(!checked){ errors.push('Please check if the referral code is available') }
67
+ if(!available){ errors.push('This code is not available to use') }
68
+ if(!active_promo){ errors.push('Add a promo code') }
69
+ return errors
70
+ }
71
+ const errors = isValid();
72
+
73
+ const checkAvailability = async(code:string) => {
74
+ if(action_loading){ return }
75
+ if(!code){ return alert('Please enter a code') }
76
+ setActionLoading(true);
77
+ const resp = await PartnerPortalApi.CompanyApi.getReferralByCode(code.toLowerCase());
78
+ setState({ ...state, checked: true, available: resp.player_referral ? false : true });
79
+ setActionLoading(false)
80
+ }
81
+
82
+ const deactivate = async() => {
83
+ if(!player_referral){ return }
84
+ if(action_loading){ return }
85
+ setActionLoading(true);
86
+ const new_code = await PartnerPortalApi.CompanyApi.deactivateCode(player_referral.player_referral_id);
87
+ if(!new_code){ return alert('Unable to process. Please try again later') }
88
+ setState({ ...state, player_referral: new_code, draft_referral:new_code })
89
+ setActionLoading(false);
90
+ }
91
+
92
+ const activate = async() => {
93
+ if(!player_referral){ return }
94
+ if(action_loading){ return }
95
+ setActionLoading(true);
96
+ const new_code = await PartnerPortalApi.CompanyApi.activateCode(player_referral.player_referral_id);
97
+ if(!new_code){ return alert('Unable to process. Please try again later') }
98
+ setState({ ...state, player_referral: new_code, draft_referral:new_code })
99
+ setActionLoading(false);
100
+ }
101
+
102
+ const deleteCode = async() => {
103
+ if(!player_referral){ return }
104
+ if(action_loading){ return }
105
+ setActionLoading(true);
106
+ const new_code = await PartnerPortalApi.CompanyApi.deleteCode(player_referral.player_referral_id);
107
+ if(!new_code){ return alert('Unable to process. Please try again later') }
108
+ setState({ ...state, player_referral: new_code, draft_referral:new_code })
109
+ setActionLoading(false);
110
+ }
111
+
112
+ const handleUpdate = async(dr:PlayerReferralProps) => {
113
+ if(action_loading){ return }
114
+ setActionLoading(true);
115
+ const new_referral = await PartnerPortalApi.CompanyApi.updateCodeOnReferral(dr);
116
+ if(!new_referral){ return alert('Unable to process at this time') }
117
+ setState({
118
+ ...state,
119
+ draft_referral: new_referral,
120
+ player_referral: new_referral
121
+ });
122
+ setActionLoading(false);
123
+ }
124
+
125
+ const handleCreate = async() => {
126
+ if(action_loading){ return }
127
+ if(!draft_referral){ return }
128
+ if(errors.length > 0){ return alert(errors.map(e => e)) }
129
+ setActionLoading(true);
130
+ const new_code = await PartnerPortalApi.CompanyApi.createCode({ ...draft_referral, company_id});
131
+ if(!new_code){ return alert('Unable to process. Please try again later') }
132
+ setState({ ...state, player_referral: new_code, draft_referral:new_code })
133
+ setActionLoading(false);
134
+ }
135
+
136
+ const renderSections = (data: { item:string, index:number }) => {
137
+ switch(data.item){
138
+ case 'header':
139
+ return (
140
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10, ...header_style }}>
141
+ <View transparent style={{ flex:1 }}>
142
+ <Text theme='h1'>Manage Referral Code</Text>
143
+ <Text theme='description' style={{ marginTop:3 }}>Update or create your referral code below</Text>
144
+ </View>
145
+ </View>
146
+ )
147
+ case 'info':
148
+ return (
149
+ <ImageBackground
150
+ source={{ uri: 'https://res.cloudinary.com/hoabts6mc/image/upload/w_1000,ar_16:9,c_fill,g_auto,e_sharpen/v1758727070/ChatGPT_Image_Sep_24_2025_10_17_44_AM_w39gdn.png' }}
151
+ style={{ width: size.width, height:225, justifyContent:'flex-end', overflow:'hidden', ...header_style}}>
152
+ <View type='dark_blur' style={{ padding:20 }}>
153
+ <Text theme='h1' size={36}>Referral Code</Text>
154
+ <Text theme='description' size={16} style={{ marginTop:3 }}>Track the users that sign up for BettorEdge with referral codes</Text>
155
+ </View>
156
+ </ImageBackground>
157
+ )
158
+ case 'code':
159
+ if(!draft_referral){ return <></> }
160
+ return (
161
+ <View transparent style={{ padding:20, borderBottomWidth:1, borderColor:Colors.borders.light }}>
162
+ <View transparent style={{ marginBottom:10 }}>
163
+ <Text theme='h1'>Referral Code</Text>
164
+ <Text theme='description' style={{ marginTop:4 }}>Enter the referral code and check its availability</Text>
165
+ </View>
166
+ <View transparent type='row'>
167
+ <TextInput
168
+ value={draft_referral.referral_code}
169
+ onFocusPosition={onFocusPosition}
170
+ editable={player_referral ? false : true}
171
+ style={{ flex:1, marginLeft:5, textAlign:'center', borderColor:available?Colors.text.success:checked?Colors.text.error:Colors.text.warning }}
172
+ onChangeText={(text) => setState({ ...state, checked:false, available: false, draft_referral: { ...draft_referral, referral_code: text } })}
173
+ />
174
+ {!player_referral ?
175
+ <Button
176
+ title='CHECK'
177
+ type='success'
178
+ loading={action_loading}
179
+ disabled={checked || !draft_referral.referral_code}
180
+ style={{ marginLeft:5, opacity: checked || !draft_referral.referral_code ? 0.5 : 1 }}
181
+ onPress={() => checkAvailability(draft_referral.referral_code)}
182
+ />
183
+ :<></>}
184
+ </View>
185
+ {player_referral ?
186
+ <Text theme='error' style={{ marginTop:4 }}>To change the referral code. Please inactivate this one and create a new one</Text>
187
+ :checked && available?
188
+ <Text theme='success' style={{ marginTop:4 }}>Great! This code is available</Text>
189
+ :checked && !available ?
190
+ <Text theme='error' style={{ marginTop:4 }}>Sorry! This code is already taken</Text>
191
+ :<></>}
192
+ </View>
193
+ )
194
+ case 'promo':
195
+ if(!draft_referral){ return <></> }
196
+ return (
197
+ <View transparent style={{ padding:20 }}>
198
+ <View transparent style={{ marginBottom:10 }}>
199
+ <Text theme='h1'>Promotion Type</Text>
200
+ <Text theme='description' style={{ marginTop:4 }}>Select the type of promotion for this code</Text>
201
+ </View>
202
+ <PromoSelector
203
+ promos={promos}
204
+ limited_type='promo_code'
205
+ max_value={20}
206
+ active_promo={active_promo}
207
+ onSelectPromo={(promo) => setState({ ...state, draft_referral: { ...draft_referral, promo_id: promo.promo_id } })}
208
+ />
209
+ </View>
210
+ )
211
+ case 'inactivate':
212
+ if(!player_referral){ return <></> }
213
+ if(player_referral.status != 'pending'){ return <></> }
214
+
215
+ return (
216
+ <View transparent style={{ padding:20 }}>
217
+ <Button
218
+ title='DEACTIVATE CODE'
219
+ loading={action_loading}
220
+ type='error'
221
+ onPress={() => deactivate()}
222
+ />
223
+ </View>
224
+ )
225
+ case 'activate':
226
+ if(!player_referral){ return <></> }
227
+ if(player_referral.status != 'inactive'){ return <></> }
228
+ return (
229
+ <View transparent style={{ flexDirection:'row', padding:20 }}>
230
+ <Button
231
+ title='ARCHVE'
232
+ loading={action_loading}
233
+ type='error'
234
+ style={{ flex:1, marginRight:5 }}
235
+ onPress={() => {
236
+ showConfirmAlert('Are You Sure?', 'Once archived the code can no longer be activated or used',
237
+ () => deleteCode(),
238
+ () => console.log('')
239
+ )
240
+ }}
241
+ />
242
+ <Button
243
+ title='ACTIVATE CODE'
244
+ loading={action_loading}
245
+ type='success'
246
+ style={{ flex:3 }}
247
+ onPress={() => activate()}
248
+ />
249
+ </View>
250
+ )
251
+ default: return <></>
252
+ }
253
+ }
254
+ const is_changed = JSON.stringify(player_referral) != JSON.stringify(draft_referral) ? true : false
255
+ return (
256
+ <View float={float} style={{ flex:1 }} onLayout={(ev) => {
257
+ const { width, height } = ev.nativeEvent.layout
258
+ setSize({ width, height })
259
+ }}>
260
+ <FlatList
261
+ data={sections}
262
+ key='code_sections'
263
+ keyExtractor={item => item}
264
+ renderItem={renderSections}
265
+ />
266
+ {player_referral?.status == 'closed' ?
267
+ <View type='blur' style={{ position:'absolute', top:0, left:0, right:0, bottom:0, justifyContent:'center', alignItems:'center' }}>
268
+ <View float style={{ height:200, width:200, justifyContent:'center', alignItems:'center' }}>
269
+ <Text theme='h1' textAlign='center'>CODE HAS BEEN ARCHIVED</Text>
270
+ </View>
271
+ </View>
272
+ :<></>}
273
+ <View type='footer' style={{ flexDirection:'row', alignItems:'center', padding:10, ...footer_style }}>
274
+ <Button
275
+ title='CLOSE'
276
+ type='close'
277
+ style={{ flex:1 }}
278
+ onPress={() => onClose()}
279
+ />
280
+ {player_referral && draft_referral ?
281
+ <Button
282
+ title='SAVE CODE'
283
+ style={{ flex:3, marginLeft:5, opacity: is_changed && !action_loading ? 1 : 0.5 }}
284
+ loading={action_loading}
285
+ type='success'
286
+ disabled={!is_changed || action_loading}
287
+ onPress={() => handleUpdate(draft_referral)}
288
+ />
289
+ :
290
+ <Button
291
+ title='CREATE CODE'
292
+ style={{ flex:3, marginLeft:5, opacity: errors.length == 0 && !action_loading ? 1 : 0.5 }}
293
+ loading={action_loading}
294
+ type='success'
295
+ disabled={action_loading}
296
+ onPress={() => handleCreate()}
297
+ />
298
+ }
299
+ </View>
300
+ </View>
301
+ )
302
+ }
303
+ export default ReferralCodeManager