💄 style: add logout confirmation popup UI
This commit is contained in:
61
shared/widgets/navbar/components/LogoutAlert.tsx
Normal file
61
shared/widgets/navbar/components/LogoutAlert.tsx
Normal file
@ -0,0 +1,61 @@
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogMedia,
|
||||
AlertDialogTitle,
|
||||
} from "@/shared/libs/shadcn/ui/alert-dialog";
|
||||
import { Spinner } from "@/shared/libs/shadcn/ui/spinner";
|
||||
import { Button } from "@base-ui/react";
|
||||
import { LogOut } from "lucide-react";
|
||||
import React from "react";
|
||||
|
||||
const LogoutAlert = ({
|
||||
openState,
|
||||
setOpenState,
|
||||
}: {
|
||||
openState: boolean;
|
||||
setOpenState: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
}) => {
|
||||
const [isLoading, setIsLoading] = React.useState(false);
|
||||
|
||||
return (
|
||||
<AlertDialog open={openState}>
|
||||
<AlertDialogContent size="sm" onEscapeKeyDown={() => setOpenState(false)}>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This action will log you out of your account. You can log back in at
|
||||
any time. Do you want to proceed?
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel
|
||||
disabled={isLoading}
|
||||
className="hover:cursor-pointer"
|
||||
variant="outline"
|
||||
onClick={() => setOpenState(false)}
|
||||
>
|
||||
Cancel
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" asChild>
|
||||
<Button
|
||||
disabled={isLoading}
|
||||
className="w-full hover:cursor-pointer"
|
||||
onClick={() => setIsLoading(true)}
|
||||
>
|
||||
{isLoading && <Spinner />}
|
||||
Logout
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default LogoutAlert;
|
||||
@ -9,6 +9,7 @@ import {
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/shared/libs/shadcn/ui/dropdown-menu";
|
||||
import { Button } from "@base-ui/react";
|
||||
import {
|
||||
Bookmark,
|
||||
CircleUserRound,
|
||||
@ -19,9 +20,16 @@ import {
|
||||
Settings,
|
||||
Webhook,
|
||||
} from "lucide-react";
|
||||
import LogoutAlert from "./LogoutAlert";
|
||||
import React from "react";
|
||||
|
||||
const UserProfile = () => {
|
||||
const { session } = useAuth();
|
||||
const [openState, setOpenState] = React.useState(false);
|
||||
const triggerLogoutPopup = () => {
|
||||
setOpenState(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="h-full flex items-center">
|
||||
<DropdownMenu>
|
||||
@ -71,13 +79,18 @@ const UserProfile = () => {
|
||||
</DropdownMenuGroup>
|
||||
<DropdownMenuGroup>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive">
|
||||
<LogOut />
|
||||
Log Out
|
||||
<DropdownMenuItem variant="destructive" asChild>
|
||||
<Button
|
||||
onClick={triggerLogoutPopup}
|
||||
className="w-full hover:cursor-pointer"
|
||||
>
|
||||
<LogOut /> Logout
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuGroup>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<LogoutAlert openState={openState} setOpenState={setOpenState} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user