2024-11-24 23:30:44 +05:00
|
|
|
'use client'
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
import {
|
|
|
|
Popover,
|
|
|
|
PopoverContent,
|
|
|
|
PopoverTrigger,
|
|
|
|
} from "@/components/ui/popover"
|
2024-12-01 07:40:21 +05:00
|
|
|
import { authClient } from "@/lib/auth-client";
|
|
|
|
import { Loader2, User as UserIcon } from "lucide-react"
|
2024-11-24 23:30:44 +05:00
|
|
|
import { useRouter } from "next/navigation"
|
|
|
|
import { useState } from "react"
|
|
|
|
|
2024-12-01 23:19:31 +05:00
|
|
|
export function AccountPopover() {
|
2024-12-01 07:40:21 +05:00
|
|
|
const session = authClient.useSession();
|
2024-11-24 23:30:44 +05:00
|
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
const router = useRouter()
|
2024-12-01 07:40:21 +05:00
|
|
|
|
|
|
|
if (session.isPending) {
|
|
|
|
<Button variant={"outline"} disabled>
|
|
|
|
<Loader2 className="animate-spin" />
|
|
|
|
</Button>
|
|
|
|
}
|
2024-11-24 23:30:44 +05:00
|
|
|
return (
|
2024-12-01 07:40:21 +05:00
|
|
|
|
2024-11-24 23:30:44 +05:00
|
|
|
<Popover>
|
|
|
|
<PopoverTrigger asChild>
|
2024-12-25 17:21:04 +05:00
|
|
|
<Button className="w-fit px-2" variant="outline">
|
2024-11-24 23:30:44 +05:00
|
|
|
<UserIcon />
|
|
|
|
</Button>
|
|
|
|
</PopoverTrigger>
|
2024-12-01 07:40:21 +05:00
|
|
|
<PopoverContent className="w-fit">
|
2024-11-24 23:30:44 +05:00
|
|
|
<div className="grid gap-4">
|
|
|
|
<div className="space-y-2">
|
2024-12-01 07:40:21 +05:00
|
|
|
<h4 className="font-medium leading-none">{session.data?.user?.name}</h4>
|
2024-11-24 23:30:44 +05:00
|
|
|
<p className="text-sm text-muted-foreground">
|
2024-12-01 07:40:21 +05:00
|
|
|
{session.data?.user?.phoneNumber}
|
2024-11-24 23:30:44 +05:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<Button disabled={loading} onClick={async () => {
|
|
|
|
setLoading(true)
|
|
|
|
await authClient.signOut({
|
|
|
|
fetchOptions: {
|
|
|
|
onSuccess: () => {
|
|
|
|
router.push("/login"); // redirect to login page
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
setLoading(false)
|
|
|
|
}}>
|
2024-12-01 07:40:21 +05:00
|
|
|
{loading ? <Loader2 className="animate-spin" /> : "Logout"}
|
2024-11-24 23:30:44 +05:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
)
|
|
|
|
}
|