Skip to content

Commit

Permalink
Merge pull request #169 from Aar-if/main
Browse files Browse the repository at this point in the history
Issue #PS-1802 feat: Create Course Planner API integration in Admin app
  • Loading branch information
itsvick authored Aug 28, 2024
2 parents 9052277 + 1d00ee5 commit 4957d1f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 52 deletions.
5 changes: 4 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 5 additions & 42 deletions src/data/cardData.js
Original file line number Diff line number Diff line change
@@ -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"],
},
];

Expand Down
50 changes: 41 additions & 9 deletions src/pages/importCsv.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
});
}
};

Expand All @@ -93,7 +125,7 @@ const ImportCsv = () => {
},
(err) => {
console.error("Failed to copy link: ", err);
},
}
);
};

Expand Down
22 changes: 22 additions & 0 deletions src/services/coursePlanner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CoursePlannerMetaData } from "@/utils/Interfaces";
import { post } from "./RestClient";


export const uploadCoursePlanner = async (file: File, metaData: CoursePlannerMetaData): Promise<any> => {
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;
}
};




11 changes: 11 additions & 0 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 4957d1f

Please sign in to comment.