@@ -46,6 +46,11 @@ export default function Competitions() {
46
46
} ) ;
47
47
} ;
48
48
49
+ const resetFields = ( ) => {
50
+ document . getElementById ( 'usernameInput' ) . value = "" ;
51
+ document . getElementById ( 'reasonInput' ) . value = "" ;
52
+ } ;
53
+
49
54
const fetchPendingChallenges = async ( ) => {
50
55
try {
51
56
const response = await request ( process . env . NEXT_PUBLIC_API_URL + '/pending' , "GET" ) ;
@@ -67,13 +72,74 @@ export default function Competitions() {
67
72
}
68
73
} ;
69
74
75
+ const handleDeleteChallenge = async ( ) => {
76
+ const challengeId = document . getElementById ( 'challengeIdInput' ) . value ;
77
+ const reason = document . getElementById ( 'challengeReasonInput' ) . value ;
78
+
79
+ try {
80
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /admin/${ challengeId } /deleteChallenge` , "POST" , { reason} ) ;
81
+ if ( response . success ) {
82
+ alert ( "Challenge deleted successfully!" ) ;
83
+ } else {
84
+ alert ( "Failed to delete challenge." ) ;
85
+ }
86
+
87
+ document . getElementById ( 'challengeIdInput' ) . value = "" ;
88
+ document . getElementById ( 'challengeReasonInput' ) . value = "" ;
89
+
90
+
91
+ } catch ( err ) {
92
+ console . log ( err ) ;
93
+ alert ( "An error occurred while deleting the challenge." ) ;
94
+ }
95
+
96
+ } ;
97
+
98
+ const handleUnapproveChallenge = async ( ) => {
99
+ const challengeId = document . getElementById ( 'challengeIdInput' ) . value ;
100
+ const reason = document . getElementById ( 'challengeReasonInput' ) . value ;
101
+
102
+ try {
103
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /admin/${ challengeId } /unapproveChallenge` , "POST" , { reason} ) ;
104
+ if ( response . success ) {
105
+ alert ( "Challenge unapproved successfully!" ) ;
106
+ } else {
107
+ alert ( "Failed to unapprove challenge." ) ;
108
+ }
109
+
110
+ document . getElementById ( 'challengeIdInput' ) . value = "" ;
111
+ document . getElementById ( 'challengeReasonInput' ) . value = "" ;
112
+
113
+
114
+ } catch ( err ) {
115
+ console . log ( err ) ;
116
+ alert ( "An error occurred while unapproving the challenge." ) ;
117
+ }
118
+
119
+ } ;
120
+
121
+ const handleResyncLeaderboard = async ( ) => {
122
+ try {
123
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /admin/syncLeaderboard` , "POST" ) ;
124
+ if ( response . success ) {
125
+ alert ( "Leaderboard resynced successfully!" ) ;
126
+ } else {
127
+ alert ( "Failed to resync leaderboard." ) ;
128
+ }
129
+ } catch ( err ) {
130
+ console . log ( err ) ;
131
+ alert ( "An error occurred while resyncing the leaderboard." ) ;
132
+ }
133
+ } ;
134
+
70
135
useEffect ( ( ) => {
71
136
fetchPendingChallenges ( ) ;
72
137
} , [ ] ) ;
73
138
74
139
const handleResetPFP = async ( ) => {
75
140
const username = document . getElementById ( 'usernameInput' ) . value ;
76
- const reason = "" ; // Set reason as blank for now
141
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
142
+ console . log ( 'REASON: ' , reason ) ;
77
143
78
144
if ( ! username ) {
79
145
alert ( "Please enter a username." ) ;
@@ -87,6 +153,9 @@ export default function Competitions() {
87
153
} else {
88
154
alert ( "Failed to reset profile picture." ) ;
89
155
}
156
+
157
+ resetFields ( ) ;
158
+
90
159
} catch ( error ) {
91
160
console . error ( error ) ;
92
161
alert ( "An error occurred while resetting the profile picture." ) ;
@@ -95,7 +164,7 @@ export default function Competitions() {
95
164
96
165
const handleResetBanner = async ( ) => {
97
166
const username = document . getElementById ( 'usernameInput' ) . value ;
98
- const reason = "" ; // Set reason as blank for now
167
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
99
168
100
169
if ( ! username ) {
101
170
alert ( "Please enter a username." ) ;
@@ -108,6 +177,9 @@ export default function Competitions() {
108
177
} else {
109
178
alert ( "Failed to reset banner." ) ;
110
179
}
180
+
181
+ resetFields ( ) ;
182
+
111
183
} catch ( err ) {
112
184
console . log ( err ) ;
113
185
alert ( "An error occurred while resetting the banner." ) ;
@@ -116,7 +188,7 @@ export default function Competitions() {
116
188
117
189
const handleDisableAccount = async ( ) => {
118
190
const username = document . getElementById ( 'usernameInput' ) . value ;
119
- const reason = "" ;
191
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
120
192
121
193
if ( ! username ) {
122
194
alert ( "Please enter a username." ) ;
@@ -130,15 +202,41 @@ export default function Competitions() {
130
202
} else {
131
203
alert ( "Failed to disable account." ) ;
132
204
}
205
+
206
+ resetFields ( ) ;
207
+
133
208
} catch ( err ) {
134
209
console . log ( err ) ;
135
210
alert ( "An error occurred while disabling the account." ) ;
136
211
}
137
212
} ;
213
+ const handleResetBio = async ( ) => {
214
+
215
+ const username = document . getElementById ( 'usernameInput' ) . value ;
216
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
217
+
218
+ if ( ! username ) {
219
+ alert ( "Please enter a username." ) ;
220
+ return ;
221
+ }
222
+ try {
223
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /admin/${ username } /resetBio` , "POST" , { reason} ) ;
224
+ if ( response . success ) {
225
+ alert ( "Bio reset successfully!" ) ;
226
+ } else {
227
+ alert ( "Failed to reset bio." ) ;
228
+ }
229
+
230
+ resetFields ( ) ;
231
+ } catch ( err ) {
232
+ console . log ( err ) ;
233
+ alert ( "An error occurred while resetting the bio." ) ;
234
+ }
235
+ } ;
138
236
139
237
const handleEnableAccount = async ( ) => {
140
238
const username = document . getElementById ( 'usernameInput' ) . value ;
141
- const reason = "" ;
239
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
142
240
143
241
if ( ! username ) {
144
242
alert ( "Please enter a username." ) ;
@@ -151,12 +249,37 @@ export default function Competitions() {
151
249
} else {
152
250
alert ( "Failed to enable account." ) ;
153
251
}
252
+
253
+ resetFields ( ) ;
154
254
} catch ( err ) {
155
255
console . log ( err ) ;
156
256
alert ( "An error occurred while enabling the account." ) ;
157
257
}
158
258
} ;
159
259
260
+ const handleWarnUser = async ( ) => {
261
+ const username = document . getElementById ( 'usernameInput' ) . value ;
262
+ const reason = document . getElementById ( 'reasonInput' ) . value ;
263
+
264
+ if ( ! username ) {
265
+ alert ( "Please enter a username." ) ;
266
+ return ;
267
+ }
268
+ try {
269
+ const response = await request ( `${ process . env . NEXT_PUBLIC_API_URL } /admin/${ username } /warnUser` , "POST" , { reason} ) ;
270
+ if ( response . success ) {
271
+ alert ( "User warned successfully!" ) ;
272
+ } else {
273
+ alert ( "Failed to warn user." ) ;
274
+ }
275
+
276
+ resetFields ( ) ;
277
+ } catch ( err ) {
278
+ console . log ( err ) ;
279
+ alert ( "An error occurred while warning the user." ) ;
280
+ }
281
+ } ;
282
+
160
283
return (
161
284
< >
162
285
< Head >
@@ -192,19 +315,22 @@ export default function Competitions() {
192
315
< textarea placeholder = 'Reason' className = 'mb-2 text-white bg-neutral-800 border-none w-full' id = "reasonInput" > </ textarea >
193
316
< button className = 'ml-auto px-2 py-1 bg-red-600 text-white mt-2' onClick = { handleDisableAccount } > Disable Account</ button >
194
317
< button className = 'ml-2 px-2 py-1 bg-green-600 text-white mt-2' onClick = { handleEnableAccount } > Enable Account</ button >
195
- < button className = 'ml-2 px-2 py-1 bg-yellow-600 text-white mt-2' > Warn User</ button >
318
+ < button className = 'ml-2 px-2 py-1 bg-yellow-600 text-white mt-2' onClick = { handleWarnUser } > Warn User</ button >
196
319
< button className = 'ml-2 px-2 py-1 bg-blue-600 text-white mt-2' onClick = { handleResetPFP } > Reset PFP</ button >
197
320
< button className = 'ml-2 px-2 py-1 bg-blue-600 text-white mt-2' onClick = { handleResetBanner } > Reset Banner</ button >
321
+ < button className = 'ml-2 px-2 py-1 bg-blue-600 text-white mt-2' onClick = { handleResetBio } > Reset Bio</ button >
322
+
198
323
199
324
</ div >
200
325
201
326
202
327
< div >
203
328
< h1 className = 'text-xl text-white mb-2' > CHALLENGE ACTIONS</ h1 >
204
- < input type = "text" placeholder = 'Enter CHALLENGE ID' className = 'mb-2 text-white bg-neutral-800 border-none w-full' > </ input >
205
- < textarea placeholder = 'Reason' className = 'mb-2 text-white bg-neutral-800 border-none w-full' > </ textarea >
206
- < button className = 'ml-auto px-2 py-1 bg-red-600 text-white mt-2' > Delete Challenge</ button >
207
- < button className = 'ml-2 px-2 py-1 bg-yellow-600 text-white mt-2' > Unapprove Challenge</ button >
329
+ < input type = "text" placeholder = 'Enter CHALLENGE ID' className = 'mb-2 text-white bg-neutral-800 border-none w-full' id = "challengeIdInput" > </ input >
330
+ < textarea placeholder = 'Reason' className = 'mb-2 text-white bg-neutral-800 border-none w-full' id = "challengeReasonInput" > </ textarea >
331
+ < button className = 'ml-auto px-2 py-1 bg-red-600 text-white mt-2' onClick = { handleDeleteChallenge } > Delete Challenge</ button >
332
+ < button className = 'ml-2 px-2 py-1 bg-yellow-600 text-white mt-2' onClick = { handleUnapproveChallenge } > Unapprove Challenge</ button >
333
+ < button className = 'ml-2 px-2 py-1 bg-red-600 text-white mt-2' onClick = { handleResyncLeaderboard } > Resync Leaderboard</ button >
208
334
</ div >
209
335
</ div >
210
336
< div className = 'grid grid-cols-2 mt-4 gap-x-5 border border-neutral-700 px-4 py-4' >
0 commit comments