Skip to content

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

Initial implementation for each notification message for each type of notification

Joshen Lim6f0ba9446764
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsx
deleted file mode 100644
index 711a8c037ef..00000000000
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover.tsx
+++ /dev/null
@@ -1,58 +0,0 @@
-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 NotificationsPopover
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/Notifications.types.ts b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/Notifications.types.ts
new file mode 100644
index 00000000000..d5d35fa1582
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/Notifications.types.ts
@@ -0,0 +1,30 @@
+// These should go into shared-types repo i think, but chucking it here for now
+// For discussion on Monday
+
+export interface TierLimitExceededNotification {
+ dimension: string // probably an enum
+ tier_limit: number
+ maximum_recent_value: number
+ // When values are updated, instead of creating a new notification
+ last_updated_at: string
+ first_violated_at: string
+}
+
+export interface PostgreslInformationalNotification {
+ type: string // probably an enum
+ new_version: string // This is assuming that all notifications are about version updates
+ extension_name: string
+}
+
+export interface PostgresqlBugfixNotification {}
+
+export interface NotificationMeta {
+ restart_required: boolean
+ services_to_restart: string[] // I don't think we need this
+}
+
+/**
+ * Other questions:
+ * - how many notifications to fetch at once?
+ * - how to mark as seen from UI
+ */
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsx
new file mode 100644
index 00000000000..69ec1b77c2d
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlBugfixNotification.tsx
@@ -0,0 +1,45 @@
+import dayjs from 'dayjs'
+import { FC } from 'react'
+import {
+ Button,
+ Dropdown,
+ IconCheck,
+ IconXSquare,
+ IconRefreshCw,
+ IconMoreVertical,
+} from '@supabase/ui'
+import { Notification } from '@supabase/shared-types/out/notifications'
+
+interface Props {
+ notification: Notification
+}
+
+const PostgresqlBugfixNotification: FC<Props> = ({ notification }) => {
+ const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')
+
+ return (
+ <div className="flex items-center justify-between space-x-4">
+ <div className="space-y-1">
+ <p className="text-sm">
+ A fix for {'{extension}'} is now available! Restart your project for changes to take
+ place.
+ </p>
+ <p className="text-scale-1000 text-sm">{insertedAt}</p>
+ </div>
+ <Dropdown
+ side="bottom"
+ align="end"
+ size="small"
+ overlay={[
+ <Dropdown.Item icon={<IconCheck size={14} />}>Mark as read</Dropdown.Item>,
+ <Dropdown.Item icon={<IconXSquare size={14} />}>Dismiss notification</Dropdown.Item>,
+ <Dropdown.Item icon={<IconRefreshCw size={14} />}>Restart project now</Dropdown.Item>,
+ ]}
+ >
+ <Button size="tiny" type="text" icon={<IconMoreVertical />} />
+ </Dropdown>
+ </div>
+ )
+}
+
+export default PostgresqlBugfixNotification
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsx
new file mode 100644
index 00000000000..7e53dd4048c
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/PostgresqlInfoNotification.tsx
@@ -0,0 +1,48 @@
+import dayjs from 'dayjs'
+import { FC } from 'react'
+import {
+ Button,
+ Dropdown,
+ IconCheck,
+ IconMoreVertical,
+ IconRefreshCw,
+ IconXSquare,
+} from '@supabase/ui'
+import { Notification } from '@supabase/shared-types/out/notifications'
+import { PostgreslInformationalNotification } from './Notifications.types'
+
+interface Props {
+ notification: Notification
+}
+
+const PostgresqlInfoNotification: FC<Props> = ({ notification }) => {
+ const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')
+ const { new_version, extension_name } = notification.data as PostgreslInformationalNotification
+
+ return (
+ <div className="flex items-center justify-between space-x-4">
+ <div className="space-y-1">
+ <p className="text-sm">
+ A new version ({new_version}) for {extension_name} is now available!{' '}
+ <span className="text-brand-900 cursor-pointer">Restart</span> your project for changes to
+ take place.
+ </p>
+ <p className="text-scale-1000 text-sm">{insertedAt}</p>
+ </div>
+ <Dropdown
+ side="bottom"
+ align="end"
+ size="small"
+ overlay={[
+ <Dropdown.Item icon={<IconCheck size={14} />}>Mark as read</Dropdown.Item>,
+ <Dropdown.Item icon={<IconXSquare size={14} />}>Dismiss notification</Dropdown.Item>,
+ <Dropdown.Item icon={<IconRefreshCw size={14} />}>Restart project now</Dropdown.Item>,
+ ]}
+ >
+ <Button size="tiny" type="text" icon={<IconMoreVertical />} />
+ </Dropdown>
+ </div>
+ )
+}
+
+export default PostgresqlInfoNotification
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsx
new file mode 100644
index 00000000000..39e7c5566d9
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/TierLimitExceededNotification.tsx
@@ -0,0 +1,59 @@
+import dayjs from 'dayjs'
+import { FC } from 'react'
+import {
+ Button,
+ Dropdown,
+ IconCheck,
+ IconMoreVertical,
+ IconRefreshCw,
+ IconXSquare,
+} from '@supabase/ui'
+import { Notification } from '@supabase/shared-types/out/notifications'
+
+import { useStore } from 'hooks'
+import { Project } from 'types'
+
+interface Props {
+ notification: Notification
+}
+
+const DIMENSION: any = {
+ db_storage: 'storage',
+}
+
+const TierLimitExceededNotification: FC<Props> = ({ notification }) => {
+ const { app } = useStore()
+ const [project] = app.projects.list((project: Project) => project.id === notification.project_id)
+
+ const { dimension, first_violated_at } = notification.data
+ const projectName = project?.name ?? 'Unknown'
+ const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')
+ const firstViolatedAt = dayjs(first_violated_at).format('DD MMM YYYY')
+
+ return (
+ <div className="flex items-center justify-between space-x-4">
+ <div className="space-y-1">
+ <p className="text-sm">
+ Your project {projectName} has exceeded it's {DIMENSION[dimension]} limit since{' '}
+ {firstViolatedAt}. <span className="text-brand-900 cursor-pointer">Upgrade</span> your
+ project to ensure its continued availability.
+ </p>
+ <p className="text-scale-1000 text-sm">{insertedAt}</p>
+ </div>
+ <Dropdown
+ side="bottom"
+ align="end"
+ size="small"
+ overlay={[
+ <Dropdown.Item icon={<IconCheck size={14} />}>Mark as read</Dropdown.Item>,
+ <Dropdown.Item icon={<IconXSquare size={14} />}>Dismiss notification</Dropdown.Item>,
+ <Dropdown.Item icon={<IconRefreshCw size={14} />}>Restart project now</Dropdown.Item>,
+ ]}
+ >
+ <Button size="tiny" type="text" icon={<IconMoreVertical />} />
+ </Dropdown>
+ </div>
+ )
+}
+
+export default TierLimitExceededNotification
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
new file mode 100644
index 00000000000..977c5145536
--- /dev/null
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
@@ -0,0 +1,77 @@
+import { FC, Fragment } from 'react'
+import { Button, IconBell, Popover } from '@supabase/ui'
+import {
+ Notification,
+ NotificationName,
+ NotificationStatus,
+} from '@supabase/shared-types/out/notifications'
+
+import { useNotifications } from 'hooks'
+import TierLimitExceededNotification from './TierLimitExceededNotification'
+import PostgresqlInfoNotification from './PostgresqlInfoNotification'
+import PostgresqlBugfixNotification from './PostgresqlBugfixNotification'
+
+interface Props {}
+
+const NotificationsPopover: FC<Props> = () => {
+ const { notifications } = useNotifications()
+
+ const hasNewNotifications =
+ notifications !== undefined &&
+ notifications.some(
+ (notification) => notification.notification_status === NotificationStatus.New
+ )
+
+ const renderNotification = (notification: Notification) => {
+ switch (notification.notification_name) {
+ case NotificationName.ProjectExceedingTierLimit:
+ return <TierLimitExceededNotification key={notification.id} notification={notification} />
+ case NotificationName.PostgresqlInformational:
+ return <PostgresqlInfoNotification key={notification.id} notification={notification} />
+ case NotificationName.PostgresqlBugfix:
+ return <PostgresqlBugfixNotification key={notification.id} notification={notification} />
+ default:
+ return <div key={notification.id}>Unknown</div>
+ }
+ }
+
+ return (
+ <Popover
+ size="content"
+ align="end"
+ side="bottom"
+ sideOffset={8}
+ overlay={
+ <div className="my-2 w-[500px]">
+ {notifications?.map((notification, i: number) => (
+ <>
+ <div className="grid grid-cols-12 py-2">
+ <div className="col-span-1 flex items-center justify-center">
+ {notification.notification_status !== NotificationStatus.Seen && (
+ <div className="h-2 w-2 rounded-full bg-green-900" />
+ )}
+ </div>
+ <div className="col-span-11 mr-5">{renderNotification(notification)}</div>
+ </div>
+ {i !== notifications.length - 1 && <Popover.Seperator />}
+ </>
+ ))}
+ </div>
+ }
+ >
+ <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 NotificationsPopover
diff --git a/studio/hooks/misc/useNotifications.tsx b/studio/hooks/misc/useNotifications.tsx
index 5f29973c6b6..f0e817306c3 100644
--- a/studio/hooks/misc/useNotifications.tsx
+++ b/studio/hooks/misc/useNotifications.tsx
@@ -1,19 +1,8 @@
-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'
+import { Notification } from '@supabase/shared-types/out/notifications'
-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
-}
+import { get } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
export const useNotifications = () => {
const { data, error, mutate } = useSWR<Notification[]>(`${API_URL}/notifications`, get)