Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/logout confirmation #108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/common/DialogPopup/DialogPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ type Props = {
errorTitle: string;
errorDescription: string;
handleClose: any;
handleAction: any;
}

const font = Josefin_Sans({
preload: false
});

function DialogPopup({ icon, errorTitle, errorDescription, handleClose }: Props) {
function DialogPopup({ icon, errorTitle, errorDescription, handleClose, handleAction }: Props) {

return (
<Dialog
Expand All @@ -31,7 +32,7 @@ function DialogPopup({ icon, errorTitle, errorDescription, handleClose }: Props)
<div className={`${styles.text} ${font.className}`}> {errorDescription} </div>
</div>

<button onClick={handleClose}> OK </button>
<button onClick={handleAction ?? handleClose}> OK </button>
</div>
</Dialog>
)
Expand Down
8 changes: 7 additions & 1 deletion components/dashboard/SidebarItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { useRouter } from "next/router";
import { Common } from "../../constants/common";
import { useLocalStorage } from "usehooks-ts";
import logout from "../../lib/logout";
import { useState } from "react"
import { useSession } from "next-auth/react";
import DialogPopup from "../common/DialogPopup/DialogPopup";

type Item = {
title: string;
Expand All @@ -21,6 +23,8 @@ export const SidebarItem = (item: Item) => {

const selected = router.pathname === item.path ? "true" : "false";

const [showLogoutDialog, setShowLogoutDialog] = useState(false);

// const logout = () => {
// setAuthorization(null);
// destroyCookie(null, Common.AUTHORIZATION, {
Expand All @@ -34,10 +38,12 @@ export const SidebarItem = (item: Item) => {

if (item.logout) {
return (
showLogoutDialog ?
<DialogPopup errorDescription="are you sure you want to logout ?" handleAction={() => logout(router, session)} handleClose={ () => setShowLogoutDialog(false)} /> :
<button
className={styles.sidebarItem}
aria-label={item.title}
onClick={() => logout(router, session)}
onClick={() => setShowLogoutDialog(true)}
>
{item.icon}
<h3>{item.title}</h3>
Expand Down