2025-02-27 23:50:46 +08:00
|
|
|
import { Link, useFetcher, useRouteLoaderData } from 'react-router'
|
2025-01-31 19:34:22 +08:00
|
|
|
|
2025-02-01 04:59:28 +08:00
|
|
|
import { Button } from '~/components/ui/button'
|
2025-02-25 06:07:45 +08:00
|
|
|
import { APP } from '~/configs/meta'
|
2025-02-22 17:34:25 +08:00
|
|
|
import { useNewsContext } from '~/contexts/news'
|
2025-03-07 12:11:48 +08:00
|
|
|
import type { loader } from '~/routes/_news'
|
2025-01-31 19:34:22 +08:00
|
|
|
|
|
|
|
|
export const HeaderTop = () => {
|
2025-02-22 17:34:25 +08:00
|
|
|
const { setIsLoginOpen } = useNewsContext()
|
2025-03-07 12:11:48 +08:00
|
|
|
const loaderData = useRouteLoaderData<typeof loader>('routes/_news')
|
2025-03-09 09:32:51 +08:00
|
|
|
const { userData } = loaderData || {}
|
2025-02-27 23:50:46 +08:00
|
|
|
const fetcher = useFetcher()
|
2025-02-27 19:37:31 +08:00
|
|
|
|
2025-01-31 19:34:22 +08:00
|
|
|
return (
|
2025-02-28 09:10:45 +08:00
|
|
|
<div className="flex h-[60px] items-center justify-between bg-white px-5 align-middle sm:h-[100px] sm:gap-[15px] sm:px-[50px] sm:py-[20px]">
|
|
|
|
|
<Link
|
2025-02-28 11:49:51 +08:00
|
|
|
to="/"
|
2025-02-28 09:10:45 +08:00
|
|
|
className="mt-2 h-full py-2"
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={APP.logo}
|
|
|
|
|
alt={APP.title}
|
|
|
|
|
className="h-3/4 w-auto sm:h-full"
|
|
|
|
|
/>
|
|
|
|
|
</Link>
|
2025-03-12 21:45:45 +08:00
|
|
|
<h1 className="hidden h-full items-center py-1.5 text-4xl font-extrabold whitespace-pre-line text-[#2E2F7C] uppercase sm:flex">
|
2025-02-28 09:10:45 +08:00
|
|
|
{APP.description}
|
2025-03-12 21:44:32 +08:00
|
|
|
</h1>
|
2025-02-28 09:10:45 +08:00
|
|
|
<div className="flex items-center gap-[15px]">
|
2025-03-02 16:36:03 +08:00
|
|
|
{userData ? (
|
2025-02-28 09:10:45 +08:00
|
|
|
<fetcher.Form
|
|
|
|
|
method="POST"
|
2025-02-28 11:49:51 +08:00
|
|
|
action="/actions/logout"
|
2025-02-28 09:10:45 +08:00
|
|
|
>
|
2025-02-27 23:50:46 +08:00
|
|
|
<Button
|
2025-03-14 23:50:27 +08:00
|
|
|
variant="outline"
|
2025-03-11 06:00:49 +08:00
|
|
|
className="hidden sm:flex"
|
2025-02-28 09:10:45 +08:00
|
|
|
type="submit"
|
2025-03-11 06:00:49 +08:00
|
|
|
disabled={fetcher.state !== 'idle'}
|
|
|
|
|
isLoading={fetcher.state !== 'idle'}
|
2025-02-27 23:50:46 +08:00
|
|
|
>
|
2025-02-28 09:10:45 +08:00
|
|
|
Logout
|
2025-02-27 23:50:46 +08:00
|
|
|
</Button>
|
2025-02-28 09:10:45 +08:00
|
|
|
</fetcher.Form>
|
|
|
|
|
) : (
|
|
|
|
|
<Button
|
2025-03-14 23:50:27 +08:00
|
|
|
variant="outline"
|
2025-02-28 09:10:45 +08:00
|
|
|
className="hidden sm:block"
|
|
|
|
|
onClick={() => setIsLoginOpen(true)}
|
|
|
|
|
>
|
|
|
|
|
Masuk
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
2025-01-31 19:34:22 +08:00
|
|
|
</div>
|
2025-02-28 09:10:45 +08:00
|
|
|
</div>
|
2025-01-31 19:34:22 +08:00
|
|
|
)
|
|
|
|
|
}
|