The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Shift delete notifications to RQ mutation
Joshen Lim256252dc0976
diff --git a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsxindex 54d19628a36..3c8971d4a30 100644--- a/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx+++ b/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopover/NotificationRow.tsx@@ -1,16 +1,15 @@import * as Tooltip from '@radix-ui/react-tooltip'import { Notification, NotificationStatus } from '@supabase/shared-types/out/notifications'-import { useQuery, useQueryClient } from '@tanstack/react-query'+import { useQuery } from '@tanstack/react-query'import dayjs from 'dayjs'-import { useState } from 'react'+import { Button, IconX } from 'ui'-import { notificationKeys } from 'data/notifications/keys'+import { useNotificationsDismissMutation } from 'data/notifications/notifications-dismiss-mutation'import { useProjectsQuery } from 'data/projects/projects-query'import { useStore } from 'hooks'-import { delete_, get } from 'lib/common/fetch'+import { get } from 'lib/common/fetch'import { API_URL } from 'lib/constants'import { Project } from 'types'-import { Button, IconX } from 'ui'import NotificationActions from './NotificationActions'import { formatNotificationCTAText, formatNotificationText } from './NotificationRows.utils'@@ -30,8 +29,6 @@ const NotificationRow = ({onSelectFinalizeMigration,}: NotificationRowProps) => {const { ui } = useStore()- const queryClient = useQueryClient()- const [dismissing, setDismissing] = useState(false)const { data: projects } = useProjectsQuery()const project = projects?.find((project) => project.id === notification.project_id)@@ -39,6 +36,19 @@ const NotificationRow = ({const changelogLink = (notification.data as any).changelog_linkconst availableActions = notification.meta?.actions_available ?? []+ const { mutate: dismissNotifications, isLoading: isDismissing } = useNotificationsDismissMutation(+ {+ onError: (error) => {+ ui.setNotification({+ error,+ category: 'error',+ message: `Failed to dismiss notification: ${error.message}`,+ duration: 4000,+ })+ },+ }+ )+// [Joshen TODO] This should be removed after the env of Feb when the migration notifications// have been removed, double check with Qiao before removing.// Relevant PR: https://github.com/supabase/supabase/pull/9229@@ -53,19 +63,7 @@ const NotificationRow = ({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 {- await queryClient.invalidateQueries(notificationKeys.list())- }- setDismissing(false)+ dismissNotifications({ ids: [notificationId] })}if (!project) return null@@ -91,7 +89,7 @@ const NotificationRow = ({<ButtonclassName="!px-1 group"type="text"- loading={dismissing}+ loading={isDismissing}icon={<IconXsize={14}diff --git a/studio/data/notifications/notifications-dismiss-mutation.ts b/studio/data/notifications/notifications-dismiss-mutation.tsnew file mode 100644index 00000000000..81f5e2c8b61--- /dev/null+++ b/studio/data/notifications/notifications-dismiss-mutation.ts@@ -0,0 +1,46 @@+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'+import { toast } from 'react-hot-toast'++import { del } from 'data/fetchers'+import { ResponseError } from 'types'+import { notificationKeys } from './keys'++export type NotificationsDismissVariables = {+ ids: string[]+}++export async function dismissNotifications({ ids }: NotificationsDismissVariables) {+ const { data, error } = await del('/platform/notifications', { body: { ids } })+ if (error) throw error+ return data+}++type NotificationsDismissData = Awaited<ReturnType<typeof dismissNotifications>>++export const useNotificationsDismissMutation = ({+ onSuccess,+ onError,+ ...options+}: Omit<+ UseMutationOptions<NotificationsDismissData, ResponseError, NotificationsDismissVariables>,+ 'mutationFn'+> = {}) => {+ const queryClient = useQueryClient()+ return useMutation<NotificationsDismissData, ResponseError, NotificationsDismissVariables>(+ (vars) => dismissNotifications(vars),+ {+ async onSuccess(data, variables, context) {+ await queryClient.invalidateQueries(notificationKeys.list())+ await onSuccess?.(data, variables, context)+ },+ async onError(data, variables, context) {+ if (onError === undefined) {+ toast.error(`Failed to dismiss notifications: ${data.message}`)+ } else {+ onError(data, variables, context)+ }+ },+ ...options,+ }+ )+}