Skip to content

Commit

Permalink
Merge pull request #335 from AkshataKatwal16/relese-changes
Browse files Browse the repository at this point in the history
Issue  feat:Add role authorisation
itsvick authored Nov 21, 2024
2 parents 2f0a9ca + cff8057 commit af80332
Showing 10 changed files with 203 additions and 204 deletions.
8 changes: 6 additions & 2 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
@@ -137,8 +137,12 @@
"ASSIGNED_TEAM_LEADERS": "{{assignedTeamLeaderNames}} and more..",
"CONTINUE": "Continue",
"DESCRIPTION": "Description",
"PAGE_NOT_FOUND": "Page Not Found",
"ALREADY_EXIST": "Cohort name already exist.Please provide another name"
"ALREADY_EXIST": "Cohort 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",
"RETURN_TO_LOGIN": "Return to Login"

},
"LOGIN_PAGE": {
"USERNAME": "Username",
16 changes: 8 additions & 8 deletions src/components/AddNewCenters.tsx
Original file line number Diff line number Diff line change
@@ -121,11 +121,11 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
const getAddLearnerFormData = async () => {
const admin = localStorage.getItem("adminInfo");
if (admin) {
const stateField = JSON.parse(admin).customFields.find(
const stateField = JSON.parse(admin).customFields?.find(
(field: any) => field.label === "STATES"
);
if (!stateField.value.includes(",")) {
setStateDefaultValueForCenter(stateField.value);
if (!stateField?.value.includes(",")) {
setStateDefaultValueForCenter(stateField?.value);
} else {
setStateDefaultValueForCenter(t("COMMON.ALL_STATES"));
}
@@ -164,7 +164,7 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
) => {
const formData = data?.formData;
console.log("selectedBlockCohortId", selectedBlockCohortId);
const bmgsData = JSON.parse(localStorage.getItem("BMGSData") ?? "");
const bmgsData = JSON?.parse(localStorage.getItem("BMGSData") ?? "");
if (selectedBlockCohortId) {
const parentId = selectedBlockCohortId;
const cohortDetails: CohortDetails = {
@@ -188,20 +188,20 @@ const AddNewCenters: React.FC<AddLearnerModalProps> = ({
};

Object.entries(formData).forEach(([fieldKey, fieldValue]) => {
const fieldSchema = schema.properties[fieldKey];
const fieldSchema = schema?.properties[fieldKey];
const fieldId = fieldSchema?.fieldId;

if (fieldId !== null) {
cohortDetails?.customFields?.push({
fieldId: fieldId,
value: formData.cohort_type,
value: formData?.cohort_type,
});
}

if (bmgsData) {
cohortDetails?.customFields?.push({
fieldId: bmgsData.board.fieldId,
value: bmgsData.board.boardName,
fieldId: bmgsData?.board.fieldId,
value: bmgsData?.board.boardName,
});
cohortDetails?.customFields?.push({
fieldId: bmgsData.medium.fieldId,
133 changes: 64 additions & 69 deletions src/components/AreaSelection.tsx
Original file line number Diff line number Diff line change
@@ -78,7 +78,7 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
isMediumScreen,
isCenterSelection = false,
inModal = false,
handleCenterChangeWrapper = () => {},
handleCenterChangeWrapper = () => { },
stateDefaultValue,
blockDefaultValue,
districtDefaultValue,
@@ -117,15 +117,15 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
},
}}
>
{userType && !reAssignModal && inModal===false && (
{userType && !reAssignModal && inModal === false && (
<Box>
<Typography marginTop="20px" variant="h1">
{userType=== Role.CONTENT_CREATOR?t("SIDEBAR.SCTA"):userType}
{userType === Role.CONTENT_CREATOR ? t("SIDEBAR.SCTA") : userType}
</Typography>
</Box>
)}

{ (<Box
{(<Box
sx={{
width: inModal ? "100%" : "62%",
"@media (max-width: 900px)": {
@@ -157,77 +157,72 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
/>
</Grid>


{
(
<><Grid
item
xs={12}
sm={inModal ? 12 : 6}
md={inModal ? 12 : 4}
lg={inModal ? 12 : isCenterSelection ? 3 : 4}
>
<MultipleSelectCheckmarks
names={districts?.map((district) => district.label)}
codes={districts?.map((district) => district.value)}
tagName={t("FACILITATORS.DISTRICT")}
selectedCategories={selectedDistrict}
onCategoryChange={handleDistrictChangeWrapper}
disabled={
districts?.length <= 0 ||
(selectedState.length === 0 &&
stateDefaultValue === t("COMMON.ALL_STATES"))
}
overall={!inModal}
defaultValue={
reAssignModal
? districtDefaultValue
: selectedState.length > 0 && districts?.length === 0
? t("COMMON.NO_DISTRICTS")
: t("COMMON.ALL_DISTRICTS")
}
/>
</Grid>
<Grid
item
xs={12}
sm={inModal ? 12 : 6}
md={inModal ? 12 : 4}
lg={inModal ? 12 : isCenterSelection ? 3 : 4}
>
{shouldRenderSelectCheckmarks &&(
<Grid
item
xs={12}
sm={inModal ? 12 : 6}
md={inModal ? 12 : 4}
lg={inModal ? 12 : isCenterSelection ? 3 : 4}
>
<MultipleSelectCheckmarks
names={capitalizeFirstLetterOfEachWordInArray(
blocks?.length > 0 ? blocks.map((block) => block.label) : []
// blocks.map((block) => block.label)

)}
codes={

blocks?.length > 0 ? blocks?.map((block) => block.value) : []
// blocks?.map((block) => block.value)
}
tagName={t("FACILITATORS.BLOCK")}
selectedCategories={capitalizeFirstLetterOfEachWordInArray(
selectedBlock
)}
onCategoryChange={handleBlockChangeWrapper}
names={districts?.map((district) => district.label)}
codes={districts?.map((district) => district.value)}
tagName={t("FACILITATORS.DISTRICT")}
selectedCategories={selectedDistrict}
onCategoryChange={handleDistrictChangeWrapper}
disabled={
blocks?.length <= 0 ||
selectedDistrict?.length === 0 ||
selectedDistrict[0] === t("COMMON.ALL_DISTRICTS")
districts?.length <= 0 ||
(selectedState.length === 0 &&
stateDefaultValue === t("COMMON.ALL_STATES"))
}
overall={!inModal}
defaultValue={
selectedDistrict?.length > 0 && (blocks?.length === 0)
? t("COMMON.NO_BLOCKS")
: t("COMMON.ALL_BLOCKS")
reAssignModal
? districtDefaultValue
: selectedState.length > 0 && districts?.length === 0
? t("COMMON.NO_DISTRICTS")
: t("COMMON.ALL_DISTRICTS")
}
/>
)}
</Grid>
</>)
}
</Grid>
<Grid
item
xs={12}
sm={inModal ? 12 : 6}
md={inModal ? 12 : 4}
lg={inModal ? 12 : isCenterSelection ? 3 : 4}
>
{shouldRenderSelectCheckmarks && (
<MultipleSelectCheckmarks
names={capitalizeFirstLetterOfEachWordInArray(
blocks?.length > 0 ? blocks.map((block) => block.label) : []
// blocks.map((block) => block.label)

)}
codes={

blocks?.length > 0 ? blocks?.map((block) => block.value) : []
// blocks?.map((block) => block.value)
}
tagName={t("FACILITATORS.BLOCK")}
selectedCategories={capitalizeFirstLetterOfEachWordInArray(
selectedBlock
)}
onCategoryChange={handleBlockChangeWrapper}
disabled={
blocks?.length <= 0 ||
selectedDistrict?.length === 0 ||
selectedDistrict[0] === t("COMMON.ALL_DISTRICTS")
}
overall={!inModal}
defaultValue={
selectedDistrict?.length > 0 && (blocks?.length === 0)
? t("COMMON.NO_BLOCKS")
: t("COMMON.ALL_BLOCKS")
}
/>
)}
</Grid>


{isCenterSelection && (
@@ -260,7 +255,7 @@ const AreaSelection: React.FC<DropdownBoxProps> = ({
/>
</Grid>
)}

</Grid>
</Box>)}
</Box>
25 changes: 16 additions & 9 deletions src/components/RouteGuard.tsx
Original file line number Diff line number Diff line change
@@ -67,17 +67,24 @@ const RouteGuard: React.FC<{ children: React.ReactNode }> = ({ children }) => {
});

// Clear all local storage
localStorage.clear();
// localStorage.clear();

// Re-add the keys to keep with their values
keysToKeep.forEach((key: string) => {
if (valuesToKeep[key] !== null) {
// Check if the key exists and has a value
localStorage.setItem(key, valuesToKeep[key]);
}
});
// // Re-add the keys to keep with their values
// keysToKeep.forEach((key: string) => {
// if (valuesToKeep[key] !== null) {
// // Check if the key exists and has a value
// localStorage.setItem(key, valuesToKeep[key]);
// }
// });
}
router.push("/logout");
router.push("/unauthorized");
}
}

if ((user.role === Role.ADMIN || user.role === Role.CENTRAL_ADMIN )&& (allowedPaths.includes(router.pathname) || isWorkspaceContent || isCoursePlannerContent)) {
if (router.pathname !== "/login" && router.pathname !== "/logout") {

router.push("/unauthorized");
}
}
}, [router.pathname]);
Loading

0 comments on commit af80332

Please sign in to comment.