@@ -21,6 +21,7 @@ import { useHibiscusSupabase } from '@hibiscus/hibiscus-supabase-context';
21
21
import BattlepassPointsBar from 'apps/dashboard/components/battlepass/battlepass-points-bar' ;
22
22
import { BsExclamationTriangle } from 'react-icons/bs' ;
23
23
import { MdCheckCircleOutline } from 'react-icons/md' ;
24
+ import axios from 'axios' ;
24
25
25
26
const COLUMN_WIDTH = 510 ;
26
27
const TEAM_MEMBER_ICONS = [
@@ -41,6 +42,8 @@ export function Index() {
41
42
const [ state , setState ] = useState ( State . LOADING ) ;
42
43
const [ isModalOpen , setModalOpen ] = useState ( false ) ;
43
44
const [ battlepassProgress , setBattlepassProgress ] = useState ( null ) ;
45
+ const [ bonusPoints , setBonusPoints ] = useState ( null ) ;
46
+ const [ hackerBonusPoints , setHackerBonusPoints ] = useState ( null ) ;
44
47
const router = useRouter ( ) ;
45
48
const { supabase } = useHibiscusSupabase ( ) ;
46
49
@@ -140,6 +143,28 @@ export function Index() {
140
143
}
141
144
} , [ router . isReady , router . query ] ) ;
142
145
146
+ useEffect ( ( ) => {
147
+ const fetchData = async ( ) => {
148
+ const res = await supabase . getClient ( ) . from ( 'bonus_points' ) . select ( ) ;
149
+ if ( res . error ) return ;
150
+
151
+ const res_ = await supabase
152
+ . getClient ( )
153
+ . from ( 'bonus_points_log' )
154
+ . select ( )
155
+ . eq ( 'user_id' , user . user_id )
156
+ . eq ( 'status' , 1 ) ;
157
+ if ( res_ . error ) return ;
158
+
159
+ setBonusPoints ( res . data ) ;
160
+ setHackerBonusPoints ( res_ . data . map ( ( d ) => d . bonus_points_id ) ) ;
161
+ } ;
162
+
163
+ if ( user != null ) {
164
+ fetchData ( ) ;
165
+ }
166
+ } , [ user ] ) ;
167
+
143
168
const { user : authUser } = useHibiscusUser ( ) ;
144
169
if ( authUser == null ) {
145
170
return < > Loading</ > ;
@@ -265,6 +290,48 @@ export function Index() {
265
290
</ ScrollableListBox >
266
291
</ div >
267
292
</ div >
293
+
294
+ < div className = "flex flex-row gap-[40px] flex-wrap" >
295
+ < div className = "flex flex-col flex-1 gap-[10px]" >
296
+ < h3 className = "text-xl m-0" > Bonus Points</ h3 >
297
+ < div className = "flex flex-col gap-[20px] border-solid border-black border-[1px] rounded-[8px] p-[30px] text-sm" >
298
+ { bonusPoints ?. map ( ( bp ) => (
299
+ < div
300
+ key = { bp . id }
301
+ className = "flex flex-row gap-[20px] items-center"
302
+ >
303
+ < p > { bp . name } </ p >
304
+ { hackerBonusPoints . includes ( bp . id ) ? (
305
+ < button
306
+ disabled = { true }
307
+ className = "bg-theme-redward px-[20px] py-[8px] text-white rounded-[8px] border-black border-[1px] border-solid text-xs"
308
+ >
309
+ Already given
310
+ </ button >
311
+ ) : (
312
+ < button
313
+ onClick = { async ( ) => {
314
+ const res = await axios . post (
315
+ '/api/battlepass/bonus-points-approve' ,
316
+ {
317
+ userId : user . user_id ,
318
+ bonusPointId : bp . id ,
319
+ }
320
+ ) ;
321
+ if ( res . status === 200 ) {
322
+ setHackerBonusPoints ( [ ...hackerBonusPoints , bp . id ] ) ;
323
+ }
324
+ } }
325
+ className = "bg-red-300 hover:bg-theme-redward active:bg-red-300 px-[20px] py-[8px] text-white rounded-[8px] border-black border-[1px] border-solid text-xs"
326
+ >
327
+ Submit
328
+ </ button >
329
+ ) }
330
+ </ div >
331
+ ) ) }
332
+ </ div >
333
+ </ div >
334
+ </ div >
268
335
</ div >
269
336
270
337
< CheckInBox
0 commit comments