Skip to content

Commit 7096daf

Browse files
committed
update
1 parent 0a47ff2 commit 7096daf

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

frontend/src/pages/Admin/ChallengeManagement.jsx

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ export default function ChallengeManagement() {
7777
: formData.dependencies.filter(dep => dep !== value);
7878

7979
setFormData({ ...formData, dependencies: newDependencies });
80+
} else if (e.target.name === "initialPoints" || e.target.name === "bonusPoints") {
81+
// Auto-calculate total points when initialPoints or bonusPoints change
82+
const newValue = e.target.value ? parseInt(e.target.value) : 0;
83+
const fieldToUpdate = e.target.name;
84+
85+
let initialPoints = fieldToUpdate === "initialPoints" ? newValue : (parseInt(formData.initialPoints) || 0);
86+
let bonusPoints = fieldToUpdate === "bonusPoints" ? newValue : (parseInt(formData.bonusPoints) || 0);
87+
88+
// Calculate total points
89+
const totalPoints = initialPoints + bonusPoints;
90+
91+
setFormData({
92+
...formData,
93+
[fieldToUpdate]: e.target.value,
94+
points: totalPoints.toString()
95+
});
8096
} else {
8197
setFormData({ ...formData, [e.target.name]: e.target.value });
8298
}
@@ -169,15 +185,19 @@ export default function ChallengeManagement() {
169185
};
170186

171187
const resetForm = () => {
188+
const initialPoints = 100;
189+
const bonusPoints = 0;
190+
172191
setFormData({
173192
title: "",
174193
description: "",
175194
tag: "",
176195
resources: [""],
196+
subject: null,
177197
dependencies: [],
178-
points: 100,
179-
initialPoints: 100,
180-
bonusPoints: 0,
198+
points: initialPoints + bonusPoints, // Auto-calculate total points
199+
initialPoints: initialPoints,
200+
bonusPoints: bonusPoints,
181201
bonusLimit: 0,
182202
isAIChallenge: false,
183203
});
@@ -463,20 +483,26 @@ export default function ChallengeManagement() {
463483

464484
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 pb-2 border-b border-gray-800 mb-4">
465485
<div>
466-
<label className="block text-sm md:text-base text-gray-300 mb-2">
467-
Points
486+
<label className="flex items-center text-sm md:text-base text-gray-300 mb-2">
487+
Total Points
488+
<span className="ml-2 px-2 py-0.5 text-xs bg-purple-900/30 text-purple-400 rounded-full">Auto-calculated</span>
468489
</label>
469-
<input
470-
type="number"
471-
name="points"
472-
value={formData.points || 100}
473-
onChange={handleInputChange}
474-
className="w-full bg-gray-800 rounded-lg px-4 py-2 md:py-3 text-sm md:text-base text-white focus:ring-2 focus:ring-purple-500"
475-
min="0"
476-
required
477-
/>
490+
<div className="relative">
491+
<input
492+
type="number"
493+
name="points"
494+
value={formData.points || 100}
495+
readOnly
496+
className="w-full bg-gray-800/50 rounded-lg px-4 py-2 md:py-3 text-sm md:text-base text-gray-300 border border-gray-700 cursor-not-allowed"
497+
/>
498+
<div className="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
499+
<svg className="h-5 w-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
500+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path>
501+
</svg>
502+
</div>
503+
</div>
478504
<p className="text-xs text-gray-500 mt-1">
479-
Total points value of the challenge
505+
Initial Points + Bonus Points = Total Points
480506
</p>
481507
</div>
482508

0 commit comments

Comments
 (0)