diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 62593ca0..bb520280 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -202,7 +202,10 @@ "IMPORT_PLANNER_TO_UPLOADING": "Click on ‘Import Planner’ to start uploading ", "TOPIC_DETAILS": "Topic Details", "BROWSE_FILE": "Browse File", - "UPLOAD": "Upload" + "UPLOAD": "Upload", + "COURSE_CREATED_SUCCESSFULLY":"Course created successfully", + "COURSE_NOT_CREATED": "Course not created" + }, "MASTER": { "STATE": "State", diff --git a/src/data/cardData.js b/src/data/cardData.js index 296fe78d..e07db8dc 100644 --- a/src/data/cardData.js +++ b/src/data/cardData.js @@ -1,50 +1,13 @@ const cardData = [ { id: "1", - state: "Andhra Pradesh", + state: "Punjab", boardsUploaded: 1, - totalBoards: 3, + totalBoards: 1, details: - "Andhra Pradesh is a state in the southeastern coastal region of India.", - boards: ["AP Board", "NIOS", "ICSE"], - subjects: ["Telugu", "English", "Maths"], - }, - { - id: "2", - state: "Maharashtra", - boardsUploaded: 2, - totalBoards: 3, - details: - "Maharashtra is a state in the western peninsular region of India.", - boards: ["Maharashtra Board", "CBSE", "ICSE"], - subjects: ["Marathi", "English", "Science"], - }, - { - id: "3", - state: "Karnataka", - boardsUploaded: 2, - totalBoards: 3, - details: "Karnataka is a state in the southwestern region of India.", - boards: ["Karnataka Board", "ICSE", "NIOS"], - subjects: ["Kannada", "Maths", "Science"], - }, - { - id: "4", - state: "Tamil Nadu", - boardsUploaded: 1, - totalBoards: 3, - details: "Tamil Nadu is a state in the southern part of India.", - boards: ["Tamil Nadu Board", "NIOS", "CBSE"], - subjects: ["Tamil", "English", "Social Studies"], - }, - { - id: "5", - state: "Kerala", - boardsUploaded: 2, - totalBoards: 2, - details: "Kerala is a state on the southwestern Malabar Coast of India.", - boards: ["Kerala Board", "ICSE", "CBSE"], - subjects: ["Malayalam", "Science", "Maths"], + "Punjab is a state in the southeastern coastal region of India.", + boards: ["PSEB"], + subjects: ["Marathi"], }, ]; diff --git a/src/pages/importCsv.tsx b/src/pages/importCsv.tsx index d0e08e7b..a81138fe 100644 --- a/src/pages/importCsv.tsx +++ b/src/pages/importCsv.tsx @@ -17,6 +17,9 @@ import AttachmentIcon from "@mui/icons-material/Attachment"; import FileUploadDialog from "@/components/FileUploadDialog"; import { useTranslation } from "react-i18next"; import Loader from "@/components/Loader"; +import { CoursePlannerMetaData } from "@/utils/Interfaces"; +import { uploadCoursePlanner } from "@/services/coursePlanner"; +import { showToastMessage } from "@/components/Toastify"; const ImportCsv = () => { const router = useRouter(); @@ -73,15 +76,44 @@ const ImportCsv = () => { setSelectedFile(null); }; - const handleUpload = () => { + const handleUpload = async () => { if (selectedFile) { - router.push({ - pathname: "/csvDetails", - query: { - fileName: selectedFile.name, - subject: subjectDetails?.subject || "", - }, - }); + const metaData: CoursePlannerMetaData = { + subject: "Gujarati", + class: "10", + state: "Punjab", + board: "PSEB", + type: "mainCourse", + role: "Teacher", + medium: "Hindi", + }; + + const result = await uploadCoursePlanner(selectedFile, metaData) + .then((response) => { + console.log( + "Upload successful:", + response.result.solutionData.message + ); + + if ( + response.result.solutionData.message == + "Solution created successfully" + ) { + showToastMessage( + t("COURSE_PLANNER.COURSE_CREATED_SUCCESSFULLY"), + "success" + ); + setOpen(false); + } else { + showToastMessage( + t("COURSE_PLANNER.COURSE_NOT_CREATED"), + "success" + ); + } + }) + .catch((error) => { + console.error("Upload failed:", error); + }); } }; @@ -93,7 +125,7 @@ const ImportCsv = () => { }, (err) => { console.error("Failed to copy link: ", err); - }, + } ); }; diff --git a/src/services/coursePlanner.ts b/src/services/coursePlanner.ts new file mode 100644 index 00000000..ff12226a --- /dev/null +++ b/src/services/coursePlanner.ts @@ -0,0 +1,22 @@ +import { CoursePlannerMetaData } from "@/utils/Interfaces"; +import { post } from "./RestClient"; + + +export const uploadCoursePlanner = async (file: File, metaData: CoursePlannerMetaData): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_TELEMETRY_URL}/user/v1/course-planner/upload`; + const formData = new FormData(); + formData.append('file', file); + formData.append('metaData', JSON.stringify(metaData)); + try { + const response = await post(apiUrl, formData, { + }); + return response?.data; + } catch (error) { + console.error('Error uploading course planner', error); + throw error; + } + }; + + + + \ No newline at end of file diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index a9ad123e..5cb474f8 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -75,3 +75,14 @@ export interface CohortMemberList { }; sort?: string[]; } + +export interface CoursePlannerMetaData { + subject: string; + class: string; + state: string; + board: string; + type: string; + role: string; + medium: string; +} +