diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 83970bbf..93d98fcb 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -62,7 +62,6 @@ "SEARCHBAR_PLACEHOLDER": "Search Facilitators..", "FACILITATOR_CREATED_SUCCESSFULLY": "Teacher has been Successfully Created", "FACILITATOR_UPDATED_SUCCESSFULLY": "Teacher has been Successfully Updated!" - }, "NAVBAR": { "SEARCHBAR_PLACEHOLDER": "Search course, topic, student, pdf etc.." @@ -73,7 +72,6 @@ "FIRST_SELECT_REQUIRED_FIELDS": "First select required fields", "LEARNER_CREATED_SUCCESSFULLY": "Leaner has been Successfully Created!", "LEARNER_UPDATED_SUCCESSFULLY": "Leaner has been Successfully Updated!" - }, "TEAM_LEADERS": { "SEARCHBAR_PLACEHOLDER": "Search Team leaders.." @@ -130,8 +128,10 @@ "RENAME": "Rename", "CENTER_RENAMED": "Center Renamed Successfully!", "SEND_REQUEST": "Send Request", - "REQUEST_TO_DELETE_HAS_BEEN_SENT": "Request to Delete has been sent", - "SURE_DELETE_COHORT": "Are you sure you want to Delete Center ?" + "SURE_DELETE_COHORT": "Are you sure you want to Delete Center ?", + "CENTER_UPDATE_SUCCESSFULLY": "Cohort has been Successfully Updated", + "CENTER_DELETE_SUCCESSFULLY": "Cohort has been Successfully Deleted", + "CENTER_CREATED_SUCCESSFULLY": "Cohort Created Successfully" }, "FORM": { "FULL_NAME": "Full Name", @@ -200,9 +200,9 @@ "MIN_LENGTH_CHARACTERS_ERROR": "Minimum {{minLength}} characters required", "MAX_LENGTH_CHARACTERS_ERROR": "Maximum {{maxLength}} characters allowed", "NUMBER_AND_SPECIAL_CHARACTERS_NOT_ALLOWED": "Numbers and special characters are not allowed", - "NAME_CANNOT_INCLUDE_DIGITS":"Name can not include digits", - "INVALID_EMAIL_FORMAT":"Invalid email format" -}, + "NAME_CANNOT_INCLUDE_DIGITS": "Name can not include digits", + "INVALID_EMAIL_FORMAT": "Invalid email format" + }, "TABLE_TITLE": { "NAME": "Name", "STATUS": "Status", diff --git a/src/pages/cohorts.tsx b/src/pages/cohorts.tsx index 670867ac..2480cfe5 100644 --- a/src/pages/cohorts.tsx +++ b/src/pages/cohorts.tsx @@ -13,7 +13,7 @@ import { getCohortList, updateCohortUpdate, } from "@/services/CohortService/cohortService"; -import { Role, SORT, Status, Storage } from "@/utils/app.constant"; +import { Numbers, Role, SORT, Status, Storage } from "@/utils/app.constant"; import EditIcon from "@mui/icons-material/Edit"; import DeleteIcon from "@mui/icons-material/Delete"; import ConfirmationModal from "@/components/ConfirmationModal"; @@ -34,6 +34,7 @@ import DynamicForm from "@/components/DynamicForm"; import { IChangeEvent } from "@rjsf/core"; import { RJSFSchema } from "@rjsf/utils"; import { CustomField } from "@/utils/Interfaces"; +import { showToastMessage } from "@/components/Toastify"; type cohortFilterDetails = { type?: string; @@ -129,15 +130,17 @@ const Cohorts: React.FC = () => { const [openAddNewCohort, setOpenAddNewCohort] = React.useState(false); - const [pageCount, setPageCount] = useState(1); - const [pageOffset, setPageOffset] = useState(0); - const [pageLimit, setPageLimit] = useState(10); + const [pageCount, setPageCount] = useState(Numbers.ONE); + const [pageOffset, setPageOffset] = useState(Numbers.ZERO); + const [pageLimit, setPageLimit] = useState(Numbers.TEN); const [pageSizeArray, setPageSizeArray] = React.useState([]); const [filters, setFilters] = useState({ type: "COHORT", }); const [sortBy, setSortBy] = useState(["createdAt", "asc"]); - + const [selectedStateCode, setSelectedStateCode] = useState(""); + const [selectedDistrictCode, setSelectedDistrictCode] = useState(""); + const [selectedBlockCode, setSelectedBlockCode] = useState(""); // use api calls useEffect(() => { if (typeof window !== "undefined" && window.localStorage) { @@ -229,34 +232,122 @@ const Cohorts: React.FC = () => { }; const PagesSelector = () => ( - + + + ); const PageSizeSelectorFunction = ({}) => ( - <> + - + ); - const handleStateChange = (selected: string[]) => { + const handleStateChange = async (selected: string[], code: string[]) => { + setSelectedDistrict([]); + setSelectedBlock([]); setSelectedState(selected); - console.log("Selected categories:", selected); + + if (selected[0] === "") { + if (filters.status) setFilters({ status: filters.status }); + // else setFilters({ role: role }); + } else { + const stateCodes = code?.join(","); + console.log("stateCodes", stateCodes); + setSelectedStateCode(stateCodes); + if (filters.status) + setFilters({ status: filters.status, states: stateCodes }); + else setFilters({ states: stateCodes }); + } + + console.log("Selected categories:", typeof code[0]); }; - const handleDistrictChange = (selected: string[]) => { + + const handleDistrictChange = (selected: string[], code: string[]) => { + setSelectedBlock([]); setSelectedDistrict(selected); + + if (selected[0] === "") { + if (filters.status) { + setFilters({ + status: filters.status, + states: selectedStateCode, + + // role: role, + }); + } else { + setFilters({ + states: selectedStateCode, + // role: role, + }); + } + } else { + const districts = code?.join(","); + setSelectedDistrictCode(districts); + if (filters.status) { + setFilters({ + status: filters.status, + states: selectedStateCode, + districts: districts, + + // role: role, + }); + } else { + setFilters({ + states: selectedStateCode, + districts: districts, + // role: role, + }); + } + } console.log("Selected categories:", selected); }; - const handleBlockChange = (selected: string[]) => { + const handleBlockChange = (selected: string[], code: string[]) => { setSelectedBlock(selected); + if (selected[0] === "") { + if (filters.status) { + setFilters({ + status: filters.status, + states: selectedStateCode, + districts: selectedDistrictCode, + // role: role, + }); + } else { + setFilters({ + states: selectedStateCode, + districts: selectedDistrictCode, + // role: role, + }); + } + } else { + const blocks = code?.join(","); + setSelectedBlockCode(blocks); + if (filters.status) { + setFilters({ + status: filters.status, + states: selectedStateCode, + districts: selectedDistrictCode, + blocks: blocks, + // role: role, + }); + } else { + setFilters({ + states: selectedStateCode, + districts: selectedDistrictCode, + blocks: blocks, + // role: role, + }); + } + } console.log("Selected categories:", selected); }; @@ -273,6 +364,7 @@ const Cohorts: React.FC = () => { console.log(resp); if (resp?.responseCode === 200) { console.log(resp?.params?.successmessage); + showToastMessage(t("CENTERS.CENTER_DELETE_SUCCESSFULLY"), "success"); fetchUserList(); } else { console.log("Cohort Not Archived"); @@ -304,17 +396,17 @@ const Cohorts: React.FC = () => { console.log(event.target.value as string); setSelectedFilter(event.target.value as string); - if (event.target.value === "Active") { + if (event.target.value === Status.ACTIVE_LABEL) { setFilters((prevFilters) => ({ ...prevFilters, - status: ["active"], + status: [Status.ACTIVE], })); - } else if (event.target.value === "Archived") { + } else if (event.target.value === Status.ARCHIVED_LABEL) { setFilters((prevFilters) => ({ ...prevFilters, - status: ["archived"], + status: [Status.ARCHIVED], })); - } else if (event.target.value === "All") { + } else if (event.target.value === Status.ALL_LABEL) { setFilters((prevFilters) => ({ ...prevFilters, status: "", @@ -381,6 +473,7 @@ const Cohorts: React.FC = () => { const resp = await updateCohortUpdate(selectedCohortId, cohortDetails); setLoading(false); console.log("resp:", resp); + showToastMessage(t("CENTERS.CENTER_UPDATE_SUCCESSFULLY"), "success"); } else { setLoading(false); console.log("No cohort Id Selected"); @@ -431,6 +524,9 @@ const Cohorts: React.FC = () => { } }); const cohortData = await createCohort(cohortDetails); + if (cohortData) { + showToastMessage(t("CENTERS.CENTER_CREATED_SUCCESSFULLY"), "success"); + } setOpenAddNewCohort(false); fetchUserList(); }; @@ -444,6 +540,7 @@ const Cohorts: React.FC = () => { userType: t("SIDEBAR.COHORTS"), searchPlaceHolder: t("COHORTS.SEARCHBAR_PLACEHOLDER"), selectedState: selectedState, + selectedStateCode: selectedStateCode, selectedDistrict: selectedDistrict, selectedBlock: selectedBlock, selectedSort: selectedSort, diff --git a/src/services/CohortService/cohortService.ts b/src/services/CohortService/cohortService.ts index 11b74da5..129e23cd 100644 --- a/src/services/CohortService/cohortService.ts +++ b/src/services/CohortService/cohortService.ts @@ -25,7 +25,6 @@ export const getCohortList = async (data: cohortListData): Promise => { } }; - export const updateCohortUpdate = async ( userId: string, cohortDetails: { @@ -82,7 +81,7 @@ export const createCohort = async (userData: any): Promise => { const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/cohort/create`; try { const response = await post(apiUrl, userData); - return response?.data?.result; + return response?.data; } catch (error) { console.error("error in getting cohort list", error); // throw error; diff --git a/src/utils/app.constant.ts b/src/utils/app.constant.ts index 23ff49f0..c8707474 100644 --- a/src/utils/app.constant.ts +++ b/src/utils/app.constant.ts @@ -7,7 +7,10 @@ export enum Role { export enum Status { ARCHIVED = "archived", + ARCHIVED_LABEL = "Archived", ACTIVE = "active", + ACTIVE_LABEL = "Active", + ALL_LABEL = "All", } export enum SORT { ASCENDING = "asc", @@ -44,3 +47,9 @@ export enum DataKey { export enum DateFormat { YYYY_MM_DD = "yyyy-MM-dd", } + +export enum Numbers { + ZERO = 0, + ONE = 1, + TEN = 10, +}