'use client' import { useHeaderTheme } from '@/providers/HeaderTheme' import Link from 'next/link' import { useParams } from 'next/navigation' import React, { useEffect, useState, useTransition } from 'react' import type { Header } from '@/payload-types' import { Logo } from '@/components/Logo/Logo' import { HeaderNav } from './Nav' import { useLocale } from 'next-intl' import localization from '@/i18n/localization' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '@/components/ui/select' import { TypedLocale } from 'payload' import { usePathname, useRouter } from '@/i18n/routing' interface HeaderClientProps { header: Header } export const HeaderClient: React.FC = ({ header }) => { /* Storing the value in a useState to avoid hydration errors */ const [theme, setTheme] = useState(null) const { headerTheme, setHeaderTheme } = useHeaderTheme() const pathname = usePathname() useEffect(() => { setHeaderTheme(null) // eslint-disable-next-line react-hooks/exhaustive-deps }, [pathname]) useEffect(() => { if (headerTheme && headerTheme !== theme) setTheme(headerTheme) // eslint-disable-next-line react-hooks/exhaustive-deps }, [headerTheme]) return (
) } function LocaleSwitcher() { // inspired by https://github.com/amannn/next-intl/blob/main/examples/example-app-router/src/components/LocaleSwitcherSelect.tsx const locale = useLocale() const router = useRouter() const [, startTransition] = useTransition() const pathname = usePathname() const params = useParams() function onSelectChange(value: TypedLocale) { startTransition(() => { router.replace( // @ts-expect-error -- TypeScript will validate that only known `params` // are used in combination with a given `pathname`. Since the two will // always match for the current route, we can skip runtime checks. { pathname, params }, { locale: value }, ) }) } return ( ) }