Skip to content

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

Add loading state when dismissing notification

Joshen Lime0f1dc162c4d
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
index e2b50d032ee..23098c93c41 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx
@@ -1,20 +1,19 @@
import dayjs from 'dayjs'
import useSWR from 'swr'
-import { FC } from 'react'
+import { FC, useState } from 'react'
import * as Tooltip from '@radix-ui/react-tooltip'
import { Notification, NotificationStatus } from '@supabase/shared-types/out/notifications'
-import { useStore } from 'hooks'
+import { useStore, useNotifications } from 'hooks'
import { Project } from 'types'
import { formatNotificationCTAText, formatNotificationText } from './NotificationRows.utils'
import NotificationActions from './NotificationActions'
-import { get } from 'lib/common/fetch'
+import { get, delete_ } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { Button, IconX } from 'ui'
interface Props {
notification: Notification
- onSelectDismissNotification: (notificationId: string) => void
onSelectRestartProject: (project: Project, notification: Notification) => void
onSelectApplyMigration: (project: Project, notification: Notification) => void
onSelectRollbackMigration: (project: Project, notification: Notification) => void
@@ -23,13 +22,14 @@ interface Props {
const NotificationRow: FC<Props> = ({
notification,
- onSelectDismissNotification,
onSelectRestartProject,
onSelectApplyMigration,
onSelectRollbackMigration,
onSelectFinalizeMigration,
}) => {
- const { app } = useStore()
+ const { app, ui } = useStore()
+ const { refresh } = useNotifications()
+ const [dismissing, setDismissing] = useState(false)
const [project] = app.projects.list((project: Project) => project.id === notification.project_id)
const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma')
@@ -46,6 +46,23 @@ const NotificationRow: FC<Props> = ({
get
)
+ const dismissNotification = async (notificationId: string) => {
+ if (!notificationId) return
+ setDismissing(true)
+ const { error } = await delete_(`${API_URL}/notifications`, { ids: [notificationId] })
+ if (error) {
+ ui.setNotification({
+ category: 'error',
+ message: 'Failed to dismiss notification',
+ error,
+ duration: 4000,
+ })
+ } else {
+ refresh()
+ }
+ setDismissing(false)
+ }
+
return (
<div className="flex py-2">
<div className="flex min-w-[50px] justify-center">
@@ -67,6 +84,7 @@ const NotificationRow: FC<Props> = ({
<Button
className="!px-1 group"
type="text"
+ loading={dismissing}
icon={
<IconX
size={14}
@@ -74,7 +92,7 @@ const NotificationRow: FC<Props> = ({
className="text-scale-1100 group-hover:text-scale-1200 transition"
/>
}
- onClick={() => onSelectDismissNotification(notification.id)}
+ onClick={() => dismissNotification(notification.id)}
/>
</Tooltip.Trigger>
<Tooltip.Content side="bottom">
@@ -92,21 +110,20 @@ const NotificationRow: FC<Props> = ({
</div>
</div>
</div>
- {availableActions.length > 0 ||
- (changelogLink !== undefined && (
- <div className="flex items-center">
- <NotificationActions
- project={project}
- changelogLink={changelogLink}
- ownerReassignStatus={ownerReassignStatus}
- availableActions={availableActions}
- onSelectRestartProject={() => onSelectRestartProject(project, notification)}
- onSelectApplyMigration={() => onSelectApplyMigration(project, notification)}
- onSelectRollbackMigration={() => onSelectRollbackMigration(project, notification)}
- onSelectFinalizeMigration={() => onSelectFinalizeMigration(project, notification)}
- />
- </div>
- ))}
+ {(availableActions.length > 0 || changelogLink !== undefined) && (
+ <div className="flex items-center">
+ <NotificationActions
+ project={project}
+ changelogLink={changelogLink}
+ ownerReassignStatus={ownerReassignStatus}
+ availableActions={availableActions}
+ onSelectRestartProject={() => onSelectRestartProject(project, notification)}
+ onSelectApplyMigration={() => onSelectApplyMigration(project, notification)}
+ onSelectRollbackMigration={() => onSelectRollbackMigration(project, notification)}
+ onSelectFinalizeMigration={() => onSelectFinalizeMigration(project, notification)}
+ />
+ </div>
+ )}
</div>
</div>
)
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
index 675312a8bc5..00b33c7de2e 100644
--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/index.tsx
@@ -49,16 +49,6 @@ const NotificationsPopover: FC<Props> = () => {
}
}
- const dismissNotification = async (notificationId: string) => {
- if (!notificationId) return
- const { error } = await delete_(`${API_URL}/notifications`, { ids: [notificationId] })
- if (error) {
- ui.setNotification({ category: 'error', message: 'Failed to dismiss notification', error })
- } else {
- refresh()
- }
- }
-
const onConfirmProjectRestart = async () => {
if (!projectToRestart || !targetNotification) return
@@ -203,7 +193,6 @@ const NotificationsPopover: FC<Props> = () => {
<Fragment key={notification.id}>
<NotificationRow
notification={notification}
- onSelectDismissNotification={dismissNotification}
onSelectRestartProject={(project, notification) => {
setProjectToRestart(project)
setTargetNotification(notification)
diff --git a/studio/hooks/misc/useNotifications.tsx b/studio/hooks/misc/useNotifications.tsx
index 23b8f35d3dd..1ca7079a3b3 100644
--- a/studio/hooks/misc/useNotifications.tsx
+++ b/studio/hooks/misc/useNotifications.tsx
@@ -10,8 +10,144 @@ export const useNotifications = () => {
const anyError = (data as any)?.error || error !== undefined
const refresh = () => mutate()
+ const mockNotifications = [
+ {
+ id: '2baae200-48fa-4c87-854e-cf7916399f33',
+ inserted_at: '2022-11-08T05:06:25.487659+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'new',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "todo-list-live" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ changelog_link: 'http://joshen.me',
+ },
+ meta: { actions_available: [{ action_type: 'project.upgrade' }] },
+ },
+ {
+ id: '1e493360-469b-4bdb-a4e8-9fc4dce930d8',
+ inserted_at: '2022-11-08T05:06:25.481716+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'new',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "postgres-email" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ changelog_link: 'http://joshen.me',
+ },
+ meta: { actions_available: [{ action_type: 'project.upgrade' }] },
+ },
+ {
+ id: '9509d9b7-a63d-45d0-8f06-cb8f7c7c7755',
+ inserted_at: '2022-11-08T05:06:24.680516+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'new',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "Realtime Multiplayer Demo (multiplayer.dev)" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: '0f8a3bad-cc81-4300-adc8-dc6c63800e51',
+ inserted_at: '2022-11-07T07:27:58.493636+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "stripe_sequin_export" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: 'bb0b13f8-2e4d-4fa4-a001-d119bde7ea8b',
+ inserted_at: '2022-11-07T07:27:57.773127+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "Slack Clone PROD" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: 'c095de3c-b3d5-4c6a-a8bd-b68f90c66aaa',
+ inserted_at: '2022-11-07T07:27:57.535813+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "joshen (safe to delete)" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: '41002dd7-5fcb-4a4e-86c3-20c9cac71b70',
+ inserted_at: '2022-11-07T07:27:57.535813+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "Simple Multiplayer Game" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: '6eb306d7-f935-4c29-bdbf-9dadf75a87d9',
+ inserted_at: '2022-11-07T07:27:57.00973+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "meme.town" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: '69baca0f-56d3-46a9-aee5-f8345a449473',
+ inserted_at: '2022-11-07T07:27:56.913767+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "supabase-eu-central-1" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ {
+ id: 'a3da0f85-5f53-4380-8d2e-c6d2631bd322',
+ inserted_at: '2022-11-07T07:27:56.844569+00:00',
+ project_id: 2,
+ notification_name: 'project.informational',
+ notification_status: 'seen',
+ data: {
+ name: 'project.informational',
+ message:
+ 'To enhance privacy, Postgres for project "supabase-ap-southeast-1" has been updated to not log statement executions. To change this behavior, refer to the "Postgres" section on https://supabase.com/docs/guides/platform/logs',
+ },
+ meta: { actions_available: [] },
+ },
+ ]
+
return {
- notifications: anyError ? undefined : data,
+ // notifications: anyError ? undefined : data,
+ notifications: mockNotifications,
isLoading: !anyError && !data,
isError: !!anyError,
refresh,