import { useParams } from 'common' import Link from 'next/link' import { UseFormReturn } from 'react-hook-form' import { Button, FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_, Select_Shadcn_, SelectContent_Shadcn_, SelectItem_Shadcn_, SelectTrigger_Shadcn_, SelectValue_Shadcn_, useWatch_Shadcn_, } from 'ui' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import { WebhookFormValues } from './EditHookPanel.constants' import { FormSection, FormSectionContent, FormSectionLabel, } from '@/components/ui/Forms/FormSection' import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' interface HTTPRequestConfigProps { form: UseFormReturn } export const HTTPRequestConfig = ({ form }: HTTPRequestConfigProps) => { const { ref } = useParams() const { data: selectedProject } = useSelectedProjectQuery() const { data: functions } = useEdgeFunctionsQuery({ projectRef: ref }) const edgeFunctions = functions ?? [] const functionType = useWatch_Shadcn_({ control: form.control, name: 'function_type' }) return ( {functionType === 'http_request' ? 'HTTP Request' : functionType === 'supabase_function' ? 'Edge Function' : ''} } > ( GET POST )} /> {functionType === 'http_request' ? ( ( )} /> ) : functionType === 'supabase_function' && edgeFunctions.length === 0 ? (

Select which edge function to trigger

No edge functions created yet

) : functionType === 'supabase_function' && edgeFunctions.length > 0 ? ( ( {edgeFunctions.map((fn) => { const restUrl = selectedProject?.restUrl const restUrlTld = restUrl ? new URL(restUrl).hostname.split('.').pop() : 'co' const functionUrl = `https://${ref}.supabase.${restUrlTld}/functions/v1/${fn.slug}` return ( {fn.name} ) })} )} /> ) : null} (
field.onChange(Number(e.target.value))} className="pr-10" /> ms
)} />
) }