Skip to content

Commit

Permalink
Merge branch 'release-1.0.0' of github.com:tekdi/shiksha-admin into n…
Browse files Browse the repository at this point in the history
…otification
  • Loading branch information
shreyas1434shinde committed Nov 26, 2024
2 parents 16766b9 + 105afac commit 9fcbedf
Show file tree
Hide file tree
Showing 12 changed files with 314 additions and 215 deletions.
4 changes: 2 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
"REASSIGN_CENTERS": "Re-assign Center",
"REASSIGN_BLOCKS": "Re-assign Blocks",
"REASSIGN": "Reassign",
"COHORT_ID_NOT_FOUND": "Could not found cohort Id for {{block}} ",
"COHORT_ID_NOT_FOUND": "Could not found center Id for {{block}} ",
"CENTERS_REASSIGN_SUCCESSFULLY": "Center reassign successfully",
"BLOCKS_REASSIGN_SUCCESSFULLY": "Block reassign successfully",
"CENTERS_REASSIGN_FAILED": "Center Reassignment fails",
Expand All @@ -137,7 +137,7 @@
"ASSIGNED_TEAM_LEADERS": "{{assignedTeamLeaderNames}} and more..",
"CONTINUE": "Continue",
"DESCRIPTION": "Description",
"ALREADY_EXIST": "Cohort name already exist.Please provide another name",
"ALREADY_EXIST": "Center name already exist.Please provide another name",
"PAGE_NOT_FOUND": "Page not found",
"ACCESS_DENIED": "Access Denied",
"YOU_DONT_HAVE_PERMISSION_TO_ACCESS_THIS_PAGE": "You don't have access to this page",
Expand Down
4 changes: 3 additions & 1 deletion src/components/AddNewCenters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
if (selectedBlockCohortId) {
const parentId = selectedBlockCohortId;
const cohortDetails: CohortDetails = {
name: formData.name,
name: (formData.name).toLowerCase(),
type: CohortTypes.COHORT,
parentId: parentId,
customFields: [
Expand Down Expand Up @@ -258,6 +258,8 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
} else {
showToastMessage(t("CENTER.NOT_ABLE_CREATE_CENTER"), "error");
}
onClose();

};

const handleChangeForm = (event: IChangeEvent<any>) => {
Expand Down
60 changes: 25 additions & 35 deletions src/components/ResourceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,46 @@ import { Card, CardContent, Typography, Box } from "@mui/material";
import Image, { StaticImageData } from "next/image";
import placeholderImage from "../../public/placeholderImage.png";
import router from "next/router";
import { getYouTubeThumbnail } from "@/utils/Helper";
import { fetchContent } from "@/services/PlayerService";

interface ResourceCardProps {
title: string;
type: string;
resource: string;
// type: string;
// resource: string;
identifier: string;
appIcon?: string;
}

const ResourceCard: React.FC<ResourceCardProps> = ({
title,
type,
resource,
// type,
// resource,
identifier,
appIcon
}) => {
const [thumbnailUrl, setThumbnailUrl] = useState<string | StaticImageData>(placeholderImage);
// const [thumbnailUrl, setThumbnailUrl] = useState<string | StaticImageData>(placeholderImage);
const thumbnailUrl = appIcon || placeholderImage;

useEffect(() => {
const loadContent = async () => {
try {
if (identifier) {
if (type === 'self') {
const data = await fetchContent(identifier);
if (data?.appIcon) {
setThumbnailUrl(data.appIcon);
}
console.log("vivek", data);
} else if (type.toLowerCase() === 'youtube') {
const img = getYouTubeThumbnail(identifier);
if (img) {
setThumbnailUrl(img);
}
}
}
} catch (error) {
console.error("Unable to fetch content", error);
}
}
loadContent();
// useEffect(() => {
// const loadContent = async () => {
// try {
// if (identifier) {
// const data = await fetchContent(identifier);
// if (data?.appIcon) {
// setThumbnailUrl(data.appIcon);
// }
// }
// } catch (error) {
// console.error("Unable to fetch content", error);
// }
// }
// loadContent();

}, [identifier, type])
// }, [identifier])

const openPlayers = () => {
sessionStorage.setItem("previousPage", window.location.href);
if (type === 'self') {
router.push(`/play/content/${identifier}`);
} else if (type.toLowerCase() === 'youtube') {
window.open(identifier);
}
router.push(`/play/content/${identifier}`);
};

return (
Expand Down Expand Up @@ -81,7 +71,7 @@ const ResourceCard: React.FC<ResourceCardProps> = ({
{title}
</Typography>
<Typography variant="body2" color="textSecondary">
{type}
{/* {type} */}
</Typography>
</CardContent>
</Card>
Expand Down
11 changes: 9 additions & 2 deletions src/pages/centers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { useQuery, useQueryClient } from "@tanstack/react-query";
import { useRouter } from "next/router";
import { telemetryFactory } from "@/utils/telemetry";
import useStore from "@/store/store";
import axios from 'axios';
type cohortFilterDetails = {
type?: string;
status?: any;
Expand Down Expand Up @@ -962,7 +963,7 @@ const response= await fetchCohortMemberList(data);
return;
}
let cohortDetails = {
name: formData?.name,
name: (formData?.name).toLowerCase(),
updatedBy:localStorage.getItem('userId'),
customFields: customFields,
};
Expand Down Expand Up @@ -994,7 +995,13 @@ const response= await fetchCohortMemberList(data);
}
} catch (error) {
console.error("Error updating cohort:", error);
showToastMessage(t("CENTERS.CENTER_UPDATE_FAILED"), "error");
if (axios.isAxiosError(error) && error.response) {
if (error.response.status === 409) {
showToastMessage(t("COMMON.ALREADY_EXIST"), "error");
}
}
else
showToastMessage(t("CENTERS.CENTER_UPDATE_FAILED"), "error");
} finally {
setLoading(false);
setConfirmButtonDisable(false);
Expand Down
8 changes: 8 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect } from "react";
import { useRouter } from "next/router";
import { useTranslation } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { Role } from "@/utils/app.constant";

// const Login = dynamic(() => import('./Login'), { ssr: false });
// const Dashboard = dynamic(() => import('./Dashboard'), { ssr: false });
Expand All @@ -17,6 +18,13 @@ const Home: React.FC = () => {
const token = localStorage.getItem("token");
setLoading(false);
if (token) {
const storedUserData = JSON.parse(
localStorage.getItem("adminInfo") || "{}"
);
if(storedUserData?.role === Role.SCTA || storedUserData?.role === Role.CCTA){
window.location.href = "/course-planner";
}
else
push("/centers");
} else {
push("/login", undefined, { locale: "en" });
Expand Down
64 changes: 43 additions & 21 deletions src/pages/resourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { serverSideTranslations } from "next-i18next/serverSideTranslations";
import { ResourceType } from "@/utils/app.constant";
import { useTranslation } from "next-i18next";
import router from "next/router";
import { fetchBulkContents } from "@/services/PlayerService";

const ResourceList = () => {
const [learnersPreReq, setLearnersPreReq] = useState<any[]>([]);
Expand All @@ -20,19 +21,37 @@ const ResourceList = () => {
const fetchData = async () => {
const resources = tstore.resources;
const fetchedLearningResources = resources.learningResources || [];
const preReqs = fetchedLearningResources.filter(
(item: any) => item.type === ResourceType.PREREQUISITE
);
const postReqs = fetchedLearningResources.filter(
(item: any) => item.type === ResourceType.POSTREQUISITE
);
const facilitatorsReqs = fetchedLearningResources.filter(
(item: any) => !item.type
);

setLearnersPreReq(preReqs);
setLearnersPostReq(postReqs);
setFacilitatorsPreReq(facilitatorsReqs);

if (fetchedLearningResources?.length) {
let contents = await fetchBulkContents(fetchedLearningResources.map((item: any) => item.id));

contents = contents.map((item: any) => {
const contentType = fetchedLearningResources.find(
(resource: any) => resource.id === item.identifier
).type;

return {
...item,
type: contentType
}
})
console.log("contents", contents);

const preRequisite = contents.filter(
(item: any) => item.type === ResourceType.LEARNER_PRE_REQUISITE
);
const postRequisite = contents.filter(
(item: any) => item.type === ResourceType.LEARNER_POST_REQUISITE
);
const facilitatorsRequisite = contents.filter(
(item: any) => item.type === ResourceType.FACILITATOR_REQUISITE
);

setLearnersPreReq(preRequisite);
setLearnersPostReq(postRequisite);
setFacilitatorsPreReq(facilitatorsRequisite);
}
};

fetchData();
Expand Down Expand Up @@ -68,9 +87,10 @@ const ResourceList = () => {
<Grid item key={index}>
<ResourceCard
title={item.name}
type={item.app}
resource={item.type}
identifier={item.id}
// type={item.app}
// resource={item.type}
appIcon={item?.appIcon}
identifier={item.identifier}
/>
</Grid>
))}
Expand All @@ -90,9 +110,10 @@ const ResourceList = () => {
<Grid item key={index}>
<ResourceCard
title={item.name}
type={item.app}
resource={item.type}
identifier={item.id}
// type={item.app}
// resource={item.type}
appIcon={item?.appIcon}
identifier={item.identifier}
/>
</Grid>
))}
Expand All @@ -112,9 +133,10 @@ const ResourceList = () => {
<Grid item key={index}>
<ResourceCard
title={item.name}
type={item.app || "Facilitator"}
resource="Facilitator Requisite"
identifier={item.id}
// type={item.app || "Facilitator"}
// resource="Facilitator Requisite"
appIcon={item?.appIcon}
identifier={item.identifier}
/>
</Grid>
))}
Expand Down
Loading

0 comments on commit 9fcbedf

Please sign in to comment.