Spaces:
Sleeping
Sleeping
File size: 58,308 Bytes
8a760a2 4bad287 8a760a2 6c9b965 8a760a2 4bad287 8a760a2 4bad287 8a760a2 f4b51b9 14ab027 8a760a2 f4b51b9 8a760a2 c4c7e4c 14ab027 eec598e 14ab027 eec598e 8a760a2 14ab027 eec598e 8a760a2 14ab027 8a760a2 eec598e 14ab027 8a760a2 14ab027 8a760a2 14ab027 eec598e 14ab027 eec598e 14ab027 eec598e 14ab027 8a760a2 14ab027 7beeec1 14ab027 7beeec1 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 eec598e 8a760a2 eec598e 8a760a2 eec598e 8a760a2 14ab027 8a760a2 14ab027 eec598e 8a760a2 14ab027 8a760a2 14ab027 8a760a2 4bad287 8a760a2 02f1559 8a760a2 02f1559 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 eec598e 8a760a2 14ab027 8a760a2 14ab027 8a760a2 4bad287 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 eec598e 14ab027 c4c7e4c 14ab027 8a760a2 14ab027 8a760a2 14ab027 0759bb6 14ab027 dd0e507 14ab027 2104f8a 8a760a2 02f1559 8a760a2 02f1559 8a760a2 14ab027 8a760a2 14ab027 eec598e 14ab027 e9c3e64 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 14ab027 eaf86e0 14ab027 8a760a2 14ab027 8a760a2 14ab027 8a760a2 6c9b965 8a760a2 f4b51b9 14ab027 f4b51b9 8a760a2 f4b51b9 8a760a2 14ab027 8a760a2 03294ba 14ab027 03294ba 14ab027 f4b51b9 14ab027 f4b51b9 14ab027 8a760a2 14ab027 0090241 14ab027 6c9b965 14ab027 0090241 14ab027 6c9b965 14ab027 0090241 03294ba 0090241 14ab027 03294ba 14ab027 8a760a2 14ab027 8a760a2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 |
import React, { useState, useEffect, useCallback } from 'react';
import { useNavigate } from 'react-router-dom';
import { api } from '../services/api';
import {
AcademicCapIcon,
DocumentTextIcon,
CheckCircleIcon,
ClockIcon,
ArrowRightIcon,
PencilIcon,
XMarkIcon,
CheckIcon,
PlusIcon,
TrashIcon
} from '@heroicons/react/24/outline';
interface TutorialTask {
_id: string;
content: string;
weekNumber: number;
translationBrief?: string;
imageUrl?: string;
imageAlt?: string;
}
interface TutorialWeek {
weekNumber: number;
translationBrief?: string;
tasks: TutorialTask[];
}
interface UserSubmission {
_id: string;
transcreation: string;
status: string;
score: number;
groupNumber?: number;
isOwner?: boolean;
userId?: {
_id: string;
username: string;
};
voteCounts: {
'1': number;
'2': number;
'3': number;
};
}
const TutorialTasks: React.FC = () => {
const [selectedWeek, setSelectedWeek] = useState<number>(() => {
const savedWeek = localStorage.getItem('selectedTutorialWeek');
return savedWeek ? parseInt(savedWeek) : 1;
});
const [tutorialTasks, setTutorialTasks] = useState<TutorialTask[]>([]);
const [tutorialWeek, setTutorialWeek] = useState<TutorialWeek | null>(null);
const [userSubmissions, setUserSubmissions] = useState<{[key: string]: UserSubmission[]}>({});
const [loading, setLoading] = useState(true);
const [submitting, setSubmitting] = useState<{[key: string]: boolean}>({});
const [translationText, setTranslationText] = useState<{[key: string]: string}>({});
const [selectedGroups, setSelectedGroups] = useState<{[key: string]: number}>({});
const [expandedSections, setExpandedSections] = useState<{[key: string]: boolean}>({});
const [editingTask, setEditingTask] = useState<string | null>(null);
const [editingBrief, setEditingBrief] = useState<{[key: number]: boolean}>({});
const [addingTask, setAddingTask] = useState<boolean>(false);
const [editForm, setEditForm] = useState<{
content: string;
translationBrief: string;
imageUrl: string;
imageAlt: string;
}>({
content: '',
translationBrief: '',
imageUrl: '',
imageAlt: ''
});
const [selectedFile, setSelectedFile] = useState<File | null>(null);
const [uploading, setUploading] = useState(false);
const [saving, setSaving] = useState(false);
const navigate = useNavigate();
const weeks = [1, 2, 3, 4, 5, 6];
const handleFileUpload = async (file: File): Promise<string> => {
try {
setUploading(true);
// Convert file to data URL for display
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => {
const dataUrl = reader.result as string;
console.log('File uploaded:', file.name, 'Size:', file.size);
console.log('Generated data URL:', dataUrl.substring(0, 50) + '...');
resolve(dataUrl);
};
reader.onerror = () => {
console.error('Error reading file:', reader.error);
reject(reader.error);
};
reader.readAsDataURL(file);
});
} catch (error) {
console.error('Error uploading file:', error);
throw error;
} finally {
setUploading(false);
}
};
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (file) {
setSelectedFile(file);
}
};
const toggleExpanded = (taskId: string) => {
setExpandedSections(prev => ({
...prev,
[taskId]: !prev[taskId]
}));
};
const fetchUserSubmissions = useCallback(async (tasks: TutorialTask[]) => {
try {
const token = localStorage.getItem('token');
const user = localStorage.getItem('user');
if (!token || !user) {
return;
}
const response = await api.get('/submissions/my-submissions');
if (response.data && response.data.submissions) {
const data = response.data;
const groupedSubmissions: {[key: string]: UserSubmission[]} = {};
// Initialize all tasks with empty arrays
tasks.forEach(task => {
groupedSubmissions[task._id] = [];
});
// Then populate with actual submissions
if (data.submissions && Array.isArray(data.submissions)) {
data.submissions.forEach((submission: any) => {
// Extract the actual ID from sourceTextId (could be string or object)
const sourceTextId = submission.sourceTextId?._id || submission.sourceTextId;
if (sourceTextId && groupedSubmissions[sourceTextId]) {
groupedSubmissions[sourceTextId].push(submission);
}
});
}
setUserSubmissions(groupedSubmissions);
}
} catch (error) {
console.error('Error fetching user submissions:', error);
}
}, []);
const fetchTutorialTasks = useCallback(async (showLoading = true) => {
try {
if (showLoading) {
setLoading(true);
}
const token = localStorage.getItem('token');
const user = localStorage.getItem('user');
if (!token || !user) {
navigate('/login');
return;
}
const response = await api.get(`/search/tutorial-tasks/${selectedWeek}`);
if (response.data) {
const tasks = response.data;
console.log('Fetched tasks:', tasks);
console.log('Tasks with images:', tasks.filter((task: TutorialTask) => task.imageUrl));
// Debug: Log each task's fields
tasks.forEach((task: any, index: number) => {
console.log(`Task ${index} fields:`, {
_id: task._id,
content: task.content,
imageUrl: task.imageUrl,
imageAlt: task.imageAlt,
translationBrief: task.translationBrief,
weekNumber: task.weekNumber,
category: task.category
});
console.log(`Task ${index} imageUrl:`, task.imageUrl);
console.log(`Task ${index} translationBrief:`, task.translationBrief);
});
setTutorialTasks(tasks);
// Use translation brief from tasks or localStorage
let translationBrief = null;
if (tasks.length > 0) {
translationBrief = tasks[0].translationBrief;
console.log('Translation brief from task:', translationBrief);
} else {
// Check localStorage for brief if no tasks exist
const briefKey = `translationBrief_week_${selectedWeek}`;
translationBrief = localStorage.getItem(briefKey);
console.log('Translation brief from localStorage:', translationBrief);
console.log('localStorage key:', briefKey);
}
console.log('Final translation brief:', translationBrief);
const tutorialWeekData: TutorialWeek = {
weekNumber: selectedWeek,
translationBrief: translationBrief,
tasks: tasks
};
setTutorialWeek(tutorialWeekData);
await fetchUserSubmissions(tasks);
} else {
console.error('Failed to fetch tutorial tasks');
}
} catch (error) {
console.error('Error fetching tutorial tasks:', error);
} finally {
if (showLoading) {
setLoading(false);
}
}
}, [selectedWeek, fetchUserSubmissions, navigate]);
useEffect(() => {
const user = localStorage.getItem('user');
if (!user) {
navigate('/login');
return;
}
fetchTutorialTasks();
}, [fetchTutorialTasks, navigate]);
// Refresh submissions when user changes (after login/logout)
useEffect(() => {
const user = localStorage.getItem('user');
if (user && tutorialTasks.length > 0) {
fetchUserSubmissions(tutorialTasks);
}
}, [tutorialTasks, fetchUserSubmissions]);
const handleSubmitTranslation = async (taskId: string) => {
if (!translationText[taskId]?.trim()) {
return;
}
if (!selectedGroups[taskId]) {
return;
}
try {
setSubmitting({ ...submitting, [taskId]: true });
const user = JSON.parse(localStorage.getItem('user') || '{}');
const response = await api.post('/submissions', {
sourceTextId: taskId,
transcreation: translationText[taskId],
groupNumber: selectedGroups[taskId],
culturalAdaptations: [],
username: user.name || 'Unknown'
});
if (response.status >= 200 && response.status < 300) {
const result = response.data;
console.log('Submission created successfully:', result);
setTranslationText({ ...translationText, [taskId]: '' });
setSelectedGroups({ ...selectedGroups, [taskId]: 0 });
await fetchUserSubmissions(tutorialTasks);
} else {
console.error('Failed to submit translation:', response.data);
}
} catch (error) {
console.error('Error submitting translation:', error);
} finally {
setSubmitting({ ...submitting, [taskId]: false });
}
};
const [editingSubmission, setEditingSubmission] = useState<{id: string, text: string} | null>(null);
const [editSubmissionText, setEditSubmissionText] = useState('');
const handleEditSubmission = async (submissionId: string, currentText: string) => {
setEditingSubmission({ id: submissionId, text: currentText });
setEditSubmissionText(currentText);
};
const saveEditedSubmission = async () => {
if (!editingSubmission || !editSubmissionText.trim()) return;
try {
const response = await api.put(`/submissions/${editingSubmission.id}`, {
transcreation: editSubmissionText
});
if (response.status >= 200 && response.status < 300) {
setEditingSubmission(null);
setEditSubmissionText('');
await fetchUserSubmissions(tutorialTasks);
} else {
console.error('Failed to update translation:', response.data);
}
} catch (error) {
console.error('Error updating translation:', error);
}
};
const cancelEditSubmission = () => {
setEditingSubmission(null);
setEditSubmissionText('');
};
const handleDeleteSubmission = async (submissionId: string) => {
try {
const response = await api.delete(`/submissions/${submissionId}`);
if (response.status === 200) {
await fetchUserSubmissions(tutorialTasks);
} else {
}
} catch (error) {
console.error('Error deleting submission:', error);
}
};
const getStatusIcon = (status: string) => {
switch (status) {
case 'approved':
return <CheckCircleIcon className="h-5 w-5 text-green-500" />;
case 'pending':
return <ClockIcon className="h-5 w-5 text-yellow-500" />;
default:
return <ClockIcon className="h-5 w-5 text-gray-500" />;
}
};
const startEditing = (task: TutorialTask) => {
setEditingTask(task._id);
setEditForm({
content: task.content,
translationBrief: task.translationBrief || '',
imageUrl: task.imageUrl || '',
imageAlt: task.imageAlt || ''
});
};
const startEditingBrief = () => {
setEditingBrief(prev => ({ ...prev, [selectedWeek]: true }));
setEditForm({
content: '',
translationBrief: tutorialWeek?.translationBrief || '',
imageUrl: '',
imageAlt: ''
});
};
const startAddingBrief = () => {
setEditingBrief(prev => ({ ...prev, [selectedWeek]: true }));
setEditForm({
content: '',
translationBrief: '',
imageUrl: '',
imageAlt: ''
});
};
const removeBrief = async () => {
try {
setSaving(true);
const token = localStorage.getItem('token');
const user = JSON.parse(localStorage.getItem('user') || '{}');
// Check if user is admin
if (user.role !== 'admin') {
return;
}
const response = await api.put(`/auth/admin/tutorial-brief/${selectedWeek}`, {
translationBrief: '',
weekNumber: selectedWeek
});
if (response.status >= 200 && response.status < 300) {
await fetchTutorialTasks();
} else {
console.error('Failed to remove translation brief:', response.data);
}
} catch (error) {
console.error('Failed to remove translation brief:', error);
} finally {
setSaving(false);
}
};
const cancelEditing = () => {
setEditingTask(null);
setEditingBrief(prev => ({ ...prev, [selectedWeek]: false }));
setEditForm({
content: '',
translationBrief: '',
imageUrl: '',
imageAlt: ''
});
setSelectedFile(null);
};
const saveTask = async () => {
if (!editingTask) return;
try {
setSaving(true);
const token = localStorage.getItem('token');
const user = JSON.parse(localStorage.getItem('user') || '{}');
// Check if user is admin
if (user.role !== 'admin') {
return;
}
const updateData = {
...editForm,
weekNumber: selectedWeek
};
console.log('Saving task with data:', updateData);
const response = await api.put(`/auth/admin/tutorial-tasks/${editingTask}`, updateData);
if (response.status >= 200 && response.status < 300) {
await fetchTutorialTasks(false);
setEditingTask(null);
} else {
console.error('Failed to update tutorial task:', response.data);
}
} catch (error) {
console.error('Failed to update tutorial task:', error);
} finally {
setSaving(false);
}
};
const saveBrief = async () => {
try {
setSaving(true);
const user = JSON.parse(localStorage.getItem('user') || '{}');
// Check if user is admin
if (user.role !== 'admin') {
return;
}
console.log('Saving brief for week:', selectedWeek);
console.log('Brief content:', editForm.translationBrief);
// Save brief by creating or updating the first task of the week
if (tutorialTasks.length > 0) {
const firstTask = tutorialTasks[0];
console.log('Updating first task with brief:', firstTask._id);
const response = await api.put(`/auth/admin/tutorial-tasks/${firstTask._id}`, {
...firstTask,
translationBrief: editForm.translationBrief,
weekNumber: selectedWeek
});
if (response.status >= 200 && response.status < 300) {
console.log('Brief saved successfully');
await fetchTutorialTasks(false);
setEditingBrief(prev => ({ ...prev, [selectedWeek]: false }));
} else {
console.error('Failed to save brief:', response.data);
}
} else {
// If no tasks exist, save the brief to localStorage
console.log('No tasks available to save brief to - saving to localStorage');
const briefKey = `translationBrief_week_${selectedWeek}`;
localStorage.setItem(briefKey, editForm.translationBrief);
setEditingBrief(prev => ({ ...prev, [selectedWeek]: false }));
}
} catch (error) {
console.error('Failed to update translation brief:', error);
} finally {
setSaving(false);
}
};
const startAddingTask = () => {
setAddingTask(true);
setEditForm({
content: '',
translationBrief: '',
imageUrl: '',
imageAlt: ''
});
};
const cancelAddingTask = () => {
setAddingTask(false);
setEditForm({
content: '',
translationBrief: '',
imageUrl: '',
imageAlt: ''
});
setSelectedFile(null);
};
const saveNewTask = async () => {
try {
setSaving(true);
const user = JSON.parse(localStorage.getItem('user') || '{}');
// Check if user is admin
if (user.role !== 'admin') {
return;
}
if (!editForm.content.trim()) {
return;
}
console.log('Saving new task for week:', selectedWeek);
console.log('Task content:', editForm.content);
console.log('Image URL:', editForm.imageUrl);
console.log('Image Alt:', editForm.imageAlt);
const taskData = {
title: `Week ${selectedWeek} Tutorial Task`,
content: editForm.content,
sourceLanguage: 'English',
weekNumber: selectedWeek,
category: 'tutorial',
imageUrl: editForm.imageUrl || null,
imageAlt: editForm.imageAlt || null
};
console.log('Task data being sent:', JSON.stringify(taskData, null, 2));
console.log('Sending task data:', taskData);
const response = await api.post('/auth/admin/tutorial-tasks', taskData);
console.log('Task save response:', response.data);
if (response.status >= 200 && response.status < 300) {
console.log('Task saved successfully');
console.log('Saved task response:', response.data);
console.log('Saved task response keys:', Object.keys(response.data || {}));
console.log('Saved task response.task:', response.data?.task);
console.log('Saved task response.task.imageUrl:', response.data?.task?.imageUrl);
console.log('Saved task response.task.translationBrief:', response.data?.task?.translationBrief);
await fetchTutorialTasks(false);
setAddingTask(false);
} else {
console.error('Failed to add tutorial task:', response.data);
}
} catch (error) {
console.error('Failed to add tutorial task:', error);
} finally {
setSaving(false);
}
};
const deleteTask = async (taskId: string) => {
try {
const token = localStorage.getItem('token');
const user = JSON.parse(localStorage.getItem('user') || '{}');
// Check if user is admin
if (user.role !== 'admin') {
return;
}
const response = await api.delete(`/auth/admin/tutorial-tasks/${taskId}`);
if (response.status >= 200 && response.status < 300) {
await fetchTutorialTasks(false);
} else {
console.error('Failed to delete tutorial task:', response.data);
}
} catch (error) {
console.error('Failed to delete tutorial task:', error);
}
};
// Remove intrusive loading screen - just show content with loading state
return (
<div className="min-h-screen bg-gray-50 py-8">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
{/* Header */}
<div className="mb-8">
<div className="flex items-center mb-4">
<AcademicCapIcon className="h-8 w-8 text-indigo-900 mr-3" />
<h1 className="text-3xl font-bold text-gray-900">Tutorial Tasks</h1>
</div>
<p className="text-gray-600">
Complete weekly tutorial tasks with your group to practice collaborative translation skills.
</p>
</div>
{/* Week Selector */}
<div className="mb-6">
<div className="flex space-x-2 overflow-x-auto pb-2">
{weeks.map((week) => (
<button
key={week}
onClick={() => {
setSelectedWeek(week);
localStorage.setItem('selectedTutorialWeek', week.toString());
}}
className={`px-4 py-2 rounded-lg font-medium whitespace-nowrap ${
selectedWeek === week
? 'bg-indigo-600 text-white'
: 'bg-white text-gray-700 hover:bg-gray-50 border border-gray-300'
}`}
>
Week {week}
</button>
))}
</div>
</div>
{/* Translation Brief - Shown once at the top */}
{tutorialWeek && tutorialWeek.translationBrief ? (
<div className="bg-white rounded-lg p-6 mb-8 border border-gray-200 shadow-sm">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-3">
<div className="bg-indigo-600 rounded-lg p-2">
<DocumentTextIcon className="h-5 w-5 text-white" />
</div>
<h3 className="text-indigo-900 font-semibold text-xl">Translation Brief</h3>
</div>
{JSON.parse(localStorage.getItem('user') || '{}').role === 'admin' && (
<div className="flex items-center space-x-2">
{editingBrief[selectedWeek] ? (
<>
<button
onClick={saveBrief}
disabled={saving}
className="bg-indigo-500 hover:bg-indigo-600 text-white px-3 py-1 rounded-md transition-colors duration-200 text-sm"
>
{saving ? (
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
) : (
<CheckIcon className="h-4 w-4" />
)}
</button>
<button
onClick={cancelEditing}
className="bg-gray-500 hover:bg-gray-600 text-white px-3 py-1 rounded-md transition-colors duration-200 text-sm"
>
<XMarkIcon className="h-4 w-4" />
</button>
</>
) : (
<>
<button
onClick={startEditingBrief}
className="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md transition-colors duration-200 text-sm"
>
<PencilIcon className="h-4 w-4" />
</button>
<button
onClick={() => removeBrief()}
className="bg-red-100 hover:bg-red-200 text-red-700 px-3 py-1 rounded-md transition-colors duration-200 text-sm"
>
<TrashIcon className="h-4 w-4" />
</button>
</>
)}
</div>
)}
</div>
{editingBrief[selectedWeek] ? (
<textarea
value={editForm.translationBrief}
onChange={(e) => setEditForm({ ...editForm, translationBrief: e.target.value })}
className="w-full p-4 border border-gray-300 rounded-lg text-gray-900 leading-relaxed text-base bg-white focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
rows={6}
placeholder="Enter translation brief..."
/>
) : (
<p className="text-gray-900 leading-relaxed text-lg font-smiley">{tutorialWeek.translationBrief}</p>
)}
<div className="mt-4 p-3 bg-indigo-50 rounded-lg">
<p className="text-indigo-900 text-sm">
<strong>Note:</strong> Tutorial tasks are completed as group submissions. Each group should collaborate to create a single translation per task.
</p>
</div>
</div>
) : (
// Show add brief button when no brief exists
JSON.parse(localStorage.getItem('user') || '{}').role === 'admin' && (
<div className="bg-white rounded-lg p-6 mb-8 border border-gray-200 border-dashed shadow-sm">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-3">
<div className="bg-indigo-100 rounded-lg p-2">
<DocumentTextIcon className="h-5 w-5 text-indigo-900" />
</div>
<h3 className="text-indigo-900 font-semibold text-xl">Translation Brief</h3>
</div>
<button
onClick={startAddingBrief}
className="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium flex items-center space-x-2 shadow-sm"
>
<PlusIcon className="h-5 w-5" />
<span className="font-medium">Add Brief</span>
</button>
</div>
{editingBrief[selectedWeek] && (
<div className="space-y-4">
<textarea
value={editForm.translationBrief}
onChange={(e) => setEditForm({ ...editForm, translationBrief: e.target.value })}
className="w-full p-4 border border-gray-300 rounded-lg text-gray-900 leading-relaxed text-base bg-white focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
rows={6}
placeholder="Enter translation brief..."
/>
<div className="flex justify-end space-x-2">
<button
onClick={saveBrief}
disabled={saving}
className="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium flex items-center space-x-2 shadow-sm"
>
{saving ? (
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
) : (
<>
<CheckIcon className="h-5 w-5" />
<span className="font-medium">Save Brief</span>
</>
)}
</button>
<button
onClick={cancelEditing}
className="bg-gray-500 hover:bg-gray-600 text-white px-6 py-3 rounded-lg font-medium flex items-center space-x-2 shadow-sm"
>
<XMarkIcon className="h-5 w-5" />
<span className="font-medium">Cancel</span>
</button>
</div>
</div>
)}
</div>
)
)}
{/* Tutorial Tasks */}
<div className="space-y-6">
{/* Add New Tutorial Task Section */}
{JSON.parse(localStorage.getItem('user') || '{}').role === 'admin' && (
<div className="mb-8">
{addingTask ? (
<div className="bg-white rounded-lg p-6 border border-gray-200 shadow-sm">
<div className="flex items-center space-x-3 mb-4">
<div className="bg-gray-100 rounded-lg p-2">
<PlusIcon className="h-4 w-4 text-gray-600" />
</div>
<h4 className="text-gray-900 font-semibold text-lg">New Tutorial Task</h4>
</div>
<div className="space-y-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Task Content *
</label>
<textarea
value={editForm.content}
onChange={(e) => setEditForm({ ...editForm, content: e.target.value })}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white"
rows={4}
placeholder="Enter tutorial task content..."
/>
</div>
<div className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Image URL (Optional)
</label>
<input
type="url"
value={editForm.imageUrl}
onChange={(e) => setEditForm({ ...editForm, imageUrl: e.target.value })}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="https://example.com/image.jpg"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">
Image Alt Text (Optional)
</label>
<input
type="text"
value={editForm.imageAlt}
onChange={(e) => setEditForm({ ...editForm, imageAlt: e.target.value })}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Description of the image"
/>
</div>
</div>
{/* File Upload Section - Only for Week 2+ */}
{selectedWeek >= 2 && (
<div className="border-t pt-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Upload Local Image (Optional)
</label>
<div className="space-y-2">
<input
type="file"
accept="image/*"
onChange={handleFileChange}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
/>
{selectedFile && (
<div className="flex items-center space-x-2">
<span className="text-sm text-gray-600">{selectedFile.name}</span>
<button
type="button"
onClick={async () => {
try {
const imageUrl = await handleFileUpload(selectedFile);
setEditForm({ ...editForm, imageUrl });
setSelectedFile(null);
} catch (error) {
console.error('Upload error:', error);
}
}}
disabled={uploading}
className="bg-green-500 hover:bg-green-600 disabled:bg-gray-400 text-white px-3 py-1 rounded text-sm"
>
{uploading ? 'Uploading...' : 'Upload'}
</button>
</div>
)}
</div>
</div>
)}
</div>
</div>
<div className="flex justify-end space-x-2 mt-4">
<button
onClick={saveNewTask}
disabled={saving}
className="bg-indigo-500 hover:bg-indigo-600 text-white px-4 py-2 rounded-lg transition-colors duration-200 flex items-center space-x-2 text-sm"
>
{saving ? (
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
) : (
<>
<CheckIcon className="h-4 w-4" />
<span>Save Task</span>
</>
)}
</button>
<button
onClick={cancelAddingTask}
className="bg-gray-500 hover:bg-gray-600 text-white px-4 py-2 rounded-lg transition-colors duration-200 flex items-center space-x-2 text-sm"
>
<XMarkIcon className="h-4 w-4" />
<span>Cancel</span>
</button>
</div>
</div>
) : (
<div className="bg-white rounded-lg p-6 border border-gray-200 border-dashed shadow-sm">
<div className="flex items-center justify-between">
<div className="flex items-center space-x-3">
<div className="bg-gray-100 rounded-lg p-2">
<PlusIcon className="h-5 w-5 text-gray-600" />
</div>
<div>
<h3 className="text-lg font-semibold text-indigo-900">Add New Tutorial Task</h3>
<p className="text-gray-600 text-sm">Create a new tutorial task for Week {selectedWeek}</p>
</div>
</div>
<button
onClick={startAddingTask}
className="bg-indigo-600 hover:bg-indigo-700 text-white px-6 py-3 rounded-lg font-medium flex items-center space-x-2 shadow-sm"
>
<PlusIcon className="h-5 w-5" />
<span className="font-medium">Add Task</span>
</button>
</div>
</div>
)}
</div>
)}
{tutorialTasks.length === 0 && !addingTask ? (
<div className="text-center py-12">
<DocumentTextIcon className="h-12 w-12 text-gray-400 mx-auto mb-4" />
<h3 className="text-lg font-medium text-gray-900 mb-2">
No tutorial tasks available
</h3>
<p className="text-gray-600">
Tutorial tasks for Week {selectedWeek} haven't been set up yet.
</p>
</div>
) : (
tutorialTasks.map((task) => (
<div key={task._id} className="bg-white rounded-xl shadow-lg border border-gray-100 p-8 hover:shadow-xl transition-shadow duration-300">
<div className="mb-6">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-3">
<div className="bg-indigo-100 rounded-full p-2">
<DocumentTextIcon className="h-5 w-5 text-indigo-900" />
</div>
<div>
<h3 className="text-lg font-semibold text-gray-900">Source Text #{tutorialTasks.indexOf(task) + 1}</h3>
</div>
</div>
{JSON.parse(localStorage.getItem('user') || '{}').role === 'admin' && (
<div className="flex items-center space-x-2">
{editingTask === task._id ? (
<>
<button
onClick={saveTask}
disabled={saving}
className="bg-green-100 hover:bg-green-200 text-green-700 px-3 py-1 rounded-lg transition-colors duration-200"
>
{saving ? (
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-green-600"></div>
) : (
<CheckIcon className="h-4 w-4" />
)}
</button>
<button
onClick={cancelEditing}
className="bg-red-100 hover:bg-red-200 text-red-700 px-3 py-1 rounded-lg transition-colors duration-200"
>
<XMarkIcon className="h-4 w-4" />
</button>
</>
) : (
<>
<button
onClick={() => startEditing(task)}
className="bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-md transition-colors duration-200 text-sm"
>
<PencilIcon className="h-4 w-4" />
</button>
<button
onClick={() => deleteTask(task._id)}
className="bg-red-100 hover:bg-red-200 text-red-700 px-3 py-1 rounded-lg transition-colors duration-200"
>
<TrashIcon className="h-4 w-4" />
</button>
</>
)}
</div>
)}
</div>
{/* Content - Clean styling with image support */}
<div className="bg-gradient-to-r from-indigo-50 to-blue-50 rounded-xl p-6 mb-6 border border-indigo-200">
{editingTask === task._id ? (
<div className="space-y-4">
<textarea
value={editForm.content}
onChange={(e) => setEditForm({...editForm, content: e.target.value})}
className="w-full px-4 py-3 border border-indigo-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white"
rows={5}
placeholder="Enter source text..."
/>
<div className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Image URL</label>
<input
type="url"
value={editForm.imageUrl}
onChange={(e) => setEditForm({...editForm, imageUrl: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="https://example.com/image.jpg"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700 mb-2">Image Alt Text</label>
<input
type="text"
value={editForm.imageAlt}
onChange={(e) => setEditForm({...editForm, imageAlt: e.target.value})}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
placeholder="Description of the image"
/>
</div>
</div>
{/* File Upload Section - Only for Week 2+ */}
{selectedWeek >= 2 && (
<div className="border-t pt-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Upload Local Image (Optional)
</label>
<div className="space-y-2">
<input
type="file"
accept="image/*"
onChange={handleFileChange}
className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500"
/>
{selectedFile && (
<div className="flex items-center space-x-2">
<span className="text-sm text-gray-600">{selectedFile.name}</span>
<button
type="button"
onClick={async () => {
try {
const imageUrl = await handleFileUpload(selectedFile);
console.log('Uploaded image URL:', imageUrl);
setEditForm({ ...editForm, imageUrl });
console.log('Updated editForm:', { ...editForm, imageUrl });
// Save the task with the new image URL
if (editingTask) {
console.log('Saving task with image URL:', imageUrl);
const response = await api.put(`/auth/admin/tutorial-tasks/${editingTask}`, {
...editForm,
imageUrl,
weekNumber: selectedWeek
});
console.log('Task save response:', response.data);
if (response.status >= 200 && response.status < 300) {
await fetchTutorialTasks(false); // Refresh tasks
}
}
setSelectedFile(null);
} catch (error) {
console.error('Upload error:', error);
}
}}
disabled={uploading}
className="bg-green-500 hover:bg-green-600 disabled:bg-gray-400 text-white px-3 py-1 rounded text-sm"
>
{uploading ? 'Uploading...' : 'Upload'}
</button>
</div>
)}
</div>
</div>
)}
</div>
</div>
) : (
<div className="space-y-4">
{task.imageUrl ? (
// Side-by-side layout when image exists
<div className="flex flex-col md:flex-row gap-6 items-start">
{/* Image on the left - 50% width */}
<div className="w-full md:w-1/2 flex justify-center">
{task.imageUrl.startsWith('data:') ? (
// Show actual image if it's a data URL
<div className="inline-block rounded-lg shadow-md overflow-hidden">
<img
src={task.imageUrl}
alt={task.imageAlt || 'Uploaded image'}
className="w-full h-auto"
style={{ height: '200px', width: 'auto', objectFit: 'contain' }} // Fixed height for consistency
onError={(e) => {
console.error('Image failed to load:', e);
e.currentTarget.style.display = 'none';
}}
/>
{task.imageAlt && (
<div className="text-xs text-gray-500 mt-2 text-center">Alt: {task.imageAlt}</div>
)}
</div>
) : (
// Show placeholder if it's not a data URL
<div className="inline-block rounded-lg shadow-md bg-green-500 text-white p-6 text-center">
<div className="text-3xl mb-2">📷</div>
<div className="font-semibold">Image Uploaded</div>
<div className="text-sm opacity-75">{task.imageUrl}</div>
{task.imageAlt && (
<div className="text-xs opacity-50 mt-2">Alt: {task.imageAlt}</div>
)}
</div>
)}
</div>
{/* Text on the right - 50% width */}
<div className="w-full md:w-1/2">
<div className="text-indigo-900 leading-relaxed text-lg font-source-text whitespace-pre-wrap">{task.content}</div>
</div>
</div>
) : (
// Text only when no image
<div>
<div className="text-indigo-900 leading-relaxed text-lg font-source-text whitespace-pre-wrap">{task.content}</div>
</div>
)}
{(() => { console.log('Task imageUrl check:', task._id, task.imageUrl, !!task.imageUrl); return null; })()}
</div>
)}
</div>
</div>
{/* All Submissions for this Task */}
{userSubmissions[task._id] && userSubmissions[task._id].length > 0 && (
<div className="bg-gradient-to-r from-white to-indigo-50 rounded-xl p-6 mb-6 border border-stone-200">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center space-x-2">
<div className="bg-indigo-100 rounded-full p-1">
<CheckCircleIcon className="h-4 w-4 text-indigo-900" />
</div>
<h4 className="text-stone-900 font-semibold text-lg">All Submissions ({userSubmissions[task._id].length})</h4>
</div>
<button
onClick={() => toggleExpanded(task._id)}
className="flex items-center space-x-1 text-indigo-900 hover:text-indigo-900 text-sm font-medium"
>
<span>{expandedSections[task._id] ? 'Collapse' : 'Expand'}</span>
<svg
className={`w-4 h-4 transition-transform duration-200 ${expandedSections[task._id] ? 'rotate-180' : ''}`}
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
</svg>
</button>
</div>
<div className={`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3 transition-all duration-300 ${
expandedSections[task._id]
? 'max-h-none overflow-visible'
: 'max-h-0 overflow-hidden'
}`}>
{userSubmissions[task._id].map((submission, index) => (
<div key={submission._id} className="bg-white rounded-lg p-3 border border-stone-200 flex flex-col justify-between h-full">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center space-x-2">
{submission.isOwner && (
<span className="inline-block bg-purple-100 text-purple-800 text-xs px-1.5 py-0.5 rounded-full">
Your Submission
</span>
)}
</div>
{getStatusIcon(submission.status)}
</div>
<p className="text-stone-800 leading-relaxed text-base mb-2 font-smiley">{submission.transcreation}</p>
<div className="flex items-center space-x-4 text-xs text-stone-700 mt-auto">
<div className="flex items-center space-x-1">
<span className="font-medium">Group:</span>
<span className="bg-indigo-100 px-1.5 py-0.5 rounded-full text-indigo-900 text-xs">
{submission.groupNumber}
</span>
</div>
<div className="flex items-center space-x-1">
<span className="font-medium">Votes:</span>
<span className="bg-indigo-100 px-1.5 py-0.5 rounded-full text-indigo-900 text-xs">
{(submission.voteCounts?.['1'] || 0) + (submission.voteCounts?.['2'] || 0) + (submission.voteCounts?.['3'] || 0)}
</span>
</div>
</div>
<div className="flex items-center space-x-2 mt-2">
{submission.isOwner && (
<button
onClick={() => handleEditSubmission(submission._id, submission.transcreation)}
className="text-indigo-900 hover:text-indigo-900 text-sm font-medium"
>
Edit
</button>
)}
{JSON.parse(localStorage.getItem('user') || '{}').role === 'admin' && (
<button
onClick={() => handleDeleteSubmission(submission._id)}
className="text-red-600 hover:text-red-800 text-sm font-medium"
>
Delete
</button>
)}
</div>
</div>
))}
</div>
</div>
)}
{/* Translation Input (always show if user is logged in) */}
{localStorage.getItem('token') && (
<div className="bg-white rounded-lg p-6 border border-gray-200 shadow-sm">
<div className="flex items-center space-x-3 mb-4">
<div className="bg-gray-100 rounded-lg p-2">
<DocumentTextIcon className="h-4 w-4 text-gray-600" />
</div>
<h4 className="text-gray-900 font-semibold text-lg">Group Translation</h4>
</div>
{/* Group Selection */}
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Select Your Group *
</label>
<select
value={selectedGroups[task._id] || ''}
onChange={(e) => setSelectedGroups({ ...selectedGroups, [task._id]: parseInt(e.target.value) })}
className="w-48 px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white text-sm"
required
>
<option value="">Choose your group...</option>
{[1, 2, 3, 4, 5, 6, 7, 8].map((group) => (
<option key={group} value={group}>
Group {group}
</option>
))}
</select>
</div>
<div className="mb-4">
<label className="block text-sm font-medium text-gray-700 mb-2">
Your Group's Translation *
</label>
<textarea
value={translationText[task._id] || ''}
onChange={(e) => setTranslationText({ ...translationText, [task._id]: e.target.value })}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500 bg-white"
rows={4}
placeholder="Enter your group's translation here..."
/>
</div>
<button
onClick={() => handleSubmitTranslation(task._id)}
disabled={submitting[task._id]}
className="bg-indigo-500 hover:bg-indigo-600 disabled:bg-gray-400 text-white px-6 py-3 rounded-lg font-medium flex items-center justify-center transition-all duration-200"
>
{submitting[task._id] ? (
<>
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
Submitting...
</>
) : (
<>
Submit Group Translation
<ArrowRightIcon className="h-4 w-4 ml-2" />
</>
)}
</button>
</div>
)}
{/* Show login message for visitors */}
{!localStorage.getItem('token') && (
<div className="bg-gradient-to-r from-gray-50 to-indigo-50 rounded-xl p-6 border border-gray-200">
<div className="flex items-center space-x-2 mb-4">
<div className="bg-gray-100 rounded-full p-1">
<DocumentTextIcon className="h-4 w-4 text-gray-600" />
</div>
<h4 className="text-gray-900 font-semibold text-lg">Login Required</h4>
</div>
<p className="text-gray-700 mb-4">
Please log in to submit translations for this tutorial task.
</p>
<button
onClick={() => window.location.href = '/login'}
className="bg-indigo-500 hover:bg-indigo-600 text-white px-6 py-3 rounded-lg font-medium flex items-center justify-center transition-all duration-200"
>
Go to Login
<ArrowRightIcon className="h-4 w-4 ml-2" />
</button>
</div>
)}
</div>
))
)}
</div>
</div>
{/* Edit Submission Modal */}
{editingSubmission && (
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
<div className="bg-white rounded-lg p-6 w-full max-w-2xl mx-4">
<div className="flex items-center justify-between mb-4">
<h3 className="text-lg font-semibold text-gray-900">Edit Translation</h3>
<button
onClick={cancelEditSubmission}
className="text-gray-400 hover:text-gray-600"
>
<XMarkIcon className="h-6 w-6" />
</button>
</div>
<div className="mb-4">
<textarea
value={editSubmissionText}
onChange={(e) => setEditSubmissionText(e.target.value)}
className="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-purple-500 focus:border-purple-500"
rows={6}
placeholder="Enter your translation..."
/>
</div>
<div className="flex justify-end space-x-3">
<button
onClick={cancelEditSubmission}
className="px-4 py-2 text-gray-600 hover:text-gray-800 border border-gray-300 rounded-lg"
>
Cancel
</button>
<button
onClick={saveEditedSubmission}
className="px-4 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700"
>
Save Changes
</button>
</div>
</div>
</div>
)}
</div>
);
};
export default TutorialTasks; |