The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Implement UI for project notifications
Joshen Lim4aa364bd4b64
diff --git a/studio/components/layouts/AccountLayout/WithSidebar.tsx b/studio/components/layouts/AccountLayout/WithSidebar.tsxindex 2a911d77eb8..9447956257f 100644--- a/studio/components/layouts/AccountLayout/WithSidebar.tsx+++ b/studio/components/layouts/AccountLayout/WithSidebar.tsx@@ -38,14 +38,14 @@ const WithSidebar: FC<Props> = ({<divid="with-sidebar"className="- w-64 h-screen overflow-auto bg-sidebar-linkbar-light dark:bg-sidebar-linkbar-dark hide-scrollbar- border-r dark:border-dark+ bg-sidebar-linkbar-light dark:bg-sidebar-linkbar-dark hide-scrollbar dark:border-dark h-screen w-64+ overflow-auto border-r"style={sidebarStyle}>{title && (<div className="mb-2">- <div className="max-h-12 h-12 flex items-center border-b dark:border-dark px-6">+ <div className="dark:border-dark flex h-12 max-h-12 items-center border-b px-6"><Typography.Title level={4} className="mb-0">{title}</Typography.Title>@@ -74,9 +74,9 @@ const WithSidebar: FC<Props> = ({</div></div>)}- <div className="flex-1 flex flex-col h-screen">+ <div className="flex h-screen flex-1 flex-col"><LayoutHeader breadcrumbs={breadcrumbs} />- <div className="flex-grow flex-1 overflow-auto">{children}</div>+ <div className="flex-1 flex-grow overflow-auto">{children}</div></div></div>)@@ -85,10 +85,10 @@ export default WithSidebarconst LinksWithHeaders: FC<any> = ({ links, subitems, subitemsParentKey }) => {return links.map((x: any) => (- <div key={x.heading} className="py-5 border-b dark:border-dark px-6">+ <div key={x.heading} className="dark:border-dark border-b py-5 px-6"><Menu.Group title={x.heading} />{x.versionLabel && (- <div className="px-3 mb-1">+ <div className="mb-1 px-3"><Badge color="yellow">{x.versionLabel}</Badge></div>)}@@ -156,7 +156,7 @@ const SidebarItem: FC<any> = ({ id, label, href, isActive, isSubitem, onClick, eonClick={onClick || (() => {})}icon={external && <IconArrowUpRight size={'tiny'} />}>- {isSubitem ? <Typography.Text small>{label}</Typography.Text> : label}+ {isSubitem ? <p className="text-sm">{label}</p> : label}</Menu.Item>)}@@ -165,15 +165,18 @@ const SidebarItem: FC<any> = ({ id, label, href, isActive, isSubitem, onClick, e<Link href={href || ''}><a className="block" target={external ? '_blank' : '_self'}><button- className="cursor-pointer flex space-x-2 items-center outline-none focus-visible:ring-1 ring-scale-1200 focus-visible:z-10 group py-1 font-normal border-scale-500 group-hover:border-scale-900"+ className="ring-scale-1200 border-scale-500 group-hover:border-scale-900 group flex max-w-full cursor-pointer items-center space-x-2 py-1 font-normal outline-none focus-visible:z-10 focus-visible:ring-1"onClick={onClick || (() => {})}>{external && (- <span className="transition truncate text-sm text-scale-900 group-hover:text-scale-1100">+ <span className="text-scale-900 group-hover:text-scale-1100 truncate text-sm transition"><IconArrowUpRight size={'tiny'} /></span>)}- <span className="transition truncate text-sm w-full text-scale-1100 group-hover:text-scale-1200">+ <span+ title={label}+ className="text-scale-1100 group-hover:text-scale-1200 w-full truncate text-sm transition"+ >{isSubitem ? <p>{label}</p> : label}</span></button>diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/BreadcrumbsView.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/BreadcrumbsView.tsxindex 395dd1d379a..b51b4a12a1a 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/BreadcrumbsView.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/BreadcrumbsView.tsx@@ -1,6 +1,5 @@import { FC, Fragment } from 'react'import { observer } from 'mobx-react-lite'-import { Typography, IconChevronRight } from '@supabase/ui'interface Props {defaultValue: any@@ -27,16 +26,15 @@ const BreadcrumbsView: FC<Props> = ({ defaultValue: breadcrumbs }) => {<path d="M16 3.549L7.12 20.600"></path></svg></span>- <Typography.Text>- <a- onClick={breadcrumb.onClick || (() => {})}- className={`block px-2 py-1 text-xs leading-5 text-gray-1100 focus:outline-none focus:bg-gray-100 focus:text-gray-900 ${- breadcrumb.onClick ? 'cursor-pointer hover:text-white' : ''- }`}- >- {breadcrumb.label}- </a>- </Typography.Text>++ <a+ onClick={breadcrumb.onClick || (() => {})}+ className={`text-gray-1100 block px-2 py-1 text-xs leading-5 focus:bg-gray-100 focus:text-gray-900 focus:outline-none ${+ breadcrumb.onClick ? 'cursor-pointer hover:text-white' : ''+ }`}+ >+ {breadcrumb.label}+ </a></Fragment>)): null}diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsxindex a96efd9c9f8..68db0e1ca2a 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx@@ -8,6 +8,7 @@ import OrgDropdown from './OrgDropdown'import ProjectDropdown from './ProjectDropdown'import FeedbackDropdown from './FeedbackDropdown'import HelpPopover from './HelpPopover'+import NotificationsPopover from './NotificationsPopover'const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder = true }: any) => {const { ui } = useStore()@@ -15,13 +16,11 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =return (<div- className={`py-2 px-5 max-h-12 h-12 flex justify-between items-center ${- headerBorder ? 'border-b dark:border-dark' : ''+ className={`flex h-12 max-h-12 items-center justify-between py-2 px-5 ${+ headerBorder ? 'dark:border-dark border-b' : ''}`}>- {/* <div className="PageHeader"> */}- {/* <div className="flex justify-between"> */}- <div className="text-sm flex items-center -ml-2">+ <div className="-ml-2 flex items-center text-sm">{/* Organization is selected */}{selectedOrganization ? (<>@@ -54,7 +53,7 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder =) : (<Link href="/"><a- className={`text-xs text-scale-1200 px-2 py-1 focus:outline-none focus:bg-transparent cursor-pointer`}+ className={`text-scale-1200 cursor-pointer px-2 py-1 text-xs focus:bg-transparent focus:outline-none`}>Supabase</a>@@ -63,10 +62,13 @@ const LayoutHeader = ({ customHeaderComponents, breadcrumbs = [], headerBorder ={/* Additional breadcrumbs are supplied */}<BreadcrumbsView defaultValue={breadcrumbs} /></div>- <div className="flex space-x-2">+ <div className="flex items-center space-x-6">{customHeaderComponents && customHeaderComponents}- {IS_PLATFORM && <HelpPopover />}- {IS_PLATFORM && <FeedbackDropdown />}+ <div className="flex items-center space-x-2">+ {IS_PLATFORM && <HelpPopover />}+ {IS_PLATFORM && <FeedbackDropdown />}+ </div>+ {IS_PLATFORM && <NotificationsPopover />}</div></div>// </div>diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsxnew file mode 100644index 00000000000..711a8c037ef--- /dev/null+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsx@@ -0,0 +1,58 @@+import dayjs from 'dayjs'+import { FC, Fragment } from 'react'+import { Button, IconBell, Popover } from '@supabase/ui'+import { NotificationStatus } from '@supabase/shared-types/out/notifications'++import { useNotifications } from 'hooks'++interface Props {}++const NotificationsPopover: FC<Props> = () => {+ const { notifications } = useNotifications()++ const hasNewNotifications =+ notifications !== undefined &&+ notifications.some(+ (notification) => notification.notification_status === NotificationStatus.New+ )+ console.log('Notifications', notifications)++ return (+ <Popover+ size="content"+ align="end"+ side="bottom"+ sideOffset={8}+ overlay={+ <div className="my-4 w-96 space-y-4">+ {notifications?.map((notification, i: number) => {+ const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')+ return (+ <Fragment key={notification.id}>+ <div className="px-4">+ <p className="text-scale-1000 text-sm">{insertedAt}</p>+ </div>+ {i !== notifications.length - 1 && <Popover.Seperator />}+ </Fragment>+ )+ })}+ </div>+ }+ onOpenChange={(open) => console.log('onOpenChange', open)}+ >+ <div className="relative">+ <Button+ as="span"+ type={hasNewNotifications ? 'default' : 'text'}+ icon={<IconBell size={16} strokeWidth={1.5} className="text-scale-1200" />}+ />+ <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>+ </Popover>+ )+}++export default NotificationsPopoverdiff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsxindex 4afadd4974d..9d80016aedc 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/ProjectDropdown.tsx@@ -40,7 +40,7 @@ const ProjectDropdown = () => {</>}>- <Button as="span" type="text" size="tiny">+ <Button as="span" type="text" size="tiny" className="my-1">{selectedProject.name}</Button></Dropdown>diff --git a/studio/hooks/index.ts b/studio/hooks/index.tsindex 09c15d6f80c..87e81884c1f 100644--- a/studio/hooks/index.ts+++ b/studio/hooks/index.ts@@ -1,5 +1,6 @@export * from './misc/useStore'export * from './misc/withAuth'+export * from './misc/useNotifications'export * from './deprecated'export * from './queries'export * from './ui'diff --git a/studio/hooks/misc/useNotifications.tsx b/studio/hooks/misc/useNotifications.tsxnew file mode 100644index 00000000000..5f29973c6b6--- /dev/null+++ b/studio/hooks/misc/useNotifications.tsx@@ -0,0 +1,29 @@+import { NotificationName, NotificationStatus } from '@supabase/shared-types/out/notifications'+import { get } from 'lib/common/fetch'+import { API_URL } from 'lib/constants'+import useSWR from 'swr'++export interface Notification {+ id: string+ project_id: number+ inserted_at: number+ notification_name: NotificationName+ notification_status: NotificationStatus+ // Contains information on the particular notification+ data: object+ // Contains e.g possible actions user should act on based on the notification+ meta: object+}++export const useNotifications = () => {+ const { data, error, mutate } = useSWR<Notification[]>(`${API_URL}/notifications`, get)+ const anyError = error !== undefined+ const refresh = () => mutate()++ return {+ notifications: anyError ? undefined : data,+ isLoading: !anyError && !data,+ isError: !!anyError,+ refresh,+ }+}