Skip to content

Commit 244a4d2

Browse files
authored
Merge pull request #171 from ctfguide-tech/feat/moderationChanges
Feat/moderation changes
2 parents 49012b9 + 2cc66f3 commit 244a4d2

File tree

1 file changed

+135
-9
lines changed

1 file changed

+135
-9
lines changed

src/pages/moderation.jsx

+135-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export default function Competitions() {
4646
});
4747
};
4848

49+
const resetFields = () => {
50+
document.getElementById('usernameInput').value = "";
51+
document.getElementById('reasonInput').value = "";
52+
};
53+
4954
const fetchPendingChallenges = async () => {
5055
try {
5156
const response = await request(process.env.NEXT_PUBLIC_API_URL + '/pending', "GET");
@@ -67,13 +72,74 @@ export default function Competitions() {
6772
}
6873
};
6974

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+
70135
useEffect(() => {
71136
fetchPendingChallenges();
72137
}, []);
73138

74139
const handleResetPFP = async () => {
75140
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);
77143

78144
if (!username) {
79145
alert("Please enter a username.");
@@ -87,6 +153,9 @@ export default function Competitions() {
87153
} else {
88154
alert("Failed to reset profile picture.");
89155
}
156+
157+
resetFields();
158+
90159
} catch (error) {
91160
console.error(error);
92161
alert("An error occurred while resetting the profile picture.");
@@ -95,7 +164,7 @@ export default function Competitions() {
95164

96165
const handleResetBanner = async () => {
97166
const username = document.getElementById('usernameInput').value;
98-
const reason = ""; // Set reason as blank for now
167+
const reason = document.getElementById('reasonInput').value;
99168

100169
if(!username) {
101170
alert("Please enter a username.");
@@ -108,6 +177,9 @@ export default function Competitions() {
108177
}else {
109178
alert("Failed to reset banner.");
110179
}
180+
181+
resetFields();
182+
111183
}catch(err){
112184
console.log(err);
113185
alert("An error occurred while resetting the banner.");
@@ -116,7 +188,7 @@ export default function Competitions() {
116188

117189
const handleDisableAccount = async () => {
118190
const username = document.getElementById('usernameInput').value;
119-
const reason = "";
191+
const reason = document.getElementById('reasonInput').value;
120192

121193
if (!username) {
122194
alert("Please enter a username.");
@@ -130,15 +202,41 @@ export default function Competitions() {
130202
} else {
131203
alert("Failed to disable account.");
132204
}
205+
206+
resetFields();
207+
133208
}catch(err){
134209
console.log(err);
135210
alert("An error occurred while disabling the account.");
136211
}
137212
};
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+
};
138236

139237
const handleEnableAccount = async () => {
140238
const username = document.getElementById('usernameInput').value;
141-
const reason = "";
239+
const reason = document.getElementById('reasonInput').value;
142240

143241
if (!username) {
144242
alert("Please enter a username.");
@@ -151,12 +249,37 @@ export default function Competitions() {
151249
}else {
152250
alert("Failed to enable account.");
153251
}
252+
253+
resetFields();
154254
}catch(err){
155255
console.log(err);
156256
alert("An error occurred while enabling the account.");
157257
}
158258
};
159259

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+
160283
return (
161284
<>
162285
<Head>
@@ -192,19 +315,22 @@ export default function Competitions() {
192315
<textarea placeholder='Reason' className='mb-2 text-white bg-neutral-800 border-none w-full' id="reasonInput"></textarea>
193316
<button className='ml-auto px-2 py-1 bg-red-600 text-white mt-2'onClick={handleDisableAccount}>Disable Account</button>
194317
<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>
196319
<button className='ml-2 px-2 py-1 bg-blue-600 text-white mt-2' onClick={handleResetPFP}>Reset PFP</button>
197320
<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+
198323

199324
</div>
200325

201326

202327
<div>
203328
<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>
208334
</div>
209335
</div>
210336
<div className='grid grid-cols-2 mt-4 gap-x-5 border border-neutral-700 px-4 py-4'>

0 commit comments

Comments
 (0)