Spaces:
Sleeping
Sleeping
Upload src/pages/Profile.tsx with huggingface_hub
Browse files- src/pages/Profile.tsx +98 -290
src/pages/Profile.tsx
CHANGED
|
@@ -15,6 +15,7 @@ interface User {
|
|
| 15 |
name: string;
|
| 16 |
email: string;
|
| 17 |
role?: string;
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
interface SystemStats {
|
|
@@ -83,7 +84,7 @@ const Manage: React.FC = () => {
|
|
| 83 |
const [editingExample, setEditingExample] = useState<PracticeExample | null>(null);
|
| 84 |
const [editingTutorialTask, setEditingTutorialTask] = useState<TutorialTask | null>(null);
|
| 85 |
const [editingWeeklyPractice, setEditingWeeklyPractice] = useState<WeeklyPractice | null>(null);
|
| 86 |
-
const [newUser, setNewUser] = useState({ name: '', email: '', role: 'student' });
|
| 87 |
const [newExample, setNewExample] = useState({
|
| 88 |
title: '',
|
| 89 |
content: '',
|
|
@@ -135,12 +136,8 @@ const Manage: React.FC = () => {
|
|
| 135 |
const fetchAdminStats = useCallback(async () => {
|
| 136 |
try {
|
| 137 |
setStatsLoading(true);
|
| 138 |
-
const response = await api.get('/auth/admin/stats');
|
| 139 |
-
|
| 140 |
-
if (response.status >= 200 && response.status < 300) {
|
| 141 |
-
const data = response.data;
|
| 142 |
-
setStats(data.stats);
|
| 143 |
-
}
|
| 144 |
} catch (error) {
|
| 145 |
console.error('Failed to fetch admin stats:', error);
|
| 146 |
} finally {
|
|
@@ -151,12 +148,8 @@ const Manage: React.FC = () => {
|
|
| 151 |
const fetchPracticeExamples = useCallback(async () => {
|
| 152 |
try {
|
| 153 |
setExamplesLoading(true);
|
| 154 |
-
const response = await api.get('/auth/admin/practice-examples');
|
| 155 |
-
|
| 156 |
-
if (response.status >= 200 && response.status < 300) {
|
| 157 |
-
const data = response.data;
|
| 158 |
-
setExamples(data.examples);
|
| 159 |
-
}
|
| 160 |
} catch (error) {
|
| 161 |
console.error('Failed to fetch practice examples:', error);
|
| 162 |
} finally {
|
|
@@ -167,12 +160,8 @@ const Manage: React.FC = () => {
|
|
| 167 |
const fetchUsers = useCallback(async () => {
|
| 168 |
try {
|
| 169 |
setUsersLoading(true);
|
| 170 |
-
const response = await api.get('/auth/admin/users');
|
| 171 |
-
|
| 172 |
-
if (response.status >= 200 && response.status < 300) {
|
| 173 |
-
const data = response.data;
|
| 174 |
-
setUsers(data.users);
|
| 175 |
-
}
|
| 176 |
} catch (error) {
|
| 177 |
console.error('Failed to fetch users:', error);
|
| 178 |
} finally {
|
|
@@ -183,12 +172,8 @@ const Manage: React.FC = () => {
|
|
| 183 |
const fetchTutorialTasks = useCallback(async () => {
|
| 184 |
try {
|
| 185 |
setTutorialTasksLoading(true);
|
| 186 |
-
const response = await api.get('/auth/admin/tutorial-tasks');
|
| 187 |
-
|
| 188 |
-
if (response.status >= 200 && response.status < 300) {
|
| 189 |
-
const data = response.data;
|
| 190 |
-
setTutorialTasks(data.tutorialTasks);
|
| 191 |
-
}
|
| 192 |
} catch (error) {
|
| 193 |
console.error('Failed to fetch tutorial tasks:', error);
|
| 194 |
} finally {
|
|
@@ -199,12 +184,8 @@ const Manage: React.FC = () => {
|
|
| 199 |
const fetchWeeklyPractice = useCallback(async () => {
|
| 200 |
try {
|
| 201 |
setWeeklyPracticeLoading(true);
|
| 202 |
-
const response = await api.get('/auth/admin/weekly-practice');
|
| 203 |
-
|
| 204 |
-
if (response.status >= 200 && response.status < 300) {
|
| 205 |
-
const data = response.data;
|
| 206 |
-
setWeeklyPractice(data.weeklyPractice);
|
| 207 |
-
}
|
| 208 |
} catch (error) {
|
| 209 |
console.error('Failed to fetch weekly practice:', error);
|
| 210 |
} finally {
|
|
@@ -224,16 +205,11 @@ const Manage: React.FC = () => {
|
|
| 224 |
|
| 225 |
const addUser = async () => {
|
| 226 |
try {
|
| 227 |
-
const response = await api.post('/auth/admin/users', newUser);
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
await fetchUsers();
|
| 233 |
-
alert('User added successfully!');
|
| 234 |
-
} else {
|
| 235 |
-
alert(`Failed to add user: ${response.data?.error || 'Unknown error'}`);
|
| 236 |
-
}
|
| 237 |
} catch (error) {
|
| 238 |
console.error('Failed to add user:', error);
|
| 239 |
alert('Failed to add user');
|
|
@@ -242,15 +218,10 @@ const Manage: React.FC = () => {
|
|
| 242 |
|
| 243 |
const updateUser = async (email: string, updates: Partial<User>) => {
|
| 244 |
try {
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
await fetchUsers();
|
| 250 |
-
alert('User updated successfully!');
|
| 251 |
-
} else {
|
| 252 |
-
alert(`Failed to update user: ${response.data?.error || 'Unknown error'}`);
|
| 253 |
-
}
|
| 254 |
} catch (error) {
|
| 255 |
console.error('Failed to update user:', error);
|
| 256 |
alert('Failed to update user');
|
|
@@ -261,14 +232,9 @@ const Manage: React.FC = () => {
|
|
| 261 |
if (!window.confirm('Are you sure you want to delete this user?')) return;
|
| 262 |
|
| 263 |
try {
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
await fetchUsers();
|
| 268 |
-
alert('User deleted successfully!');
|
| 269 |
-
} else {
|
| 270 |
-
alert(`Failed to delete user: ${response.data?.error || 'Unknown error'}`);
|
| 271 |
-
}
|
| 272 |
} catch (error) {
|
| 273 |
console.error('Failed to delete user:', error);
|
| 274 |
alert('Failed to delete user');
|
|
@@ -277,31 +243,17 @@ const Manage: React.FC = () => {
|
|
| 277 |
|
| 278 |
const addExample = async () => {
|
| 279 |
try {
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
body: JSON.stringify(newExample)
|
| 288 |
});
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
title: '',
|
| 293 |
-
content: '',
|
| 294 |
-
sourceLanguage: 'English',
|
| 295 |
-
sourceCulture: 'American',
|
| 296 |
-
difficulty: 'intermediate'
|
| 297 |
-
});
|
| 298 |
-
setShowAddExample(false);
|
| 299 |
-
await fetchPracticeExamples();
|
| 300 |
-
alert('Example added successfully!');
|
| 301 |
-
} else {
|
| 302 |
-
const error = await response.json();
|
| 303 |
-
alert(`Failed to add example: ${error.error}`);
|
| 304 |
-
}
|
| 305 |
} catch (error) {
|
| 306 |
console.error('Failed to add example:', error);
|
| 307 |
alert('Failed to add example');
|
|
@@ -310,24 +262,10 @@ const Manage: React.FC = () => {
|
|
| 310 |
|
| 311 |
const updateExample = async (id: string, updates: Partial<PracticeExample>) => {
|
| 312 |
try {
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
'Authorization': `Bearer ${token}`,
|
| 318 |
-
'Content-Type': 'application/json'
|
| 319 |
-
},
|
| 320 |
-
body: JSON.stringify(updates)
|
| 321 |
-
});
|
| 322 |
-
|
| 323 |
-
if (response.ok) {
|
| 324 |
-
setEditingExample(null);
|
| 325 |
-
await fetchPracticeExamples();
|
| 326 |
-
alert('Example updated successfully!');
|
| 327 |
-
} else {
|
| 328 |
-
const error = await response.json();
|
| 329 |
-
alert(`Failed to update example: ${error.error}`);
|
| 330 |
-
}
|
| 331 |
} catch (error) {
|
| 332 |
console.error('Failed to update example:', error);
|
| 333 |
alert('Failed to update example');
|
|
@@ -338,22 +276,9 @@ const Manage: React.FC = () => {
|
|
| 338 |
if (!window.confirm('Are you sure you want to delete this example?')) return;
|
| 339 |
|
| 340 |
try {
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
headers: {
|
| 345 |
-
'Authorization': `Bearer ${token}`,
|
| 346 |
-
'Content-Type': 'application/json'
|
| 347 |
-
}
|
| 348 |
-
});
|
| 349 |
-
|
| 350 |
-
if (response.ok) {
|
| 351 |
-
await fetchPracticeExamples();
|
| 352 |
-
alert('Example deleted successfully!');
|
| 353 |
-
} else {
|
| 354 |
-
const error = await response.json();
|
| 355 |
-
alert(`Failed to delete example: ${error.error}`);
|
| 356 |
-
}
|
| 357 |
} catch (error) {
|
| 358 |
console.error('Failed to delete example:', error);
|
| 359 |
alert('Failed to delete example');
|
|
@@ -363,36 +288,18 @@ const Manage: React.FC = () => {
|
|
| 363 |
// Tutorial Tasks CRUD
|
| 364 |
const addTutorialTask = async () => {
|
| 365 |
try {
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
'Content-Type': 'application/json',
|
| 375 |
-
'user-role': user?.role || 'student'
|
| 376 |
-
},
|
| 377 |
-
body: JSON.stringify(newTutorialTask)
|
| 378 |
});
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
title: '',
|
| 383 |
-
content: '',
|
| 384 |
-
sourceLanguage: 'English',
|
| 385 |
-
sourceCulture: 'American',
|
| 386 |
-
weekNumber: 1,
|
| 387 |
-
difficulty: 'intermediate'
|
| 388 |
-
});
|
| 389 |
-
setShowAddTutorialTask(false);
|
| 390 |
-
await fetchTutorialTasks();
|
| 391 |
-
alert('Tutorial task added successfully!');
|
| 392 |
-
} else {
|
| 393 |
-
const error = await response.json();
|
| 394 |
-
alert(`Failed to add tutorial task: ${error.error}`);
|
| 395 |
-
}
|
| 396 |
} catch (error) {
|
| 397 |
console.error('Failed to add tutorial task:', error);
|
| 398 |
alert('Failed to add tutorial task');
|
|
@@ -401,24 +308,10 @@ const Manage: React.FC = () => {
|
|
| 401 |
|
| 402 |
const updateTutorialTask = async (id: string, updates: Partial<TutorialTask>) => {
|
| 403 |
try {
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
'Authorization': `Bearer ${token}`,
|
| 409 |
-
'Content-Type': 'application/json'
|
| 410 |
-
},
|
| 411 |
-
body: JSON.stringify(updates)
|
| 412 |
-
});
|
| 413 |
-
|
| 414 |
-
if (response.ok) {
|
| 415 |
-
setEditingTutorialTask(null);
|
| 416 |
-
await fetchTutorialTasks();
|
| 417 |
-
alert('Tutorial task updated successfully!');
|
| 418 |
-
} else {
|
| 419 |
-
const error = await response.json();
|
| 420 |
-
alert(`Failed to update tutorial task: ${error.error}`);
|
| 421 |
-
}
|
| 422 |
} catch (error) {
|
| 423 |
console.error('Failed to update tutorial task:', error);
|
| 424 |
alert('Failed to update tutorial task');
|
|
@@ -429,22 +322,9 @@ const Manage: React.FC = () => {
|
|
| 429 |
if (!window.confirm('Are you sure you want to delete this tutorial task?')) return;
|
| 430 |
|
| 431 |
try {
|
| 432 |
-
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
headers: {
|
| 436 |
-
'Authorization': `Bearer ${token}`,
|
| 437 |
-
'Content-Type': 'application/json'
|
| 438 |
-
}
|
| 439 |
-
});
|
| 440 |
-
|
| 441 |
-
if (response.ok) {
|
| 442 |
-
await fetchTutorialTasks();
|
| 443 |
-
alert('Tutorial task deleted successfully!');
|
| 444 |
-
} else {
|
| 445 |
-
const error = await response.json();
|
| 446 |
-
alert(`Failed to delete tutorial task: ${error.error}`);
|
| 447 |
-
}
|
| 448 |
} catch (error) {
|
| 449 |
console.error('Failed to delete tutorial task:', error);
|
| 450 |
alert('Failed to delete tutorial task');
|
|
@@ -454,36 +334,18 @@ const Manage: React.FC = () => {
|
|
| 454 |
// Weekly Practice CRUD
|
| 455 |
const addWeeklyPractice = async () => {
|
| 456 |
try {
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
'Content-Type': 'application/json',
|
| 466 |
-
'user-role': user?.role || 'student'
|
| 467 |
-
},
|
| 468 |
-
body: JSON.stringify(newWeeklyPractice)
|
| 469 |
});
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
title: '',
|
| 474 |
-
content: '',
|
| 475 |
-
sourceLanguage: 'English',
|
| 476 |
-
sourceCulture: 'American',
|
| 477 |
-
weekNumber: 1,
|
| 478 |
-
difficulty: 'intermediate'
|
| 479 |
-
});
|
| 480 |
-
setShowAddWeeklyPractice(false);
|
| 481 |
-
await fetchWeeklyPractice();
|
| 482 |
-
alert('Weekly practice added successfully!');
|
| 483 |
-
} else {
|
| 484 |
-
const error = await response.json();
|
| 485 |
-
alert(`Failed to add weekly practice: ${error.error}`);
|
| 486 |
-
}
|
| 487 |
} catch (error) {
|
| 488 |
console.error('Failed to add weekly practice:', error);
|
| 489 |
alert('Failed to add weekly practice');
|
|
@@ -492,24 +354,10 @@ const Manage: React.FC = () => {
|
|
| 492 |
|
| 493 |
const updateWeeklyPractice = async (id: string, updates: Partial<WeeklyPractice>) => {
|
| 494 |
try {
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
'Authorization': `Bearer ${token}`,
|
| 500 |
-
'Content-Type': 'application/json'
|
| 501 |
-
},
|
| 502 |
-
body: JSON.stringify(updates)
|
| 503 |
-
});
|
| 504 |
-
|
| 505 |
-
if (response.ok) {
|
| 506 |
-
setEditingWeeklyPractice(null);
|
| 507 |
-
await fetchWeeklyPractice();
|
| 508 |
-
alert('Weekly practice updated successfully!');
|
| 509 |
-
} else {
|
| 510 |
-
const error = await response.json();
|
| 511 |
-
alert(`Failed to update weekly practice: ${error.error}`);
|
| 512 |
-
}
|
| 513 |
} catch (error) {
|
| 514 |
console.error('Failed to update weekly practice:', error);
|
| 515 |
alert('Failed to update weekly practice');
|
|
@@ -520,22 +368,9 @@ const Manage: React.FC = () => {
|
|
| 520 |
if (!window.confirm('Are you sure you want to delete this weekly practice?')) return;
|
| 521 |
|
| 522 |
try {
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
headers: {
|
| 527 |
-
'Authorization': `Bearer ${token}`,
|
| 528 |
-
'Content-Type': 'application/json'
|
| 529 |
-
}
|
| 530 |
-
});
|
| 531 |
-
|
| 532 |
-
if (response.ok) {
|
| 533 |
-
await fetchWeeklyPractice();
|
| 534 |
-
alert('Weekly practice deleted successfully!');
|
| 535 |
-
} else {
|
| 536 |
-
const error = await response.json();
|
| 537 |
-
alert(`Failed to delete weekly practice: ${error.error}`);
|
| 538 |
-
}
|
| 539 |
} catch (error) {
|
| 540 |
console.error('Failed to delete weekly practice:', error);
|
| 541 |
alert('Failed to delete weekly practice');
|
|
@@ -544,55 +379,20 @@ const Manage: React.FC = () => {
|
|
| 544 |
|
| 545 |
const addTranslationBrief = async () => {
|
| 546 |
try {
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
headers: {
|
| 554 |
-
'Authorization': `Bearer ${token}`,
|
| 555 |
-
'Content-Type': 'application/json',
|
| 556 |
-
'user-role': user?.role || 'student'
|
| 557 |
-
},
|
| 558 |
-
body: JSON.stringify(newTranslationBrief)
|
| 559 |
});
|
| 560 |
-
|
| 561 |
-
if (response.ok) {
|
| 562 |
-
setShowAddTranslationBrief(false);
|
| 563 |
-
setNewTranslationBrief({
|
| 564 |
-
weekNumber: 1,
|
| 565 |
-
translationBrief: '',
|
| 566 |
-
type: 'tutorial'
|
| 567 |
-
});
|
| 568 |
-
alert('Translation brief added successfully!');
|
| 569 |
-
} else {
|
| 570 |
-
const error = await response.json();
|
| 571 |
-
alert(`Failed to add translation brief: ${error.error}`);
|
| 572 |
-
}
|
| 573 |
} catch (error) {
|
| 574 |
console.error('Failed to add translation brief:', error);
|
| 575 |
alert('Failed to add translation brief');
|
| 576 |
}
|
| 577 |
};
|
| 578 |
|
| 579 |
-
const initializeWeeklyPractice = async () => {
|
| 580 |
-
try {
|
| 581 |
-
const response = await api.post('/search/initialize-practice-examples');
|
| 582 |
-
|
| 583 |
-
if (response.status >= 200 && response.status < 300) {
|
| 584 |
-
alert('Weekly practice data initialized successfully!');
|
| 585 |
-
await fetchWeeklyPractice();
|
| 586 |
-
} else {
|
| 587 |
-
console.error('Failed to initialize weekly practice:', response.data);
|
| 588 |
-
alert('Failed to initialize weekly practice data');
|
| 589 |
-
}
|
| 590 |
-
} catch (error) {
|
| 591 |
-
console.error('Failed to initialize weekly practice:', error);
|
| 592 |
-
alert('Failed to initialize weekly practice data');
|
| 593 |
-
}
|
| 594 |
-
};
|
| 595 |
-
|
| 596 |
const handleLogout = () => {
|
| 597 |
localStorage.removeItem('token');
|
| 598 |
localStorage.removeItem('user');
|
|
@@ -685,6 +485,13 @@ const Manage: React.FC = () => {
|
|
| 685 |
onChange={(e) => setNewUser({...newUser, name: e.target.value})}
|
| 686 |
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 687 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
<input
|
| 689 |
type="email"
|
| 690 |
placeholder="Email"
|
|
@@ -765,6 +572,13 @@ const Manage: React.FC = () => {
|
|
| 765 |
onChange={(e) => setEditingUser({...editingUser, name: e.target.value})}
|
| 766 |
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 767 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
<input
|
| 769 |
type="email"
|
| 770 |
placeholder="Email"
|
|
@@ -1370,12 +1184,6 @@ const Manage: React.FC = () => {
|
|
| 1370 |
>
|
| 1371 |
Refresh
|
| 1372 |
</button>
|
| 1373 |
-
<button
|
| 1374 |
-
onClick={initializeWeeklyPractice}
|
| 1375 |
-
className="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-md text-sm font-medium ml-2"
|
| 1376 |
-
>
|
| 1377 |
-
Initialize Week 1 Practice
|
| 1378 |
-
</button>
|
| 1379 |
</div>
|
| 1380 |
|
| 1381 |
{/* Weekly Practice List */}
|
|
|
|
| 15 |
name: string;
|
| 16 |
email: string;
|
| 17 |
role?: string;
|
| 18 |
+
displayName?: string;
|
| 19 |
}
|
| 20 |
|
| 21 |
interface SystemStats {
|
|
|
|
| 84 |
const [editingExample, setEditingExample] = useState<PracticeExample | null>(null);
|
| 85 |
const [editingTutorialTask, setEditingTutorialTask] = useState<TutorialTask | null>(null);
|
| 86 |
const [editingWeeklyPractice, setEditingWeeklyPractice] = useState<WeeklyPractice | null>(null);
|
| 87 |
+
const [newUser, setNewUser] = useState({ name: '', displayName: '', email: '', role: 'student' });
|
| 88 |
const [newExample, setNewExample] = useState({
|
| 89 |
title: '',
|
| 90 |
content: '',
|
|
|
|
| 136 |
const fetchAdminStats = useCallback(async () => {
|
| 137 |
try {
|
| 138 |
setStatsLoading(true);
|
| 139 |
+
const response = await api.get('/api/auth/admin/stats');
|
| 140 |
+
setStats(response.data.stats);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
} catch (error) {
|
| 142 |
console.error('Failed to fetch admin stats:', error);
|
| 143 |
} finally {
|
|
|
|
| 148 |
const fetchPracticeExamples = useCallback(async () => {
|
| 149 |
try {
|
| 150 |
setExamplesLoading(true);
|
| 151 |
+
const response = await api.get('/api/auth/admin/practice-examples');
|
| 152 |
+
setExamples(response.data.examples);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
} catch (error) {
|
| 154 |
console.error('Failed to fetch practice examples:', error);
|
| 155 |
} finally {
|
|
|
|
| 160 |
const fetchUsers = useCallback(async () => {
|
| 161 |
try {
|
| 162 |
setUsersLoading(true);
|
| 163 |
+
const response = await api.get('/api/auth/admin/users');
|
| 164 |
+
setUsers(response.data.users);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
} catch (error) {
|
| 166 |
console.error('Failed to fetch users:', error);
|
| 167 |
} finally {
|
|
|
|
| 172 |
const fetchTutorialTasks = useCallback(async () => {
|
| 173 |
try {
|
| 174 |
setTutorialTasksLoading(true);
|
| 175 |
+
const response = await api.get('/api/auth/admin/tutorial-tasks');
|
| 176 |
+
setTutorialTasks(response.data.tutorialTasks);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
} catch (error) {
|
| 178 |
console.error('Failed to fetch tutorial tasks:', error);
|
| 179 |
} finally {
|
|
|
|
| 184 |
const fetchWeeklyPractice = useCallback(async () => {
|
| 185 |
try {
|
| 186 |
setWeeklyPracticeLoading(true);
|
| 187 |
+
const response = await api.get('/api/auth/admin/weekly-practice');
|
| 188 |
+
setWeeklyPractice(response.data.weeklyPractice);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
} catch (error) {
|
| 190 |
console.error('Failed to fetch weekly practice:', error);
|
| 191 |
} finally {
|
|
|
|
| 205 |
|
| 206 |
const addUser = async () => {
|
| 207 |
try {
|
| 208 |
+
const response = await api.post('/api/auth/admin/users', newUser);
|
| 209 |
+
setNewUser({ name: '', email: '', role: 'student' });
|
| 210 |
+
setShowAddUser(false);
|
| 211 |
+
await fetchUsers();
|
| 212 |
+
alert('User added successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
} catch (error) {
|
| 214 |
console.error('Failed to add user:', error);
|
| 215 |
alert('Failed to add user');
|
|
|
|
| 218 |
|
| 219 |
const updateUser = async (email: string, updates: Partial<User>) => {
|
| 220 |
try {
|
| 221 |
+
await api.put(`/api/auth/admin/users/${email}`, updates);
|
| 222 |
+
setEditingUser(null);
|
| 223 |
+
await fetchUsers();
|
| 224 |
+
alert('User updated successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
} catch (error) {
|
| 226 |
console.error('Failed to update user:', error);
|
| 227 |
alert('Failed to update user');
|
|
|
|
| 232 |
if (!window.confirm('Are you sure you want to delete this user?')) return;
|
| 233 |
|
| 234 |
try {
|
| 235 |
+
await api.delete(`/api/auth/admin/users/${email}`);
|
| 236 |
+
await fetchUsers();
|
| 237 |
+
alert('User deleted successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
} catch (error) {
|
| 239 |
console.error('Failed to delete user:', error);
|
| 240 |
alert('Failed to delete user');
|
|
|
|
| 243 |
|
| 244 |
const addExample = async () => {
|
| 245 |
try {
|
| 246 |
+
await api.post('/api/auth/admin/practice-examples', newExample);
|
| 247 |
+
setNewExample({
|
| 248 |
+
title: '',
|
| 249 |
+
content: '',
|
| 250 |
+
sourceLanguage: 'English',
|
| 251 |
+
sourceCulture: 'American',
|
| 252 |
+
difficulty: 'intermediate'
|
|
|
|
| 253 |
});
|
| 254 |
+
setShowAddExample(false);
|
| 255 |
+
await fetchPracticeExamples();
|
| 256 |
+
alert('Example added successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
} catch (error) {
|
| 258 |
console.error('Failed to add example:', error);
|
| 259 |
alert('Failed to add example');
|
|
|
|
| 262 |
|
| 263 |
const updateExample = async (id: string, updates: Partial<PracticeExample>) => {
|
| 264 |
try {
|
| 265 |
+
await api.put(`/api/auth/admin/practice-examples/${id}`, updates);
|
| 266 |
+
setEditingExample(null);
|
| 267 |
+
await fetchPracticeExamples();
|
| 268 |
+
alert('Example updated successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
} catch (error) {
|
| 270 |
console.error('Failed to update example:', error);
|
| 271 |
alert('Failed to update example');
|
|
|
|
| 276 |
if (!window.confirm('Are you sure you want to delete this example?')) return;
|
| 277 |
|
| 278 |
try {
|
| 279 |
+
await api.delete(`/api/auth/admin/practice-examples/${id}`);
|
| 280 |
+
await fetchPracticeExamples();
|
| 281 |
+
alert('Example deleted successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
} catch (error) {
|
| 283 |
console.error('Failed to delete example:', error);
|
| 284 |
alert('Failed to delete example');
|
|
|
|
| 288 |
// Tutorial Tasks CRUD
|
| 289 |
const addTutorialTask = async () => {
|
| 290 |
try {
|
| 291 |
+
await api.post('/api/auth/admin/tutorial-tasks', newTutorialTask);
|
| 292 |
+
setNewTutorialTask({
|
| 293 |
+
title: '',
|
| 294 |
+
content: '',
|
| 295 |
+
sourceLanguage: 'English',
|
| 296 |
+
sourceCulture: 'American',
|
| 297 |
+
weekNumber: 1,
|
| 298 |
+
difficulty: 'intermediate'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
});
|
| 300 |
+
setShowAddTutorialTask(false);
|
| 301 |
+
await fetchTutorialTasks();
|
| 302 |
+
alert('Tutorial task added successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
} catch (error) {
|
| 304 |
console.error('Failed to add tutorial task:', error);
|
| 305 |
alert('Failed to add tutorial task');
|
|
|
|
| 308 |
|
| 309 |
const updateTutorialTask = async (id: string, updates: Partial<TutorialTask>) => {
|
| 310 |
try {
|
| 311 |
+
await api.put(`/api/auth/admin/tutorial-tasks/${id}`, updates);
|
| 312 |
+
setEditingTutorialTask(null);
|
| 313 |
+
await fetchTutorialTasks();
|
| 314 |
+
alert('Tutorial task updated successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
} catch (error) {
|
| 316 |
console.error('Failed to update tutorial task:', error);
|
| 317 |
alert('Failed to update tutorial task');
|
|
|
|
| 322 |
if (!window.confirm('Are you sure you want to delete this tutorial task?')) return;
|
| 323 |
|
| 324 |
try {
|
| 325 |
+
await api.delete(`/api/auth/admin/tutorial-tasks/${id}`);
|
| 326 |
+
await fetchTutorialTasks();
|
| 327 |
+
alert('Tutorial task deleted successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 328 |
} catch (error) {
|
| 329 |
console.error('Failed to delete tutorial task:', error);
|
| 330 |
alert('Failed to delete tutorial task');
|
|
|
|
| 334 |
// Weekly Practice CRUD
|
| 335 |
const addWeeklyPractice = async () => {
|
| 336 |
try {
|
| 337 |
+
await api.post('/api/auth/admin/weekly-practice', newWeeklyPractice);
|
| 338 |
+
setNewWeeklyPractice({
|
| 339 |
+
title: '',
|
| 340 |
+
content: '',
|
| 341 |
+
sourceLanguage: 'English',
|
| 342 |
+
sourceCulture: 'American',
|
| 343 |
+
weekNumber: 1,
|
| 344 |
+
difficulty: 'intermediate'
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
});
|
| 346 |
+
setShowAddWeeklyPractice(false);
|
| 347 |
+
await fetchWeeklyPractice();
|
| 348 |
+
alert('Weekly practice added successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
} catch (error) {
|
| 350 |
console.error('Failed to add weekly practice:', error);
|
| 351 |
alert('Failed to add weekly practice');
|
|
|
|
| 354 |
|
| 355 |
const updateWeeklyPractice = async (id: string, updates: Partial<WeeklyPractice>) => {
|
| 356 |
try {
|
| 357 |
+
await api.put(`/api/auth/admin/weekly-practice/${id}`, updates);
|
| 358 |
+
setEditingWeeklyPractice(null);
|
| 359 |
+
await fetchWeeklyPractice();
|
| 360 |
+
alert('Weekly practice updated successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
} catch (error) {
|
| 362 |
console.error('Failed to update weekly practice:', error);
|
| 363 |
alert('Failed to update weekly practice');
|
|
|
|
| 368 |
if (!window.confirm('Are you sure you want to delete this weekly practice?')) return;
|
| 369 |
|
| 370 |
try {
|
| 371 |
+
await api.delete(`/api/auth/admin/weekly-practice/${id}`);
|
| 372 |
+
await fetchWeeklyPractice();
|
| 373 |
+
alert('Weekly practice deleted successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
} catch (error) {
|
| 375 |
console.error('Failed to delete weekly practice:', error);
|
| 376 |
alert('Failed to delete weekly practice');
|
|
|
|
| 379 |
|
| 380 |
const addTranslationBrief = async () => {
|
| 381 |
try {
|
| 382 |
+
await api.post('/api/auth/admin/translation-brief', newTranslationBrief);
|
| 383 |
+
setShowAddTranslationBrief(false);
|
| 384 |
+
setNewTranslationBrief({
|
| 385 |
+
weekNumber: 1,
|
| 386 |
+
translationBrief: '',
|
| 387 |
+
type: 'tutorial'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
});
|
| 389 |
+
alert('Translation brief added successfully!');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
} catch (error) {
|
| 391 |
console.error('Failed to add translation brief:', error);
|
| 392 |
alert('Failed to add translation brief');
|
| 393 |
}
|
| 394 |
};
|
| 395 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 396 |
const handleLogout = () => {
|
| 397 |
localStorage.removeItem('token');
|
| 398 |
localStorage.removeItem('user');
|
|
|
|
| 485 |
onChange={(e) => setNewUser({...newUser, name: e.target.value})}
|
| 486 |
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 487 |
/>
|
| 488 |
+
<input
|
| 489 |
+
type="text"
|
| 490 |
+
placeholder="Display Name (optional)"
|
| 491 |
+
value={newUser.displayName}
|
| 492 |
+
onChange={(e) => setNewUser({...newUser, displayName: e.target.value})}
|
| 493 |
+
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 494 |
+
/>
|
| 495 |
<input
|
| 496 |
type="email"
|
| 497 |
placeholder="Email"
|
|
|
|
| 572 |
onChange={(e) => setEditingUser({...editingUser, name: e.target.value})}
|
| 573 |
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 574 |
/>
|
| 575 |
+
<input
|
| 576 |
+
type="text"
|
| 577 |
+
placeholder="Display Name (optional)"
|
| 578 |
+
value={editingUser.displayName || ''}
|
| 579 |
+
onChange={(e) => setEditingUser({...editingUser, displayName: e.target.value})}
|
| 580 |
+
className="w-full px-3 py-2 border border-gray-300 rounded-md"
|
| 581 |
+
/>
|
| 582 |
<input
|
| 583 |
type="email"
|
| 584 |
placeholder="Email"
|
|
|
|
| 1184 |
>
|
| 1185 |
Refresh
|
| 1186 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1187 |
</div>
|
| 1188 |
|
| 1189 |
{/* Weekly Practice List */}
|