Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pagination limit added #31

Merged
merged 3 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"axios": "^0.24.0",
"expo-font": "^10.0.3",
"i18next": "^21.6.7",
"lodash": "^4.17.21",
"moment": "^2.29.1",
"native-base": "^3.2.2",
"react": "^17.0.2",
Expand Down
4 changes: 3 additions & 1 deletion packages/admin/src/api/studentBulkAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const studentBulkAPI = async (student) => {
headers: headers,
})
.then((res) => {

// Extract student information and store it in localStorage
const responses = res.data.responses;

Expand All @@ -38,9 +38,11 @@ const studentBulkAPI = async (student) => {

// studentId to the storage key to avoid overwriting
localStorage.setItem(`student_${studentId}`, JSON.stringify(studentData));

});

localStorage.setItem("successCount", res.data.successCount);
localStorage.setItem("errorCount", res.data.errors.length);

if (res.status === 201) {
result = true;
Expand Down
34 changes: 34 additions & 0 deletions packages/admin/src/api/studentUsernamePasswordAPI.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import axios from "axios";
import { studentSearch } from "../routes/links";
const studentUsernamePasswordAPI = 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 studentUsernamePasswordAPI;

4 changes: 4 additions & 0 deletions packages/admin/src/components/StudentCSV.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ function CSVImportForm() {
{showSuccessCount && (
<div>Success Count: {localStorage.getItem("successCount") || ""}</div>
)}

{showSuccessCount && (
<div>Error Count: {localStorage.getItem("errorCount") || ""}</div>
)}
</div>
);
}
Expand Down
186 changes: 127 additions & 59 deletions packages/admin/src/components/StudentListView.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// export default listView;

import React, {
useState,
useCallback,
Expand All @@ -18,11 +16,16 @@ import studentResetPasswordAPI from "api/StudentResetPasswordAPI";
import SyncLockIcon from "@mui/icons-material/SyncLock";
import useSWR from 'swr';
import { studentSearch } from "routes/links";
import { Button } from "native-base";
import { result } from "lodash";
import studentUsernamePasswordAPI from "api/studentUsernamePasswordAPI";

function StudentListView() {
const [token, setToken] = useState([]);
const gridRef = useRef();
const [rowData, setRowData] = useState([]);
const [currentPage, setCurrentPage] = useState(2);


const openPrompt = async (data) => {
let person = window.prompt(
Expand Down Expand Up @@ -143,9 +146,7 @@ function StudentListView() {
{ field: "noOfSiblings" },
]);

const onBtnExport = useCallback(() => {
gridRef.current.api.exportDataAsCsv();
}, []);


//Download username and pass with prompt

Expand Down Expand Up @@ -192,20 +193,27 @@ function StudentListView() {
console.log("cellClicked", event);
}, []);

const onBtnExportFields = useCallback(() => {
// Get the visible (filtered) rows from the grid
const filteredData = gridRef.current.api.getModel().rowsToDisplay;
const onBtnExportFields = async() => {

if (filteredData.length === 0) {
alert("No data to export. Please apply a filter.");
return;
}
let person = window.prompt(
`Enter a School Udise`
);
if (person == null || person == "") {
alert("Please enter a valid password");
} else {
console.log(person)


const result = await studentUsernamePasswordAPI(person);
if (result) {

const filteredData = result.data.data;
console.log(filteredData);

// Extract the "UserID" and "Password" fields
const selectedFieldsData = filteredData.map((row) => ({
Name: row.data.name,
UserName: row.data.username,
Password: row.data.password,
Name: row.name,
UserName: row.username,
Password: row.password,
}));

// Convert the data to CSV format using PapaParse
Expand All @@ -222,59 +230,110 @@ function StudentListView() {
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}, []);

// Fetching data using useSWR
const { data } = useSWR(studentSearch, async () => {

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

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

const response = await axios.post(studentSearch, requestData, { headers });
return response.data.data;
});

useEffect(() => {
useEffect(() => {
const token = sessionStorage.getItem("token");
setToken(token);
}, []);

// Fetching data using useSWR
useEffect(() => {
if (data) {
setRowData(data);
const fetchData = async () => {
try {
const headers = {
Accept: "*/*",
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};

const requestData = {
limit: "5",
page: 1,
filters: {},
};

const response = await axios.post(studentSearch, requestData, { headers });
setRowData(response.data.data);
} catch (error) {
console.error("Error fetching data:", error);
}
};

fetchData();
}, [token]);


const handlePaginationChanged = () => {
// Increment the current page when the "Next Page" button is clicked
console.log('clicked');

const fetchData = async () => {
try {
const headers = {
Accept: "*/*",
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};

const requestData = {
limit: "5",
page: currentPage,
filters: {},
};

const response = await axios.post(studentSearch, requestData, { headers });
setRowData(response.data.data);
setCurrentPage(currentPage + 1);
} catch (error) {
console.error("Error fetching data:", error);
}
};

fetchData();

};


const handlePaginationChanged2 = () => {
// Increment the current page when the "Next Page" button is clicked
console.log('clicked');

const fetchData = async () => {
try {
const headers = {
Accept: "*/*",
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
};

const requestData = {
limit: "5",
page: currentPage,
filters: {},
};

const response = await axios.post(studentSearch, requestData, { headers });
setRowData(response.data.data);
setCurrentPage(currentPage - 1);
} catch (error) {
console.error("Error fetching data:", error);
}
}, [data]);
};

fetchData();

};


return (
<div className="ag-theme-material" style={{ height: 400, width: "100%" }}>
<div style={{ display: "flex", flexDirection: "row" }}>
<button
onClick={onBtnExport}
style={{
background: "#41C88E",
border: "none",
borderRadius: "5px",
display: "flex", // Center align vertically

alignItems: "center",
}}
>
<FileDownloadOutlinedIcon
style={{ color: "white", fontSize: "largest" }}
/>
<H4 style={{ color: "white" }}> Download Template </H4>
</button>
<div style={{ display: "flex", flexDirection: "row" }}>

<button
onClick={onBtnExportFields}
style={{
Expand All @@ -283,7 +342,7 @@ function StudentListView() {
borderRadius: "5px",
marginLeft: "10px", // Add some spacing between the buttons
display: "flex", // Center align vertically

cursor: "pointer",
alignItems: "center",
}}
>
Expand All @@ -295,18 +354,27 @@ function StudentListView() {
/>
<H4 style={{ color: "white" }}> Download username & password </H4>
</button>
</div>
<div style={{display: "flex", flexDirection: "row",justifyContent: "flex-end", paddingBottom: "10px", cursor: "pointer", zIndex: "1"}}>
<Button style={{cursor: "pointer"}}
onPress={handlePaginationChanged}>Previous Page</Button>
<Button style={{cursor: "pointer", marginLeft:"20px"}}
onPress={handlePaginationChanged2}>Next Page</Button>

</div>

<AgGridReact
ref={gridRef}
rowData={rowData}
columnDefs={columnDefs}
pagination={true}
paginationAutoPageSize={true}
onCellClicked={cellClickedListener}
overlayNoRowsTemplate={'<span>Loading Student records....</span>'}

></AgGridReact>{" "}


</div>
);
}

export default StudentListView;
export default StudentListView;
1 change: 0 additions & 1 deletion packages/admin/src/components/TeacherCSV.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ function CSVImportForm() {
const [currentIndex, setCurrentIndex] = useState(0);
const batchSize = 100; // Number of records per batch
const [overallProgress, setOverallProgress] = useState(0);

const [showSuccessCount, setShowSuccessCount] = useState(false);
const [showBulkErrors, setShowBulkErrors] = useState(false);

Expand Down
3 changes: 3 additions & 0 deletions packages/admin/src/pages/StudentPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ function StudentPage() {
</div>
</FORMmodal>
)}

<StudentListView />


</VStack>
</Stack>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion packages/common-lib/src/services/courseRegistryService.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const lessontracking = async (
} else {
return {}
}
}, 1500)
}, 3000)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/studentprogram/src/pages/lessonList.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export default function LessonList({ footerLinks }) {
})
) : (
<H1 textAlign={"center"} p="5">
{t("LESSON_NOT_FOUND")}
{t("LOADING")}
</H1>
)}
</Stack>
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15415,11 +15415,16 @@ lodash@^3.10.1:
resolved "https://registry.npmjs.org/lodash/-/lodash-3.10.1.tgz"
integrity sha512-9mDDwqVIma6OZX79ZlDACZl8sBm0TEnkf99zV3iMA4GzkIT/9hiqP5mY0HoT1iNLCrKc/R1HByV+yJfRWVJryQ==

lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.5, lodash@^4.5.0, lodash@^4.7.0:
lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.5, lodash@^4.5.0, lodash@^4.7.0:
version "4.17.21"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

lodash@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

log4js@^3.0.0:
version "3.0.6"
resolved "https://registry.npmjs.org/log4js/-/log4js-3.0.6.tgz"
Expand Down