Skip to content

Commit

Permalink
Merge pull request #92 from transform1234/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ankush-maherwal authored Nov 27, 2024
2 parents a2d0005 + 165c85f commit 9287fe7
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 165 deletions.
21 changes: 16 additions & 5 deletions packages/admin/src/api/filterStudentDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const fetchStates = async (token) => {
{ state: "" }, // Fetch all states
{ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }}
);
return response.data.data.map(item => item.state);
return response.data.data.map(item => ({
label: `${item.state}`
}));
} catch (error) {
console.error("Error fetching states:", error);
throw error;
Expand All @@ -24,7 +26,9 @@ export const fetchDistricts = async (token, state = "") => {
{ state }, // Send selected state as payload
{ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }}
);
return response.data.data.map(item => item.district);
return response.data.data.map(item => ({
label: `${item.district}`
}));
} catch (error) {
console.error("Error fetching districts:", error);
throw error;
Expand All @@ -39,7 +43,9 @@ export const fetchBlocks = async (token, state = "", district = "") => {
{ state, district }, // Send both state and district as payload
{ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }}
);
return response.data.data.map(item => item.block);
return response.data.data.map(item => ({
label: `${item.block}`
}));
} catch (error) {
console.error("Error fetching blocks:", error);
throw error;
Expand All @@ -54,7 +60,10 @@ export const fetchSchools = async (token, state = "", district = "", block = "")
{ state, district, block }, // Send state, district, and block as payload
{ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }}
);
return response.data.data.map(item => item.name);
return response.data.data.map(item => ({
label: `${item.name}`,
udiseCode: `${item.udiseCode}`
}));
} catch (error) {
console.error("Error fetching schools:", error);
throw error;
Expand All @@ -69,7 +78,9 @@ export const fetchClasses = async (token, schoolName = "") => {
{ schoolName }, // Send selected schoolName as payload
{ headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" }}
);
return response.data.data.map(item => item.name);
return response.data.data.map(item => ({
label: `${item.name}`
}));
} catch (error) {
console.error("Error fetching classes:", error);
throw error;
Expand Down
18 changes: 9 additions & 9 deletions packages/admin/src/api/studentBulkAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ const studentBulkAPI = async (student) => {
.then((res) => {

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

responses.forEach(response => {
const studentId = response.studentId;
const message = response.message;
const username = response.username;
const schoolUdise = response.schoolUdise;
const studentId = response?.studentId;
const message = response?.message;
const username = response?.username;
const schoolUdise = response?.schoolUdise;

const studentData = {
studentId,
Expand All @@ -41,17 +41,17 @@ const studentBulkAPI = async (student) => {

});

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

if (res.status === 201) {
if (res?.status === 201) {
result = true;
} else {
result = false;
}
})
.catch(function (error) {
console.log(error.response.data.error);
console.log(error?.response?.data?.error);
let err = 0;
return err;
});
Expand Down
11 changes: 6 additions & 5 deletions packages/admin/src/api/teacherBulkAPI.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ const teacherBulkAPI = async (teacher) => {
headers: headers,
})
.then((res) => {
const names = res.data.errors.map((error) => error.name).filter(Boolean);
if (res.data.errors && res.data.errors.length > 0) {
const firstError = res.data.errors[0];
const names = res?.data?.data?.errors.map((error) => error.name).filter(Boolean);
if (res?.data?.data?.errors && res?.data?.data?.errors.length > 0) {
const firstError = res?.data?.data?.errors[0];
if (firstError.teacherRes && firstError.teacherRes.errorMessage) {
const errorMessage = firstError.teacherRes.errorMessage;
localStorage.setItem("errorMessage", errorMessage);
Expand All @@ -32,9 +32,10 @@ const teacherBulkAPI = async (teacher) => {
console.log("No errors in the response data.");
}

localStorage.setItem("bulkErrors", res.data.errors.length - 1);
const errorCount = res?.data?.data?.errors?.length ?? 0;
localStorage.setItem("bulkErrors", errorCount > 0 ? errorCount - 1 : 0);
localStorage.setItem("bulkErrorsNames", names);
localStorage.setItem("successCount", res.data.successCount);
localStorage.setItem("successCount", res?.data?.data?.successCount);
if (res.status === 201) {
result = true;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/assets/images/FinalSchool.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
School UDISE code,School Name,Location,School Management,School Composition,Board,Medium of Instruction,Head Master,Headmaster Type,Headmaster Mobile,Number of teachers sanctioned -Upper Primary,Number of teachers sanctioned -Secondary,Library Functional,Computer Lab functional,Number of functional computers,Number of Boys toilet,Number of Girls toilet,Smart Board functional in Class 6,Smart Board functional in Class 7,Smart Board functional in Class 8,Smart Board functional in Class 9,Smart Board functional in Class 10,State,District,Block,Adequate Rooms For EveryClass,Drinking Water Supply,Separate Toilet For Girls And Boys,Whether Toilet Being Used,Playground Available,Boundary Wall Fence,Electric Fittings Are Insulated,Building Is Resistant To Earthquake Fire Flood Other Calamity,Building Is Free From Inflammable And Toxic Materials,Roof And Walls Are In Good Condition
234234234,New Park School,Urban,Others,Boys,Odisha,English,dummy,FullTime,8805852647,1,5,Yes,Yes,1,1,1,Yes,Yes,Yes,Yes,Yes,Maharashtra,Pune,Pune,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE
6969696969,New Park School,Urban,Others,Boys,Odisha,English,dummy,FullTime,8805852647,1,5,Yes,Yes,1,1,1,Yes,Yes,Yes,Yes,Yes,Maharashtra,Pune,Pune,True,True,True,True,True,True,True,True,True,True
4 changes: 2 additions & 2 deletions packages/admin/src/assets/images/FinalStudent.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name,username,email,mobile,gender,dateOfBirth,board,password,status,className,religion,school_udise,caste,annual_income,mother_education,father_education,mother_occupation,father_occupation,No_of_siblings,promotion
Test,retesttekdiwb600112121884,,9999999999,Female ,1990-01-03,West Bengal,NA ,TRUE,Class 7,Hindu,12345678,General,668,,,,,,,
name,username,email,mobile,gender,dateOfBirth,board,password,status,className,religion,school_udise,caste,annual_income,mother_education,father_education,mother_occupation,father_occupation,No_of_siblings,promotion,state,district,block,promotion
Ankushkumar Maherwal,696969696969,,9999999999,Male,1991-11-02,West Bengal,696969696969 ,True,Class 7,Hindu,12345678,General,668,,,,,,,Maharashtra,Pune,Pune,,
2 changes: 1 addition & 1 deletion packages/admin/src/assets/images/FinalTeacher.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Name,Email Id,Mobile,Gender,DoB,board,Status,Classes taught,School Udise,Educational Qualification,Current role,Nature of appointment,Appointed Postname,Total Experience in teaching,Total experience as Head Teacher,Core subject taught,Attended In service teacher training,Last training attended (Topic),Last training attended (Year),Trained in use of computer & digital teaching
xyzabcd teacher xyz,,1234567890,female,1992-05-12,Maharashtra,true,Secondary,123456789,BA,teacher,NA,teacher,5,5,Science,no,,,yes
Ankushkumar Maherwal,,9878767678,Male,1992-05-12,Maharashtra,True,Secondary,123456789,Graduation,Teacher,Regular,TGTCBZ,2_5yrs,2_5yrs,Science,,,,
63 changes: 32 additions & 31 deletions packages/admin/src/components/DownloadCsv.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ const DownloadCsv = ({ open, handleClose }) => {
// Update districts based on selected state
useEffect(() => {
const loadDistricts = async () => {
if (!dropdownValues.stateDropdown) return; // Check for selected state
if (!dropdownValues.stateDropdown?.label) return; // Check for selected state
try {
const token = sessionStorage.getItem("token");
const districts = await fetchDistricts(
token,
dropdownValues.stateDropdown
dropdownValues.stateDropdown?.label
);
setDistrictOptions(districts);

const blocks = await fetchBlocks(token, dropdownValues.stateDropdown);
const blocks = await fetchBlocks(token, dropdownValues.stateDropdown?.label);
setBlockOptions(blocks);

const schools = await fetchSchools(token, dropdownValues.stateDropdown);
const schools = await fetchSchools(token, dropdownValues.stateDropdown?.label);
setSchoolOptions(schools);
} catch (error) {
console.error("Error loading districts:", error);
Expand All @@ -121,14 +121,14 @@ const DownloadCsv = ({ open, handleClose }) => {
// Update blocks based on selected district
useEffect(() => {
const loadBlocks = async () => {
if (!dropdownValues.districtDropdown) return; // Check for selected district
if (!dropdownValues.districtDropdown?.label) return; // Check for selected district
try {
const token = sessionStorage.getItem("token");

const blocks = await fetchBlocks(
token,
dropdownValues.stateDropdown,
dropdownValues.districtDropdown
dropdownValues.stateDropdown?.label,
dropdownValues.districtDropdown?.label
);
setBlockOptions(blocks);
} catch (error) {
Expand All @@ -145,9 +145,9 @@ const DownloadCsv = ({ open, handleClose }) => {
const token = sessionStorage.getItem("token");
const schools = await fetchSchools(
token,
dropdownValues.stateDropdown,
dropdownValues.districtDropdown,
dropdownValues.blockDropdown
dropdownValues.stateDropdown?.label,
dropdownValues.districtDropdown?.label,
dropdownValues.blockDropdown?.label
);
setSchoolOptions(schools);
} catch (error) {
Expand All @@ -164,7 +164,7 @@ const DownloadCsv = ({ open, handleClose }) => {
const token = sessionStorage.getItem("token");
const classes = await fetchClasses(
token,
dropdownValues.schoolNameDropdown
dropdownValues?.schoolNameDropdown?.label
);
console.log("classes", classes);
setClassOptions(classes);
Expand All @@ -184,11 +184,11 @@ const DownloadCsv = ({ open, handleClose }) => {

// Ensure at least one dropdown value is selected before allowing download
if (
!dropdownValues.stateDropdown &&
!dropdownValues.districtDropdown &&
!dropdownValues.blockDropdown &&
!dropdownValues.schoolNameDropdown &&
!dropdownValues.classNameDropdown
!dropdownValues.stateDropdown?.label &&
!dropdownValues.districtDropdown?.label &&
!dropdownValues.blockDropdown?.label &&
!dropdownValues.schoolNameDropdown?.label &&
!dropdownValues.classNameDropdown?.label
) {
alert("Please select at least one filter before downloading.");
return false;
Expand All @@ -199,20 +199,20 @@ const DownloadCsv = ({ open, handleClose }) => {
filters: {},
};

if (dropdownValues.stateDropdown) {
payload.filters.state = { eq: dropdownValues.stateDropdown };
if (dropdownValues.stateDropdown?.label) {
payload.filters.state = { eq: dropdownValues.stateDropdown?.label };
}
if (dropdownValues.districtDropdown) {
payload.filters.district = { eq: dropdownValues.districtDropdown };
if (dropdownValues.districtDropdown?.label) {
payload.filters.district = { eq: dropdownValues.districtDropdown?.label };
}
if (dropdownValues.blockDropdown) {
payload.filters.block = { eq: dropdownValues.blockDropdown };
if (dropdownValues.blockDropdown?.label) {
payload.filters.block = { eq: dropdownValues.blockDropdown?.label };
}
if (dropdownValues.schoolNameDropdown) {
payload.filters.schoolName = { eq: dropdownValues.schoolNameDropdown };
if (dropdownValues.schoolNameDropdown?.label) {
payload.filters.udiseCode = { eq: dropdownValues?.schoolNameDropdown?.udiseCode };
}
if (dropdownValues.classNameDropdown) {
payload.filters.class = { eq: dropdownValues.classNameDropdown };
if (dropdownValues.classNameDropdown?.label) {
payload.filters.class = { eq: dropdownValues.classNameDropdown?.label };
}

try {
Expand Down Expand Up @@ -292,11 +292,11 @@ const DownloadCsv = ({ open, handleClose }) => {
};

const isDownloadDisabled =
!dropdownValues.stateDropdown &&
!dropdownValues.districtDropdown &&
!dropdownValues.blockDropdown &&
!dropdownValues.schoolNameDropdown &&
!dropdownValues.classNameDropdown;
!dropdownValues.stateDropdown?.label &&
!dropdownValues.districtDropdown?.label &&
!dropdownValues.blockDropdown?.label &&
!dropdownValues.schoolNameDropdown?.label &&
!dropdownValues.classNameDropdown?.label;

const handleChange = (event, value, name) => {
const dropdownOrder = [
Expand Down Expand Up @@ -452,6 +452,7 @@ const DownloadCsv = ({ open, handleClose }) => {
<Autocomplete
disablePortal
options={schoolOptions}
getOptionLabel={(option) => `${option?.label} (${option?.udiseCode})`}
value={dropdownValues.schoolNameDropdown} // Manage this state accordingly
onChange={(event, value) =>
handleChange(event, value, "schoolNameDropdown")
Expand Down
3 changes: 2 additions & 1 deletion packages/admin/src/components/FilterTableData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const FilterTableData = ({ open, handleClose, rowData, onApplyFilter }) => {
<Autocomplete
disablePortal
options={filterOptions}
getOptionLabel={(option) => option.label}
getOptionLabel={(option) => option.label || ""}
value={filterOption}
onChange={(event, value) => setFilterOption(value)}
sx={{ width: "100%", marginBottom: 2 }}
Expand All @@ -88,6 +88,7 @@ const FilterTableData = ({ open, handleClose, rowData, onApplyFilter }) => {
<Autocomplete
disablePortal
options={filterValues}
getOptionLabel={(option) => option.label || ""}
value={selectedFilterValue}
onChange={(event, value) => setSelectedFilterValue(value)}
disabled={!filterOption} // Disable until a filter option is selected
Expand Down
29 changes: 17 additions & 12 deletions packages/admin/src/components/StudentFilters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ const StudentFilters = ({ handleFiltersChange }) => {

useEffect(() => {
const loadDistricts = async () => {
if (!dropdownValues.stateDropdown) return;
if (!dropdownValues.stateDropdown.label) return;
try {
const token = sessionStorage.getItem("token");
const districts = await fetchDistricts(
token,
dropdownValues.stateDropdown
dropdownValues.stateDropdown.label
);
setDistrictOptions(districts);

const blocks = await fetchBlocks(token, dropdownValues.stateDropdown);
const blocks = await fetchBlocks(token, dropdownValues.stateDropdown.label);
setBlockOptions(blocks);

const schools = await fetchSchools(token, dropdownValues.stateDropdown);
const schools = await fetchSchools(token, dropdownValues.stateDropdown.label);
setSchoolOptions(schools);
} catch (error) {
console.error("Error loading districts:", error);
Expand All @@ -98,14 +98,14 @@ const StudentFilters = ({ handleFiltersChange }) => {
// Update blocks based on selected district
useEffect(() => {
const loadBlocks = async () => {
if (!dropdownValues.districtDropdown) return;
if (!dropdownValues.districtDropdown.label) return;
try {
const token = sessionStorage.getItem("token");

const blocks = await fetchBlocks(
token,
dropdownValues.stateDropdown,
dropdownValues.districtDropdown
dropdownValues.stateDropdown.label,
dropdownValues.districtDropdown.label
);
setBlockOptions(blocks);
} catch (error) {
Expand All @@ -122,9 +122,9 @@ const StudentFilters = ({ handleFiltersChange }) => {
const token = sessionStorage.getItem("token");
const schools = await fetchSchools(
token,
dropdownValues.stateDropdown,
dropdownValues.districtDropdown,
dropdownValues.blockDropdown
dropdownValues.stateDropdown.label,
dropdownValues.districtDropdown.label,
dropdownValues.blockDropdown.label
);
setSchoolOptions(schools);
} catch (error) {
Expand All @@ -137,12 +137,12 @@ const StudentFilters = ({ handleFiltersChange }) => {
// Fetch classes based on selected school
useEffect(() => {
const loadClasses = async () => {
if (!dropdownValues.schoolNameDropdown) return;
if (!dropdownValues.schoolNameDropdown.label) return;
try {
const token = sessionStorage.getItem("token");
const classes = await fetchClasses(
token,
dropdownValues.schoolNameDropdown
dropdownValues.schoolNameDropdown.label
);
setClassOptions(classes);
} catch (error) {
Expand Down Expand Up @@ -186,6 +186,7 @@ const StudentFilters = ({ handleFiltersChange }) => {
<Autocomplete
disablePortal
options={stateOptions}
getOptionLabel={(option) => option.label || ""}
value={dropdownValues.stateDropdown}
onChange={(event, value) =>
handleChange(event, value, "stateDropdown")
Expand All @@ -207,6 +208,7 @@ const StudentFilters = ({ handleFiltersChange }) => {
<Autocomplete
disablePortal
options={districtOptions}
getOptionLabel={(option) => option.label || ""}
value={dropdownValues.districtDropdown}
onChange={(event, value) =>
handleChange(event, value, "districtDropdown")
Expand All @@ -228,6 +230,7 @@ const StudentFilters = ({ handleFiltersChange }) => {
<Autocomplete
disablePortal
options={blockOptions}
getOptionLabel={(option) => option.label || ""}
value={dropdownValues.blockDropdown}
onChange={(event, value) =>
handleChange(event, value, "blockDropdown")
Expand All @@ -249,6 +252,7 @@ const StudentFilters = ({ handleFiltersChange }) => {
<Autocomplete
disablePortal
options={schoolOptions}
getOptionLabel={(option) => `${option.label} (${option.udiseCode})`}
value={dropdownValues.schoolNameDropdown}
onChange={(event, value) =>
handleChange(event, value, "schoolNameDropdown")
Expand All @@ -270,6 +274,7 @@ const StudentFilters = ({ handleFiltersChange }) => {
<Autocomplete
disablePortal
options={classOptions}
getOptionLabel={(option) => option.label || ""}
value={dropdownValues.classNameDropdown}
onChange={(event, value) =>
handleChange(event, value, "classNameDropdown")
Expand Down
Loading

0 comments on commit 9287fe7

Please sign in to comment.