Files
Joshen Lim cab0585533 Fe 1799/consolidate to useselectedprojectquery and (#37684)
* Replace all usage of useProjectContext with useSelectedProjectQuery

* Replace all usage of useSelectedProject with useSelectedProjectQuery

* Replace all usage of useProjectByRef with useProjectByRefQuery

* Replace all usage of useSelectedOrganization with useSelectedOrganizationQuery

* Deprecate useSelectedProject, useSelectedOrganization, and useProjectByRef hooks

* Deprecate ProjecContext
2025-08-06 10:53:10 +07:00

45 lines
1.3 KiB
TypeScript

import { Link } from 'lucide-react'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { Badge, copyToClipboard } from 'ui'
import { useRegisterCommands, useSetCommandMenuOpen } from 'ui-patterns/CommandMenu'
import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
import { orderCommandSectionsByPriority } from './ordering'
export function useApiUrlCommand() {
const setIsOpen = useSetCommandMenuOpen()
const { data: project } = useSelectedProjectQuery()
const { data: settings } = useProjectSettingsV2Query(
{ projectRef: project?.ref },
{ enabled: !!project }
)
const protocol = settings?.app_config?.protocol ?? 'https'
const endpoint = settings?.app_config?.endpoint
const apiUrl = endpoint ? `${protocol}://${endpoint}` : undefined
useRegisterCommands(
COMMAND_MENU_SECTIONS.ACTIONS,
[
{
id: 'api-url',
name: 'Copy API URL',
action: () => {
copyToClipboard(apiUrl ?? '')
setIsOpen(false)
},
icon: () => <Link />,
badge: () => <Badge>Project: {project?.name}</Badge>,
},
],
{
enabled: !!project,
deps: [apiUrl, project],
orderSection: orderCommandSectionsByPriority,
sectionMeta: { priority: 3 },
}
)
}