diff --git a/shared/helpers/backendFetch.ts b/shared/helpers/backendFetch.ts index f41c5d2..abb0e99 100644 --- a/shared/helpers/backendFetch.ts +++ b/shared/helpers/backendFetch.ts @@ -38,7 +38,7 @@ export const backendFetch = async (path: string, options: RequestInit = {}) => { const resJson = (await res.json()) as BackendResponse; - if (!res.ok || !resJson.success) { + if (!res.ok) { throw new Error(`Elysia error: ${resJson.error}`); } diff --git a/shared/libs/shadcn/ui/alert-dialog.tsx b/shared/libs/shadcn/ui/alert-dialog.tsx new file mode 100644 index 0000000..d22b360 --- /dev/null +++ b/shared/libs/shadcn/ui/alert-dialog.tsx @@ -0,0 +1,184 @@ +"use client" + +import * as React from "react" +import { AlertDialog as AlertDialogPrimitive } from "radix-ui" + +import { cn } from "@/shared/libs/shadcn/lib/utils" +import { Button } from "@/shared/libs/shadcn/ui/button" + +function AlertDialog({ + ...props +}: React.ComponentProps) { + return +} + +function AlertDialogTrigger({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogPortal({ + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogOverlay({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogContent({ + className, + size = "default", + ...props +}: React.ComponentProps & { + size?: "default" | "sm" +}) { + return ( + + + + + ) +} + +function AlertDialogHeader({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function AlertDialogFooter({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function AlertDialogMedia({ + className, + ...props +}: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function AlertDialogTitle({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogDescription({ + className, + ...props +}: React.ComponentProps) { + return ( + + ) +} + +function AlertDialogAction({ + className, + variant = "default", + size = "default", + ...props +}: React.ComponentProps & + Pick, "variant" | "size">) { + return ( + + ) +} + +function AlertDialogCancel({ + className, + variant = "outline", + size = "default", + ...props +}: React.ComponentProps & + Pick, "variant" | "size">) { + return ( + + ) +} + +export { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogMedia, + AlertDialogOverlay, + AlertDialogPortal, + AlertDialogTitle, + AlertDialogTrigger, +} diff --git a/shared/widgets/navbar/components/LogoutAlert.tsx b/shared/widgets/navbar/components/LogoutAlert.tsx new file mode 100644 index 0000000..1e5b254 --- /dev/null +++ b/shared/widgets/navbar/components/LogoutAlert.tsx @@ -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>; +}) => { + const [isLoading, setIsLoading] = React.useState(false); + + return ( + + setOpenState(false)}> + + Are you sure? + + This action will log you out of your account. You can log back in at + any time. Do you want to proceed? + + + + setOpenState(false)} + > + Cancel + + + + + + + + ); +}; + +export default LogoutAlert; diff --git a/shared/widgets/navbar/components/UserProfile.tsx b/shared/widgets/navbar/components/UserProfile.tsx index a83a307..d3eb8c0 100644 --- a/shared/widgets/navbar/components/UserProfile.tsx +++ b/shared/widgets/navbar/components/UserProfile.tsx @@ -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 (
@@ -71,13 +79,18 @@ const UserProfile = () => { - - - Log Out + + +
); };