be-components 7.0.5 → 7.0.6

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 (52) hide show
  1. package/lib/commonjs/Discord/api/index.js +61 -0
  2. package/lib/commonjs/Discord/api/index.js.map +1 -0
  3. package/lib/commonjs/Discord/index.js +516 -0
  4. package/lib/commonjs/Discord/index.js.map +1 -0
  5. package/lib/commonjs/Squares/index.js +0 -3
  6. package/lib/commonjs/Squares/index.js.map +1 -1
  7. package/lib/commonjs/SquaresManager/index.js +1 -1
  8. package/lib/commonjs/SquaresManager/index.js.map +1 -1
  9. package/lib/commonjs/index.js +7 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/types.d.js +2 -0
  12. package/lib/commonjs/types.d.js.map +1 -1
  13. package/lib/module/Discord/api/index.js +54 -0
  14. package/lib/module/Discord/api/index.js.map +1 -0
  15. package/lib/module/Discord/index.js +509 -0
  16. package/lib/module/Discord/index.js.map +1 -0
  17. package/lib/module/Squares/index.js +0 -3
  18. package/lib/module/Squares/index.js.map +1 -1
  19. package/lib/module/SquaresManager/index.js +1 -1
  20. package/lib/module/SquaresManager/index.js.map +1 -1
  21. package/lib/module/index.js +2 -1
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/types.d.js +2 -0
  24. package/lib/module/types.d.js.map +1 -1
  25. package/lib/typescript/lib/commonjs/Discord/api/index.d.ts +9 -0
  26. package/lib/typescript/lib/commonjs/Discord/api/index.d.ts.map +1 -0
  27. package/lib/typescript/lib/commonjs/Discord/index.d.ts +11 -0
  28. package/lib/typescript/lib/commonjs/Discord/index.d.ts.map +1 -0
  29. package/lib/typescript/lib/commonjs/Squares/index.d.ts.map +1 -1
  30. package/lib/typescript/lib/commonjs/index.d.ts +1 -0
  31. package/lib/typescript/lib/commonjs/index.d.ts.map +1 -1
  32. package/lib/typescript/lib/module/Discord/api/index.d.ts +8 -0
  33. package/lib/typescript/lib/module/Discord/api/index.d.ts.map +1 -0
  34. package/lib/typescript/lib/module/Discord/index.d.ts +11 -0
  35. package/lib/typescript/lib/module/Discord/index.d.ts.map +1 -0
  36. package/lib/typescript/lib/module/Squares/index.d.ts.map +1 -1
  37. package/lib/typescript/lib/module/index.d.ts +2 -1
  38. package/lib/typescript/lib/module/index.d.ts.map +1 -1
  39. package/lib/typescript/src/Discord/api/index.d.ts +9 -0
  40. package/lib/typescript/src/Discord/api/index.d.ts.map +1 -0
  41. package/lib/typescript/src/Discord/index.d.ts +13 -0
  42. package/lib/typescript/src/Discord/index.d.ts.map +1 -0
  43. package/lib/typescript/src/Squares/index.d.ts.map +1 -1
  44. package/lib/typescript/src/index.d.ts +2 -1
  45. package/lib/typescript/src/index.d.ts.map +1 -1
  46. package/package.json +1 -1
  47. package/src/Discord/api/index.ts +57 -0
  48. package/src/Discord/index.tsx +300 -0
  49. package/src/Squares/index.tsx +0 -1
  50. package/src/SquaresManager/index.tsx +1 -1
  51. package/src/index.tsx +2 -0
  52. package/src/types.d.ts +15 -1
@@ -0,0 +1,57 @@
1
+
2
+ import axios from 'axios';
3
+ import { APIOverrides } from '../../ApiOverrides';
4
+ import type { DiscordPlayerProps } from '../../types';
5
+
6
+ //let SOCIAL_SVC_API = '';
7
+ //let EVENT_SVC_API = '';
8
+ //let MK_SVC_API = '';
9
+ let AUTH_SVC_API = '';
10
+ //let TP_SVC_API = ''
11
+
12
+ export const DiscordPlayerApi = {
13
+ setEnvironment: () => {
14
+ const endpoints = APIOverrides.getEndpoints();
15
+ //SOCIAL_SVC_API = endpoints['SOCIAL_SVC_API'] as string;
16
+ //EVENT_SVC_API = endpoints['EVENT_SVC_API'] as string;
17
+ //MK_SVC_API = endpoints['MK_SVC_API'] as string;
18
+ AUTH_SVC_API = endpoints['AUTH_SVC_API'] as string;
19
+ //TP_SVC_API = endpoints['TP_SVC_API'] as string;
20
+ },
21
+ getMyDiscordConnection: async():Promise<DiscordPlayerProps | undefined> => {
22
+ try {
23
+ const resp = await axios.get(`${AUTH_SVC_API}/v1/players/discord/me`);
24
+ return resp.data.discord_player
25
+ } catch (e) {
26
+ console.log(e);
27
+ return undefined
28
+ }
29
+ },
30
+ startConnnection: async():Promise<DiscordPlayerProps | undefined> => {
31
+ try {
32
+ const resp = await axios.post(`${AUTH_SVC_API}/v1/players/discord/connect`);
33
+ return resp.data.discord_player
34
+ } catch (e) {
35
+ console.log(e)
36
+ return undefined
37
+
38
+ }
39
+ },
40
+ confirmConnection: async():Promise<DiscordPlayerProps | undefined> => {
41
+ try {
42
+ const resp = await axios.post(`${AUTH_SVC_API}/v1/players/discord/confirm`);
43
+ return resp.data.discord_player
44
+ } catch (e) {
45
+ console.log(e);
46
+ return undefined
47
+ }
48
+ },
49
+ disconnect: async():Promise<DiscordPlayerProps | undefined> => {
50
+ try {
51
+ const resp = await axios.post(`${AUTH_SVC_API}/v1/players/discord/disconnect`);
52
+ return resp.data.discord_player
53
+ } catch (e) {
54
+ return undefined
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,300 @@
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Button, Text, View } from "../Components/Themed"
3
+ import { DiscordPlayerApi } from './api';
4
+ import type { DiscordPlayerProps } from '../types';
5
+ import { FlatList, Image, type ViewStyle } from 'react-native';
6
+ import { Icons, Toggle } from '../Components';
7
+ import { useColors } from '../constants/useColors';
8
+ import * as Clipboard from 'expo-clipboard';
9
+
10
+ type DiscordConnectionManagerProps = {
11
+ player_id?:string,
12
+ refresh_key?:string,
13
+ header_style?:ViewStyle,
14
+ float?:boolean,
15
+ footer_style?:ViewStyle,
16
+ onRequestAuthenticate: () => void
17
+ }
18
+
19
+ const sections = ['header','toggle', 'logo', 'success', 'step_1','step_2','step_3']
20
+ const DiscordConnectionManager = ({ player_id, refresh_key, header_style, footer_style, float, onRequestAuthenticate }:DiscordConnectionManagerProps) => {
21
+ const Colors = useColors();
22
+ const [ state, setState ] = useState<{
23
+ loading:boolean,
24
+ discord_player?:DiscordPlayerProps,
25
+ active_step:string
26
+ }>({
27
+ loading: false,
28
+ active_step: 'step_1'
29
+ });
30
+ const { loading, discord_player, active_step } = state;
31
+
32
+ useEffect(() => {
33
+ DiscordPlayerApi.setEnvironment();
34
+ if(!player_id){ return onRequestAuthenticate() }
35
+ getData();
36
+ },[player_id, refresh_key]);
37
+
38
+ const getData = async() => {
39
+ setState({ ...state, loading:true });
40
+ const dp = await DiscordPlayerApi.getMyDiscordConnection();
41
+ if(!dp){ return alert('Unable to get your connection status') }
42
+ const step = dp.status == 'inactive' ? 'step_1' : dp.status == 'requested' ? 'step_2' : dp.status == 'pending' ? 'step_3' : 'step_1'
43
+ setState({
44
+ ...state,
45
+ loading:false,
46
+ discord_player: dp,
47
+ active_step: step
48
+ });
49
+ }
50
+
51
+ const handleStartConnection = async() => {
52
+ if(loading){ return }
53
+ setState({ ...state, loading:true });
54
+ const dp = await DiscordPlayerApi.startConnnection();
55
+ if(!dp){
56
+ alert('Unable to process at this time. Please try again')
57
+ getData();
58
+ return
59
+ }
60
+ setState({
61
+ ...state,
62
+ discord_player: dp,
63
+ active_step: 'step_2',
64
+ loading:false
65
+ });
66
+ }
67
+
68
+ const handleConfirmConnection = async() => {
69
+ if(loading){ return }
70
+ setState({ ...state, loading:true });
71
+ const dp = await DiscordPlayerApi.confirmConnection();
72
+ if(!dp){
73
+ alert('Unable to process at this time. Please try again')
74
+ getData();
75
+ return
76
+ }
77
+ setState({
78
+ ...state,
79
+ discord_player: dp,
80
+ loading:false
81
+ });
82
+ }
83
+
84
+ const handleDisconnect = async() => {
85
+ if(loading){ return }
86
+ setState({ ...state, loading:true });
87
+ const dp = await DiscordPlayerApi.disconnect();
88
+ if(!dp){
89
+ alert('Unable to process at this time. Please try again')
90
+ getData();
91
+ return
92
+ }
93
+ setState({
94
+ ...state,
95
+ discord_player: dp,
96
+ loading:false
97
+ });
98
+ }
99
+
100
+
101
+ const renderSections = (data:{item:string, index:number}) => {
102
+ switch(data.item){
103
+ case 'header':
104
+ return (
105
+ <View type='header' style={{ flexDirection:'row', alignItems:'center', padding:10, ...header_style }}>
106
+ <Image
107
+ source={{ uri: 'https://res.cloudinary.com/hoabts6mc/image/upload/v1758212751/discord_xkfzgw.jpg' }}
108
+ style={{ height:40, width:40 }}
109
+ resizeMode='contain'
110
+ />
111
+ <View transparent style={{ flex:1, marginLeft:10 }}>
112
+ <Text theme='h1'>Connect Your Discord!</Text>
113
+ <Text theme='description'>Follow the instructions below to authenticate discord with your account</Text>
114
+ </View>
115
+ <Button float style={{ padding:10 }} onPress={() => getData()}>
116
+ <Icons.RefreshIcon size={18} color={Colors.text.h1}/>
117
+ </Button>
118
+ </View>
119
+ )
120
+ case 'toggle':
121
+ if(discord_player?.status == 'active'){ return <></> }
122
+ return (
123
+ <View style={{padding:10}}>
124
+ <Toggle
125
+ options={[
126
+ { key: 'step_1', label: 'Step 1' },
127
+ { key: 'step_2', label: 'Step 2' },
128
+ { key: 'step_3', label: 'Step 3' }
129
+ ]}
130
+ selected_option={active_step}
131
+ onSelectOption={(step) => setState({ ...state, active_step:step })}
132
+ />
133
+ </View>
134
+ )
135
+ case 'success':
136
+ if(discord_player?.status != 'active'){ return <></> }
137
+ return (
138
+ <View style={{ padding:10 }}>
139
+ <View float style={{ padding:2, backgroundColor: '#7289da', borderRadius:100, alignSelf:'center' }}>
140
+ {discord_player.image?
141
+ <Image
142
+ source={{ uri: discord_player.image.url }}
143
+ style={{ height:125, width:125, borderRadius:100 }}
144
+ resizeMode='cover'
145
+ />
146
+ :
147
+ <Image
148
+ source={{ uri: 'https://res.cloudinary.com/hoabts6mc/image/upload/v1758213727/discord-logo_zsufoi.png' }}
149
+ style={{ height:125, width:125, borderRadius:100 }}
150
+ resizeMode='cover'
151
+ />
152
+ }
153
+ </View>
154
+ <View float style={{ marginTop:40}}>
155
+ <View transparent style={{ flexDirection:'row', alignItems:'center', padding:10}}>
156
+ {discord_player.image?
157
+ <Image
158
+ source={{ uri: discord_player.image.url }}
159
+ style={{ height:50, width:50, borderRadius:100 }}
160
+ resizeMode='cover'
161
+ />
162
+ :
163
+ <Image
164
+ source={{ uri: 'https://res.cloudinary.com/hoabts6mc/image/upload/v1758213727/discord-logo_zsufoi.png' }}
165
+ style={{ height:50, width:50, borderRadius:100 }}
166
+ resizeMode='cover'
167
+ />
168
+ }
169
+ <View transparent style={{ flex:1, marginLeft:10, marginRight:10 }}>
170
+ <Text theme='h1' size={18}>@{discord_player.username}</Text>
171
+ <Text theme='success' style={{ marginTop:5 }}>CONNECTED</Text>
172
+ </View>
173
+ <Icons.CheckCirlceIcon color={Colors.text.success} size={20} />
174
+ </View>
175
+ </View>
176
+ </View>
177
+ )
178
+ case 'logo':
179
+ if(discord_player?.status == 'active'){ return <></> }
180
+ return (
181
+ <View transparent style={{ flexDirection:'row', paddingLeft:10, paddingRight:10 }}>
182
+ {active_step == 'step_2' ?
183
+ <View style={{ flex:1 }} />
184
+ :active_step == 'step_3' ?
185
+ <View style={{ flex:2 }} />
186
+ :<></>}
187
+ <View style={{ flex:1, justifyContent:'center', alignItems:'center' }}>
188
+ <View float style={{ padding:10, backgroundColor: '#7289da', borderRadius:100 }}>
189
+ <Image
190
+ source={{ uri: 'https://res.cloudinary.com/hoabts6mc/image/upload/v1758213727/discord-logo_zsufoi.png' }}
191
+ style={{ height:50, width:50, borderRadius:100 }}
192
+ resizeMode='cover'
193
+ />
194
+ </View>
195
+ </View>
196
+ {active_step == 'step_1' ?
197
+ <View style={{ flex:2 }} />
198
+ :active_step == 'step_2' ?
199
+ <View style={{ flex:1 }} />
200
+ :<></>}
201
+ </View>
202
+ )
203
+ case 'step_1':
204
+ if(active_step != 'step_1'){ return <></> }
205
+ if(discord_player && discord_player.status == 'active'){ return <></> }
206
+ return (
207
+ <View float style={{ padding:20, margin:10, justifyContent:'center', alignItems:'center' }}>
208
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Press Start Connection below</Text>
209
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>You’ll get a temporary code valid for 10 minutes</Text>
210
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Keep this code handy—you’ll need it in Discord</Text>
211
+ </View>
212
+ )
213
+ case 'step_2':
214
+ if(active_step != 'step_2' || !discord_player){ return <></> }
215
+ if(discord_player?.status == 'active'){ return <></> }
216
+ return (
217
+ <View float style={{ padding:20, margin:10, justifyContent:'center', alignItems:'center' }}>
218
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Open Discord where the bot is installed.</Text>
219
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Use the slash command{'\n'} /connect {discord_player.auth_code}</Text>
220
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Make sure to enter the code exactly as shown. It will expire in 10 minutes</Text>
221
+ </View>
222
+ )
223
+ case 'step_3':
224
+ if(active_step != 'step_3' || !discord_player){ return <></> }
225
+ if(discord_player?.status == 'active'){ return <></> }
226
+ return (
227
+ <View float style={{ padding:20, margin:10, justifyContent:'center', alignItems:'center' }}>
228
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Once Validated, you can confirm the connection</Text>
229
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Press confirm connection below.</Text>
230
+ <Text theme='h1' size={20} style={{ marginTop:20 }} textAlign='center'>Once confirmed, you can use authenticated commands in descord!</Text>
231
+ </View>
232
+ )
233
+ default: return <></>
234
+ }
235
+ }
236
+
237
+ return (
238
+ <View float={float} style={{ flex:1 }}>
239
+ <FlatList
240
+ data={sections}
241
+ key={'discord_connection_sections'}
242
+ keyExtractor={item => item}
243
+ renderItem={renderSections}
244
+ />
245
+ {discord_player ?
246
+ <View type='footer' style={{ flexDirection:'row', alignItems:'center', padding:10, ...footer_style }}>
247
+ {discord_player.status == 'inactive' ?
248
+ <Button
249
+ title='START CONNECTION'
250
+ title_color={Colors.text.white}
251
+ backgroundColor='#7289da'
252
+ loading={loading}
253
+ style={{ flex:1 }}
254
+ onPress={() => handleStartConnection()}
255
+ />
256
+ :discord_player.status == 'requested' ?
257
+ <Button
258
+ type='text'
259
+ loading={loading}
260
+ style={{ flex:1, alignItems:'center', justifyContent:'center' }}
261
+ onPress={async() => {
262
+ if(!discord_player.auth_code){ return }
263
+ await Clipboard.setStringAsync(discord_player.auth_code)
264
+ alert('Code copied to clipboard')
265
+ }}>
266
+ <Text theme='action' size={14}>Press to Copy: {discord_player.auth_code}</Text>
267
+ </Button>
268
+ :discord_player.status == 'pending' ?
269
+ <Button
270
+ title='CONFIRM CONNECTION'
271
+ type='success'
272
+ loading={loading}
273
+ style={{ flex:1 }}
274
+ onPress={() => handleConfirmConnection()}
275
+ />
276
+ :discord_player.status == 'active'?
277
+ <Button
278
+ title='DISCONNECT'
279
+ type='error'
280
+ loading={loading}
281
+ style={{ flex:1 }}
282
+ onPress={() => handleDisconnect()}
283
+ />
284
+ :<></>}
285
+ </View>
286
+ :
287
+ <View type='footer' style={{ flexDirection:'row', alignItems:'center', padding:10, ...footer_style }}>
288
+ <Button
289
+ type='success'
290
+ style={{ flex:1 }}
291
+ title='LOG IN FIRST'
292
+ onPress={() => onRequestAuthenticate()}
293
+ />
294
+ </View>
295
+ }
296
+ </View>
297
+ )
298
+ }
299
+
300
+ export default DiscordConnectionManager
@@ -632,7 +632,6 @@ const SquaresModule = ({ sq_comp_id, info_header, view_mode, insets, player_id,
632
632
  <View type='footer' style={{ padding:10 }}>
633
633
  <Button
634
634
  title='CLOSE'
635
- style={{ flex:1 }}
636
635
  type='close'
637
636
  onPress={() => onClose()}
638
637
  />
@@ -403,7 +403,7 @@ const SquaresManager = ({ sq_comp_id, float, player, header_style, onFocusPositi
403
403
  <View transparent style={{ marginTop:20 }}>
404
404
  <FlatList
405
405
  data={leagues.sort((a,b) => a.priority - b.priority)}
406
- key={'competition_reult_types'}
406
+ key={'competition_leagues_list'}
407
407
  keyExtractor={item => item.league_id.toString()}
408
408
  renderItem={renderLeagues}
409
409
  />
package/src/index.tsx CHANGED
@@ -61,10 +61,12 @@ import GroupComponent from './Group';
61
61
  import CreateGroupWizard from './Group/components/CreateGroupWizard';
62
62
  import CreateEngagement from './CreateEngagement';
63
63
  import SquaresManager from './SquaresManager';
64
+ import DiscordConnectionManager from './Discord';
64
65
  export {
65
66
  Authenticator,
66
67
  Observer,
67
68
  CreateEngagement,
69
+ DiscordConnectionManager,
68
70
  BEEventApi,
69
71
  RankingsCard,
70
72
  BELinkApi,
package/src/types.d.ts CHANGED
@@ -132,7 +132,21 @@ export interface PublicPlayerProps {
132
132
  }
133
133
 
134
134
 
135
-
135
+ //DiscordPlayer
136
+ export interface DiscordPlayerProps {
137
+ discord_player_id:string,
138
+ player_id:string,
139
+ discord_id?:string,
140
+ token?: string,
141
+ username?:string,
142
+ image?:{url:string},
143
+ refresh_token?:string,
144
+ status: 'active'|'inactive'|'requested'|'pending',
145
+ auth_code?: string,
146
+ expire_time?: any,
147
+ create_datetime:any,
148
+ last_update_datetime:any
149
+ }
136
150
 
137
151
  export interface GolfLeaderProps {
138
152
  tournament_id:string,