Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add help, notifications, feedback widgets to new nav bar, scaffold user settings dropdown

Joshen Lim5d1b88d4dc6f
diff --git a/studio/components/layouts/AccountLayout/AccountLayout.tsx b/studio/components/layouts/AccountLayout/AccountLayout.tsx
index f4b7599e8a6..3abeb892928 100644
--- a/studio/components/layouts/AccountLayout/AccountLayout.tsx
+++ b/studio/components/layouts/AccountLayout/AccountLayout.tsx
@@ -28,7 +28,6 @@ const AccountLayout = ({ children, title, breadcrumbs }: PropsWithChildren<Accou
const signOut = useSignOut()
const onClickLogout = async () => {
await signOut()
-
await router.push('/sign-in')
}
diff --git a/studio/components/layouts/AppLayout/HeaderBar.tsx b/studio/components/layouts/AppLayout/HeaderBar.tsx
index 543159b4785..2e2dfa5dad6 100644
--- a/studio/components/layouts/AppLayout/HeaderBar.tsx
+++ b/studio/components/layouts/AppLayout/HeaderBar.tsx
@@ -1,19 +1,18 @@
import Link from 'next/link'
import { useRouter } from 'next/router'
import FeedbackDropdown from '../ProjectLayout/LayoutHeader/FeedbackDropdown'
-import { Button, Dropdown, IconHelpCircle, IconInbox } from 'ui'
-import { useProfile } from 'lib/profile'
+import HelpPopover from '../ProjectLayout/LayoutHeader/HelpPopover'
+import NotificationsPopover from '../ProjectLayout/LayoutHeader/NotificationsPopover'
import OrganizationDropdown from './OrganizationDropdown'
+import UserSettingsDropdown from './UserSettingsDropdown'
const HeaderBar = () => {
const router = useRouter()
- const { profile } = useProfile()
return (
<div className="flex items-center justify-between px-4 py-2 bg-scale-100 shadow-md">
- {/* Organization + Project */}
<div className="flex items-center space-x-4">
- <Link href="/projects-v2">
+ <Link href="/">
<a className="block">
<img
src={`${router.basePath}/img/supabase-logo.svg`}
@@ -25,20 +24,11 @@ const HeaderBar = () => {
<OrganizationDropdown />
</div>
- {/* Account, Settings, etc */}
<div className="flex items-center space-x-4">
<FeedbackDropdown />
- <Button type="text" className="px-1" icon={<IconInbox size={18} />} />
- <Button type="text" className="px-1" icon={<IconHelpCircle size={18} />} />
- <Dropdown
- align="end"
- side="bottom"
- overlay={[<Dropdown.Item key="test">Hello</Dropdown.Item>]}
- >
- <div className="flex items-center justify-center border rounded-full h-7 w-7 text-scale-1100">
- {profile?.first_name[0]}
- </div>
- </Dropdown>
+ <NotificationsPopover alt />
+ <HelpPopover alt />
+ <UserSettingsDropdown />
</div>
</div>
)
diff --git a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx b/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
index b5e5a9426df..3149b62b941 100644
--- a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
+++ b/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
@@ -1,9 +1,10 @@
import { useRouter } from 'next/router'
-import { Button, Dropdown, IconChevronDown, IconChevronsDown, IconPlus } from 'ui'
+import { Button, Dropdown, IconChevronDown, IconChevronsDown, IconCode, IconPlus } from 'ui'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useFlag, useSelectedOrganization, useStore } from 'hooks'
import { IS_PLATFORM } from 'lib/constants'
+import Link from 'next/link'
const OrganizationDropdown = () => {
const router = useRouter()
@@ -21,50 +22,35 @@ const OrganizationDropdown = () => {
{organizations
?.sort((a, b) => a.name.localeCompare(b.name))
.map((x) => {
- const slug = x.slug
-
+ // [Joshen] Improvement: maintain URL if navigating in between org pages
return (
- <Dropdown.Item
- key={slug}
- onClick={() => {
- if (!slug) {
- // The user should not see this error as the page should
- // be rerendered with the value of slug before they can click.
- // It is just here in case they are the flash.
- return ui.setNotification({
- category: 'error',
- message:
- 'Could not navigate to organization settings, please try again or contact support',
- })
- }
-
- router.push({
- pathname: `/org/[slug]/general`,
- query: { slug },
- hash: router.asPath.split('#')[1]?.toLowerCase(),
- })
- }}
- >
- {x.name}
- </Dropdown.Item>
+ <Link key={x.slug} href={`/org/${x.slug}`}>
+ <a>
+ <Dropdown.Item>{x.name}</Dropdown.Item>
+ </a>
+ </Link>
)
})}
<Dropdown.Separator />
- <Dropdown.Item icon={<IconPlus size="tiny" />} onClick={() => router.push(`/new`)}>
- New organization
- </Dropdown.Item>
+ <Link href="/new">
+ <a>
+ <Dropdown.Item icon={<IconPlus size="tiny" />}>New organization</Dropdown.Item>
+ </a>
+ </Link>
{orgCreationV2 && (
- <Dropdown.Item
- icon={<IconPlus size="tiny" />}
- onClick={() => router.push(`/new-with-subscription`)}
- >
- New organization V2
- </Dropdown.Item>
+ <Link href="/new-with-subscription">
+ <a>
+ <Dropdown.Item icon={<IconPlus size="tiny" />}>New organization V2</Dropdown.Item>
+ </a>
+ </Link>
)}
</>
}
>
- <Button type="text" iconRight={<IconChevronDown />}>
+ <Button
+ type="text"
+ iconRight={<IconCode className="text-scale-1100 rotate-90" strokeWidth={2} size={12} />}
+ >
<span className="text-sm">{selectedOrganization?.name}</span>
</Button>
</Dropdown>
diff --git a/studio/components/layouts/AppLayout/UserSettingsDropdown.tsx b/studio/components/layouts/AppLayout/UserSettingsDropdown.tsx
new file mode 100644
index 00000000000..6f62bd4f28f
--- /dev/null
+++ b/studio/components/layouts/AppLayout/UserSettingsDropdown.tsx
@@ -0,0 +1,50 @@
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import { Dropdown, IconLogOut } from 'ui'
+
+import { useSignOut } from 'lib/auth'
+import { useProfile } from 'lib/profile'
+
+const UserSettingsDropdown = () => {
+ const signOut = useSignOut()
+ const router = useRouter()
+ const { profile } = useProfile()
+
+ const onClickLogout = async () => {
+ await signOut()
+ await router.push('/sign-in')
+ }
+
+ return (
+ <Dropdown
+ align="end"
+ side="bottom"
+ overlay={[
+ <Link key="preferences" href="/">
+ <a>
+ <Dropdown.Item>Preferences</Dropdown.Item>
+ </a>
+ </Link>,
+ <Link key="access-tokens" href="/">
+ <a>
+ <Dropdown.Item>Access tokens</Dropdown.Item>
+ </a>
+ </Link>,
+ <Dropdown.Separator key="sep-1" />,
+ <Dropdown.Item
+ key="log out"
+ icon={<IconLogOut size={14} strokeWidth={1.5} />}
+ onClick={() => onClickLogout()}
+ >
+ Logout
+ </Dropdown.Item>,
+ ]}
+ >
+ <div className="flex items-center justify-center border rounded-full h-7 w-7 text-scale-1100">
+ {profile?.first_name[0]}
+ </div>
+ </Dropdown>
+ )
+}
+
+export default UserSettingsDropdown
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
index 6b6add879bd..770b8d65722 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
@@ -1,22 +1,23 @@
+import Image from 'next/image'
+import Link from 'next/link'
+import { useRouter } from 'next/router'
+import SVG from 'react-inlinesvg'
import {
Button,
+ IconActivity,
+ IconBookOpen,
IconHelpCircle,
IconMail,
IconMessageCircle,
Popover,
- IconBookOpen,
- IconActivity,
} from 'ui'
-import { useRouter } from 'next/router'
-import { FC } from 'react'
-import Link from 'next/link'
-import Image from 'next/image'
-
-import SVG from 'react-inlinesvg'
+import * as Tooltip from '@radix-ui/react-tooltip'
-interface Props {}
+interface HelpPopoverProps {
+ alt?: boolean
+}
-const HelpPopover: FC<Props> = () => {
+const HelpPopover = ({ alt = false }: HelpPopoverProps) => {
const router = useRouter()
const projectRef = router.query.ref
const supportUrl = `/support/new${projectRef ? `?ref=${projectRef}` : ''}`
@@ -127,13 +128,39 @@ const HelpPopover: FC<Props> = () => {
</div>
}
>
- <Button
- asChild
- type="default"
- icon={<IconHelpCircle size={16} strokeWidth={1.5} className="text-scale-900" />}
- >
- <span>Help</span>
- </Button>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger asChild>
+ <Button
+ asChild={alt ? false : true}
+ type={alt ? 'text' : 'default'}
+ className={alt ? 'px-1' : ''}
+ icon={
+ <IconHelpCircle
+ size={alt ? 18 : 16}
+ strokeWidth={1.5}
+ className={alt ? 'text-scale-1100' : 'text-scale-900'}
+ />
+ }
+ >
+ {!alt && <span>Help</span>}
+ </Button>
+ </Tooltip.Trigger>
+ {alt && (
+ <Tooltip.Portal>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
+ 'space-y-2 border border-scale-200',
+ ].join(' ')}
+ >
+ <p className="text-xs text-scale-1200">Help</p>
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Portal>
+ )}
+ </Tooltip.Root>
</Popover>
)
}
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
index 1ff8530f549..f4e3db7e003 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
@@ -12,15 +12,19 @@ import { Fragment, useState } from 'react'
import ConfirmModal from 'components/ui/Dialogs/ConfirmDialog'
import { useNotificationsQuery } from 'data/notifications/notifications-query'
import { getProjectDetail } from 'data/projects/project-detail-query'
-import { invalidateProjectsQuery, setProjectPostgrestStatus } from 'data/projects/projects-query'
+import { setProjectPostgrestStatus } from 'data/projects/projects-query'
import { useStore } from 'hooks'
import { delete_, patch, post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { Project } from 'types'
-import { Alert, Button, IconArrowRight, IconBell, Popover } from 'ui'
+import { Alert, Button, IconArrowRight, IconBell, IconInbox, Popover } from 'ui'
import NotificationRow from './NotificationRow'
-const NotificationsPopover = () => {
+interface NotificationsPopoverProps {
+ alt?: boolean
+}
+
+const NotificationsPopover = ({ alt = false }: NotificationsPopoverProps) => {
const queryClient = useQueryClient()
const router = useRouter()
const { meta, ui } = useStore()
@@ -35,9 +39,10 @@ const NotificationsPopover = () => {
if (!notifications) return <></>
- const hasNewNotifications = notifications?.some(
+ const newNotifications = notifications?.filter(
(notification) => notification.notification_status === NotificationStatus.New
)
+ const hasNewNotifications = newNotifications.length > 0
const onOpenChange = async (open: boolean) => {
// TODO(alaister): move this to a mutation
@@ -232,21 +237,51 @@ const NotificationsPopover = () => {
>
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger asChild>
- <div className="relative flex">
+ <div className="relative flex items-center">
+ {/* hasNewNotifications */}
+ {true && (
+ <>
+ {alt ? null : (
+ // <div className="translate-x-[10px] z-10 h-4 w-4 flex items-center justify-center rounded-full bg-white">
+ // <p className="text-xs text-scale-100">5</p>
+ // </div>
+ <div className="absolute -top-1 -right-1 z-50 flex h-3 w-3 items-center justify-center">
+ <div className="h-full w-full animate-ping rounded-full bg-green-800 opacity-60"></div>
+ <div className="z-60 absolute top-0 right-0 h-full w-full rounded-full bg-green-900 opacity-80"></div>
+ </div>
+ )}
+ </>
+ )}
<Button
asChild
id="notification-button"
- type="default"
- icon={<IconBell size={16} strokeWidth={1.5} className="text-scale-1200" />}
+ type={alt ? 'text' : 'default'}
+ className={alt ? 'px-1' : ''}
+ icon={
+ hasNewNotifications ? (
+ <div className="-mr-3.5 z-10 h-4 w-4 flex items-center justify-center rounded-full bg-white">
+ <p className="text-xs text-scale-100">{newNotifications.length}</p>
+ </div>
+ ) : alt ? (
+ <IconInbox size={18} strokeWidth={1.5} className="text-scale-1100" />
+ ) : (
+ <IconBell size={16} strokeWidth={1.5} className="text-scale-1200" />
+ )
+ }
+ iconRight={
+ hasNewNotifications ? (
+ <>
+ {alt ? (
+ <IconInbox size={18} strokeWidth={1.5} className="text-scale-1100" />
+ ) : (
+ <IconBell size={16} strokeWidth={1.5} className="text-scale-1200" />
+ )}
+ </>
+ ) : null
+ }
>
<span></span>
</Button>
- {hasNewNotifications && (
- <div className="absolute -top-1 -right-1 z-50 flex h-3 w-3 items-center justify-center">
- <div className="h-full w-full animate-ping rounded-full bg-green-800 opacity-60"></div>
- <div className="z-60 absolute top-0 right-0 h-full w-full rounded-full bg-green-900 opacity-80"></div>
- </div>
- )}
</div>
</Tooltip.Trigger>
<Tooltip.Portal>