The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Add empty state for auth hooks page (#26889)
Joshen Lim97853287f352
diff --git a/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsxnew file mode 100644index 00000000000..05de44ca4d1--- /dev/null+++ b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx@@ -0,0 +1,100 @@+import { ChevronDown } from 'lucide-react'++import { useParams } from 'common'+import { useAuthConfigQuery } from 'data/auth/auth-config-query'+import {+ Button,+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuItem,+ DropdownMenuLabel,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from 'ui'+import { HOOKS_DEFINITIONS, HOOK_DEFINITION_TITLE, Hook } from './hooks.constants'+import { extractMethod, isValidHook } from './hooks.utils'+import { useSelectedOrganization } from 'hooks'+import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'+import { IS_PLATFORM } from 'lib/constants'++interface AddHookDropdownProps {+ buttonText?: string+ onSelectHook: (hook: HOOK_DEFINITION_TITLE) => void+}++export const AddHookDropdown = ({+ buttonText = 'Add hook',+ onSelectHook,+}: AddHookDropdownProps) => {+ const { ref: projectRef } = useParams()+ const organization = useSelectedOrganization()++ const { data: subscription } = useOrgSubscriptionQuery(+ { orgSlug: organization?.slug },+ { enabled: IS_PLATFORM }+ )+ const { data: authConfig, error: authConfigError, isError } = useAuthConfigQuery({ projectRef })++ const hooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => {+ return {+ ...definition,+ enabled: authConfig?.[definition.enabledKey] || false,+ method: extractMethod(+ authConfig?.[definition.uriKey] || '',+ authConfig?.[definition.secretsKey] || ''+ ),+ }+ })++ const nonEnterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && !h.enterprise)+ const enterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && h.enterprise)++ return (+ <DropdownMenu modal={false}>+ <DropdownMenuTrigger asChild>+ <Button type="primary" iconRight={<ChevronDown className="w-4 h-4" strokeWidth={1} />}>+ {buttonText}+ </Button>+ </DropdownMenuTrigger>+ <DropdownMenuContent className="w-76 p-0" align="end">+ <div className="p-1">+ {nonEnterpriseHookOptions.map((h) => (+ <DropdownMenuItem key={h.title} onClick={() => onSelectHook(h.title)}>+ {h.title}+ </DropdownMenuItem>+ ))}+ </div>+ {nonEnterpriseHookOptions.length > 0 && <DropdownMenuSeparator />}++ <div className="bg-surface-200 p-1 -mt-2">+ {subscription?.plan.id !== 'enterprise' && (+ <DropdownMenuLabel className="grid gap-1 bg-surface-200">+ <p className="text-foreground-light">Enterprise plan required</p>+ <p className="text-foreground-lighter text-xs">+ The following hooks are not available on{' '}+ <a+ target="_href"+ href="https://forms.supabase.com/enterprise"+ className="underline"+ >+ your plan+ </a>+ .+ </p>+ </DropdownMenuLabel>+ )}+ {enterpriseHookOptions.map((h) => (+ <DropdownMenuItem+ key={h.title}+ disabled={true}+ className="cursor-not-allowed"+ onClick={() => onSelectHook(h.title)}+ >+ {h.title}+ </DropdownMenuItem>+ ))}+ </div>+ </DropdownMenuContent>+ </DropdownMenu>+ )+}diff --git a/apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx b/apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsxindex 94ee3b7b4db..d5e45723fb8 100644--- a/apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx+++ b/apps/studio/components/interfaces/Auth/Hooks/HooksListing.tsx@@ -1,27 +1,15 @@import { PermissionAction } from '@supabase/shared-types/out/constants'-import { IS_PLATFORM, useParams } from 'common'import { useState } from 'react'import toast from 'react-hot-toast'-import {- AlertDescription_Shadcn_,- AlertTitle_Shadcn_,- Alert_Shadcn_,- Button,- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuLabel,- DropdownMenuSeparator,- DropdownMenuTrigger,-} from 'ui'+import { useParams } from 'common'+import AlertError from 'components/ui/AlertError'import { FormHeader } from 'components/ui/Forms'import { useAuthConfigQuery } from 'data/auth/auth-config-query'import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation'-import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'-import { useCheckPermissions, useSelectedOrganization } from 'hooks'-import { AlertCircle, ChevronDown } from 'lucide-react'+import { useCheckPermissions } from 'hooks'import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'+import { AddHookDropdown } from './AddHookDropdown'import { CreateHookSheet } from './CreateHookSheet'import { HookCard } from './HookCard'import { HOOKS_DEFINITIONS, HOOK_DEFINITION_TITLE, Hook } from './hooks.constants'@@ -30,11 +18,6 @@ import { extractMethod, isValidHook } from './hooks.utils'export const HooksListing = () => {const { ref: projectRef } = useParams()const { data: authConfig, error: authConfigError, isError } = useAuthConfigQuery({ projectRef })- const organization = useSelectedOrganization()- const { data: subscription } = useOrgSubscriptionQuery(- { orgSlug: organization?.slug },- { enabled: IS_PLATFORM }- )const [selectedHook, setSelectedHook] = useState<HOOK_DEFINITION_TITLE | null>(null)const [selectedHookForDeletion, setSelectedHookForDeletion] = useState<Hook | null>(null)@@ -42,17 +25,6 @@ export const HooksListing = () => {const { mutateAsync: updateAuthConfig } = useAuthConfigUpdateMutation()const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue')- if (isError) {- return (- <Alert_Shadcn_ variant="destructive">- <AlertCircle strokeWidth={2} />- <AlertTitle_Shadcn_>Failed to retrieve auth configuration</AlertTitle_Shadcn_>- <AlertDescription_Shadcn_>{authConfigError.message}</AlertDescription_Shadcn_>- </Alert_Shadcn_>- )- }-- // configuration for all auth hooks.const hooks: Hook[] = HOOKS_DEFINITIONS.map((definition) => {return {...definition,@@ -64,67 +36,36 @@ export const HooksListing = () => {}})- const nonEnterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && !h.enterprise)- const enterpriseHookOptions = hooks.filter((h) => !isValidHook(h) && h.enterprise)+ if (isError) {+ return (+ <AlertError+ error={authConfigError}+ subject="Failed to retrieve auth configuration for hooks"+ />+ )+ }return (- <>+ <div className="pb-4"><FormHeadertitle="Auth Hooks"description="Use Postgres functions or HTTP endpoints to customize the behavior of Supabase Auth to meet your needs."- actions={- <DropdownMenu modal={false}>- <DropdownMenuTrigger asChild>- <Button- type="default"- iconRight={<ChevronDown className="w-4 h-4" strokeWidth={1} />}- >- Add hook- </Button>- </DropdownMenuTrigger>- <DropdownMenuContent className="w-76 p-0" align="end">- <div className="p-1">- {nonEnterpriseHookOptions.map((h) => (- <DropdownMenuItem key={h.title} onClick={() => setSelectedHook(h.title)}>- {h.title}- </DropdownMenuItem>- ))}- </div>- {nonEnterpriseHookOptions.length > 0 && <DropdownMenuSeparator />}-- <div className="bg-surface-200 p-1 -mt-2">- {subscription?.plan.id !== 'enterprise' && (- <DropdownMenuLabel className="grid gap-1 bg-surface-200">- <p className="text-foreground-light">Enterprise plan required</p>- <p className="text-foreground-lighter text-xs">- The following hooks are not available on{' '}- <a- target="_href"- href="https://forms.supabase.com/enterprise"- className="underline"- >- your plan- </a>- .- </p>- </DropdownMenuLabel>- )}- {enterpriseHookOptions.map((h) => (- <DropdownMenuItem- key={h.title}- disabled={true}- className="cursor-not-allowed"- onClick={() => setSelectedHook(h.title)}- >- {h.title}- </DropdownMenuItem>- ))}- </div>- </DropdownMenuContent>- </DropdownMenu>- }+ actions={<AddHookDropdown onSelectHook={setSelectedHook} />}/>- <div className="pb-2 -space-y-px">++ {hooks.filter((h) => isValidHook(h)).length === 0 && (+ <div+ className={[+ 'border rounded border-default px-20 py-16',+ 'flex flex-col items-center justify-center space-y-4',+ ].join(' ')}+ >+ <p className="text-sm text-foreground-light">No hooks configured yet</p>+ <AddHookDropdown buttonText="Add a new hook" onSelectHook={setSelectedHook} />+ </div>+ )}++ <div className="-space-y-px">{hooks.filter((h) => isValidHook(h)).map((hook) => {@@ -146,6 +87,7 @@ export const HooksListing = () => {)})}</div>+<CreateHookSheettitle={selectedHook}visible={!!selectedHook}@@ -158,6 +100,7 @@ export const HooksListing = () => {onClose={() => setSelectedHook(null)}authConfig={authConfig!}/>+<ConfirmationModalvisible={!!selectedHookForDeletion}variant="destructive"@@ -186,6 +129,6 @@ export const HooksListing = () => {{`Are you sure you want to delete the ${selectedHookForDeletion?.title}?`}</p></ConfirmationModal>- </>+ </div>)}diff --git a/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx b/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsxindex 05b2d08d4ae..07192e18e4f 100644--- a/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx+++ b/apps/studio/components/interfaces/Database/Wrappers/Wrappers.tsx@@ -33,7 +33,7 @@ const Wrappers = ({ isEnabled }: { isEnabled: boolean }) => {'flex flex-col items-center justify-center space-y-4',].join(' ')}>- <p className="text-sm">No wrappers created yet</p>+ <p className="text-foreground-light text-sm">No wrappers created yet</p><WrappersDropdown align="center" buttonText="Create a new wrapper" /></div>) : (diff --git a/apps/studio/pages/project/[ref]/auth/hooks.tsx b/apps/studio/pages/project/[ref]/auth/hooks.tsxindex c6bd000e3df..0c03fa82b30 100644--- a/apps/studio/pages/project/[ref]/auth/hooks.tsx+++ b/apps/studio/pages/project/[ref]/auth/hooks.tsx@@ -2,7 +2,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'import { HooksListing } from 'components/interfaces/Auth/Hooks/HooksListing'import { AuthLayout } from 'components/layouts'-import { ScaffoldContainer } from 'components/layouts/Scaffold'+import { FormsContainer } from 'components/ui/Forms'import NoPermission from 'components/ui/NoPermission'import { useCheckPermissions, usePermissionsLoaded } from 'hooks'import type { NextPageWithLayout } from 'types'@@ -15,9 +15,9 @@ const Hooks: NextPageWithLayout = () => {return <NoPermission isFullPage resourceText="access your project's auth hooks" />} else {return (- <ScaffoldContainer className="pt-12 pb-20">+ <FormsContainer><HooksListing />- </ScaffoldContainer>+ </FormsContainer>)}}