be-components 2.3.0 → 2.3.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.
@@ -1,15 +1,24 @@
1
1
  import axios from "axios";
2
2
  import { APIOverrides } from "../../ApiOverrides";
3
- import type { BEEventProps, GeneratedLinkProps } from '../../types';
3
+ import type { BEEventProps, GeneratedLinkProps, PlayerReferralProps } from '../../types';
4
4
  import { Platform, Share } from 'react-native';
5
5
  let ANALYTICS_SVC_API = '';
6
-
6
+ let AUTH_SVC_API = '';
7
7
  export { ShareApi, ShareHelpers }
8
8
 
9
9
  const ShareApi = {
10
10
  setEnvironment: () => {
11
11
  const endpoints = APIOverrides.getEndpoints();
12
12
  ANALYTICS_SVC_API = endpoints['ANALYTICS_SVC_API'] as string;
13
+ AUTH_SVC_API = endpoints['AUTH_SVC_API'] as string;
14
+ },
15
+ getMyReferralCode: async():Promise<PlayerReferralProps | undefined> => {
16
+ try {
17
+ const resp = await axios.get(`${AUTH_SVC_API}/v1/promos/referral/me`)
18
+ return resp.data.player_referral
19
+ } catch (e) {
20
+ return undefined
21
+ }
13
22
  },
14
23
  generateShortLink: async(generated_link:GeneratedLinkProps):Promise<{ generated_link:GeneratedLinkProps, url:string }> => {
15
24
  try {
@@ -110,5 +119,19 @@ const ShareHelpers = {
110
119
  query_params.push({ key: queryVariable, value: queryValue })
111
120
  })
112
121
  return query_params
122
+ },
123
+ appendPlayerReferral: async(url:string) => {
124
+ //First lets snag the parameters
125
+ let params = ShareHelpers.extractQueryParams(url);
126
+ let refer_param = params.find(p => p.key == 'refer');
127
+ if(!refer_param){
128
+ const pr = await ShareApi.getMyReferralCode();
129
+ if(pr){
130
+ //Now let us update the url with the players referral code!
131
+ if(params.length == 0){ url += `?refer=${pr.referral_code}` }
132
+ else { url += `&refer=${pr.referral_code}` }
133
+ }
134
+ }
135
+ return url
113
136
  }
114
137
  }
@@ -25,7 +25,6 @@ type ShareWidgetProps = {
25
25
  link_type: GeneratedLinkProps['link_type'],
26
26
  link_sub_type: GeneratedLinkProps['link_sub_type'],
27
27
  type_id?:string,
28
- onEvent?:(be_event:BEEventProps) => void,
29
28
  embed?:{
30
29
  embed_code:string,
31
30
  script_source?:string,
@@ -33,13 +32,13 @@ type ShareWidgetProps = {
33
32
  div_id?:string
34
33
  },
35
34
  onCancel:() => void,
36
- onShare:(generated_link_id:string) => void,
35
+ onShare?:(be_event:BEEventProps) => void,
37
36
  allow_edit?:boolean,
38
37
  maxWidth?:number
39
38
  maxHeight?:number
40
39
  }
41
40
 
42
- const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, maxHeight, generator, allow_edit, player_id, link_type, link_sub_type, type_id, embed, onEvent }:ShareWidgetProps) => {
41
+ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, maxHeight, generator, allow_edit, player_id, link_type, link_sub_type, type_id, embed, onCancel, onShare }:ShareWidgetProps) => {
43
42
  const [ preview_embed, setPreviewEmbed ] = useState(false);
44
43
  const [ link_height, setLinkHeight ] = useState(0);
45
44
  const [ active_tab, setActiveTab ] = useState('link');
@@ -73,6 +72,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
73
72
  else if(redirect_url){ generateLink(redirect_url) }
74
73
  },[redirect_url, generated_link_id]);
75
74
 
75
+
76
76
  const getGeneratedLink = async(generated_link_id:string) => {
77
77
  setLinkStatus({ ...link_status, loading:true });
78
78
  const retrieved_link = await ShareApi.getGeneratedLinkById(generated_link_id);
@@ -89,7 +89,8 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
89
89
 
90
90
  const generateLink = async(redirect_url:string) => {
91
91
  setLinkStatus({ ...link_status, loading: true });
92
-
92
+ //If there is a player id - lets append the referral code if one is not supplied!
93
+ if(player_id){ redirect_url = await ShareHelpers.appendPlayerReferral(redirect_url) }
93
94
  const { generated_link, url } = await ShareApi.generateShortLink({
94
95
  generator: generator,
95
96
  generated_link_id:'',
@@ -99,6 +100,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
99
100
  link_type,
100
101
  link_sub_type
101
102
  });
103
+
102
104
  setLinkStatus({
103
105
  ...link_status,
104
106
  loading: false,
@@ -126,6 +128,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
126
128
  <View style={{ ...view_styles.section_header, borderBottomWidth:1, borderColor:Colors.shades.shade600 }}>
127
129
  <View style={{ flex:1 }}>
128
130
  <Text theme='header'>Share Modal</Text>
131
+ <Text style={{ marginTop:3 }} theme='body'>{title}</Text>
129
132
  </View>
130
133
  <Button
131
134
  title='X'
@@ -133,7 +136,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
133
136
  borderRadius={100}
134
137
  backgroundColor={Colors.shades.shade100}
135
138
  padding={5}
136
- onPress={() => console.log('HELLP')}
139
+ onPress={() => onCancel()}
137
140
  />
138
141
  </View>
139
142
  <ScrollView style={{ flex:1 }}>
@@ -244,7 +247,9 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
244
247
  setLinkStatus({
245
248
  ...link_status,
246
249
  update_loading: false,
250
+ editing: false,
247
251
  generated_link: new_link?.generated_link,
252
+ draft_generated_link: new_link?.generated_link,
248
253
  url: new_link?.url
249
254
  });
250
255
  }}
@@ -261,7 +266,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
261
266
  {native_share_allowed() ?
262
267
  <TouchableOpacity style={{ ...view_styles.body_row }} onPress={async() => {
263
268
  const share_event = await ShareApi.share(title, body, link_status.url, generated_link.generated_link_id);
264
- if(onEvent && share_event){ onEvent(share_event) }
269
+ if(onShare && share_event){ onShare(share_event) }
265
270
  }}>
266
271
  <View style={{ flexDirection:'row', alignItems:'center', padding:3, paddingRight:10, borderWidth:1, borderRadius:22, borderColor:Colors.highlights.highlight400Faded, backgroundColor: Colors.shades.white, ...view_styles.float }}>
267
272
  <View style={{ height:36, width:36, marginRight:10, backgroundColor:Colors.brand.electric, borderRadius:100, justifyContent:'center', alignItems:'center' }}>
@@ -299,7 +304,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
299
304
  </View>
300
305
  }
301
306
  </View>
302
- : active_tab == 'embed' && embed ?
307
+ : active_tab == 'embed' && embed?.embed_code ?
303
308
  <View style={{ ...view_styles.section_body, paddingTop:0 }}>
304
309
  <View style={{ ...view_styles.body_row }}>
305
310
  <View style={{ flex:1 }}>
@@ -351,7 +356,7 @@ const ShareWidget = ({ generated_link_id, title, body, redirect_url, maxWidth, m
351
356
  <Icons.LinkIcon color={Colors.brand.midnight} size={18}/>
352
357
  </View>
353
358
  </TouchableOpacity>
354
- : active_tab == 'link' ?
359
+ : active_tab == 'link' && embed?.embed_code ?
355
360
  <TouchableOpacity style={{ ...view_styles.section_footer }} onPress={() => setActiveTab('embed')}>
356
361
  <View style={{ flex:1, marginRight:10 }}>
357
362
  <Text theme='header'>Available For Embed</Text>
package/src/types.d.ts CHANGED
@@ -1719,7 +1719,7 @@ export interface GeneratedLinkProps {
1719
1719
  generator_id?:string,
1720
1720
  generator:'player'|'company'|'tool'
1721
1721
  link_type: 'user_generated_link'|'brand_generated_link'|'bettoredge_tool'|'marketing'|'widget',
1722
- link_sub_type: 'user_referral_link'|'h2h_share_link'|'social_post_link'|'podcast_link'|'competition_link'|'bracket_link'|'squares_link'|'room_link'|'poll_link'
1722
+ link_sub_type: 'user_referral_link'|'h2h_share_link'|'social_post_link'|'podcast_link'|'competition_link'|'bracket_link'|'squares_link'|'room_link'|'poll_link'|'team_contest_link'
1723
1723
  company_id?:string,
1724
1724
  type_id?:string,
1725
1725
  status?:string,