Files
supabase/apps/studio/components/interfaces/Docs/Introduction.tsx
T
Ivan VasilovandJoshen Lim f29003e0e7 fix: Use protocol property when building API url (#30332)
* Fix the types for API settings to include protocol.

* Use the protocol property in all usages of endpoints.

* Update

* Lint

* Revert changes to retrieving protocol

* Remove console.logs

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-11-06 22:22:24 +01:00

38 lines
1.2 KiB
TypeScript

import { useParams } from 'common'
import Snippets from 'components/interfaces/Docs/Snippets'
import { useProjectPostgrestConfigQuery } from 'data/config/project-postgrest-config-query'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import CodeSnippet from './CodeSnippet'
import PublicSchemaNotEnabledAlert from './PublicSchemaNotEnabledAlert'
interface Props {
selectedLang: 'bash' | 'js'
}
export default function Introduction({ selectedLang }: Props) {
const { ref: projectRef } = useParams()
const { data: settings } = useProjectSettingsV2Query({ projectRef })
const { data: config } = useProjectPostgrestConfigQuery({ projectRef })
const protocol = settings?.app_config?.protocol ?? 'https'
const hostEndpoint = settings?.app_config?.endpoint
const endpoint = `${protocol}://${hostEndpoint ?? ''}`
const isPublicSchemaEnabled = config?.db_schema
.split(',')
.map((name) => name.trim())
.includes('public')
return (
<div className="doc-section doc-section--client-libraries">
<article className="code">
<CodeSnippet selectedLang={selectedLang} snippet={Snippets.init(endpoint)} />
{!isPublicSchemaEnabled && <PublicSchemaNotEnabledAlert />}
</article>
</div>
)
}