Skip to content

Commit

Permalink
fix: hot fix for infinite looping for users with expired token.
Browse files Browse the repository at this point in the history
  • Loading branch information
syam babu committed Jun 11, 2024
1 parent 983ef99 commit fbf2c52
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/components/ImageUpload/imageUpload.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
max-height: 100%;
display: inline-block;
margin-left: 10px;
}
Expand Down
20 changes: 10 additions & 10 deletions src/pages/Dashboard/AddUser/AddUser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const AddUser = () => {
}

if (userId && userId !== user?.id) {
getUser({ userId, calendarId })
getUser({ userId, calendarId, sessionId: timestampRef })
.unwrap()
.then((response) => {
const activeCalendars = response?.roles?.filter((r) => {
Expand Down Expand Up @@ -869,26 +869,26 @@ const AddUser = () => {
<Col flex={'423px'}>
<Col>
<div style={{ display: 'flex', gap: '16px', flexDirection: 'column' }}>
{selectedCalendars?.map((calendar, index) => (
{selectedCalendars?.map((selectedCalendar, index) => (
<CalendarAccordion
form={formInstance}
data-cy="accordion-selected-calendars"
key={index}
selectedCalendarId={calendar?.calendarId}
selectedCalendarId={selectedCalendar?.calendarId}
name={contentLanguageBilingual({
en: calendar?.name?.en,
fr: calendar?.name?.fr,
en: selectedCalendar?.name?.en,
fr: selectedCalendar?.name?.fr,
interfaceLanguage: user?.interfaceLanguage?.toLowerCase(),
calendarContentLanguage: calendarContentLanguage,
})}
role={calendar?.role}
role={selectedCalendar?.role}
readOnly={adminCheckHandler({ calendar, user }) ? false : true}
disabled={calendar?.disabled}
organizationIds={calendar?.organizations}
peopleIds={calendar?.people}
disabled={selectedCalendar?.disabled}
organizationIds={selectedCalendar?.organizations}
peopleIds={selectedCalendar?.people}
isCurrentUser={isCurrentUser}
removeCalendarHandler={() => {
removeCalendarHandler({ item: calendar, index });
removeCalendarHandler({ item: selectedCalendar, index });
}}
/>
))}
Expand Down
20 changes: 12 additions & 8 deletions src/pages/Dashboard/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Dashboard() {
isLoading,
isSuccess,
refetch,
} = useGetAllCalendarsQuery({ sessionId: timestampRef }, { skip: accessToken ? false : true });
} = useGetAllCalendarsQuery({ sessionId: timestampRef });

const [getCurrentUserDetails, { isLoading: isCurrentUserLoading }] = useLazyGetCurrentUserQuery();

Expand All @@ -69,6 +69,15 @@ function Dashboard() {
};

useEffect(() => {
if (location?.state?.previousPath?.toLowerCase() === 'login') {
dispatch(setInterfaceLanguage(user?.interfaceLanguage?.toLowerCase()));
i18n.changeLanguage(user?.interfaceLanguage?.toLowerCase());
}
}, [accessToken]);

useEffect(() => {
if (!isSuccess) return;

const accessTokenFromCookie = Cookies.get('accessToken');
const refreshTokenFromCookie = Cookies.get('refreshToken');
const calendarIdFromCookie = Cookies.get('calendarId');
Expand All @@ -80,7 +89,7 @@ function Dashboard() {

const token = accessToken || accessTokenFromCookie;

getCurrentUserDetails({ accessToken: token, calendarId: calId })
getCurrentUserDetails({ accessToken: token, calendarId: calId, sessionId: timestampRef })
.unwrap()
.then((response) => {
dispatch(
Expand All @@ -90,12 +99,7 @@ function Dashboard() {
.catch(() => {
navigate(PathName.Login);
});

if (location?.state?.previousPath?.toLowerCase() === 'login') {
dispatch(setInterfaceLanguage(user?.interfaceLanguage?.toLowerCase()));
i18n.changeLanguage(user?.interfaceLanguage?.toLowerCase());
}
}, [accessToken, isSuccess]);
}, [isSuccess]);

useEffect(() => {
if (!isSuccess) return;
Expand Down

0 comments on commit fbf2c52

Please sign in to comment.