mirror of
https://github.com/supabase/supabase.git
synced 2026-05-16 15:49:19 +08:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { Link } from 'lucide-react'
|
|
import { toast } from 'sonner'
|
|
import { Badge, copyToClipboard } from 'ui'
|
|
import {
|
|
useRegisterCommands,
|
|
useResetCommandMenu,
|
|
useSetCommandMenuOpen,
|
|
} from 'ui-patterns/CommandMenu'
|
|
|
|
import { COMMAND_MENU_SECTIONS } from './CommandMenu.utils'
|
|
import { orderCommandSectionsByPriority } from './ordering'
|
|
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
export function useApiUrlCommand() {
|
|
const setIsOpen = useSetCommandMenuOpen()
|
|
const resetCommandMenu = useResetCommandMenu()
|
|
|
|
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 ?? '', () => {
|
|
toast.success('API URL copied to clipboard')
|
|
})
|
|
setIsOpen(false)
|
|
resetCommandMenu()
|
|
},
|
|
icon: () => <Link />,
|
|
badge: () => <Badge>Project: {project?.name}</Badge>,
|
|
},
|
|
],
|
|
{
|
|
enabled: !!project,
|
|
deps: [apiUrl, project],
|
|
orderSection: orderCommandSectionsByPriority,
|
|
sectionMeta: { priority: 3 },
|
|
}
|
|
)
|
|
}
|