Skip to content

Commit

Permalink
Task #223476: Add tostify messages , Filter cohort by district , bloc…
Browse files Browse the repository at this point in the history
…k, center
  • Loading branch information
upendraTekdi committed Jul 30, 2024
1 parent 987d933 commit 24bea6b
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 31 deletions.
14 changes: 7 additions & 7 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.."
Expand All @@ -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.."
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
141 changes: 119 additions & 22 deletions src/pages/cohorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down Expand Up @@ -129,15 +130,17 @@ const Cohorts: React.FC = () => {
const [openAddNewCohort, setOpenAddNewCohort] =
React.useState<boolean>(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<number[]>([]);
const [filters, setFilters] = useState<cohortFilterDetails>({
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) {
Expand Down Expand Up @@ -229,34 +232,122 @@ const Cohorts: React.FC = () => {
};

const PagesSelector = () => (
<Pagination
color="primary"
count={pageCount}
page={pageOffset + 1}
onChange={handlePaginationChange}
/>
<Box mt={3}>
<Pagination
color="primary"
count={pageCount}
page={pageOffset + 1}
onChange={handlePaginationChange}
/>
</Box>
);

const PageSizeSelectorFunction = ({}) => (
<>
<Box mt={2}>
<PageSizeSelector
handleChange={handleChange}
pageSize={pageSize}
options={pageSizeArray}
/>
</>
</Box>
);

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);
};

Expand All @@ -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");
Expand Down Expand Up @@ -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: "",
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
};
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/services/CohortService/cohortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const getCohortList = async (data: cohortListData): Promise<any> => {
}
};


export const updateCohortUpdate = async (
userId: string,
cohortDetails: {
Expand Down Expand Up @@ -82,7 +81,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?.result;
return response?.data;
} catch (error) {
console.error("error in getting cohort list", error);
// throw error;
Expand Down
9 changes: 9 additions & 0 deletions src/utils/app.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}

0 comments on commit 24bea6b

Please sign in to comment.