2025-03-11 06:08:20 +08:00
|
|
|
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/react'
|
2025-03-14 23:50:27 +08:00
|
|
|
import {
|
|
|
|
|
ArrowRightStartOnRectangleIcon,
|
|
|
|
|
UserIcon,
|
|
|
|
|
} from '@heroicons/react/24/outline'
|
2025-03-03 19:10:50 +08:00
|
|
|
import { Link, useFetcher, useRouteLoaderData } from 'react-router'
|
2025-02-23 17:00:17 +08:00
|
|
|
|
2025-02-24 14:10:15 +07:00
|
|
|
import { ChevronIcon } from '~/components/icons/chevron'
|
2025-03-04 04:41:59 +07:00
|
|
|
import { ProfileIcon } from '~/components/icons/profile'
|
2025-03-11 06:08:20 +08:00
|
|
|
import { Button } from '~/components/ui/button'
|
2025-02-25 06:07:45 +08:00
|
|
|
import { APP } from '~/configs/meta'
|
2025-03-14 23:50:27 +08:00
|
|
|
import { useAdminContext } from '~/contexts/admin'
|
2025-03-03 19:10:50 +08:00
|
|
|
import type { loader } from '~/routes/_admin.lg-admin'
|
2025-02-23 17:00:17 +08:00
|
|
|
|
2025-02-23 12:18:10 +08:00
|
|
|
export const Navbar = () => {
|
2025-03-03 19:10:50 +08:00
|
|
|
const loaderData = useRouteLoaderData<typeof loader>('routes/_admin.lg-admin')
|
2025-03-09 09:32:51 +08:00
|
|
|
const { staffData } = loaderData || {}
|
2025-03-03 19:03:04 +08:00
|
|
|
const fetcher = useFetcher()
|
2025-03-14 23:50:27 +08:00
|
|
|
const { setEditProfile } = useAdminContext()
|
2025-02-23 17:41:54 +08:00
|
|
|
|
2025-02-23 17:00:17 +08:00
|
|
|
return (
|
|
|
|
|
<div className="flex h-20 items-center justify-between border-b border-[#ECECEC] bg-white px-10 py-5">
|
|
|
|
|
<Link
|
2025-02-28 11:49:51 +08:00
|
|
|
to="/"
|
2025-02-23 17:00:17 +08:00
|
|
|
className="h-full"
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={APP.logo}
|
|
|
|
|
alt={APP.title}
|
|
|
|
|
className="h-3/4 w-auto sm:h-full"
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
2025-02-23 17:41:54 +08:00
|
|
|
<div className="flex items-center gap-x-8">
|
2025-03-03 19:03:04 +08:00
|
|
|
<Popover className="relative">
|
2025-03-09 13:39:52 +08:00
|
|
|
<PopoverButton className="flex w-3xs cursor-pointer items-center justify-between rounded-xl p-2 ring-1 ring-[#707FDD]/10 hover:shadow focus:outline-none">
|
2025-03-08 15:23:22 +08:00
|
|
|
<div className="flex items-center space-x-3">
|
|
|
|
|
{staffData?.profile_picture ? (
|
2025-03-04 04:41:59 +07:00
|
|
|
<img
|
|
|
|
|
src={staffData?.profile_picture}
|
|
|
|
|
alt={staffData?.name}
|
2025-03-08 15:23:22 +08:00
|
|
|
className="h-8 w-8 rounded-full bg-[#C4C4C4] object-cover"
|
2025-03-04 04:41:59 +07:00
|
|
|
/>
|
2025-03-08 15:23:22 +08:00
|
|
|
) : (
|
|
|
|
|
<ProfileIcon className="h-8 w-8 rounded-full bg-[#C4C4C4]" />
|
2025-03-04 04:41:59 +07:00
|
|
|
)}
|
|
|
|
|
|
2025-03-09 13:39:52 +08:00
|
|
|
<span className="text-sm">{staffData?.name}</span>
|
2025-03-03 19:03:04 +08:00
|
|
|
</div>
|
|
|
|
|
<ChevronIcon className="opacity-50" />
|
|
|
|
|
</PopoverButton>
|
|
|
|
|
<PopoverPanel
|
|
|
|
|
anchor={{ to: 'bottom', gap: '8px' }}
|
|
|
|
|
transition
|
2025-03-14 23:50:27 +08:00
|
|
|
className="flex w-3xs flex-col divide-y divide-black/5 rounded-xl border border-[#ECECEC] bg-white transition duration-200 ease-in-out data-[closed]:-translate-y-1 data-[closed]:opacity-0"
|
2025-03-03 19:03:04 +08:00
|
|
|
>
|
2025-03-14 23:50:27 +08:00
|
|
|
<div className="p-2">
|
2025-03-03 19:03:04 +08:00
|
|
|
<Button
|
2025-03-14 23:50:27 +08:00
|
|
|
variant="secondary"
|
|
|
|
|
className="w-full justify-start rounded p-1 px-3 text-lg font-semibold"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setEditProfile(true)
|
|
|
|
|
}}
|
2025-03-03 19:03:04 +08:00
|
|
|
>
|
2025-03-14 23:50:27 +08:00
|
|
|
<UserIcon className="size-5" />
|
|
|
|
|
<span>Profile</span>
|
2025-03-03 19:03:04 +08:00
|
|
|
</Button>
|
2025-03-14 23:50:27 +08:00
|
|
|
</div>
|
|
|
|
|
<div className="p-2">
|
|
|
|
|
<fetcher.Form
|
|
|
|
|
method="POST"
|
|
|
|
|
action="/actions/admin/logout"
|
|
|
|
|
className="grid"
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
disabled={fetcher.state !== 'idle'}
|
|
|
|
|
isLoading={fetcher.state !== 'idle'}
|
|
|
|
|
type="submit"
|
|
|
|
|
className="w-full justify-start rounded p-1 px-3 text-lg font-semibold"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
>
|
|
|
|
|
<ArrowRightStartOnRectangleIcon className="size-5" />
|
|
|
|
|
<span>Logout</span>
|
|
|
|
|
</Button>
|
|
|
|
|
</fetcher.Form>
|
|
|
|
|
</div>
|
2025-03-03 19:03:04 +08:00
|
|
|
</PopoverPanel>
|
|
|
|
|
</Popover>
|
2025-02-23 17:00:17 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2025-02-23 12:18:10 +08:00
|
|
|
}
|