Skip to content

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

Allow auth warning banner to be dismissible (#29733)

Joshen Lim4e36d1f0bb25
diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
index eddcea1ad72..c4a8540e494 100644
--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.constants.ts
@@ -5,6 +5,7 @@ interface ResourceWarningMessage {
bannerContent: {
warning: { title: string; description: string }
critical: { title?: string; description?: string }
+ allowDismissable?: boolean
}
cardContent: {
warning: { title: string; description: string }
@@ -226,6 +227,7 @@ export const RESOURCE_WARNING_MESSAGES: Record<string, ResourceWarningMessage> =
description:
'Set up a custom SMTP provider to handle flows like password reset which require sending emails to any user',
},
+ allowDismissable: true,
},
cardContent: {
warning: {
diff --git a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
index 65eee860ab5..01a303471c0 100644
--- a/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
+++ b/apps/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx
@@ -1,4 +1,4 @@
-import { AlertTriangle, ExternalLink } from 'lucide-react'
+import { AlertTriangle, ExternalLink, X } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
@@ -7,6 +7,8 @@ import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, cn } from 'ui'
import { RESOURCE_WARNING_MESSAGES } from './ResourceExhaustionWarningBanner.constants'
import { getWarningContent } from './ResourceExhaustionWarningBanner.utils'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
+import { LOCAL_STORAGE_KEYS } from 'lib/constants'
const ResourceExhaustionWarningBanner = () => {
const { ref } = useParams()
@@ -15,6 +17,12 @@ const ResourceExhaustionWarningBanner = () => {
const projectResourceWarnings = (resourceWarnings ?? [])?.find(
(warning) => warning.project === ref
)
+
+ const [bannerAcknowledged, setBannerAcknowledged] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.AUTH_EMAIL_WARNING_BANNER_ACKNOWLEDGE(ref ?? ''),
+ false
+ )
+
// [Joshen] Read only takes higher precedence over multiple resource warnings
const activeWarnings =
projectResourceWarnings !== undefined
@@ -77,6 +85,10 @@ const ResourceExhaustionWarningBanner = () => {
default: (metric: string) => `/project/[ref]/settings/[infra-path]#${metric}`,
}
+ const isDismissable =
+ RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES]?.bannerContent
+ .allowDismissable ?? false
+
const getCorrectionUrl = (metric: string | undefined | null) => {
const variant = metric === undefined ? 'undefined' : metric === null ? 'null' : metric
const url =
@@ -125,12 +137,19 @@ const ResourceExhaustionWarningBanner = () => {
return isMatch
})
+ // [Joshen] Only certain warnings should be dismissable, in this case for now,
+ // only the auth email banner should be, everything else should not be dismissable
+ const dismissBanner = () => {
+ setBannerAcknowledged(true)
+ }
+
if (
hasNoWarnings ||
hasNoWarningContent ||
onUsageOrInfraAndNotInReadOnlyMode ||
onDatabaseSettingsAndInReadOnlyMode ||
- !isVisible
+ !isVisible ||
+ bannerAcknowledged
) {
return null
}
@@ -161,6 +180,16 @@ const ResourceExhaustionWarningBanner = () => {
<Link href={correctionUrl}>{buttonText ?? 'Check'}</Link>
</Button>
)}
+ {isDismissable && (
+ <Button
+ type="text"
+ icon={<X />}
+ className="px-1.5 !space-x-0"
+ onClick={() => dismissBanner()}
+ >
+ <span className="sr-only">Close</span>
+ </Button>
+ )}
</div>
</Alert_Shadcn_>
)
diff --git a/apps/studio/lib/constants/index.ts b/apps/studio/lib/constants/index.ts
index 0b75ce4ae57..3fe036d1d63 100644
--- a/apps/studio/lib/constants/index.ts
+++ b/apps/studio/lib/constants/index.ts
@@ -70,6 +70,8 @@ export const LOCAL_STORAGE_KEYS = {
AUTH_SMTP_CHANGES_WARNING: 'auth-smtp-changes-warning-dismissed',
AUTH_USERS_COLUMNS_CONFIGURATION: (ref: string) => `supabase-auth-users-columns-${ref}`,
+ AUTH_EMAIL_WARNING_BANNER_ACKNOWLEDGE: (ref: string) =>
+ `supabase-auth-email-warning-banner-${ref}`,
}
export const OPT_IN_TAGS = {