import { ChevronDown } from 'lucide-react' import { useMemo, useRef, useState } from 'react' import { Badge, Button, cn, Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, Popover, PopoverContent, PopoverTrigger, } from 'ui' import { getHasInstalledObject } from '@/components/layouts/IntegrationsLayout/Integrations.utils' import PartnerIcon from '@/components/ui/PartnerIcon' import { useIntegrationsQuery } from '@/data/integrations/integrations-query' import type { IntegrationName } from '@/data/integrations/integrations.types' import { useOrganizationsQuery } from '@/data/organizations/organizations-query' import type { Organization } from '@/types' export interface OrganizationPickerProps { integrationName: IntegrationName configurationId?: string selectedOrg: Organization | null onSelectedOrgChange: (organization: Organization) => void disabled?: boolean } const OrganizationPicker = ({ integrationName, configurationId, selectedOrg, onSelectedOrgChange, disabled, }: OrganizationPickerProps) => { const [open, setOpen] = useState(false) const ref = useRef(null) const { data: integrationData } = useIntegrationsQuery() const { data: organizationsData, isPending: isLoadingOrganization } = useOrganizationsQuery() const installed = useMemo( () => integrationData && organizationsData ? getHasInstalledObject({ integrationName, integrationData, organizationsData, installationId: configurationId, }) : {}, [configurationId, integrationData, integrationName, organizationsData] ) return ( <> No results found. {organizationsData?.map((org) => { return ( { const org = organizationsData?.find( (org) => org.slug.toLowerCase() === slug.toLowerCase() ) if (org) { onSelectedOrgChange(org) } setOpen(false) }} > {org.name}{' '} {configurationId && installed[org.slug] && ( Integration Installed )} ) })} ) } export default OrganizationPicker