Skip to content

Commit 4fd5680

Browse files
Merge pull request #177 from PeerPrep/kevin/new
feat: add error msg for duplicate qn names
2 parents 5e7cb1b + fd18888 commit 4fd5680

File tree

6 files changed

+18
-13
lines changed

6 files changed

+18
-13
lines changed

frontend/src/app/admin/question/page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ const QuestionPage = () => {
198198
});
199199

200200
const allQuestionsFiltered = useMemo(() => {
201-
console.log(allQuestions?.payload);
202201
if (Array.isArray(allQuestions?.payload)) {
203202
return allQuestions?.payload.filter((question) => {
204203
return (
@@ -212,8 +211,6 @@ const QuestionPage = () => {
212211
}
213212
}, [allQuestions?.payload, searchValue, filterQnType]);
214213

215-
console.log({ allQuestionsFiltered });
216-
217214
const deleteQuestionMutation = useMutation(
218215
async (questionId: string) => deleteQuestionUrl(questionId),
219216
{

frontend/src/app/api/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export const fetchAllQuestionsDoneByUser = async () => {
6060
);
6161

6262
const questionIds = payload.map((ele: any) => ele.questionId).join("-");
63-
console.log({ questionIds });
6463
// console.log({ res });
6564
const questions = await FetchAuth.fetch(
6665
`${API_URL}/questions/group/${questionIds}`,
@@ -120,7 +119,14 @@ export const createQuestionUrl = async (newQuestion: QuestionType) => {
120119
"Content-Type": "application/json",
121120
},
122121
body: JSON.stringify(newQuestion),
123-
}).then((res) => res.json());
122+
})
123+
.then((res) => res.json())
124+
.then((res) => {
125+
if (res.statusMessage?.type?.toLowerCase() === "error") {
126+
throw Error();
127+
}
128+
return res;
129+
});
124130
};
125131

126132
export const updateQuestionUrl = async (updatedQuestion: QuestionType) => {
@@ -130,7 +136,14 @@ export const updateQuestionUrl = async (updatedQuestion: QuestionType) => {
130136
"Content-Type": "application/json",
131137
},
132138
body: JSON.stringify(updatedQuestion),
133-
}).then((res) => res.json());
139+
})
140+
.then((res) => res.json())
141+
.then((res) => {
142+
if (res.statusMessage?.type?.toLowerCase() === "error") {
143+
throw Error();
144+
}
145+
return res;
146+
});
134147
};
135148

136149
export const deleteQuestionUrl = async (questionId: string) => {

frontend/src/app/components/matching/MatchingPage.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,6 @@ const MatchingPage = () => {
139139
return fetchAllQuestionsDoneByUser();
140140
});
141141

142-
console.log({ allQuestions });
143-
144142
return (
145143
<>
146144
<main className="flex h-full flex-col items-center justify-center">

frontend/src/app/components/modal/AddQuestionModal.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const AddQuestionModal = ({
7070
onError: (e) => {
7171
api.open({
7272
type: "error",
73-
content: "Failed to add question!",
73+
content: "Failed to add question due to same name!",
7474
});
7575
},
7676
},
@@ -92,8 +92,7 @@ const AddQuestionModal = ({
9292
description: e.currentTarget.description.value,
9393
};
9494

95-
console.log("Form Submission Data:", submissionData);
96-
createQuestionMutation.mutate(submissionData);
95+
createQuestionMutation && createQuestionMutation.mutate(submissionData);
9796
e.currentTarget.reset();
9897
setDefaultValues();
9998
closeModal("my_modal_1");

frontend/src/app/components/modal/EditQuestionModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ const EditQuestionModal = ({
6969
successCallback();
7070
},
7171
onError: (e) => {
72-
console.log({ e });
7372
api.open({
7473
type: "error",
7574
content: "Failed to add question due to having same question name!",

frontend/src/app/matching/page.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ const roomPage = () => {
5858
);
5959
}
6060

61-
console.log(isMatched);
6261
if (isMatched === "UNMATCHED") {
6362
return <MatchingPage />;
6463
}

0 commit comments

Comments
 (0)