import { Notification, NotificationStatus } from '@supabase/shared-types/out/notifications' import dayjs from 'dayjs' import { Button, IconX } from 'ui' import { useNotificationsDismissMutation } from 'data/notifications/notifications-dismiss-mutation' import { useProjectsQuery } from 'data/projects/projects-query' import { useStore } from 'hooks' import { Project } from 'types' import NotificationActions from './NotificationActions' import { formatNotificationCTAText, formatNotificationText } from './NotificationRows.utils' import { useOrganizationsQuery } from 'data/organizations/organizations-query' export interface NotificationRowProps { notification: Notification onSelectRestartProject: (project: Project, notification: Notification) => void onSelectApplyMigration: (project: Project, notification: Notification) => void onSelectRollbackMigration: (project: Project, notification: Notification) => void } const NotificationRow = ({ notification, onSelectRestartProject, onSelectApplyMigration, onSelectRollbackMigration, }: NotificationRowProps) => { const { ui } = useStore() const { data: projects } = useProjectsQuery() const { data: organizations } = useOrganizationsQuery() const project = projects?.find((project) => project.id === notification.project_id) const organization = organizations?.find((org) => org.id === project?.organization_id) const insertedAt = dayjs(notification.inserted_at).format('DD MMM YYYY, HH:mma') const changelogLink = (notification.data as any).changelog_link const 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, }) }, } ) const dismissNotification = async (notificationId: string) => { if (!notificationId) return dismissNotifications({ ids: [notificationId] }) } if (!project || !organization) return null return (
{insertedAt}