From d47048dcd6fe81eede090147f01adfaef2664583 Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Tue, 22 Oct 2024 20:49:20 +0800 Subject: [PATCH] Update auth hooks to allow selection of fns that return void (#30022) * Update auth hooks to allow selection of fns that return void * Update for only send email hook --- .../interfaces/Auth/Hooks/CreateHookSheet.tsx | 34 ++++++++++++------- .../studio/components/ui/FunctionSelector.tsx | 6 ++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx b/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx index ca32ae51599..cfc81587e92 100644 --- a/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx +++ b/apps/studio/components/interfaces/Auth/Hooks/CreateHookSheet.tsx @@ -123,6 +123,11 @@ export const CreateHookSheet = ({ [title] ) + const supportedReturnTypes = + definition.enabledKey === 'HOOK_SEND_EMAIL_ENABLED' + ? ['json', 'jsonb', 'void'] + : ['json', 'jsonb'] + const hook: Hook = useMemo(() => { return { ...definition, @@ -288,20 +293,21 @@ export const CreateHookSheet = ({ - +
( ( - + -
+
( ( { - if (func.return_type === 'json' || func.return_type === 'jsonb') { + if (supportedReturnTypes.includes(func.return_type)) { const { value } = convertArgumentTypes(func.argument_types) if (value.length !== 1) return false return value[0].type === 'json' || value[0].type === 'jsonb' @@ -403,7 +409,11 @@ export const CreateHookSheet = ({ No function with a single JSON/B argument
- and JSON/B return type found in this schema. + and JSON/B + {definition.enabledKey === 'HOOK_SEND_EMAIL_ENABLED' + ? ' or void' + : ''}{' '} + return type found in this schema.
} /> @@ -413,8 +423,8 @@ export const CreateHookSheet = ({ />
-

- The following statements will be executed on the function: +

+ The following statements will be executed on the selected function:

) : (
-

Choose a function...

+

Select a function

)} @@ -124,7 +124,7 @@ const FunctionSelector = ({ No functions found 7 ? 'h-[210px]' : ''}> - {!(functions || []).length && ( + {!functions.length && ( )} - {functions?.map((func) => ( + {functions.map((func) => (