Skip to content

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

Chore/fix hooks sheet (#29746)

Terry Sutton692e363bc3e9
diff --git a/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx
index 06fe207d252..f2802eafb60 100644
--- a/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx
+++ b/apps/studio/components/interfaces/Auth/Hooks/AddHookDropdown.tsx
@@ -16,6 +16,7 @@ import {
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
+ SheetSection,
} from 'ui'
import { HOOKS_DEFINITIONS, HOOK_DEFINITION_TITLE, Hook } from './hooks.constants'
import { extractMethod, isValidHook } from './hooks.utils'
@@ -78,53 +79,52 @@ export const AddHookDropdown = ({
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-76 p-0" align="end">
- <div className="p-1">
+ <div>
{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">
- {!isTeamsOrEnterprisePlan && (
- <DropdownMenuLabel className="grid gap-1 bg-surface-200">
- <p className="text-foreground-light">Team or Enterprise Plan required</p>
- <p className="text-foreground-lighter text-xs">
- The following hooks are not available on{' '}
- <a
- target="_href"
- href={`https://supabase.com/dashboard/org/${organization?.slug ?? '_'}/billing`}
- className="underline"
- >
- your plan
- </a>
- .
- </p>
- </DropdownMenuLabel>
- )}
- {enterpriseHookOptions.map((h) =>
- isTeamsOrEnterprisePlan ? (
- <DropdownMenuItem
- key={h.title}
- disabled={!isTeamsOrEnterprisePlan}
- className=""
- onClick={() => onSelectHook(h.title)}
- >
- {h.title}
- </DropdownMenuItem>
- ) : (
- <DropdownMenuItem
- key={h.title}
- disabled={!isTeamsOrEnterprisePlan}
- onClick={() => onSelectHook(h.title)}
+ <DropdownMenuSeparator className="my-0" />
+
+ {!isTeamsOrEnterprisePlan && (
+ <DropdownMenuLabel className="grid gap-1 bg-surface-200">
+ <p className="text-foreground-light">Team or Enterprise Plan required</p>
+ <p className="text-foreground-lighter text-xs">
+ The following hooks are not available on{' '}
+ <a
+ target="_href"
+ href={`https://supabase.com/dashboard/org/${organization?.slug ?? '_'}/billing`}
+ className="underline"
>
- {h.title}
- </DropdownMenuItem>
- )
- )}
- </div>
+ your plan
+ </a>
+ .
+ </p>
+ </DropdownMenuLabel>
+ )}
+ {enterpriseHookOptions.map((h) =>
+ isTeamsOrEnterprisePlan ? (
+ <DropdownMenuItem
+ key={h.title}
+ disabled={!isTeamsOrEnterprisePlan}
+ className=""
+ onClick={() => onSelectHook(h.title)}
+ >
+ {h.title}
+ </DropdownMenuItem>
+ ) : (
+ <DropdownMenuItem
+ key={h.title}
+ disabled={!isTeamsOrEnterprisePlan}
+ onClick={() => onSelectHook(h.title)}
+ >
+ {h.title}
+ </DropdownMenuItem>
+ )
+ )}
</DropdownMenuContent>
</DropdownMenu>
)
diff --git a/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx b/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx
index 6a3275c5643..5a25cd7643f 100644
--- a/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx
+++ b/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx
@@ -31,6 +31,7 @@ import {
SheetContent,
SheetFooter,
SheetHeader,
+ SheetSection,
SheetTitle,
Switch,
cn,
@@ -290,196 +291,198 @@ export const CreateHookSheet = ({
</div>
</SheetHeader>
<Separator />
- <Form_Shadcn_ {...form}>
- <form
- id={FORM_ID}
- className="space-y-6 w-full py-8 flex-1"
- onSubmit={form.handleSubmit(onSubmit)}
- >
- <FormField_Shadcn_
- key="enabled"
- control={form.control}
- name="enabled"
- render={({ field }) => (
- <FormItemLayout
- layout="flex"
- className="px-8"
- label={`Enable ${values.hookType}`}
- description={
- values.hookType === 'Send SMS hook'
- ? 'SMS Provider settings will be disabled in favor of SMS hooks'
- : undefined
- }
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- disabled={field.disabled}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- <Separator />
- {httpsAuthHooksEnabled && (
+ <SheetSection className="overflow-auto flex-grow">
+ <Form_Shadcn_ {...form}>
+ <form
+ id={FORM_ID}
+ className="space-y-6 w-full py-8 flex-1"
+ onSubmit={form.handleSubmit(onSubmit)}
+ >
<FormField_Shadcn_
+ key="enabled"
control={form.control}
- name="selectedType"
+ name="enabled"
render={({ field }) => (
- <FormItemLayout label="Hook type" className="px-8">
+ <FormItemLayout
+ layout="flex"
+ label={`Enable ${values.hookType}`}
+ description={
+ values.hookType === 'Send SMS hook'
+ ? 'SMS Provider settings will be disabled in favor of SMS hooks'
+ : undefined
+ }
+ >
<FormControl_Shadcn_>
- <RadioGroupStacked
- value={field.value}
- onValueChange={(value) => field.onChange(value)}
- >
- <RadioGroupStackedItem
- value="postgres"
- id="postgres"
- key="postgres"
- label="Postgres"
- description="Used to call a Postgres function."
- />
- <RadioGroupStackedItem
- value="https"
- id="https"
- key="https"
- label="HTTPS"
- description="Used to call any HTTPS endpoint."
- />
- </RadioGroupStacked>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={field.disabled}
+ />
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
- )}
- {values.selectedType === 'postgres' ? (
- <>
- <div className="grid grid-cols-2 gap-8 px-8">
+ <Separator />
+ {httpsAuthHooksEnabled && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="selectedType"
+ render={({ field }) => (
+ <FormItemLayout label="Hook type">
+ <FormControl_Shadcn_>
+ <RadioGroupStacked
+ value={field.value}
+ onValueChange={(value) => field.onChange(value)}
+ >
+ <RadioGroupStackedItem
+ value="postgres"
+ id="postgres"
+ key="postgres"
+ label="Postgres"
+ description="Used to call a Postgres function."
+ />
+ <RadioGroupStackedItem
+ value="https"
+ id="https"
+ key="https"
+ label="HTTPS"
+ description="Used to call any HTTPS endpoint."
+ />
+ </RadioGroupStacked>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ )}
+ {values.selectedType === 'postgres' ? (
+ <>
+ <div className="grid grid-cols-2 gap-8">
+ <FormField_Shadcn_
+ key="postgresValues.schema"
+ control={form.control}
+ name="postgresValues.schema"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Postgres Schema"
+ description="Postgres schema where the function is defined."
+ >
+ <FormControl_Shadcn_>
+ <SchemaSelector
+ size="small"
+ showError={false}
+ selectedSchemaName={field.value}
+ onSelectSchema={(name) => field.onChange(name)}
+ disabled={field.disabled}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ <FormField_Shadcn_
+ key="postgresValues.functionName"
+ control={form.control}
+ name="postgresValues.functionName"
+ render={({ field }) => (
+ <FormItemLayout
+ label="Function name"
+ description="Postgres function which will be called by Supabase Auth each time the hook is triggered."
+ >
+ <FormControl_Shadcn_>
+ <FunctionSelector
+ size="small"
+ schema={values.postgresValues.schema}
+ value={field.value}
+ onChange={field.onChange}
+ disabled={field.disabled}
+ filterFunction={(func) => {
+ if (func.return_type === 'json' || func.return_type === 'jsonb') {
+ const { value } = convertArgumentTypes(func.argument_types)
+ if (value.length !== 1) return false
+ return value[0].type === 'json' || value[0].type === 'jsonb'
+ }
+ return false
+ }}
+ noResultsLabel={
+ <span>
+ No function with a single JSON/B argument
+ <br />
+ and JSON/B return type found in this schema.
+ </span>
+ }
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </div>
+ <div className="h-72 w-full gap-3 flex flex-col">
+ <p className="text-sm text-foreground-light">
+ The following statements will be executed on the function:
+ </p>
+ <CodeEditor
+ id="postgres-hook-editor"
+ isReadOnly={true}
+ language="pgsql"
+ value={statements.join('\n\n')}
+ />
+ </div>
+ </>
+ ) : (
+ <div className="flex flex-col gap-4">
<FormField_Shadcn_
- key="postgresValues.schema"
+ key="httpsValues.url"
control={form.control}
- name="postgresValues.schema"
+ name="httpsValues.url"
render={({ field }) => (
<FormItemLayout
- label="Postgres Schema"
- description="Postgres schema where the function is defined."
+ label="URL"
+ description="Supabase Auth will send a HTTPS POST request to this URL each time the hook is triggered."
>
<FormControl_Shadcn_>
- <SchemaSelector
- size="small"
- showError={false}
- selectedSchemaName={field.value}
- onSelectSchema={(name) => field.onChange(name)}
- disabled={field.disabled}
- />
+ <Input_Shadcn_ {...field} />
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
<FormField_Shadcn_
- key="postgresValues.functionName"
+ key="httpsValues.secret"
control={form.control}
- name="postgresValues.functionName"
+ name="httpsValues.secret"
render={({ field }) => (
<FormItemLayout
- label="Function name"
- description="Postgres function which will be called by Supabase Auth each time the hook is triggered."
+ label="Secret"
+ description={
+ <ReactMarkdown>
+ It should be a base64 encoded hook secret with a prefix `v1,whsec_`.
+ `v1` denotes the signature version, and `whsec_` signifies a symmetric
+ secret.
+ </ReactMarkdown>
+ }
>
<FormControl_Shadcn_>
- <FunctionSelector
- size="small"
- schema={values.postgresValues.schema}
- value={field.value}
- onChange={field.onChange}
- disabled={field.disabled}
- filterFunction={(func) => {
- if (func.return_type === 'json' || func.return_type === 'jsonb') {
- const { value } = convertArgumentTypes(func.argument_types)
- if (value.length !== 1) return false
- return value[0].type === 'json' || value[0].type === 'jsonb'
- }
- return false
- }}
- noResultsLabel={
- <span>
- No function with a single JSON/B argument
- <br />
- and JSON/B return type found in this schema.
- </span>
- }
- />
+ <div className="flex flex-row">
+ <Input_Shadcn_ {...field} className="rounded-r-none border-r-0" />
+ <Button
+ type="default"
+ size="small"
+ className="rounded-l-none"
+ onClick={() => {
+ const authHookSecret = generateAuthHookSecret()
+ form.setValue('httpsValues.secret', authHookSecret)
+ }}
+ >
+ Generate secret
+ </Button>
+ </div>
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
</div>
- <div className="h-72 w-full px-8 gap-3 flex flex-col">
- <p className="text-sm text-foreground-light">
- The following statements will be executed on the function:
- </p>
- <CodeEditor
- id="postgres-hook-editor"
- isReadOnly={true}
- language="pgsql"
- value={statements.join('\n\n')}
- />
- </div>
- </>
- ) : (
- <div className="flex flex-col px-8 gap-4">
- <FormField_Shadcn_
- key="httpsValues.url"
- control={form.control}
- name="httpsValues.url"
- render={({ field }) => (
- <FormItemLayout
- label="URL"
- description="Supabase Auth will send a HTTPS POST request to this URL each time the hook is triggered."
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_ {...field} />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- <FormField_Shadcn_
- key="httpsValues.secret"
- control={form.control}
- name="httpsValues.secret"
- render={({ field }) => (
- <FormItemLayout
- label="Secret"
- description={
- <ReactMarkdown>
- It should be a base64 encoded hook secret with a prefix `v1,whsec_`. `v1`
- denotes the signature version, and `whsec_` signifies a symmetric secret.
- </ReactMarkdown>
- }
- >
- <FormControl_Shadcn_>
- <div className="flex flex-row">
- <Input_Shadcn_ {...field} className="rounded-r-none border-r-0" />
- <Button
- type="default"
- size="small"
- className="rounded-l-none"
- onClick={() => {
- const authHookSecret = generateAuthHookSecret()
- form.setValue('httpsValues.secret', authHookSecret)
- }}
- >
- Generate secret
- </Button>
- </div>
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </div>
- )}
- </form>
- </Form_Shadcn_>
+ )}
+ </form>
+ </Form_Shadcn_>
+ </SheetSection>
<SheetFooter>
{!isCreating && (
<div className="flex-1">
diff --git a/packages/ui/src/components/shadcn/ui/sheet.tsx b/packages/ui/src/components/shadcn/ui/sheet.tsx
index 41d0f1cb5e8..52e86a7e248 100644
--- a/packages/ui/src/components/shadcn/ui/sheet.tsx
+++ b/packages/ui/src/components/shadcn/ui/sheet.tsx
@@ -185,7 +185,7 @@ const SheetHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElemen
SheetHeader.displayName = 'SheetHeader'
const SheetSection = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
- <div className={cn('px-content py-content', className)} {...props} />
+ <div className={cn('px-5 py-4', className)} {...props} />
)
SheetSection.displayName = 'SheetSection'