Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

redesigned the header for authed users

Blue Mouse490d07975b01
diff --git a/public/locales/en.json b/public/locales/en.json
index 40c5f4339..eddbc1065 100644
--- a/public/locales/en.json
+++ b/public/locales/en.json
@@ -32,7 +32,7 @@
"billing": "Billing",
"pricing": "Pricing",
"faqs": "FAQs",
- "you": "You",
+ "accountSettings": "Account settings",
"explore": "Explore",
"liveDemo": "Live demo",
"dashboard": "Dashboard",
@@ -750,6 +750,12 @@
"main": "Ultimate open-source analytics to satisfy all your needs",
"press": "Media & Press"
},
+ "header": {
+ "switchTheme": "Switch theme",
+ "dark": "Dark",
+ "light": "Light",
+ "signedInAs": "Signed in as"
+ },
"footer": {
"slogan": "The best apps need the best services.",
"description": "Swetrix is a powerful analytics platform that respects user privacy.",
diff --git a/src/components/Header/index.jsx b/src/components/Header/index.jsx
index 6fbeaa45f..cae918526 100644
--- a/src/components/Header/index.jsx
+++ b/src/components/Header/index.jsx
@@ -9,14 +9,18 @@ import { useDispatch } from 'react-redux'
import { useTranslation } from 'react-i18next'
import Flag from 'react-flagkit'
import i18next from 'i18next'
-import { Popover, Transition } from '@headlessui/react'
+import {
+ Popover, Transition, Menu,
+} from '@headlessui/react'
import {
Bars3Icon, XMarkIcon, DocumentTextIcon, CreditCardIcon, CircleStackIcon, RssIcon,
+ ChevronDownIcon, PresentationChartLineIcon,
} from '@heroicons/react/24/outline'
import { MoonIcon, SunIcon } from '@heroicons/react/24/solid'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import duration from 'dayjs/plugin/duration'
+import _map from 'lodash/map'
import cx from 'clsx'
import routes from 'routes'
@@ -39,10 +43,450 @@ const TRIAL_STATUS_MAPPING = {
ENDS_IN_X_DAYS: 4,
}
+const ThemeMenu = ({
+ theme, t, switchTheme,
+}) => (
+ <Menu as='div' className='relative ml-3'>
+ <div>
+ <Menu.Button className='flex justify-center items-center text-base font-medium text-white focus:outline-none hover:text-indigo-100 hover:dark:text-gray-200'>
+ <span className='sr-only'>
+ {t('header.switchTheme')}
+ </span>
+ {theme === 'dark' ? (
+ <SunIcon className='h-6 w-6 text-gray-200 hover:text-gray-300 cursor-pointer' aria-hidden='true' />
+ ) : (
+ <MoonIcon className='h-6 w-6 text-indigo-100 hover:text-indigo-200 cursor-pointer' aria-hidden='true' />
+ )}
+ </Menu.Button>
+ </div>
+ <Transition
+ as={Fragment}
+ enter='transition ease-out duration-100'
+ enterFrom='transform opacity-0 scale-95'
+ enterTo='transform opacity-100 scale-100'
+ leave='transition ease-in duration-75'
+ leaveFrom='transform opacity-100 scale-100'
+ leaveTo='transform opacity-0 scale-95'
+ >
+ <Menu.Items className='absolute right-0 z-10 mt-2 w-36 min-w-max origin-top-right rounded-md bg-white dark:bg-gray-800 py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none'>
+ <Menu.Item>
+ {({ active }) => (
+ <div
+ className={cx('flex w-full font-semibold cursor-pointer px-4 py-2 text-sm text-indigo-600 dark:text-gray-50 hover:bg-gray-100 hover:dark:bg-gray-700', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ onClick={() => switchTheme('light')}
+ >
+ <SunIcon className='h-5 w-5 mr-2 text-indigo-600 dark:text-gray-200' aria-hidden='true' />
+ {t('header.light')}
+ </div>
+ )}
+ </Menu.Item>
+ <Menu.Item>
+ {({ active }) => (
+ <div
+ className={cx('flex w-full font-semibold cursor-pointer px-4 py-2 text-sm text-gray-700 dark:text-indigo-400 hover:bg-gray-100 hover:dark:bg-gray-700', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ onClick={() => switchTheme('dark')}
+ >
+ <MoonIcon className='h-5 w-5 mr-2 text-gray-200 dark:text-indigo-400' aria-hidden='true' />
+ {t('header.dark')}
+ </div>
+ )}
+ </Menu.Item>
+ </Menu.Items>
+ </Transition>
+ </Menu>
+)
+
+const ProfileMenu = ({
+ user, logoutHandler, t, onLanguageChange, language,
+}) => (
+ <Menu as='div' className='relative ml-3'>
+ <div>
+ <Menu.Button className='flex justify-center items-center text-base font-medium text-white focus:outline-none hover:text-indigo-100 hover:dark:text-gray-200'>
+ <span>Account</span>
+ <ChevronDownIcon className='h-4 w-4 ml-1' aria-hidden='true' />
+ </Menu.Button>
+ </div>
+ <Transition
+ as={Fragment}
+ enter='transition ease-out duration-100'
+ enterFrom='transform opacity-0 scale-95'
+ enterTo='transform opacity-100 scale-100'
+ leave='transition ease-in duration-75'
+ leaveFrom='transform opacity-100 scale-100'
+ leaveTo='transform opacity-0 scale-95'
+ >
+ <Menu.Items className='absolute right-0 z-10 mt-2 w-60 min-w-max origin-top-right rounded-md bg-white dark:bg-gray-800 py-1 shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none'>
+ <div className='border-gray-200 dark:border-gray-700 border-b-[1px]'>
+ <Menu.Item>
+ <p className='truncate py-2 px-4' role='none'>
+ <span
+ className='block text-xs text-gray-500 dark:text-gray-300'
+ role='none'
+ >
+ {t('header.signedInAs')}
+ </span>
+ <span
+ className='mt-0.5 text-sm font-semibold text-gray-700 dark:text-gray-50'
+ role='none'
+ >
+ {user?.email}
+ </span>
+ </p>
+ </Menu.Item>
+ </div>
+
+ <div className='border-gray-200 dark:border-gray-700 border-b-[1px]'>
+ {/* Language selector */}
+ <Menu as='div'>
+ {({ open }) => (
+ <>
+ <div>
+ <Menu.Button
+ // className='inline-flex w-full rounded-md border border-gray-300 shadow-sm px-3 md:px-4 py-2 bg-white text-sm font-medium text-gray-700 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500'
+ className='flex justify-between w-full px-4 py-2 text-sm text-gray-700 dark:text-gray-50 hover:bg-gray-100 hover:dark:bg-gray-700'
+ >
+ <div className='flex'>
+ <Flag className='rounded-sm mr-1.5' country={languageFlag[language]} size={20} alt='' aria-hidden='true' />
+ {languages[language]}
+ </div>
+ <ChevronDownIcon className='-mr-1 ml-2 h-5 w-5' aria-hidden='true' />
+ </Menu.Button>
+ </div>
+
+ <Transition
+ show={open}
+ as={Fragment}
+ enter='transition ease-out duration-100'
+ enterFrom='transform opacity-0 scale-95'
+ enterTo='transform opacity-100 scale-100'
+ leave='transition ease-in duration-75'
+ leaveFrom='transform opacity-100 scale-100'
+ leaveTo='transform opacity-0 scale-95'
+ >
+ <Menu.Items
+ className='z-50 origin-top-right absolute right-0 mt-1 w-full min-w-max rounded-md shadow-lg bg-white dark:bg-gray-700 ring-1 ring-black ring-opacity-5 focus:outline-none'
+ static
+ >
+ <div className='py-1'>
+ {_map(whitelist, lng => (
+ <Menu.Item key={lng}>
+ <span
+ className='text-gray-700 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 block px-4 py-2 text-sm cursor-pointer hover:bg-gray-200 dark:hover:bg-gray-600'
+ role='menuitem'
+ tabIndex='-1'
+ id='menu-item-0'
+ onClick={() => onLanguageChange(lng)}
+ >
+ <div className='flex'>
+ <div className='pt-1'>
+ <Flag className='rounded-sm mr-1.5' country={languageFlag[lng]} size={20} alt={languageFlag[lng]} />
+ </div>
+ {languages[lng]}
+ </div>
+ </span>
+ </Menu.Item>
+ ))}
+ </div>
+ </Menu.Items>
+ </Transition>
+ </>
+ )}
+ </Menu>
+
+ <Menu.Item>
+ {({ active }) => (
+ <Link
+ to={routes.changelog}
+ className={cx('block px-4 py-2 text-sm text-gray-700 dark:text-gray-50', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ >
+ {t('footer.changelog')}
+ </Link>
+ )}
+ </Menu.Item>
+ <Menu.Item>
+ {({ active }) => (
+ <Link
+ to={routes.contact}
+ className={cx('block px-4 py-2 text-sm text-gray-700 dark:text-gray-50', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ >
+ {t('footer.support')}
+ </Link>
+ )}
+ </Menu.Item>
+ <Menu.Item>
+ {({ active }) => (
+ <Link
+ to={routes.billing}
+ className={cx('block px-4 py-2 text-sm text-gray-700 dark:text-gray-50', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ >
+ {t('common.billing')}
+ </Link>
+ )}
+ </Menu.Item>
+ </div>
+
+ {!isSelfhosted && (
+ <Menu.Item>
+ {({ active }) => (
+ <Link
+ to={routes.user_settings}
+ className={cx('block px-4 py-2 text-sm text-gray-700 dark:text-gray-50', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ >
+ {t('common.accountSettings')}
+ </Link>
+ )}
+ </Menu.Item>
+ )}
+ <Menu.Item>
+ {({ active }) => (
+ <p
+ className={cx('cursor-pointer px-4 py-2 text-sm text-gray-700 dark:text-gray-50', {
+ 'bg-gray-100 dark:bg-gray-700': active,
+ })}
+ onClick={logoutHandler}
+ >
+ {t('common.logout')}
+ </p>
+ )}
+ </Menu.Item>
+ </Menu.Items>
+ </Transition>
+ </Menu>
+)
+
+const AuthedHeader = ({
+ user, switchTheme, theme, onLanguageChange, rawStatus, status, t, language, logoutHandler,
+}) => (
+ <header className='bg-indigo-600 dark:bg-gray-750 relative overflow-x-clip'>
+ <nav className='mx-auto px-4 sm:px-6 lg:px-8' aria-label='Top'>
+ <div className='w-full py-4 flex items-center justify-between border-b border-indigo-500 dark:border-gray-300 lg:border-none'>
+ <div className='flex items-center'>
+ {/* Logo */}
+ <Link to={routes.main}>
+ <span className='sr-only'>Swetrix</span>
+ <img className='h-10' src='/assets/logo_white.svg' alt='Swetrix' />
+ </Link>
+
+ <div className='hidden ml-10 space-x-1 lg:flex'>
+ {!isSelfhosted && user?.planCode === 'trial' && (
+ <Link
+ to={routes.billing}
+ className={cx('flex justify-center items-center text-base select-none font-medium py-2 px-2 rounded-md', {
+ 'text-amber-800 bg-amber-200 dark:bg-amber-300 hover:bg-amber-300 dark:hover:bg-amber-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS,
+ 'text-rose-800 bg-rose-200 dark:bg-rose-300 hover:bg-rose-300 dark:hover:bg-rose-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_TODAY || rawStatus === TRIAL_STATUS_MAPPING.ENDS_TOMORROW || rawStatus === TRIAL_STATUS_MAPPING.ENDED,
+ })}
+ key='TrialNotification'
+ >
+ {status}
+ </Link>
+ )}
+ {user?.planCode === 'none' && (
+ <Link
+ to={routes.billing}
+ className='flex justify-center items-center text-base select-none font-medium py-2 px-2 rounded-md text-rose-800 bg-rose-200 dark:bg-rose-300 hover:bg-rose-300 dark:hover:bg-rose-200'
+ key='NoSubscription'
+ >
+ {t('billing.inactive')}
+ </Link>
+ )}
+ <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <RssIcon className='w-5 h-5 mr-1' />
+ {t('footer.blog')}
+ </a>
+ <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <DocumentTextIcon className='w-5 h-5 mr-1' />
+ {t('common.docs')}
+ </a>
+ <Link to={routes.dashboard} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Billing'>
+ <PresentationChartLineIcon className='w-5 h-5 mr-1' />
+ {t('common.dashboard')}
+ </Link>
+ </div>
+ </div>
+ <div className='hidden md:flex justify-center items-center flex-wrap ml-1 md:ml-10 space-y-1 sm:space-y-0 space-x-2 md:space-x-4'>
+ <ThemeMenu
+ theme={theme}
+ switchTheme={switchTheme}
+ t={t}
+ />
+ <ProfileMenu
+ user={user}
+ logoutHandler={logoutHandler}
+ onLanguageChange={onLanguageChange}
+ language={language}
+ t={t}
+ />
+ </div>
+ <div className='md:hidden flex justify-center items-center'>
+ {/* Theme switch */}
+ {theme === 'dark' ? (
+ <div className='transition-all duration-1000 ease-in-out rotate-180'>
+ <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />
+ </div>
+ ) : (
+ <div className='transition-all duration-1000 ease-in-out'>
+ <MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />
+ </div>
+ )}
+ <Popover.Button className='bg-white dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200 rounded-md p-2 ml-3 inline-flex items-center justify-center text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500'>
+ <span className='sr-only'>
+ {t('common.openMenu')}
+ </span>
+ <Bars3Icon className='h-6 w-6' aria-hidden='true' />
+ </Popover.Button>
+ </div>
+ </div>
+ <div className='py-4 flex flex-wrap justify-center space-x-2 lg:hidden'>
+ <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <RssIcon className='w-5 h-5 mr-1' />
+ {t('footer.blog')}
+ </a>
+ <NavLink to={routes.billing} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Billing'>
+ <CreditCardIcon className='w-5 h-5 mr-1' />
+ {t('common.billing')}
+ </NavLink>
+ <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <DocumentTextIcon className='w-5 h-5 mr-1' />
+ {t('common.docs')}
+ </a>
+ </div>
+ </nav>
+ </header>
+)
+
+const NotAuthedHeader = ({
+ switchTheme, theme, onLanguageChange, t, language,
+}) => (
+ <header className='bg-indigo-600 dark:bg-gray-750 relative overflow-x-clip'>
+ <nav className='mx-auto px-4 sm:px-6 lg:px-8' aria-label='Top'>
+ <div className='w-full py-4 flex items-center justify-between border-b border-indigo-500 dark:border-gray-300 lg:border-none'>
+ <div className='flex items-center'>
+ {/* Logo */}
+ <Link to={routes.main}>
+ <span className='sr-only'>Swetrix</span>
+ <img className='h-10' src='/assets/logo_white.svg' alt='Swetrix' />
+ </Link>
+
+ <div className='hidden ml-10 space-x-1 lg:flex'>
+ <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <RssIcon className='w-5 h-5 mr-1' />
+ {t('footer.blog')}
+ </a>
+ {!isSelfhosted && (
+ <>
+ <NavLink to={routes.features} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Features'>
+ <CircleStackIcon className='w-5 h-5 mr-1' />
+ {t('common.features')}
+ </NavLink>
+ <HashLink to={`${routes.main}#pricing`} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' key='Pricing'>
+ <CreditCardIcon className='w-5 h-5 mr-1' />
+ {t('common.pricing')}
+ </HashLink>
+ </>
+ )}
+ <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <DocumentTextIcon className='w-5 h-5 mr-1' />
+ {t('common.docs')}
+ </a>
+ </div>
+ </div>
+ <div className='hidden md:flex justify-center items-center flex-wrap ml-1 md:ml-10 space-y-1 sm:space-y-0 space-x-2 md:space-x-4'>
+ {/* Theme switch */}
+ {theme === 'dark' ? (
+ <div className='transition-all duration-1000 ease-in-out rotate-180'>
+ <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />
+ </div>
+ ) : (
+ <div className='transition-all duration-1000 ease-in-out'>
+ <MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />
+ </div>
+ )}
+
+ {/* Language selector */}
+ <Dropdown
+ items={whitelist}
+ buttonClassName='flex items-center w-full rounded-md border border-gray-300 shadow-sm px-3 md:px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
+ selectItemClassName='text-gray-700 block px-4 py-2 text-base cursor-pointer hover:bg-gray-200 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
+ title={(
+ <>
+ <Flag className='rounded-sm mr-1.5' country={languageFlag[language]} size={21} alt='' aria-hidden='true' />
+ {languages[language]}
+ </>
+ )}
+ labelExtractor={(lng) => (
+ <div className='flex'>
+ <div className='pt-1'>
+ <Flag className='rounded-sm mr-1.5' country={languageFlag[lng]} size={21} alt={languageFlag[lng]} />
+ </div>
+ {languages[lng]}
+ </div>
+ )}
+ onSelect={onLanguageChange}
+ />
+ <Link to={routes.signin} className='inline-block select-none bg-indigo-500 dark:bg-gray-700 mt-1 sm:mt-0 py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-white hover:bg-opacity-75 hover:dark:bg-gray-600'>
+ {t('auth.common.signin')}
+ </Link>
+ {!isSelfhosted && (
+ <Link to={routes.signup} className='inline-block select-none bg-white dark:bg-gray-700 dark:text-gray-50 py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50 hover:dark:bg-gray-600' aria-label={t('titles.signup')}>
+ {t('common.getStarted')}
+ </Link>
+ )}
+ </div>
+ <div className='md:hidden flex justify-center items-center'>
+ {/* Theme switch */}
+ {theme === 'dark' ? (
+ <div className='transition-all duration-1000 ease-in-out rotate-180'>
+ <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />
+ </div>
+ ) : (
+ <div className='transition-all duration-1000 ease-in-out'>
+ <MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />
+ </div>
+ )}
+ <Popover.Button className='bg-white dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200 rounded-md p-2 ml-3 inline-flex items-center justify-center text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500'>
+ <span className='sr-only'>
+ {t('common.openMenu')}
+ </span>
+ <Bars3Icon className='h-6 w-6' aria-hidden='true' />
+ </Popover.Button>
+ </div>
+ </div>
+ <div className='py-4 flex flex-wrap justify-center space-x-2 lg:hidden'>
+ <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <RssIcon className='w-5 h-5 mr-1' />
+ {t('footer.blog')}
+ </a>
+ <HashLink to={`${routes.main}#pricing`} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' key='Pricing'>
+ <CreditCardIcon className='w-5 h-5 mr-1' />
+ {t('common.pricing')}
+ </HashLink>
+ <NavLink to={routes.features} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Features'>
+ <CircleStackIcon className='w-5 h-5 mr-1' />
+ {t('common.features')}
+ </NavLink>
+ <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
+ <DocumentTextIcon className='w-5 h-5 mr-1' />
+ {t('common.docs')}
+ </a>
+ </div>
+ </nav>
+ </header>
+)
+
const Header = ({
- authenticated, theme,
- // themeType,
- user,
+ authenticated, theme, user,
}) => {
const { t, i18n: { language } } = useTranslation('common')
const dispatch = useDispatch()
@@ -86,8 +530,8 @@ const Header = ({
dispatch(authActions.logout())
}
- const switchTheme = () => {
- dispatch(UIActions.setTheme(theme === 'dark' ? 'light' : 'dark'))
+ const switchTheme = (switchTo = theme === 'dark' ? 'light' : 'dark') => {
+ dispatch(UIActions.setTheme(switchTo))
}
const onLanguageChange = (id) => {
@@ -97,199 +541,27 @@ const Header = ({
return (
<Popover className='relative bg-white'>
{/* Computer / Laptop / Tablet layout header */}
- <header className='bg-indigo-600 dark:bg-gray-750 relative overflow-x-clip'>
- {/* {themeType === THEME_TYPE.christmas && (
- <div className='santa-claus group'>
- <div className='group-hover:cursor-pointer group-hover:translate-y-[-100px] transition-all ease-linear delay-100 duration-500'>
- <div className='sc-head'>
- <div className='sc-hat'>
- <div className='hat-tip' />
- </div>
- <div className='eyes' />
- <div className='nose' />
- <div className='beard' />
- <div className='ears'>
- <div className='ear left' />
- <div className='ear right' />
- </div>
- </div>
- </div>
- <div className='sc-body' />
- </div>
- )} */}
- <nav className='mx-auto px-4 sm:px-6 lg:px-8' aria-label='Top'>
- <div className='w-full py-4 flex items-center justify-between border-b border-indigo-500 dark:border-gray-300 lg:border-none'>
- <div className='flex items-center'>
- {/* Logo */}
- <Link to={routes.main}>
- <span className='sr-only'>Swetrix</span>
- {/* {themeType === THEME_TYPE.christmas ? (
- <img className='h-10' src='/assets/logo_white_christmas.png' alt='Swetrix' />
- ) : (
- <img className='h-10' src='/assets/logo_white.svg' alt='Swetrix' />
- )} */}
- <img className='h-10' src='/assets/logo_white.svg' alt='Swetrix' />
- </Link>
-
- <div className='hidden ml-10 space-x-1 lg:flex'>
- {!isSelfhosted && authenticated && user?.planCode === 'trial' && (
- <Link
- to={routes.billing}
- className={cx('flex justify-center items-center text-base select-none font-medium py-2 px-2 rounded-md', {
- 'text-amber-800 bg-amber-200 dark:bg-amber-300 hover:bg-amber-300 dark:hover:bg-amber-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_IN_X_DAYS,
- 'text-rose-800 bg-rose-200 dark:bg-rose-300 hover:bg-rose-300 dark:hover:bg-rose-200': rawStatus === TRIAL_STATUS_MAPPING.ENDS_TODAY || rawStatus === TRIAL_STATUS_MAPPING.ENDS_TOMORROW || rawStatus === TRIAL_STATUS_MAPPING.ENDED,
- })}
- key='TrialNotification'
- >
- {status}
- </Link>
- )}
- {authenticated && user?.planCode === 'none' && (
- <Link
- to={routes.billing}
- className='flex justify-center items-center text-base select-none font-medium py-2 px-2 rounded-md text-rose-800 bg-rose-200 dark:bg-rose-300 hover:bg-rose-300 dark:hover:bg-rose-200'
- key='NoSubscription'
- >
- {t('billing.inactive')}
- </Link>
- )}
- <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
- <RssIcon className='w-5 h-5 mr-1' />
- {t('footer.blog')}
- </a>
- {!isSelfhosted && (
- authenticated ? (
- <NavLink to={routes.billing} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Billing'>
- <CreditCardIcon className='w-5 h-5 mr-1' />
- {t('common.billing')}
- </NavLink>
- ) : (
- <>
- <NavLink to={routes.features} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Features'>
- <CircleStackIcon className='w-5 h-5 mr-1' />
- {t('common.features')}
- </NavLink>
- <HashLink to={`${routes.main}#pricing`} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' key='Pricing'>
- <CreditCardIcon className='w-5 h-5 mr-1' />
- {t('common.pricing')}
- </HashLink>
- </>
- )
- )}
- <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
- <DocumentTextIcon className='w-5 h-5 mr-1' />
- {t('common.docs')}
- </a>
- </div>
- </div>
- <div className='hidden md:flex justify-center items-center flex-wrap ml-1 md:ml-10 space-y-1 sm:space-y-0 space-x-2 md:space-x-4'>
- {/* Theme switch */}
- {theme === 'dark' ? (
- <div className='transition-all duration-1000 ease-in-out rotate-180'>
- <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />
- </div>
- ) : (
- <div className='transition-all duration-1000 ease-in-out'>
- <MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />
- </div>
- )}
-
- {/* Language selector */}
- <Dropdown
- items={whitelist}
- buttonClassName='flex items-center w-full rounded-md border border-gray-300 shadow-sm px-3 md:px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-indigo-500 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
- selectItemClassName='text-gray-700 block px-4 py-2 text-base cursor-pointer hover:bg-gray-200 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'
- title={(
- <>
- <Flag className='rounded-sm mr-1.5' country={languageFlag[language]} size={21} alt='' aria-hidden='true' />
- {languages[language]}
- </>
- )}
- labelExtractor={(lng) => (
- <div className='flex'>
- <div className='pt-1'>
- <Flag className='rounded-sm mr-1.5' country={languageFlag[lng]} size={21} alt={languageFlag[lng]} />
- </div>
- {languages[lng]}
- </div>
- )}
- onSelect={onLanguageChange}
- />
- {authenticated ? (
- <>
- {!isSelfhosted && (
- <NavLink to={routes.user_settings} className='text-base select-none font-medium text-white hover:text-indigo-50 py-2 px-3 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700'>
- {t('common.you')}
- </NavLink>
- )}
- <Link to={routes.dashboard} className='inline-block select-none bg-white py-2 px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50 dark:text-gray-50 dark:border-gray-800 dark:bg-gray-700 dark:hover:bg-gray-600'>
- {t('common.dashboard')}
- </Link>
- <Link to='#' className='text-base font-medium select-none text-white hover:text-indigo-50 py-2 px-3 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' onClick={logoutHandler}>
- {t('common.logout')}
- </Link>
- </>
- ) : (
- <>
- <Link to={routes.signin} className='inline-block select-none bg-indigo-500 dark:bg-gray-700 mt-1 sm:mt-0 py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-white hover:bg-opacity-75 hover:dark:bg-gray-600'>
- {t('auth.common.signin')}
- </Link>
- {!isSelfhosted && (
- <Link to={routes.signup} className='inline-block select-none bg-white dark:bg-gray-700 dark:text-gray-50 py-2 px-3 md:px-4 border border-transparent rounded-md text-base font-medium text-indigo-600 hover:bg-indigo-50 hover:dark:bg-gray-600' aria-label={t('titles.signup')}>
- {t('common.getStarted')}
- </Link>
- )}
- </>
- )}
- </div>
- <div className='md:hidden flex justify-center items-center'>
- {/* Theme switch */}
- {theme === 'dark' ? (
- <div className='transition-all duration-1000 ease-in-out rotate-180'>
- <SunIcon onClick={switchTheme} className='h-10 w-10 text-gray-200 hover:text-gray-300 cursor-pointer' />
- </div>
- ) : (
- <div className='transition-all duration-1000 ease-in-out'>
- <MoonIcon onClick={switchTheme} className='h-10 w-10 text-indigo-100 hover:text-indigo-200 cursor-pointer' />
- </div>
- )}
- <Popover.Button className='bg-white dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200 rounded-md p-2 ml-3 inline-flex items-center justify-center text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-indigo-500'>
- <span className='sr-only'>
- {t('common.openMenu')}
- </span>
- <Bars3Icon className='h-6 w-6' aria-hidden='true' />
- </Popover.Button>
- </div>
- </div>
- <div className='py-4 flex flex-wrap justify-center space-x-2 lg:hidden'>
- <a href={BLOG_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
- <RssIcon className='w-5 h-5 mr-1' />
- {t('footer.blog')}
- </a>
- {authenticated ? (
- <NavLink to={routes.billing} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Billing'>
- <CreditCardIcon className='w-5 h-5 mr-1' />
- {t('common.billing')}
- </NavLink>
- ) : (
- <>
- <HashLink to={`${routes.main}#pricing`} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' key='Pricing'>
- <CreditCardIcon className='w-5 h-5 mr-1' />
- {t('common.pricing')}
- </HashLink>
- <NavLink to={routes.features} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' activeClassName='bg-indigo-700 hover:bg-indigo-700 dark:bg-gray-700' key='Features'>
- <CircleStackIcon className='w-5 h-5 mr-1' />
- {t('common.features')}
- </NavLink>
- </>
- )}
- <a href={DOCS_URL} className='flex justify-center items-center text-base select-none font-medium text-white hover:text-indigo-50 py-1 px-2 dark:hover:bg-gray-700 hover:bg-indigo-500 rounded-md' target='_blank' rel='noreferrer noopener'>
- <DocumentTextIcon className='w-5 h-5 mr-1' />
- {t('common.docs')}
- </a>
- </div>
- </nav>
- </header>
+ {authenticated ? (
+ <AuthedHeader
+ user={user}
+ rawStatus={rawStatus}
+ status={status}
+ logoutHandler={logoutHandler}
+ switchTheme={switchTheme}
+ theme={theme}
+ onLanguageChange={onLanguageChange}
+ language={language}
+ t={t}
+ />
+ ) : (
+ <NotAuthedHeader
+ switchTheme={switchTheme}
+ theme={theme}
+ onLanguageChange={onLanguageChange}
+ language={language}
+ t={t}
+ />
+ )}
{/* Mobile header popup */}
<Transition
@@ -374,7 +646,7 @@ const Header = ({
)}
<div onClick={() => buttonRef.current?.click()}>
<Link to={routes.user_settings} className='w-full flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-base font-medium text-white bg-indigo-600 hover:bg-indigo-700'>
- {t('common.you')}
+ {t('common.accountSettings')}
</Link>
</div>
<div onClick={() => buttonRef.current?.click()}>