EdgeFunction.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useParams } from 'common'
  2. import { DOCS_RESOURCE_CONTENT } from '../ProjectAPIDocs.constants'
  3. import ResourceContent from '../ResourceContent'
  4. import type { ContentProps } from './Content.types'
  5. import { useEdgeFunctionsQuery } from '@/data/edge-functions/edge-functions-query'
  6. import { useAppStateSnapshot } from '@/state/app-state'
  7. export const EdgeFunction = ({ language, apikey = 'API_KEY', endpoint }: ContentProps) => {
  8. const { ref } = useParams()
  9. const snap = useAppStateSnapshot()
  10. const { data } = useEdgeFunctionsQuery({ projectRef: ref })
  11. const resource = snap.activeDocsSection[1]
  12. const edgeFunctions = data ?? []
  13. const edgeFunction = edgeFunctions.find((fn) => fn.name === resource)
  14. if (edgeFunction === undefined) return null
  15. return (
  16. <div className="divide-y">
  17. <div className="space-y-1 px-4 py-4">
  18. <div className="flex items-center space-x-2">
  19. <h2>{edgeFunction.name}</h2>
  20. </div>
  21. </div>
  22. <ResourceContent
  23. selectedLanguage={language}
  24. snippet={DOCS_RESOURCE_CONTENT.invokeEdgeFunction}
  25. codeSnippets={DOCS_RESOURCE_CONTENT.invokeEdgeFunction.code({
  26. name: resource,
  27. endpoint: `${endpoint}`,
  28. apikey: apikey,
  29. })}
  30. />
  31. </div>
  32. )
  33. }