mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-02-23 10:22:01 +00:00
- Updated AccountPopover to utilize session data for user information display. - Modified ApplicationLayout to fetch user details from the database using Prisma. - Replaced Checkbox components with native input elements in SignUpForm for better accessibility. - Enhanced seed script to include default islands and create related data in the database.
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
'use client'
|
|
import { Button } from "@/components/ui/button"
|
|
import {
|
|
Popover,
|
|
PopoverContent,
|
|
PopoverTrigger,
|
|
} from "@/components/ui/popover"
|
|
import { authClient } from "@/lib/auth-client";
|
|
import type { User } from "@prisma/client";
|
|
import { Loader2, User as UserIcon } from "lucide-react"
|
|
import { useRouter } from "next/navigation"
|
|
import { useState } from "react"
|
|
|
|
export function AccountPopover({ user }: { user?: User }) {
|
|
const session = authClient.useSession();
|
|
const [loading, setLoading] = useState(false)
|
|
const router = useRouter()
|
|
|
|
if (session.isPending) {
|
|
<Button variant={"outline"} disabled>
|
|
<Loader2 className="animate-spin" />
|
|
</Button>
|
|
}
|
|
return (
|
|
|
|
<Popover>
|
|
<PopoverTrigger asChild>
|
|
<Button variant="outline">
|
|
<UserIcon />
|
|
</Button>
|
|
</PopoverTrigger>
|
|
<PopoverContent className="w-fit">
|
|
<div className="grid gap-4">
|
|
<div className="space-y-2">
|
|
<h4 className="font-medium leading-none">{session.data?.user?.name}</h4>
|
|
<p className="text-sm text-muted-foreground">
|
|
{session.data?.user?.phoneNumber}
|
|
</p>
|
|
<span className="text-xs text-gray-500">{user?.address}</span>
|
|
</div>
|
|
<Button disabled={loading} onClick={async () => {
|
|
setLoading(true)
|
|
await authClient.signOut({
|
|
fetchOptions: {
|
|
onSuccess: () => {
|
|
router.push("/login"); // redirect to login page
|
|
},
|
|
},
|
|
})
|
|
setLoading(false)
|
|
}}>
|
|
{loading ? <Loader2 className="animate-spin" /> : "Logout"}
|
|
</Button>
|
|
</div>
|
|
</PopoverContent>
|
|
</Popover>
|
|
)
|
|
}
|