import dayjs from 'dayjs' import { Project } from 'types' import { Action, ActionReason, ActionType, ExtensionsUpgrade, Notification, NotificationName, ServerUpgrade, ServiceUpgrade, ViolatedLimit, } from '@supabase/shared-types/out/notifications' import { IconArrowRight, IconExternalLink } from 'ui' import Link from 'next/link' export const formatNotificationText = ( project: Project, notification: Notification, ownerReassignStatus?: any ) => { const projectName = project.name if (notification.data.name === NotificationName.ProjectExceedingTierLimit) { const { violations } = notification.data const violationsText = violations .map((violation: ViolatedLimit) => violation.dimension as string) .reduce((a: string, b: string) => `${a}, ${b}`) return (

Your project "{projectName}" has exceeded its limits in the following areas:{' '} {violationsText}.

) } else if (notification.data.name === NotificationName.PostgresqlUpgradeAvailable) { const { upgrade_type, additional } = notification.data if (upgrade_type === 'postgresql-server') { const { version_to } = additional as ServerUpgrade return (

New version of Postgres ({version_to}) is now available for project "{projectName}".

) } else if (upgrade_type === 'extensions') { const { name, version_to } = additional as ExtensionsUpgrade return (

New version of "{name}" ({version_to}) is now available for project "{projectName}".

) } else if (upgrade_type === 'schema-migration') { const { name, version_to } = additional as ExtensionsUpgrade return (

A new schema migration is available for your project "{projectName}".

  1. {name}

    {version_to}

) } return '' } else if (notification.data.name === NotificationName.PostgresqlUpgradeCompleted) { const { upgrade_type, additional } = notification.data if (upgrade_type === 'postgresql-server') { const { version_to } = additional as ServerUpgrade return (

Postgres ({version_to}) has been successfully updated to {version_to} for project " {projectName}".

) } else if (upgrade_type === 'extensions') { const { name, version_to } = additional as ExtensionsUpgrade return (

The extension "{name}" has been successfully updated to {version_to} for project " {projectName}".

) } else if (upgrade_type === 'schema-migration') { const { version_to } = additional if (ownerReassignStatus?.desired === 'unmigrated') { return (

The schema migration "{version_to}" will be applied for project "{projectName}" within a few days. You may opt to apply the changes now, or it'll be done so automatically.

) } else if (ownerReassignStatus?.desired === 'temp_role') { return (

The schema migration "{version_to}" will be finalized for project "{projectName}" within a few days. You may opt to finalize the changes now, or it'll be done so automatically.

) } else { return (

The schema migration "{version_to}" has been successfully applied for project " {projectName}".

) } } } else if (notification.data.name === NotificationName.ProjectUpdateCompleted) { const { upgrades } = notification.data return (

The following services have been successfully updated for project "{projectName}":

    {upgrades.map((upgrade: ServiceUpgrade) => (
  1. {upgrade.name}

    {upgrade.version_to}

    {upgrade.changelog_link && ( )}
  2. ))}
) } else if (notification.data.name === NotificationName.ProjectInformational) { return

{notification.data.message}

} else { return (

Unknown notification type: {notification.notification_name} - Please reach out to support for more information.

) } } export const formatNotificationCTAText = ( availableActions: Action[], ownerReassignStatus?: any ) => { const [action] = availableActions if (!action) return

switch (action.action_type) { case ActionType.SchedulePostgresRestart: return

Restart your project to get the latest updates.

case ActionType.UpgradeProjectToPro: return

Upgrade your project to ensure continued availability.

case ActionType.PgBouncerRestart: return

Restart your connection pooler to get the latest updates.

case ActionType.MigratePostgresSchema: if (action.deadline) { if (ownerReassignStatus?.desired === 'migrated') { return (

This patch was applied on{' '} {dayjs(new Date(ownerReassignStatus.migrated_at ?? action.deadline)).format( 'DD MMM YYYY, HH:mma' )}

) } else if (ownerReassignStatus?.desired === 'temp_role') { if (action.reason === ActionReason.Finalize) { return (

This patch will be automatically applied after{' '} {dayjs(new Date(action.deadline)).format('DD MMM YYYY, HH:mma')}

) } else { return (

This patch was applied on{' '} {dayjs(new Date(ownerReassignStatus.modified_at)).format('DD MMM YYYY, HH:mma')}

) } } else { return (

This patch will be automatically applied after{' '} {dayjs(new Date(action.deadline)).format('DD MMM YYYY, HH:mma')}

) } } else { return '' } default: return '' } }