Skip to content

Commit

Permalink
feat: show loading overlay when user logs out
Browse files Browse the repository at this point in the history
  • Loading branch information
er-santosh committed Mar 21, 2024
1 parent 1b7dfa5 commit 16323e9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 53 deletions.
78 changes: 41 additions & 37 deletions packages/webapp/src/components/Dashboard/TopbarUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';

import { useAuthOidcLogout, useAuthenticatedAccount } from '@/hooks/query';
import { firstLettersArgs, compose } from '@/utils';
import { LoadingOverlay } from '@/components/LoadingOverlay'

/**
* Dashboard topbar user.
Expand All @@ -24,7 +25,7 @@ function DashboardTopbarUser({
openDialog,
}) {
const history = useHistory();
const { mutateAsync: oidcLogoutMutate } = useAuthOidcLogout();
const {isLoading:isLoggingOut, mutateAsync: oidcLogoutMutate } = useAuthOidcLogout();

// Retrieve authenticated user information.
const { data: user } = useAuthenticatedAccount();
Expand All @@ -38,43 +39,46 @@ function DashboardTopbarUser({
};

return (
<Popover
content={
<Menu className={'menu--logged-user-dropdown'}>
<MenuItem
multiline={true}
className={'menu-item--profile'}
text={
<div>
<div class="person">
{user.first_name} {user.last_name}
<>
<Popover
content={
<Menu className={'menu--logged-user-dropdown'}>
<MenuItem
multiline={true}
className={'menu-item--profile'}
text={
<div>
<div class="person">
{user.first_name} {user.last_name}
</div>
<div class="org">
<T id="organization_id" />: {user.tenant_id}
</div>
</div>
<div class="org">
<T id="organization_id" />: {user.tenant_id}
</div>
</div>
}
/>
<MenuDivider />
<MenuItem
text={<T id={'keyboard_shortcuts'} />}
onClick={onKeyboardShortcut}
/>
<MenuItem
text={<T id={'preferences'} />}
onClick={() => history.push('/preferences')}
/>
<MenuItem text={<T id={'logout'} />} onClick={onClickLogout} />
</Menu>
}
position={Position.BOTTOM}
>
<Button>
<div className="user-text">
{firstLettersArgs(user.first_name, user.last_name)}
</div>
</Button>
</Popover>
}
/>
<MenuDivider />
<MenuItem
text={<T id={'keyboard_shortcuts'} />}
onClick={onKeyboardShortcut}
/>
<MenuItem
text={<T id={'preferences'} />}
onClick={() => history.push('/preferences')}
/>
<MenuItem text={<T id={'logout'} />} onClick={onClickLogout} />
</Menu>
}
position={Position.BOTTOM}
>
<Button>
<div className="user-text">
{firstLettersArgs(user.first_name, user.last_name)}
</div>
</Button>
</Popover>
{isLoggingOut && <LoadingOverlay/>}
</>
);
}
export default compose(
Expand Down
23 changes: 23 additions & 0 deletions packages/webapp/src/components/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Spinner } from "@blueprintjs/core"
import styled from "styled-components"

export function LoadingOverlay() {
return (
<OverlayContainer>
<Spinner size={50} />
</OverlayContainer>
);
}

const OverlayContainer = styled.div`
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
z-index:999;
background: rgba(252, 253, 255, 0.5);
display: flex;
justify-content: center;
`;

37 changes: 21 additions & 16 deletions packages/webapp/src/containers/Setup/SetupLeftSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Icon, For, FormattedMessage as T } from '@/components';

import { getFooterLinks } from '@/constants/footerLinks';
import { useAuthOidcLogout } from '@/hooks/query'
import { LoadingOverlay } from '@/components/LoadingOverlay'

/**
* Footer item link.
Expand Down Expand Up @@ -38,32 +39,36 @@ function SetupLeftSectionFooter() {
* Setup left section header.
*/
function SetupLeftSectionHeader() {
const { mutateAsync: oidcLogoutMutate } = useAuthOidcLogout();
const {isLoading:isLoggingOut, mutateAsync: oidcLogoutMutate } = useAuthOidcLogout();

// Handle logout link click.
const onClickLogout = () => {
oidcLogoutMutate();
};

return (
<div className={'content__header'}>
<h1 className={'content__title'}>
<T id={'setup.left_side.title'} />
</h1>
<>
<div className={'content__header'}>
<h1 className={'content__title'}>
<T id={'setup.left_side.title'} />
</h1>

<p className={'content__text'}>
<T id={'setup.left_side.description'} />
</p>
<div class="content__divider"></div>
<p className={'content__text'}>
<T id={'setup.left_side.description'} />
</p>
<div class="content__divider"></div>

<div className={'content__organization'}>
<span class="signout">
<a onClick={onClickLogout} href="#">
<T id={'sign_out'} />
</a>
</span>
<div className={'content__organization'}>
<span class="signout">
<a onClick={onClickLogout} href="#">
<T id={'sign_out'} />
</a>
</span>
</div>
</div>
</div>

{isLoggingOut && <LoadingOverlay />}
</>
);
}

Expand Down

0 comments on commit 16323e9

Please sign in to comment.