Skip to content

Commit

Permalink
update pr
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshataKatwal16 committed Feb 4, 2025
1 parent 174a664 commit 9234c41
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/components/AddLeanerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const AddLearnerModal: React.FC<AddLearnerModalProps> = ({
);
const apiBody: any = {
username: username,
password: password,
password: username,
tenantCohortRoleMapping: [
{
tenantId: tenantId,
Expand Down
3 changes: 3 additions & 0 deletions src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ const LoginPage = () => {
const token = localStorage.getItem('token');
const tenant = localStorage.getItem('tenantName');
if (token && (tenant?.toLocaleLowerCase() === TENANT_DATA?.SECOND_CHANCE_PROGRAM?.toLowerCase() || tenant?.toLocaleLowerCase() === TENANT_DATA?.PRATHAM_SCP?.toLowerCase())) {
localStorage.setItem("previousPage", "login");
router.push('/dashboard');
} else if (token && tenant?.toLowerCase() == TENANT_DATA?.YOUTHNET?.toLowerCase()) {
router.push('/youthboard');
localStorage.setItem("previousPage", "login");

}
}
}, []);
Expand Down
27 changes: 2 additions & 25 deletions src/pages/logout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ReactGA from 'react-ga4';
import { Telemetry } from '@/utils/app.constant';
import { useQueryClient } from '@tanstack/react-query';
import useStore from '@/store/store';
import { preserveLocalStorage } from '@/utils/Helper';

function Logout() {
const queryClient = useQueryClient();
Expand All @@ -15,31 +16,7 @@ function Logout() {
const clearLocalStorage = () => {
if (typeof window !== 'undefined' && window.localStorage) {
// Specify the keys you want to keep
const keysToKeep = [
'preferredLanguage',
'mui-mode',
'mui-color-scheme-dark',
'mui-color-scheme-light',
'hasSeenTutorial',
// 'deviceID',
];
// Retrieve the values of the keys to keep
const valuesToKeep: { [key: string]: any } = {};
keysToKeep.forEach((key: string) => {
valuesToKeep[key] = localStorage.getItem(key);
});

// Clear all local storage
localStorage.clear();
queryClient.clear();
setCohorts([]);
// 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]);
}
});
preserveLocalStorage();
}
};

Expand Down
35 changes: 14 additions & 21 deletions src/pages/unauthorized.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { preserveLocalStorage } from '@/utils/Helper';
import WarningIcon from '@mui/icons-material/Warning';
import { Link, useTheme } from '@mui/material';
import Box from '@mui/material/Box';
Expand All @@ -13,30 +14,22 @@ const Unauthorized = () => {
useEffect(() => {
const handleBackButton = () => {
console.log("User pressed the browser back button");
// localStorage.clear()
const keysToKeep = [
'preferredLanguage',
'mui-mode',
'mui-color-scheme-dark',
'mui-color-scheme-light',
'hasSeenTutorial',
];
// Retrieve the values of the keys to keep
const valuesToKeep: { [key: string]: any } = {};
keysToKeep.forEach((key: string) => {
valuesToKeep[key] = localStorage.getItem(key);
});
const previousPage = localStorage.getItem("previousPage");

// Clear all local storage
localStorage.clear();
if (previousPage === "login") {
{
const handleBackButton = () => {
preserveLocalStorage();
};

// 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]);
window.addEventListener("popstate", handleBackButton);

return () => {
window.removeEventListener("popstate", handleBackButton);
};
}
})}
}
}


window.addEventListener("popstate", handleBackButton);
Expand Down
28 changes: 27 additions & 1 deletion src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -938,4 +938,30 @@ export const getAssessmentType = (type: string) => {
} else {
return AssessmentType.OTHER;
}
}
}
export const preserveLocalStorage = () => {
const keysToKeep = [
'preferredLanguage',
'mui-mode',
'mui-color-scheme-dark',
'mui-color-scheme-light',
'hasSeenTutorial',
];

const valuesToKeep: { [key: string]: any } = {};

keysToKeep.forEach((key: string) => {
const value = localStorage.getItem(key);
if (value !== null) {
valuesToKeep[key] = value;
}
});

localStorage.clear();

keysToKeep.forEach((key: string) => {
if (valuesToKeep[key] !== undefined) {
localStorage.setItem(key, valuesToKeep[key]);
}
});
};

0 comments on commit 9234c41

Please sign in to comment.