Skip to content

Commit

Permalink
Merge pull request #64 from upendraTekdi/cohort_list
Browse files Browse the repository at this point in the history
 Task #223738: Integrate cohort search API on cohort list,
  • Loading branch information
itsvick authored Jul 30, 2024
2 parents 26932a9 + cd25825 commit 2e9d938
Show file tree
Hide file tree
Showing 10 changed files with 401 additions and 192 deletions.
9 changes: 7 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"INCORRECT_DATA_ENTRY": "Incorrect Data Entry",
"DUPLICATED_USER": "Duplicate User",
"NO_USER_FOUND": "User not found",
"NO_CENTER_FOUND": "Centers not found",
"ALL": "All",
"NO_GO_BACK": "No, go back",
"YES": "Yes",
Expand All @@ -26,7 +27,8 @@
"DELETE": "Delete",
"NO_DATA_FOUND": "No data found",
"SUBMIT": "Submit",
"BACK": "Back"
"BACK": "Back",
"CANCEL": "Cancel"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -126,7 +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 ?",
"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
5 changes: 2 additions & 3 deletions src/components/ActionIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from "react";
import MoreVertIcon from "@mui/icons-material/MoreVert";
import { useTranslation } from "next-i18next";
import { Box, Typography, Tooltip } from "@mui/material";
import EditIcon from '@mui/icons-material/Edit';
import EditIcon from "@mui/icons-material/Edit";
import DeleteIcon from "@mui/icons-material/Delete";

interface ActionCellProps {
Expand Down Expand Up @@ -41,8 +41,7 @@ const ActionIcon: React.FC<ActionCellProps> = ({
flexDirection: "column",
alignItems: "center",
cursor: "pointer",
// opacity: 0.5, // Reduced opacity to make it appear disabled
pointerEvents: "auto", // Enable pointer events to allow click
// pointerEvents: "none",
}}
>
<EditIcon/>
Expand Down
6 changes: 3 additions & 3 deletions src/components/CustomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const CustomModal: React.FC<CustomModalProps> = ({
children,
}) => {
const isSmallScreen = useMediaQuery((theme: Theme) =>
theme.breakpoints.down("sm"),
theme.breakpoints.down("sm")
);

return (
Expand Down Expand Up @@ -86,9 +86,9 @@ const CustomModal: React.FC<CustomModalProps> = ({
</Box>
<Divider sx={{ my: 2 }} />
<Box id="modal-description">{children}</Box>
<Box mt={2} display="flex" justifyContent="center" gap={2}>
<Box mt={2} display="flex" justifyContent="space-around" gap={2}>
<Button
fullWidth
// fullWidth
onClick={primaryBtnClick}
variant="contained"
disabled={primaryBtnDisabled}
Expand Down
15 changes: 14 additions & 1 deletion src/components/KaTableComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { SortingMode, PagingPosition } from "ka-table/enums";
import { Paper, Checkbox } from "@mui/material";
import "ka-table/style.css";
import ActionIcon from "./ActionIcon";
import { format } from "date-fns";
import { DataKey, DateFormat } from "@/utils/app.constant";
import { useTranslation } from "react-i18next";

interface KaTableComponentProps {
Expand Down Expand Up @@ -92,7 +94,7 @@ const KaTableComponent: React.FC<KaTableComponentProps> = ({
},
cell: {
content: (props) => {
if (props.column.key === "actions") {
if (props.column.key === DataKey.ACTIONS) {
return (
<ActionIcon
rowData={props.rowData}
Expand All @@ -101,6 +103,17 @@ const KaTableComponent: React.FC<KaTableComponentProps> = ({
/>
);
}
if (props.column.key === DataKey.UPDATEDAT) {
return format(
props.rowData?.updatedAt,
DateFormat.YYYY_MM_DD
);
} else if (props.column.key === DataKey.CREATEDAT) {
return format(
props.rowData?.createdAt,
DateFormat.YYYY_MM_DD
);
}
if (props.column.key === "selection-cell") {
return (
<Checkbox
Expand Down
2 changes: 1 addition & 1 deletion src/components/PageSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const PageSizeSelector = ({ handleChange, pageSize, options }: any) => {
<MenuItem value="">
<em>None</em>
</MenuItem>
{options.map((option: any) => (
{options?.map((option: any) => (
<MenuItem key={option} value={option}>
{option}
</MenuItem>
Expand Down
90 changes: 42 additions & 48 deletions src/components/SimpleModal.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import {
Box,
Button,
Divider,
Modal,
Typography
} from '@mui/material';
import React, { ReactNode } from 'react';
import { Box, Button, Divider, Modal, Typography } from "@mui/material";
import React, { ReactNode } from "react";

import manageUserStore from '@/store/manageUserStore';
import CloseSharpIcon from '@mui/icons-material/CloseSharp';
import { useTheme, useMediaQuery } from '@mui/material';
import { useTranslation } from 'next-i18next';
import manageUserStore from "@/store/manageUserStore";
import CloseSharpIcon from "@mui/icons-material/CloseSharp";
import { useTheme, useMediaQuery } from "@mui/material";
import { useTranslation } from "next-i18next";

interface SimpleModalProps {
secondaryActionHandler?: () => void;
Expand All @@ -37,32 +31,32 @@ const SimpleModal: React.FC<SimpleModalProps> = ({
const { t } = useTranslation();
const store = manageUserStore();
const theme = useTheme<any>();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
const isMediumScreen = useMediaQuery(theme.breakpoints.between('sm', 'md'));
const isSmallScreen = useMediaQuery(theme.breakpoints.down("sm"));
const isMediumScreen = useMediaQuery(theme.breakpoints.between("sm", "md"));

const isLargeScreen = useMediaQuery(theme.breakpoints.up('lg'));
const isLargeScreen = useMediaQuery(theme.breakpoints.up("lg"));

const modalStyle = {
paddingTop: '0',
paddingTop: "0",
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(2),
paddingBottom: theme.spacing(2),
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
width: isSmallScreen ? '90%' : isLargeScreen ? '65%' : '85%',
maxHeight: '80vh',
overflowY: 'auto',
backgroundColor: '#fff',
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
width: isSmallScreen ? "90%" : isLargeScreen ? "65%" : "85%",
maxHeight: "80vh",
overflowY: "auto",
backgroundColor: "#fff",
borderRadius: theme.shape.borderRadius,
boxShadow: theme.shadows[5],
};

const titleStyle = {
position: 'sticky',
top: '0',
backgroundColor: '#fff',
position: "sticky",
top: "0",
backgroundColor: "#fff",
padding: theme.spacing(2),
zIndex: 9999,
borderBottom: `1px solid ${theme.palette.divider}`,
Expand All @@ -75,16 +69,12 @@ const SimpleModal: React.FC<SimpleModalProps> = ({
aria-describedby="child-modal-description"
>
<Box sx={modalStyle}>
<Box
display={'flex'}
justifyContent={'space-between'}
sx={titleStyle}
>
<Box marginBottom={'0px'}>
<Box display={"flex"} justifyContent={"space-between"} sx={titleStyle}>
<Box marginBottom={"0px"}>
<Typography
variant="h2"
sx={{
color: theme.palette.warning['A200'],
color: theme.palette.warning["A200"],
}}
component="h2"
>
Expand All @@ -94,7 +84,7 @@ const SimpleModal: React.FC<SimpleModalProps> = ({
<Box>
<CloseSharpIcon
sx={{
cursor: 'pointer',
cursor: "pointer",
}}
onClick={onClose}
aria-label="Close"
Expand All @@ -106,39 +96,43 @@ const SimpleModal: React.FC<SimpleModalProps> = ({
<Divider />

{showFooter ? (
<Box alignContent={"center"} alignItems={"center"} justifyContent={"center"} display={'flex'}>
<Box
alignContent={"center"}
alignItems={"center"}
justifyContent={"center"}
display={"flex"}
>
{primaryText && (
<Button
variant="contained"
color="primary"
sx={{
'&.Mui-disabled': {
"&.Mui-disabled": {
backgroundColor: theme?.palette?.primary?.main,
},
// minWidth: '84px',
// height: '2.5rem',
// minWidth: '84px',
// height: '2.5rem',
padding: theme.spacing(1),
fontWeight: '500',
// width: '100%',
fontWeight: "500",
// width: '100%',
}}
onClick={primaryActionHandler}
>
</Button>
></Button>
)}

{secondaryText && (
<Button
variant="contained"
color="primary"
sx={{
'&.Mui-disabled': {
"&.Mui-disabled": {
backgroundColor: theme?.palette?.primary?.main,
},
minWidth: '84px',
height: '2.5rem',
minWidth: "84px",
height: "2.5rem",
padding: theme.spacing(1),
fontWeight: '500',
width: '100%',
fontWeight: "500",
width: "100%",
}}
onClick={secondaryActionHandler}
>
Expand Down
49 changes: 26 additions & 23 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,36 @@ const UserTable: React.FC<UserTableProps> = ({
let initialFormData: any = {};
formFields.fields.forEach((item: any) => {
const userData = response?.userData;
const customField = userData?.customFields?.find((field: any) => field.fieldId === item.fieldId);

const customField = userData?.customFields?.find(
(field: any) => field.fieldId === item.fieldId
);

const getValue = (data: any, field: any) => {
if (item?.isMultiSelect) {
if (item?.type === 'checkbox') {
return String(field.value).split(',');
if (item?.type === "checkbox") {
return String(field.value).split(",");
}
return [field.value];
} else {
if (item?.type === 'numeric') {
if (item?.type === "numeric") {
return Number(field.value);
} else if (item?.type === 'text') {
} else if (item?.type === "text") {
return String(field.value);
} else {
return field.value;
}
}
};

if (item.coreField) {
initialFormData[item.name] = item?.isMultiSelect
? userData[item.name] ? [userData[item.name]] : userData[item.name] || ''
: item?.type === 'numeric' ? Number(userData[item.name])
: item?.type === 'text' ? String(userData[item.name])
? userData[item.name]
? [userData[item.name]]
: userData[item.name] || ""
: item?.type === "numeric"
? Number(userData[item.name])
: item?.type === "text"
? String(userData[item.name])
: userData[item.name];
} else {
initialFormData[item.name] = getValue(userData, customField);
Expand All @@ -395,14 +401,14 @@ const UserTable: React.FC<UserTableProps> = ({
};
const handleEdit = async (rowData: any) => {
console.log("Edit row:", rowData);

try {
const userId = rowData.userId;
setUserId(userId);
const fieldValue = true;
const response = await getUserDetails(userId, fieldValue);
console.log(role);

let formFields;
if (Role.STUDENT === role) {
formFields = await getFormRead("USERS", "STUDENT");
Expand All @@ -413,7 +419,7 @@ const UserTable: React.FC<UserTableProps> = ({
setFormData(mapFields(formFields, response));
handleOpenAddFacilitatorModal();
}

console.log("response", response);
console.log("formFields", formFields);
} catch (error) {
Expand Down Expand Up @@ -553,12 +559,10 @@ const UserTable: React.FC<UserTableProps> = ({
console.log(selectedUserId);
const userId = selectedUserId;
const userData = {
userData: [
{
reason: selectedReason,
status: "archived",
},
],
userData: {
reason: selectedReason,
status: "archived",
},
};
const response = await deleteUser(userId, userData);
handleCloseDeleteModal();
Expand Down Expand Up @@ -587,10 +591,9 @@ const UserTable: React.FC<UserTableProps> = ({
handleFilterChange: handleFilterChange,
handleSearch: handleSearch,
handleAddUserClick: handleAddUserClick,
selectedBlockCode:selectedBlockCode,
selectedDistrictCode:selectedDistrictCode,
selectedStateCode:selectedStateCode

selectedBlockCode: selectedBlockCode,
selectedDistrictCode: selectedDistrictCode,
selectedStateCode: selectedStateCode,
};

return (
Expand Down
Loading

0 comments on commit 2e9d938

Please sign in to comment.