import { useIsMFAEnabled } from 'common' import { Boxes, Lock, Plus } from 'lucide-react' import Link from 'next/link' import { Fragment, type ReactNode } from 'react' import { cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import { ActionCard } from '@/components/ui/ActionCard' import PartnerIcon from '@/components/ui/PartnerIcon' import { useOrgProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query' import type { Organization } from '@/types' export const OrganizationCard = ({ organization, href, isLink = true, className, onClick, description, }: { organization: Organization href?: string isLink?: boolean className?: string onClick?: () => void description?: ReactNode }) => { const isUserMFAEnabled = useIsMFAEnabled() const isPlatformOrg = organization.plan?.id === 'platform' const shouldRenderDefaultDescription = description === undefined const { data } = useOrgProjectsInfiniteQuery( { slug: organization.slug }, { enabled: !isPlatformOrg && shouldRenderDefaultDescription } ) const numProjects = data?.pages[0].pagination.count ?? 0 const isMfaRequired = organization.organization_requires_mfa const renderContent = () => ( div]:w-full [&>div]:items-center max-h-min', className )} icon={} title={organization.name} onClick={onClick} description={ shouldRenderDefaultDescription ? (
{organization.plan.name} Plan {numProjects > 0 && ( <> ยท {numProjects} project{numProjects > 1 ? 's' : ''} )}
{isMfaRequired && ( MFA enforced )}
) : ( description ) } /> ) if (isLink) { return {renderContent()} } else { return {renderContent()} } } export const CreateOrganizationCard = ({ params = {}, label = 'Create new organization', }: { params?: { [key: string]: string } label?: string }) => { const createOrganizationHref = `/new${Object.keys(params).length > 0 ? `?${new URLSearchParams(params).toString()}` : ''}` return ( div]:w-full [&>div]:items-center max-h-min', 'border-dashed shadow-none transition-colors group-hover:border-default group-hover:bg-surface-200' )} icon={} title={label} /> ) }