Skip to content

Commit

Permalink
Merge branch 'main' of github.com:tekdi/shiksha-admin into admin_uk
Browse files Browse the repository at this point in the history
  • Loading branch information
upendraTekdi committed Aug 13, 2024
2 parents 0b4449e + 4309843 commit 49337fe
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 122 deletions.
4 changes: 2 additions & 2 deletions src/components/AreaSelection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
tagName={t("FACILITATORS.DISTRICT")}
selectedCategories={selectedDistrict}
onCategoryChange={handleDistrictChangeWrapper}
disabled={selectedState?.length === 0 || (selectedState && selectedState[0] === "")}
disabled={selectedState?.length === 0 || (selectedState && selectedState[0] === "" ||selectedState[0] === t("COMMON.ALL_STATES"))}
overall={!inModal}
defaultValue={t("COMMON.ALL_DISTRICTS")}

Expand All @@ -124,7 +124,7 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
selectedCategories={selectedBlock}
onCategoryChange={handleBlockChangeWrapper}
disabled={
selectedDistrict?.length === 0 || (selectedDistrict && selectedDistrict[0] === "")
selectedDistrict?.length === 0 || (selectedDistrict && selectedDistrict[0] === "" || selectedDistrict[0] === t("COMMON.ALL_DISTRICTS"))
}
overall={!inModal}
defaultValue={t("COMMON.ALL_BLOCKS")}
Expand Down
28 changes: 18 additions & 10 deletions src/components/FormControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface MultipleSelectCheckmarksProps {
onCategoryChange: (selectedNames: string[], selectedCodes: string[]) => void;
disabled?: boolean;
overall?: boolean;
defaultValue?:string
defaultValue?: string;
}

const MultipleSelectCheckmarks: React.FC<MultipleSelectCheckmarksProps> = ({
Expand All @@ -36,22 +36,29 @@ const MultipleSelectCheckmarks: React.FC<MultipleSelectCheckmarksProps> = ({
selectedCategories,
onCategoryChange,
disabled = false,
overall = true,
defaultValue
overall = false,
defaultValue,
}) => {
console.log(selectedCategories.length, selectedCategories[0])
const { t } = useTranslation();

const handleChange = (
event: SelectChangeEvent<typeof selectedCategories>,
) => {
// console.log(value)
const {
target: { value },
} = event;
const selectedNames = typeof value === "string" ? value.split(",") : value;

let selectedNames =
typeof value === "string" ? value.split(",") : value;

if (selectedNames.includes("all")) {
selectedNames = defaultValue ? [defaultValue] : [];
}

const selectedCodes = selectedNames?.map(
(name) => codes[names.indexOf(name)],
);

onCategoryChange(selectedNames, selectedCodes);
};

Expand All @@ -68,19 +75,20 @@ const MultipleSelectCheckmarks: React.FC<MultipleSelectCheckmarksProps> = ({
? [defaultValue]
: ""
: selectedCategories
} onChange={handleChange}
}
onChange={handleChange}
input={<OutlinedInput label={tagName} />}
renderValue={(selected) => selected.join(", ")}
MenuProps={MenuProps}
>
{overall && (
<MenuItem value="">
<em> {t("COMMON.ALL")}</em>
<MenuItem value="all">
<em>{t("COMMON.ALL")}</em>
</MenuItem>
)}

{names?.map((name) => (
<MenuItem key={name} value={name}>
{/* <Checkbox checked={selectedCategories.indexOf(name) > -1} /> */}
<ListItemText primary={name} />
</MenuItem>
))}
Expand Down
22 changes: 19 additions & 3 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const HeaderComponent = ({
selectedNames: string[],
selectedCodes: string[],
) => {

if (selectedNames[0] === "") {
// if(districts.length!==0)
// {
Expand Down Expand Up @@ -130,9 +131,23 @@ const HeaderComponent = ({
// "offset": 0,
fieldName: "states",
};
const response = await getStateBlockDistrictList(object);
const result = response?.result?.values;
setStates(result);
// const response = await getStateBlockDistrictList(object);
// const result = response?.result?.values;
if (typeof window !== "undefined" && window.localStorage) {
const admin = localStorage.getItem("adminInfo");
if(admin)
{
const stateField = JSON.parse(admin).customFields.find((field: any) => field.label === "STATES");
console.log(stateField.value, stateField.code)
const object=[{
value:stateField.code,
label:stateField.value
}]
setStates(object);

}
}
// setStates(result);
console.log(typeof states);
} catch (error) {
console.log(error);
Expand Down Expand Up @@ -166,6 +181,7 @@ const HeaderComponent = ({
handleBlockChangeWrapper={handleBlockChangeWrapper}
isMobile={isMobile}
isMediumScreen={isMediumScreen}
inModal={false}
/>
)}
<Typography variant="h1" sx={{ mt: isMobile ? "12px" : "20px" }}>
Expand Down
63 changes: 32 additions & 31 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ const UserTable: React.FC<UserTableProps> = ({
setSelectedBlock([]);

setSelectedState(selected);

if (selected[0] === "") {
console.log(selected[0])
if (selected[0] === "" || selected[0] === t("COMMON.ALL_STATES")) {
if (filters.status) setFilters({ status: [filters.status], role: role });
else setFilters({ role: role });
} else {
Expand Down Expand Up @@ -233,7 +233,8 @@ const UserTable: React.FC<UserTableProps> = ({
setSelectedBlock([]);
setSelectedDistrict(selected);

if (selected[0] === "") {

if (selected[0] === "" || selected[0] === t("COMMON.ALL_DISTRICTS")) {
if (filters.status) {
setFilters({
status: [filters.status],
Expand Down Expand Up @@ -268,7 +269,7 @@ const UserTable: React.FC<UserTableProps> = ({
};
const handleBlockChange = (selected: string[], code: string[]) => {
setSelectedBlock(selected);
if (selected[0] === "") {
if (selected[0] === "" || selected[0] === t("COMMON.ALL_BLOCKS")) {
if (filters.status) {
setFilters({
status: [filters.status],
Expand Down Expand Up @@ -690,33 +691,33 @@ const UserTable: React.FC<UserTableProps> = ({
) : (
loading === false &&
data.length === 0 && (
// <Box display="flex" marginLeft="40%" gap="20px">
// {/* <Image src={glass} alt="" /> */}
// <PersonSearchIcon fontSize="large" />
// <Typography marginTop="10px" variant="h2">
// {t("COMMON.NO_USER_FOUND")}
// </Typography>
// </Box>

<KaTableComponent
columns={
role === Role.TEAM_LEADER
? getTLTableColumns(t, isMobile)
: getUserTableColumns(t, isMobile)
}
data={data}
limit={pageLimit}
offset={pageOffset}
PagesSelector={PagesSelector}
PageSizeSelector={PageSizeSelectorFunction}
pageSizes={pageSizeArray}
extraActions={extraActions}
showIcons={true}
onEdit={handleEdit}
onDelete={handleDelete}
pagination={false}
noDataMessage={data.length === 0 ? noUserFoundJSX : ""}
/>
<Box display="flex" marginLeft="40%" gap="20px">
{/* <Image src={glass} alt="" /> */}
<PersonSearchIcon fontSize="large" />
<Typography marginTop="10px" variant="h2">
{t("COMMON.NO_USER_FOUND")}
</Typography>
</Box>

// <KaTableComponent
// columns={
// role === Role.TEAM_LEADER
// ? getTLTableColumns(t, isMobile)
// : getUserTableColumns(t, isMobile)
// }
// data={data}
// limit={pageLimit}
// offset={pageOffset}
// PagesSelector={PagesSelector}
// PageSizeSelector={PageSizeSelectorFunction}
// pageSizes={pageSizeArray}
// extraActions={extraActions}
// showIcons={true}
// onEdit={handleEdit}
// onDelete={handleDelete}
// pagination={false}
// noDataMessage={data.length === 0 ? noUserFoundJSX : ""}
// />
)
)}

Expand Down
79 changes: 29 additions & 50 deletions src/components/layouts/header/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const Profile = () => {
const [openEditModal, setOpenEditModal] = React.useState(false);
const [userName, setUserName] = React.useState<string | null>("");
const [userId, setUserId] = React.useState<string>("");
const [adminInfo, setAdminInfo] = React.useState<any>();

const [formdata, setFormData] = React.useState<any>();
const adminInformation = useSubmittedButtonStore(
(state: any) => state?.adminInformation
Expand Down Expand Up @@ -185,49 +187,31 @@ const Profile = () => {
useEffect(() => {
getUserName();
}, [formdata]);
// useEffect(() => {
// // getUserName();

// console.log(profileClick);
// const fetchUserDetail = async () => {
// let userId;
// try {
// if (typeof window !== "undefined" && window.localStorage) {
// userId = localStorage.getItem(Storage.USER_ID);
// }
// console.log(profileClick, userId);

// if (userId && profileClick) {
// setUserId(userId);

// console.log("true");
// const fieldValue=true
// const response = await getUserDetailsInfo(userId, fieldValue);
// console.log(response.userData);
// // setUserName(response?.userData?.name);
// console.log(userName);
// setMobile(response?.userData?.mobile);
// setEmail(response?.userData?.email);
// setRole(response?.userData?.role);
// console.log(userName, mobile, email);
useEffect(() => {
if (typeof window !== "undefined" && window.localStorage) {
const admin = localStorage.getItem("adminInfo");
if(admin)
setAdminInfo(JSON.parse(admin))

// const initialLetters = userName
// ?.split(" ")
// .map((word) => word[0])
// .join("");
// console.log(initialLetters);
// if (initialLetters) setInitials(initialLetters);
// }
// } catch (error) {
// console.log(error);
// }
// };
// fetchUserDetail();
// }, [profileClick, submitValue]);
}
}, []);

const handleModalSubmit = (value: boolean) => {
submitValue ? setSubmitValue(false) : setSubmitValue(true);
};
const userType = (() => {
switch (adminInfo?.role) {
case Role.STUDENT:
return FormContextType.STUDENT;
case Role.TEACHER:
return FormContextType.TEACHER;
case Role.ADMIN:
return FormContextType.ADMIN;
default:
return FormContextType.TEAM_LEADER;
}
})();

return (
<>
<Button
Expand Down Expand Up @@ -319,30 +303,30 @@ const Profile = () => {
}}
>
<Typography variant="h6" sx={{ fontWeight: "bold" }}>
{adminInformation?.name
{adminInfo?.name
?.split(" ")
.map((word: any) => word[0])
.join("")}
</Typography>
</Box>

<Typography variant="h5" sx={{ marginBottom: "10px" }}>
{adminInformation?.name}
{adminInfo?.name}
</Typography>
<Typography variant="subtitle1" sx={{ marginBottom: "20px" }}>
{adminInformation?.role}
{adminInfo?.role}
</Typography>
<Box
sx={{ display: "flex", alignItems: "center", marginBottom: "10px" }}
>
<PhoneIcon sx={{ marginRight: "10px" }} />
<Typography variant="body1">{adminInformation?.mobile}</Typography>
<Typography variant="body1">{adminInfo?.mobile}</Typography>
</Box>
<Box
sx={{ display: "flex", alignItems: "center", marginBottom: "20px" }}
>
<MailIcon sx={{ marginRight: "10px" }} />
<Typography variant="body1">{adminInformation?.email}</Typography>
<Typography variant="body1">{adminInfo?.email}</Typography>
</Box>
<Button
fullWidth
Expand All @@ -355,7 +339,7 @@ const Profile = () => {
</Button>
</Box>
</Menu>
{console.log(adminInformation?.role)}
{console.log(adminInfo?.role)}
{ openEditModal && ( <CommonUserModal
open={openEditModal}
onClose={handleCloseAddLearnerModal}
Expand All @@ -364,12 +348,7 @@ const Profile = () => {
userId={userId}
onSubmit={handleModalSubmit}
userType={
// FormContextType.TEACHER
adminInformation?.role === Role.STUDENT
? FormContextType.STUDENT
: adminInformation?.role === Role.TEACHER
? FormContextType.TEACHER
: adminInformation?.role === Role.ADMIN? FormContextType.ADMIN :FormContextType.TEAM_LEADER
userType
}
/>
)
Expand Down
Loading

0 comments on commit 49337fe

Please sign in to comment.