Skip to content

Commit

Permalink
Merge pull request #236 from upendraTekdi/latest_code_admin_oblf
Browse files Browse the repository at this point in the history
Task #224820: update all changes of oblf admin
  • Loading branch information
itsvick authored Oct 3, 2024
2 parents 1f9a31f + 5af246f commit 9c64b27
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 53 deletions.
23 changes: 15 additions & 8 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@
"UPDATE_CLASS": "Update Class",
"CLASS_UPDATED_SUCCESS": "Class Updated Successfully!",
"CLASS_ADDED_SUCCESS": "Class Added Successfully!",
"CLASS_NOT_FOUND": "Class not found"
"CLASS_NOT_FOUND": "Class not found",
"SCHOOL_NAME_REQUIRED": "School Name Required",
"SCHOOL_CODE_REQUIRED": "School Code Required"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -300,7 +302,10 @@
"TAKEN_TC": "Taken TC",
"ALLOCATION_CHANGE": "Allocation Change",
"INCORRECT_ENTRY": "Incorrect Entry",
"DUPLICATION_ENTRY": "Duplicate Entry"
"DUPLICATION_ENTRY": "Duplicate Entry",
"CENTER_CREATED_SUCCESSFULLY": "Center Created Successfully",
"NOT_ABLE_CREATE_CENTER": "Not Able To Create Center",
"NO_COHORT_ID_SELECTED":"No Cohort Id Selected"
},
"FORM": {
"FULL_NAME": "Full Name",
Expand Down Expand Up @@ -397,12 +402,14 @@
"PROGRAM": "Program",
"IS_STUDENT_INVOLVED_IN_ANY_SUB_PROGRAM": "Is Student Involved In Any Sub Program",
"SUB_PROGRAM": "Sub Program",
"VILLAGE_NAME":"Village Name",
"DATE_OF_JOINING":"Date Of joining",
"OLD_TEACHER_ID":"Old Teacher Id",
"DATE_OF_LEAVING":"Date Of Leaving",
"REASON_FOR_LEAVING":"Reason For Leaving",
"EMPLOYEE_ID":"Employee Id"
"VILLAGE_NAME": "Village Name",
"DATE_OF_JOINING": "Date Of joining",
"OLD_TEACHER_ID": "Old Teacher Id",
"DATE_OF_LEAVING": "Date Of Leaving",
"REASON_FOR_LEAVING": "Reason For Leaving",
"EMPLOYEE_ID": "Employee Id",
"FROM_TIME": "From Time",
"TO_TIME": "To Time"
},
"FORM_ERROR_MESSAGES": {
"INVALID_INPUT": "Invalid Input.",
Expand Down
3 changes: 3 additions & 0 deletions src/components/AddNewCenters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
}
} else {
showToastMessage("Please Input Data", "warning");
onClose();
}
} else {

showToastMessage(t("CENTER.NOT_ABLE_CREATE_CENTER"), "error");
onClose();
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/components/layouts/sidebar/MenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ const Menuitems = [
title: "Class",
href: "/class",
},
{
title: "Slot",
href: "/slot",
},
// {
// title: "Slot",
// href: "/slot",
// },
],
},
showCoursePlanner && {
Expand Down
144 changes: 111 additions & 33 deletions src/pages/centers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ const Center: React.FC = () => {

const [filters, setFilters] = useState<cohortFilterDetails>({
type: CohortTypes.COHORT,
states: selectedStateCode,
// states: selectedStateCode,
status: [statusValue],
});
const handleCloseAddLearnerModal = () => {
Expand Down Expand Up @@ -208,21 +208,12 @@ const Center: React.FC = () => {
sort: sort,
filters: filters,
};
const resp = await queryClient.fetchQuery({
queryKey: [
QueryKeys.GET_COHORT_LIST,
data.limit,
data.offset,
JSON.stringify(data.filters),
JSON.stringify(data.sort),
],
queryFn: () => getCohortList(data),
});
const resp = await getCohortList(data);
if (resp) {
const result = resp?.results?.cohortDetails;
const result = await resp?.results?.cohortDetails;
const resultData: centerData[] = [];

const cohortIds = result.map((item: any) => item.cohortId); // Extract cohort IDs
const cohortIds = result?.map((item: any) => item.cohortId); // Extract cohort IDs

// Fetch member counts for each cohort
const memberCounts = await Promise.all(
Expand Down Expand Up @@ -257,7 +248,11 @@ const Center: React.FC = () => {
};
resultData?.push(requiredData);
});
setCohortData(resultData);
if (resultData) {
setCohortData(resultData);
}

console.log("resultData", resultData);
const totalCount = resp?.count;
setTotalCound(totalCount);

Expand All @@ -273,12 +268,14 @@ const Center: React.FC = () => {
);
const pageCount = Math.ceil(totalCount / pageLimit);
setPageCount(pageCount);
setLoading(false);
// setLoading(false);
}
} catch (error) {
setCohortData([]);
setLoading(false);
console.error("Error fetching user list:", error);
} finally {
setLoading(false);
}
};

Expand All @@ -299,7 +296,7 @@ const Center: React.FC = () => {

const getCohortMemberlistData = async (cohortId: string) => {
const data = {
limit: 300,
limit: 0,
page: 0,
filters: {
cohortId: cohortId,
Expand Down Expand Up @@ -361,7 +358,7 @@ const Center: React.FC = () => {
useEffect(() => {
fetchUserList();
getFormData();
}, [pageOffset, pageLimit, sortBy, filters, filters.states, filters.status]);
}, [pageOffset, pageLimit, sortBy, filters, filters.status]);

// handle functions
const handleChange = (event: SelectChangeEvent<typeof pageSize>) => {
Expand Down Expand Up @@ -607,6 +604,7 @@ const Center: React.FC = () => {

const cohortDetails = resp?.results?.cohortDetails?.[0] || {};
setEditFormData(mapFields(formFields, cohortDetails));

setLoading(false);
setIsEditForm(true);
}
Expand Down Expand Up @@ -752,20 +750,76 @@ const Center: React.FC = () => {
) => {
setLoading(true);
const formData = data?.formData;
const schoolFieldOptions = centerFormData.fields.find(
(item: any) => item.name === "nondependantschools"
);
const schoolField = schoolFieldOptions.options.find(
(item: any) => item.value === formData.nondependantschools
);

const classFieldOptions = centerFormData.fields.find(
(item: any) => item.name === "classes"
);
const classField = classFieldOptions.options.find(
(item: any) => item.value === formData.classes
);
//const schemaProperties = schema.properties;
const originalTime = formData.from_time;
const timeBefore = adjustTime(originalTime, -5); // 5 minutes before
const timeAfter = adjustTime(originalTime, 5); // 5 minutes after

const fromTimeOption = centerFormData.fields.find(
(item: any) => item.name === "from_time"
);

const schoolOption = centerFormData.fields.find(
(item: any) => item.name === "nondependantschools"
);
const classOption = centerFormData.fields.find(
(item: any) => item.name === "classes"
);
const toTimeOption = centerFormData.fields.find(
(item: any) => item.name === "to_time"
);

console.log("fromTimeOption", fromTimeOption);

// Extract the field IDs dynamically
const fromTimeFieldId = fromTimeOption?.fieldId || "";
const toTimeFieldId = toTimeOption?.fieldId || "";
const schoolFieldId = schoolOption?.fieldId || "";
const classFieldId = classOption?.fieldId || "";

console.log("formDataFOR EDIT", formData);


// Initialize the API body similar to handleSubmit
let cohortDetails: CohortDetails = {
name: formData?.name,
customFields: [],
name: schoolField.label + ", " + classField.label + ", ",
customFields: [
{
fieldId: fromTimeFieldId,
value: formData.from_time,
},
{
fieldId: toTimeFieldId,
value: formData.to_time,
},
{
fieldId: schoolFieldId,
value: [schoolField.value],
},
{
fieldId: classFieldId,
value: [classField.value],
},
],
params: {
self: {
allowed: 1,
allow_late_marking: 1,
restrict_attendance_timings: 1,
attendance_starts_at: formData?.attendance_starts_at,
attendance_ends_at: formData?.attendance_ends_at,
attendance_starts_at: timeBefore,
attendance_ends_at: timeAfter,
back_dated_attendance: 0,
back_dated_attendance_allowed_days: 0,
can_be_updated: 0,
Expand Down Expand Up @@ -801,6 +855,7 @@ const Center: React.FC = () => {
}
const resp = await updateCohortUpdate(selectedCohortId, cohortDetails);
if (resp?.responseCode === 200 || resp?.responseCode === 201) {
fetchUserList();
showToastMessage(t("CENTERS.CLASS_UPDATE_SUCCESSFULLY"), "success");
} else {
showToastMessage(t("CENTERS.CLASS_UPDATE_FAILED"), "error");
Expand Down Expand Up @@ -938,6 +993,12 @@ const Center: React.FC = () => {
(item: any) => item.name === "from_time"
);

const schoolOption = centerFormData.fields.find(
(item: any) => item.name === "nondependantschools"
);
const classOption = centerFormData.fields.find(
(item: any) => item.name === "classes"
);
const toTimeOption = centerFormData.fields.find(
(item: any) => item.name === "to_time"
);
Expand All @@ -947,6 +1008,8 @@ const Center: React.FC = () => {
// Extract the field IDs dynamically
const fromTimeFieldId = fromTimeOption?.fieldId || "";
const toTimeFieldId = toTimeOption?.fieldId || "";
const schoolFieldId = schoolOption?.fieldId || "";
const classFieldId = classOption?.fieldId || "";

console.log(
"cohortName",
Expand Down Expand Up @@ -1004,14 +1067,26 @@ const Center: React.FC = () => {
fieldId: toTimeFieldId,
value: formData.to_time,
},
{
fieldId: schoolFieldId,
value: [schoolField.value],
},
{
fieldId: classFieldId,
value: [classField.value],
},
],
};
console.log("cohortDetails", newClassCohort);

const cohortData = await createCohort(newClassCohort);

if (cohortData) {
showToastMessage(t("CENTERS.CENTER_CREATED_SUCCESSFULLY"), "success");
setOpenAddNewCohort(false);
// onClose();
} else {
showToastMessage(t("CENTER.NOT_ABLE_CREATE_CENTER"), "error");
setOpenAddNewCohort(false);
}
fetchUserList();
};
Expand Down Expand Up @@ -1106,6 +1181,7 @@ const Center: React.FC = () => {
/>

<HeaderComponent {...userProps}>
{/* {console.log("cohortData",cohortData)} */}
{loading ? (
<Box
width={"100%"}
Expand Down Expand Up @@ -1133,16 +1209,18 @@ const Center: React.FC = () => {
onDelete={handleDelete}
/>
) : (
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="20vh"
>
<Typography marginTop="10px" textAlign={"center"}>
{t("COMMON.NO_CLASSES_FOUND")}
</Typography>
</Box>
!loading && (
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="20vh"
>
<Typography marginTop="10px" textAlign={"center"}>
{t("COMMON.NO_CLASSES_FOUND")}
</Typography>
</Box>
)
)}

<AddNewCenters
Expand Down
12 changes: 4 additions & 8 deletions src/services/CohortService/cohortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const createUser = async (userData: any): Promise<any> => {
return response?.data?.result;
} catch (error) {
console.error("error in getting cohort list", error);
return error
return error;
// throw error;
}
};
Expand All @@ -85,7 +85,7 @@ export const createCohort = async (userData: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/create`;
try {
const response = await post(apiUrl, userData);
return response?.data;
return response?.data ? response?.data :response;
} catch (error) {
console.error("error in getting cohort list", error);
// throw error;
Expand Down Expand Up @@ -113,20 +113,17 @@ export const fetchCohortMemberList = async ({
}
};



export const bulkCreateCohortMembers = async (payload: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohortmember/bulkCreate`;
try {
const response = await post(apiUrl, payload);
return response.data;
} catch (error) {
console.error('Error in bulk creating cohort members', error);
console.error("Error in bulk creating cohort members", error);
throw error;
}
};


export const updateCohortMemberStatus = async ({
memberStatus,
statusReason,
Expand All @@ -138,10 +135,9 @@ export const updateCohortMemberStatus = async ({
status: memberStatus,
statusReason,
});
console.log('data', response?.data);
return response?.data;
} catch (error) {
console.error('error in attendance report api ', error);
console.error("error in attendance report api ", error);
// throw error;
}
};
Loading

0 comments on commit 9c64b27

Please sign in to comment.