import { PermissionAction } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import { ChevronDown, Plus, Trash } from 'lucide-react' import { useFieldArray, UseFormReturn } from 'react-hook-form' import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, FormControl_Shadcn_, FormField_Shadcn_, Input_Shadcn_, useWatch_Shadcn_, } from 'ui' import { WebhookFormValues } from './EditHookPanel.constants' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import { FormSection, FormSectionContent, FormSectionLabel, } from '@/components/ui/Forms/FormSection' import { getKeys, useAPIKeysQuery } from '@/data/api-keys/api-keys-query' import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' import { uuidv4 } from '@/lib/helpers' interface HTTPHeadersProps { form: UseFormReturn } export const HTTPHeaders = ({ form }: HTTPHeadersProps) => { const { ref } = useParams() const { can: canReadAPIKeys } = useAsyncCheckPermissions(PermissionAction.SECRETS_READ, '*') const { data: apiKeys } = useAPIKeysQuery( { projectRef: ref, reveal: true }, { enabled: canReadAPIKeys } ) const { serviceKey, secretKey } = getKeys(apiKeys) const apiKey = secretKey?.api_key ?? serviceKey?.api_key ?? '[YOUR API KEY]' const functionType = useWatch_Shadcn_({ control: form.control, name: 'function_type' }) const { fields: headerFields, append: appendHeader, remove: removeHeader, } = useFieldArray({ control: form.control, name: 'httpHeaders', }) const onAddHeaders = (headers?: { id: string; name: string; value: string }[]) => { if (headers) { headers.forEach((header) => appendHeader(header)) } else { appendHeader({ id: uuidv4(), name: '', value: '' }) } } return ( HTTP Headers} >
{headerFields.map((field, index) => (
( )} /> ( )} /> } className="py-4" onClick={() => removeHeader(index)} tooltip={{ content: { side: 'bottom', text: 'Remove header' } }} />
))}
{functionType === 'supabase_function' && (
) }