Tristan Yu commited on
Commit
602de9e
·
1 Parent(s): fb4ef02

Fix submission API calls - add /api prefix to match backend routes

Browse files
client/src/pages/TutorialTasks.tsx CHANGED
@@ -350,7 +350,7 @@ const TutorialTasks: React.FC = () => {
350
  try {
351
  setSubmitting({ ...submitting, [taskId]: true });
352
  const user = JSON.parse(localStorage.getItem('user') || '{}');
353
- const response = await api.post('/submissions', {
354
  sourceTextId: taskId,
355
  transcreation: translationText[taskId],
356
  groupNumber: selectedGroups[taskId],
 
350
  try {
351
  setSubmitting({ ...submitting, [taskId]: true });
352
  const user = JSON.parse(localStorage.getItem('user') || '{}');
353
+ const response = await api.post('/api/submissions', {
354
  sourceTextId: taskId,
355
  transcreation: translationText[taskId],
356
  groupNumber: selectedGroups[taskId],
client/src/pages/WeeklyPractice.tsx CHANGED
@@ -807,28 +807,20 @@ const WeeklyPractice: React.FC = () => {
807
  setSubmitting({ ...submitting, [practiceId]: true });
808
  const token = localStorage.getItem('token');
809
  const user = JSON.parse(localStorage.getItem('user') || '{}');
810
- const response = await fetch('/api/submissions', {
811
- method: 'POST',
812
- headers: {
813
- 'Authorization': `Bearer ${token}`,
814
- 'Content-Type': 'application/json'
815
- },
816
- body: JSON.stringify({
817
- sourceTextId: practiceId,
818
- transcreation: translationText[practiceId],
819
- culturalAdaptations: [],
820
- isAnonymous: anonymousSubmissions[practiceId] || false,
821
- username: user.name || 'Unknown'
822
- })
823
  });
824
 
825
- if (response.ok) {
826
-
827
  setTranslationText({ ...translationText, [practiceId]: '' });
828
  await fetchUserSubmissions(weeklyPractice);
829
  } else {
830
- const error = await response.json();
831
-
832
  }
833
  } catch (error) {
834
  console.error('Error submitting translation:', error);
@@ -851,25 +843,17 @@ const WeeklyPractice: React.FC = () => {
851
 
852
  try {
853
  const token = localStorage.getItem('token');
854
- const response = await fetch(`/api/submissions/${editingSubmission.id}`, {
855
- method: 'PUT',
856
- headers: {
857
- 'Authorization': `Bearer ${token}`,
858
- 'Content-Type': 'application/json'
859
- },
860
- body: JSON.stringify({
861
- transcreation: editSubmissionText
862
- })
863
  });
864
 
865
- if (response.ok) {
866
-
867
  setEditingSubmission(null);
868
  setEditSubmissionText('');
869
  await fetchUserSubmissions(weeklyPractice);
870
  } else {
871
- const error = await response.json();
872
-
873
  }
874
  } catch (error) {
875
  console.error('Error updating translation:', error);
@@ -886,7 +870,7 @@ const WeeklyPractice: React.FC = () => {
886
 
887
 
888
  try {
889
- const response = await api.delete(`/submissions/${submissionId}`);
890
 
891
  if (response.status === 200) {
892
 
 
807
  setSubmitting({ ...submitting, [practiceId]: true });
808
  const token = localStorage.getItem('token');
809
  const user = JSON.parse(localStorage.getItem('user') || '{}');
810
+ const response = await api.post('/api/submissions', {
811
+ sourceTextId: practiceId,
812
+ transcreation: translationText[practiceId],
813
+ culturalAdaptations: [],
814
+ isAnonymous: anonymousSubmissions[practiceId] || false,
815
+ username: user.name || 'Unknown'
 
 
 
 
 
 
 
816
  });
817
 
818
+ if (response.status === 201 || response.status === 200) {
819
+ console.log('✅ Translation submitted successfully');
820
  setTranslationText({ ...translationText, [practiceId]: '' });
821
  await fetchUserSubmissions(weeklyPractice);
822
  } else {
823
+ console.error('❌ Submission failed:', response.data);
 
824
  }
825
  } catch (error) {
826
  console.error('Error submitting translation:', error);
 
843
 
844
  try {
845
  const token = localStorage.getItem('token');
846
+ const response = await api.put(`/api/submissions/${editingSubmission.id}`, {
847
+ transcreation: editSubmissionText
 
 
 
 
 
 
 
848
  });
849
 
850
+ if (response.status === 200) {
851
+ console.log('✅ Translation updated successfully');
852
  setEditingSubmission(null);
853
  setEditSubmissionText('');
854
  await fetchUserSubmissions(weeklyPractice);
855
  } else {
856
+ console.error('❌ Update failed:', response.data);
 
857
  }
858
  } catch (error) {
859
  console.error('Error updating translation:', error);
 
870
 
871
 
872
  try {
873
+ const response = await api.delete(`/api/submissions/${submissionId}`);
874
 
875
  if (response.status === 200) {
876