Skip to content

Commit

Permalink
Merge pull request #1127 from culturecreates/bugfix/issue-1122
Browse files Browse the repository at this point in the history
fix: fixed no calendar id causing looping in the
  • Loading branch information
AbhishekPAnil authored May 28, 2024
2 parents dc8b021 + d3c9d4a commit 9de5325
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,38 @@ function Dashboard() {
const [isModalVisible, setIsModalVisible] = useState(false);

useEffect(() => {
if (!accessToken && accessToken === '') {
const accessToken = Cookies.get('accessToken');
const refreshToken = Cookies.get('refreshToken');
const accessTokenFromCookie = Cookies.get('accessToken');
const refreshTokenFromCookie = Cookies.get('refreshToken');
const calendarIdFromCookie = Cookies.get('calendarId');
const calId = calendarId || calendarIdFromCookie;

if (!calendarId) {
calendarId = Cookies.get('calendarId');
}
if (accessToken && calendarId) {
getCurrentUserDetails({ accessToken: accessToken, calendarId: calendarId })
if (!calId) {
return;
}

if (!accessToken && !accessTokenFromCookie) {
navigate(PathName.Login);
} else if (location?.state?.previousPath?.toLowerCase() !== 'login') {
const token = accessToken || accessTokenFromCookie;
if (token && calId) {
getCurrentUserDetails({ accessToken: token, calendarId: calId })
.unwrap()
.then((response) => {
dispatch(
setUser({ user: { ...response }, refreshToken: { token: refreshToken }, accessToken: accessToken }),
setUser({ user: { ...response }, refreshToken: { token: refreshTokenFromCookie }, accessToken: token }),
);
})
.catch(() => {
navigate(PathName.Login);
});
} else if (location?.state?.previousPath?.toLowerCase() === 'login' || !calendarId) {
dispatch(setInterfaceLanguage(user?.interfaceLanguage?.toLowerCase()));
i18n.changeLanguage(user?.interfaceLanguage?.toLowerCase());
} else {
navigate(PathName.Login);
}
} else {
if (location?.state?.previousPath?.toLowerCase() === 'login' || !calendarId)
dispatch(setInterfaceLanguage(user?.interfaceLanguage?.toLowerCase()));
i18n.changeLanguage(user?.interfaceLanguage?.toLowerCase());
}
}, [accessToken]);
}, [accessToken, isSuccess]);

useEffect(() => {
if (isSuccess) {
Expand Down

0 comments on commit 9de5325

Please sign in to comment.