implement initialization of approval workflows on exam creation.
This commit is contained in:
@@ -17,6 +17,7 @@ import ListeningComponents from "./listening/components";
|
||||
import ReadingComponents from "./reading/components";
|
||||
import SpeakingComponents from "./speaking/components";
|
||||
import SectionPicker from "./Shared/SectionPicker";
|
||||
import { getExamById } from "@/utils/exams";
|
||||
|
||||
|
||||
const LevelSettings: React.FC = () => {
|
||||
@@ -213,6 +214,28 @@ const LevelSettings: React.FC = () => {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("level", result.data.id);
|
||||
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "level"
|
||||
};
|
||||
})();
|
||||
await axios.post(`/api/approval-workflows`, requestBody)
|
||||
.then(() => {
|
||||
toast.success(`Approval Workflow for exam has been created`);
|
||||
})
|
||||
.catch((reason) => {
|
||||
if (reason.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor.");
|
||||
}
|
||||
else {
|
||||
toast.error("Something went wrong while creating approval workflow, please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Error submitting exam:', error);
|
||||
toast.error(
|
||||
|
||||
@@ -17,6 +17,7 @@ import { usePersistentExamStore } from "@/stores/exam";
|
||||
import { playSound } from "@/utils/sound";
|
||||
import { toast } from "react-toastify";
|
||||
import ListeningComponents from "./components";
|
||||
import { getExamById } from "@/utils/exams";
|
||||
|
||||
const ListeningSettings: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -151,6 +152,28 @@ const ListeningSettings: React.FC = () => {
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("listening", result.data.id);
|
||||
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "listening"
|
||||
};
|
||||
})();
|
||||
await axios.post(`/api/approval-workflows`, requestBody)
|
||||
.then(() => {
|
||||
toast.success(`Approval Workflow for exam has been created`);
|
||||
})
|
||||
.catch((reason) => {
|
||||
if (reason.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor.");
|
||||
}
|
||||
else {
|
||||
toast.error("Something went wrong while creating approval workflow, please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
toast.error('No audio sections found in the exam! Please either import them or generate them.');
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import axios from "axios";
|
||||
import { playSound } from "@/utils/sound";
|
||||
import { toast } from "react-toastify";
|
||||
import ReadingComponents from "./components";
|
||||
import { getExamById } from "@/utils/exams";
|
||||
|
||||
const ReadingSettings: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -46,15 +47,15 @@ const ReadingSettings: React.FC = () => {
|
||||
{
|
||||
label: "Preset: Reading Passage 1",
|
||||
value: "Welcome to {part} of the {label}. You will read texts relating to everyday topics and situations. These may include advertisements, brochures, manuals, or official documents. Answer questions that test your ability to locate specific information and understand main ideas."
|
||||
},
|
||||
{
|
||||
label: "Preset: Reading Passage 2",
|
||||
},
|
||||
{
|
||||
label: "Preset: Reading Passage 2",
|
||||
value: "Welcome to {part} of the {label}. You will read texts dealing with general interest topics that may include news articles, company policies, or workplace documents. Answer questions testing your understanding of main ideas, specific details, and the author's views."
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
label: "Preset: Reading Passage 3",
|
||||
value: "Welcome to {part} of the {label}. You will read longer academic texts that may include journal articles, academic essays, or research papers. Answer questions testing your ability to understand complex arguments, identify key points, and follow the development of ideas."
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
const canPreviewOrSubmit = sections.some(
|
||||
@@ -89,11 +90,29 @@ const ReadingSettings: React.FC = () => {
|
||||
.then((result) => {
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
|
||||
return getExamById("reading", result.data.id);
|
||||
})
|
||||
.then((handledExam) => {
|
||||
const requestBody = {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "reading"
|
||||
};
|
||||
|
||||
return axios.post(`/api/approval-workflows`, requestBody);
|
||||
})
|
||||
.then(() => {
|
||||
toast.success(`Approval Workflow for exam has been created`);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error);
|
||||
toast.error(error.response.data.error || "Something went wrong while submitting, please try again later.");
|
||||
})
|
||||
if (error.response && error.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor.");
|
||||
} else {
|
||||
// This error could come from either of the requests
|
||||
toast.error(error.response?.data?.error || "Something went wrong, please try again later.");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const preview = () => {
|
||||
|
||||
@@ -11,6 +11,7 @@ import openDetachedTab from "@/utils/popout";
|
||||
import axios from "axios";
|
||||
import { playSound } from "@/utils/sound";
|
||||
import SpeakingComponents from "./components";
|
||||
import { getExamById } from "@/utils/exams";
|
||||
|
||||
export interface Avatar {
|
||||
name: string;
|
||||
@@ -194,6 +195,28 @@ const SpeakingSettings: React.FC = () => {
|
||||
Array.from(urlMap.values()).forEach(url => {
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("speaking", result.data.id);
|
||||
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "speaking"
|
||||
};
|
||||
})();
|
||||
await axios.post(`/api/approval-workflows`, requestBody)
|
||||
.then(() => {
|
||||
toast.success(`Approval Workflow for exam has been created`);
|
||||
})
|
||||
.catch((reason) => {
|
||||
if (reason.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor.");
|
||||
}
|
||||
else {
|
||||
toast.error("Something went wrong while creating approval workflow, please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
toast.error(
|
||||
|
||||
@@ -12,6 +12,8 @@ import axios from "axios";
|
||||
import { playSound } from "@/utils/sound";
|
||||
import { toast } from "react-toastify";
|
||||
import WritingComponents from "./components";
|
||||
import { getExamById } from "@/utils/exams";
|
||||
import { ApprovalWorkflow } from "@/interfaces/approval.workflow";
|
||||
|
||||
const WritingSettings: React.FC = () => {
|
||||
const router = useRouter();
|
||||
@@ -140,6 +142,28 @@ const WritingSettings: React.FC = () => {
|
||||
playSound("sent");
|
||||
toast.success(`Submitted Exam ID: ${result.data.id}`);
|
||||
|
||||
const requestBody = await (async () => {
|
||||
const handledExam = await getExamById("writing", result.data.id);
|
||||
|
||||
return {
|
||||
examAuthor: handledExam?.createdBy ?? "Unknown Author",
|
||||
examId: handledExam?.id ?? "Unknown ID",
|
||||
examModule: "writing"
|
||||
};
|
||||
})();
|
||||
await axios.post(`/api/approval-workflows`, requestBody)
|
||||
.then(() => {
|
||||
toast.success(`Approval Workflow for exam has been created`);
|
||||
})
|
||||
.catch((reason) => {
|
||||
if (reason.response.status === 404) {
|
||||
toast.error("No configured workflow found for examAuthor.");
|
||||
}
|
||||
else {
|
||||
toast.error("Something went wrong while creating approval workflow, please try again later.");
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Error submitting exam:', error);
|
||||
toast.error(
|
||||
|
||||
Reference in New Issue
Block a user