Skip to content

Commit

Permalink
Merge pull request #16 from Aar-if/newaltv1
Browse files Browse the repository at this point in the history
Batching fix for records less than 100 or more than 100 + Reset Password added
  • Loading branch information
snehal0904 authored Oct 3, 2023
2 parents 2ac592b + e232fff commit 8fa3721
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 54 deletions.
15 changes: 9 additions & 6 deletions packages/admin/src/api/StudentResetPasswordAPI.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import axios from "axios";
import { studentReset } from "../routes/links";

const studentAPI = async (data) => {
const studentResetPasswordAPI = async (username, password) => {
console.log("INSIDE RESET PASS API");
console.log(username, password);

const token = localStorage.getItem("token");

const headers = {
Expand All @@ -12,8 +15,8 @@ const studentAPI = async (data) => {
};

const jsonData = {
username: data.username,
newPassword: data.newPassword,
username: username,
newPassword: password,
};

let result;
Expand All @@ -26,8 +29,8 @@ const studentAPI = async (data) => {
.then((res) => {
console.log(res);
console.log(res.data);
console.log(res.status);
if (res.status === 201) {
console.log(res.data.statusCode);
if (res.data.statusCode === 200) {
result = true;
} else {
result = false;
Expand All @@ -41,4 +44,4 @@ const studentAPI = async (data) => {
return result;
};

export default studentAPI;
export default studentResetPasswordAPI;
18 changes: 17 additions & 1 deletion packages/admin/src/components/StudentCSV.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,23 @@ function CSVImportForm() {
return;
}

sendBatch(currentIndex, currentIndex + batchSize);
// Determine the number of full batches and the number of remaining records
const numFullBatches = Math.floor(csvData.length / batchSize);
const remainingRecords = csvData.length % batchSize;

// Send full batches
for (let i = 0; i < numFullBatches; i++) {
const startIndex = i * batchSize;
const endIndex = startIndex + batchSize;
await sendBatch(startIndex, endIndex);
}

// Send remaining records if there are any
if (remainingRecords > 0) {
const startIndex = numFullBatches * batchSize;
const endIndex = startIndex + remainingRecords;
await sendBatch(startIndex, endIndex);
}
};

function downloadCSV(data, filename) {
Expand Down
125 changes: 78 additions & 47 deletions packages/admin/src/components/StudentListView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import axios from "axios";
import { Button } from "native-base";
import Modal from "react-modal";
import StudentResetPassword from "./StudentResetPassword";
import studentResetPasswordAPI from "api/StudentResetPasswordAPI";
import SyncLockIcon from "@mui/icons-material/SyncLock";

const customStyles = {
content: {
Expand All @@ -36,42 +38,51 @@ function StudentListView() {
const navigate = useNavigate();
const gridRef = useRef();
const [rowData, setRowData] = useState([]);
const [isOpen, setIsOpen] = useState(false);

useEffect(() => {
Modal.setAppElement("#root"); // Set the app element for modal
}, []);

const openModal = () => {
setIsOpen(true);
};

const closeModal = () => {
setIsOpen(false);
const openPrompt = async (data) => {
console.log(data);
let person = window.prompt(
`Enter a new password for user ${data.username}`
);
if (person == null || person == "") {
alert("Please enter a valid password");
} else {
const result = await studentResetPasswordAPI(data.username, person);
if (result == true) {
alert("Password reset Successful.");
window.location.reload();
} else {
alert("Password reset failed");
}
}
};

const [columnDefs] = useState([
{
width: 150,
cellRenderer: function () {
cellRenderer: function (params) {
// Replace with your desired label
const combinedFunction = () => {
// openModal();
alert("Work in progress");
const combinedFunction = (rowData) => {
openPrompt(rowData);
};

return (
<div>
<button onClick={combinedFunction}> Reset Password</button>
<Modal
isOpen={isOpen}
onRequestClose={closeModal}
contentLabel="Edit Modal"
// className={modalStyles.modalDiv}
style={customStyles.content}
<button
onClick={() => combinedFunction(params.data)}
style={{
background: "none",
border: "none",
color: "#6461D2",
textDecoration: "underline",
display: "flex", // Center align vertically
alignItems: "center",
marginTop: "10px",
}}
>
Hello
</Modal>
{" "}
<SyncLockIcon /> Password
</button>
</div>
);
},
Expand Down Expand Up @@ -192,6 +203,10 @@ function StudentListView() {
// document.body.removeChild(link);
// }, [rowData]);

const cellClickedListener = useCallback((event) => {
console.log("cellClicked", event);
}, []);

const onBtnExportFields = useCallback(() => {
// Get the visible (filtered) rows from the grid
const filteredData = gridRef.current.api.getModel().rowsToDisplay;
Expand Down Expand Up @@ -256,35 +271,51 @@ function StudentListView() {

return (
<div className="ag-theme-material" style={{ height: 400, width: "100%" }}>
<button
onClick={onBtnExport}
style={{ background: "#41C88E", border: "none", borderRadius: "5px" }}
>
<FileDownloadOutlinedIcon
style={{ color: "white", fontSize: "largest" }}
/>
<H4 style={{ color: "white" }}> Download Template </H4>
</button>
<button
onClick={onBtnExportFields}
style={{
background: "#41C88E",
border: "none",
borderRadius: "5px",
marginLeft: "10px", // Add some spacing between the buttons
}}
>
<FileDownloadOutlinedIcon
style={{ color: "white", fontSize: "largest" }}
/>
<H4 style={{ color: "white" }}> Download username & password </H4>
</button>
<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>
<button
onClick={onBtnExportFields}
style={{
background: "#41C88E",
border: "none",
borderRadius: "5px",
marginLeft: "10px", // Add some spacing between the buttons
display: "flex", // Center align vertically

alignItems: "center",
}}
>
<FileDownloadOutlinedIcon
style={{
color: "white",
fontSize: "largest",
}}
/>
<H4 style={{ color: "white" }}> Download username & password </H4>
</button>
</div>
<AgGridReact
ref={gridRef}
rowData={rowData}
columnDefs={columnDefs}
pagination={true}
paginationAutoPageSize={true}
onCellClicked={cellClickedListener}
></AgGridReact>{" "}
</div>
);
Expand Down

0 comments on commit 8fa3721

Please sign in to comment.