Skip to content

Commit

Permalink
Student details based on UDISE api and button chamges added
Browse files Browse the repository at this point in the history
  • Loading branch information
Arif-tekdi-technologies committed Mar 16, 2024
1 parent 3b14db4 commit d7729b6
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/admin/src/api/studentUdiseAPI.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import axios from "axios";
import { studentSearch } from "../routes/links";
const studentUdiseAPI = async (person) => {
const token = sessionStorage.getItem("token");
console.log("INSIDE API CALL");
console.log(person);

const apiUrl = studentSearch;
const headers = {
Accept: "*/*",
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};

const requestData = {
limit: "",
page: 0,
filters: { schoolUdise: { eq: person } },
};

try {
const response = await axios.post(apiUrl, requestData, { headers });
console.log("INSIDE API CALL 2");
console.log(response);
return response; // Return the response here
} catch (error) {
// Handle any errors here
console.error("Error fetching data:", error);
return null; // Return null or an error object in case of an error
}
};

export default studentUdiseAPI;
57 changes: 57 additions & 0 deletions packages/admin/src/components/StudentListView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { studentSearch } from "routes/links";
import { Button } from "native-base";
import { result } from "lodash";
import studentUsernamePasswordAPI from "api/studentUsernamePasswordAPI";
import studentUdiseAPI from "api/studentUdiseAPI";

function StudentListView() {
const [token, setToken] = useState([]);
Expand Down Expand Up @@ -185,6 +186,42 @@ function StudentListView() {
// document.body.removeChild(link);
// }, [rowData]);

const onBtnExportUdise = async () => {
let person = window.prompt(`Enter a School Udise`);
person = person.trim();
if (person == null || person == "") {
alert("Please enter a valid Udise");
} else {
console.log(person);

const result = await studentUdiseAPI(person);
if (result) {
const filteredData = result.data.data.map((item) => {
// Create a copy of the item without the password field
const { password, ...rest } = item;
return rest;
});
console.log(filteredData);

// Convert the data to CSV format using PapaParse
const csvData = Papa.unparse(filteredData);
// Now, csvData will not contain the password field

// Create a Blob containing the CSV data
const blob = new Blob([csvData], { type: "text/csv;charset=utf-8;" });

// Create a download link and trigger the download
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "student_data_filtered_UDISE.csv";
link.style.display = "none";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}
};

const cellClickedListener = useCallback((event) => {
console.log("cellClicked", event);
}, []);
Expand Down Expand Up @@ -396,6 +433,26 @@ function StudentListView() {
/>
<H4 style={{ color: "white" }}> Download student details </H4>
</button>
<button
onClick={onBtnExportUdise}
style={{
background: "#41C88E",
border: "none",
borderRadius: "5px",
marginLeft: "10px", // Add some spacing between the buttons
display: "flex", // Center align vertically
cursor: "pointer",
alignItems: "center",
}}
>
<FileDownloadOutlinedIcon
style={{
color: "white",
fontSize: "largest",
}}
/>
<H4 style={{ color: "white" }}> Get Students by UDISE Code </H4>
</button>
</div>
<div
style={{
Expand Down

0 comments on commit d7729b6

Please sign in to comment.