import { createFileRoute, Link } from '@tanstack/react-router' import { PlusIcon, SearchIcon } from 'lucide-react' import { useState } from 'react' import { Button, Skeleton } from 'ui' import { Input } from 'ui-patterns/DataInputs/Input' import { PageContainer } from 'ui-patterns/PageContainer' import { PageHeader, PageHeaderMeta, PageHeaderSummary, PageHeaderTitle, } from 'ui-patterns/PageHeader' import { PageSection } from 'ui-patterns/PageSection' import { useDebouncedCallback } from 'use-debounce' import { NoOrganizationsState } from '@/components/interfaces/Home/ProjectList/EmptyStates' import { OrganizationCard } from '@/components/interfaces/Organization/OrganizationCard' import { AlertError } from '@/components/ui/AlertError' import { NoSearchResults } from '@/components/ui/NoSearchResults' import { useOrganizationsQuery } from '@/data/organizations/organizations-query' import { useCustomContent } from '@/hooks/custom-content/useCustomContent' import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { withAuth } from '@/hooks/misc/withAuth' import { onSearchInputEscape } from '@/lib/keyboard' import { buildStudioPageTitle } from '@/lib/page-title' import { useTrack } from '@/lib/telemetry/track' export const Route = createFileRoute('/_app/organizations')({ component: Organizations, staticData: { defaultLayoutHeaderTitle: 'Organizations', hideMobileMenu: true, }, }) function Organizations() { return ( <> Your organizations ) } function OrganizationsPage() { const { appTitle } = useCustomContent(['app:title']) const track = useTrack() const [search, setSearch] = useState('') const pageTitle = buildStudioPageTitle({ section: 'Organizations', brand: appTitle || 'Supabase', }) const { data: organizations = [], error, isPending: isLoading, isError, isSuccess, } = useOrganizationsQuery() const organizationCreationEnabled = useIsFeatureEnabled('organizations:create') const searchTerm = search.trim().toLowerCase() const filteredOrganizations = searchTerm.length === 0 ? organizations : organizations?.filter( (x) => x.name.toLowerCase().includes(searchTerm) || x.slug.toLowerCase().includes(searchTerm) ) const trackSearch = useDebouncedCallback((value: string) => { if (value.trim().length === 0) return track('org_list_search_submitted', { orgCount: filteredOrganizations.length }) }, 500) const handleSearchChange = (value: string) => { setSearch(value) trackSearch(value) } return ( <> {pageTitle} {organizations.length > 0 && (
} className="w-full flex-1 md:w-64" value={search} onChange={(event) => handleSearchChange(event.target.value)} onKeyDown={onSearchInputEscape(search, handleSearchChange)} /> {organizationCreationEnabled && ( )}
)} {isSuccess && organizations.length === 0 && !isError && } {searchTerm.length > 0 && filteredOrganizations.length === 0 && ( )}
{isLoading && ( <> )} {isError && } {isSuccess && filteredOrganizations.map((org) => ( ))}
) } const OrganizationsPageWithAuth = withAuth(OrganizationsPage)