Skip to content

Commit

Permalink
Merge branch 'release-1.0.0' of github.com:tekdi/shiksha-admin into r…
Browse files Browse the repository at this point in the history
…elease-1.0.0
  • Loading branch information
itsvick committed Nov 9, 2024
2 parents 395f28c + d71e89c commit 58d4ee9
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 150 deletions.
1 change: 1 addition & 0 deletions src/components/CommonUserModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ const CommonUserModal: React.FC<UserModalProps> = ({
mobile: apiBody?.mobile,
father_name: apiBody?.father_name,
email: apiBody?.email,
updatedBy:localStorage.getItem("userId")
};
const customFields = apiBody?.customFields;
console.log(customFields);
Expand Down
4 changes: 2 additions & 2 deletions src/components/HeaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ const HeaderComponent = ({
</Box>
)}
</Box>
{showAddNew && (
{/* {showAddNew && ( */}
<Box
sx={{
display: "flex",
Expand Down Expand Up @@ -765,7 +765,7 @@ const HeaderComponent = ({
</FormControl>
)}
</Box>
)}
{/* )} */}
{children}
</Box>
</Box>
Expand Down
6 changes: 5 additions & 1 deletion src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { updateCohortMemberStatus } from "@/services/CohortService/cohortService
import useSubmittedButtonStore from "@/utils/useSharedState";
import { useRouter } from "next/router";
import { telemetryFactory } from "@/utils/telemetry";
import useStore from "@/store/store";
type UserDetails = {
userId: any;
username: any;
Expand Down Expand Up @@ -99,6 +100,8 @@ const UserTable: React.FC<UserTableProps> = ({
const [blockMembershipIdList, setBlockMembershipIdList] = React.useState<string[]>([]);
const [centerMembershipIdList, setCenterMembershipIdList] = React.useState<string[]>([]);
const router = useRouter();
const store = useStore();
const isActiveYear = store.isActiveYearSelected;

const selectedBlockStore = useSubmittedButtonStore(
(state: any) => state.selectedBlockStore
Expand Down Expand Up @@ -1534,7 +1537,8 @@ console.log(selectedBlockStore)
setSelectedCenter:setSelectedCenter,
selectedCenterCode:selectedCenterCode,
setSelectedCenterCode: setSelectedCenterCode,
setSelectedStateCode:setSelectedStateCode
setSelectedStateCode:setSelectedStateCode,
showAddNew: !!isActiveYear
};


Expand Down
11 changes: 11 additions & 0 deletions src/components/layouts/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useTranslation } from "next-i18next";
import { createTheme, useTheme } from "@mui/material/styles";
import Profile from "./Profile";
import { AcademicYear } from "@/utils/Interfaces";
import useStore from "@/store/store";

const Header = ({ sx, customClass, toggleMobileSidebar, position }: any) => {
const { t } = useTranslation();
Expand All @@ -23,6 +24,9 @@ const Header = ({ sx, customClass, toggleMobileSidebar, position }: any) => {
const router = useRouter();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
const setIsActiveYearSelected = useStore(
(state: { setIsActiveYearSelected: any }) => state.setIsActiveYearSelected
);

const [selectedLanguage, setSelectedLanguage] = useState(lang);
const [academicYearList, setAcademicYearList] = useState<AcademicYear[]>([]);
Expand Down Expand Up @@ -50,6 +54,13 @@ const Header = ({ sx, customClass, toggleMobileSidebar, position }: any) => {
setSelectedSessionId(event.target.value);
console.log("selected academic year id", event.target.value);
localStorage.setItem("academicYearId", event.target.value);
// Check if the selected academic year is active
const selectedYear = academicYearList?.find(
(year) => year.id === event.target.value
);
const isActive = selectedYear ? selectedYear.isActive : false;
// localStorage.setItem('isActiveYearSelected', JSON.stringify(isActive));
setIsActiveYearSelected(isActive);
window.location.reload();
};

Expand Down
24 changes: 14 additions & 10 deletions src/components/layouts/sidebar/MenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import masterIcon from "../../../../public/images/database.svg";
import centerIcon from "../../../../public/images/centers.svg";
import dashboardIcon from "../../../../public/images/dashboard.svg";
import userIcon from "../../../../public/images/group.svg";
import coursePannerIcon from "../../../../public/images/event_available.svg";
const ENV = process.env.NEXT_PUBLIC_SHOW_WORKSPACE;
import coursePlannerIcon from "../../../../public/images/event_available.svg";
import { store } from "@/store/store";

//
const ENV = process.env.NEXT_PUBLIC_SHOW_WORKSPACE;
const isActiveYear = store.getState().isActiveYearSelected;

const Menuitems = [
// {
Expand Down Expand Up @@ -37,7 +38,6 @@ const Menuitems = [
},
],
},

{
title: "Master ",
icon: masterIcon,
Expand All @@ -57,12 +57,16 @@ const Menuitems = [
},
],
},
{
title: "SIDEBAR.COURSE_PLANNER",
icon: coursePannerIcon,
href: "/course-planner",
},
...(ENV === "true"
...(isActiveYear
? [
{
title: "SIDEBAR.COURSE_PLANNER",
icon: coursePlannerIcon,
href: "/course-planner",
},
]
: []),
...(isActiveYear && ENV === "true"
? [
{
title: "SIDEBAR.WORKSPACE",
Expand Down
47 changes: 33 additions & 14 deletions src/data/tableColumns.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { store } from "@/store/store";
import { DataType, SortDirection } from "ka-table";

interface ColumnConfig {
Expand All @@ -7,6 +8,7 @@ interface ColumnConfig {
sortDirection?: SortDirection;
isSortable?: boolean;
}
const isActiveYear = store.getState().isActiveYearSelected;

const generateColumns = (
t: any,
Expand Down Expand Up @@ -36,13 +38,16 @@ export const getUserTableColumns = (t: any, isMobile: boolean) => {
// { key: "createdBy", titleKey: "TABLE_TITLE.CREATED_BY", width: 130, sortDirection: SortDirection.Ascend },
// { key: "createdAt", titleKey: "TABLE_TITLE.CREATED_DATE", width: 160, sortDirection: SortDirection.Ascend },
{ key: "updatedAt", titleKey: "TABLE_TITLE.UPDATED_DATE", width: 160 },
{
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
width: 170,
isSortable: false,
},
];
});
}

return generateColumns(t, configs, isMobile);
};
Expand All @@ -58,13 +63,16 @@ export const getTLTableColumns = (t: any, isMobile: boolean) => {
{ key: "createdBy", titleKey: "TABLE_TITLE.CREATED_BY", width: 130 },
{ key: "createdAt", titleKey: "TABLE_TITLE.CREATED_DATE", width: 160 },
{ key: "updatedAt", titleKey: "TABLE_TITLE.UPDATED_DATE", width: 160 },
{
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
width: 170,
isSortable: false,
},
];
});
}

return generateColumns(t, configs, isMobile);
};
Expand All @@ -88,9 +96,15 @@ export const getCenterTableData = (t: any, isMobile: boolean) => {
titleKey: "TABLE_TITLE.ARCHIVED_LEARNERS",
width: 130,
},
{ key: "actions", titleKey: "TABLE_TITLE.ACTIONS", width: 125 },
];

// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
configs.push({
key: "actions",
titleKey: "TABLE_TITLE.ACTIONS",
width: 125,
});
}
return generateColumns(t, configs, isMobile);
};

Expand Down Expand Up @@ -156,12 +170,15 @@ export const getDistrictTableData = (t: any, isMobile: boolean) => {
titleKey: t("TABLE_TITLE.UPDATED_DATE").toUpperCase(),
width: 130,
},
{
];
// Conditionally add the "actions" column if isActiveYear is true
if (isActiveYear) {
configs.push({
key: "actions",
titleKey: t("TABLE_TITLE.ACTIONS").toUpperCase(),
width: 160,
},
];
});
}

return generateColumns(t, configs, isMobile);
};
Expand Down Expand Up @@ -190,12 +207,14 @@ export const getBlockTableData = (t: any, isMobile: boolean) => {
titleKey: t("TABLE_TITLE.UPDATED_DATE").toUpperCase(),
width: 130,
},
{
];
if (isActiveYear) {
configs.push({
key: "actions",
titleKey: t("TABLE_TITLE.ACTIONS").toUpperCase(),
width: 160,
},
];
});
}

return generateColumns(t, configs, isMobile);
};
116 changes: 65 additions & 51 deletions src/pages/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
import { getBlockTableData } from "@/data/tableColumns";
import { Theme } from "@mui/system";
import { telemetryFactory } from "@/utils/telemetry";
import useStore from "@/store/store";

type StateDetail = {
name: string | undefined;
Expand Down Expand Up @@ -77,6 +78,8 @@ interface BlockOption {

const Block: React.FC = () => {
const { t } = useTranslation();
const store = useStore();
const isActiveYear = store.isActiveYearSelected;
const [selectedSort, setSelectedSort] = useState<string>("Sort");
const [selectedState, setSelectedState] = useState<string>("");
const [selectedDistrict, setSelectedDistrict] = useState<string>("");
Expand Down Expand Up @@ -858,66 +861,76 @@ const Block: React.FC = () => {
DistrictId?: string,
extraArgument?: any
) => {
const newDistrict = {
options: [
{
controllingfieldfk: controllingField,
name,
value,
},
],
};
try {
const response = await createOrUpdateOption(blocksFieldId, newDistrict);
const updatedBy=localStorage.getItem("userId")
if(updatedBy)
{
const newDistrict = {

options: [
{
controllingfieldfk: controllingField,
name,
value,
updatedBy

if (response) {
filteredCohortOptionData();
}
} catch (error) {
console.error("Error adding district:", error);
},
],
};
try {
const response = await createOrUpdateOption(blocksFieldId, newDistrict);

if (response) {
filteredCohortOptionData();
}
} catch (error) {
console.error("Error adding district:", error);
}

const queryParameters = {
name: name,
};
const queryParameters = {
name: name,
updatedBy:localStorage.getItem('userId'),

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);
if (cohortCreateResponse) {
await fetchBlocks();
await getCohortSearchBlock(selectedDistrict);
showToastMessage(t("COMMON.BLOCK_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];
};

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);
if (cohortCreateResponse) {
await fetchBlocks();
await getCohortSearchBlock(selectedDistrict);
showToastMessage(t("COMMON.BLOCK_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];

const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'block-update-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'block-update-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
setModalOpen(false);
setSelectedStateForEdit(null);
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
setModalOpen(false);
setSelectedStateForEdit(null);
}

};

const userProps = {
Expand All @@ -928,6 +941,7 @@ const Block: React.FC = () => {
searchPlaceHolder: t("MASTER.SEARCHBAR_PLACEHOLDER_BLOCK"),
showFilter: true,
showSort: true,
showAddNew: !!isActiveYear,
statusValue: statusValue,
setStatusValue: setStatusValue,
handleFilterChange: handleFilterChange,
Expand Down
Loading

0 comments on commit 58d4ee9

Please sign in to comment.