OrganizationDropdownCommandContent.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { Plus } from 'lucide-react'
  2. import Link from 'next/link'
  3. import {
  4. Button,
  5. cn,
  6. Command,
  7. CommandEmpty,
  8. CommandGroup,
  9. CommandInput,
  10. CommandItem,
  11. CommandList,
  12. CommandSeparator,
  13. ScrollArea,
  14. } from 'ui'
  15. import { OrgCommandItem } from './OrgCommandItem'
  16. import type { Organization } from '@/types'
  17. export interface OrganizationDropdownCommandContentProps {
  18. embedded: boolean
  19. className?: string
  20. organizations: Organization[]
  21. selectedSlug: string | undefined
  22. routePathname: string
  23. hasRouteSlug: boolean
  24. organizationCreationEnabled: boolean
  25. onClose: () => void
  26. }
  27. export function OrganizationDropdownCommandContent({
  28. embedded,
  29. className,
  30. organizations,
  31. selectedSlug,
  32. routePathname,
  33. hasRouteSlug,
  34. organizationCreationEnabled,
  35. onClose,
  36. }: OrganizationDropdownCommandContentProps) {
  37. const orgList = (
  38. <>
  39. {organizations?.map((org) => (
  40. <OrgCommandItem
  41. key={org.slug}
  42. org={org}
  43. selectedSlug={selectedSlug}
  44. routePathname={routePathname}
  45. hasRouteSlug={hasRouteSlug}
  46. onClose={onClose}
  47. compactPadding={!embedded}
  48. />
  49. ))}
  50. </>
  51. )
  52. if (embedded) {
  53. return (
  54. <Command className={cn(className, 'flex flex-col flex-1 min-h-0 overflow-hidden')}>
  55. <div className="flex items-center gap-2 shrink-0 border-b p-2">
  56. <Button type="text" block size="small" asChild>
  57. <Link
  58. href="/organizations"
  59. className="text-xs text-foreground-light hover:text-foreground"
  60. onClick={onClose}
  61. >
  62. All Organizations
  63. </Link>
  64. </Button>
  65. {organizationCreationEnabled && (
  66. <Button
  67. type="default"
  68. block
  69. size="small"
  70. asChild
  71. icon={<Plus size={14} strokeWidth={1.5} />}
  72. >
  73. <Link
  74. href="/new"
  75. className="text-xs text-foreground-light hover:text-foreground"
  76. onClick={onClose}
  77. >
  78. New organization
  79. </Link>
  80. </Button>
  81. )}
  82. </div>
  83. <CommandInput
  84. placeholder="Find organization..."
  85. wrapperClassName="shrink-0"
  86. className="text-base sm:text-sm"
  87. />
  88. <CommandList className="flex flex-col flex-1 min-h-0 overflow-y-auto p-1 max-h-none!">
  89. <CommandEmpty>No organizations found</CommandEmpty>
  90. <CommandGroup className="min-h-0">{orgList}</CommandGroup>
  91. </CommandList>
  92. </Command>
  93. )
  94. }
  95. return (
  96. <Command className={className}>
  97. <CommandInput placeholder="Find organization..." />
  98. <CommandList>
  99. <CommandEmpty>No organizations found</CommandEmpty>
  100. <CommandGroup>
  101. <ScrollArea className={(organizations || []).length > 7 ? 'md:h-[210px]' : ''}>
  102. {orgList}
  103. </ScrollArea>
  104. </CommandGroup>
  105. <CommandSeparator />
  106. <CommandGroup>
  107. <CommandItem className="cursor-pointer w-full" onSelect={() => onClose()}>
  108. <Link href="/organizations" className="flex items-center gap-2 w-full">
  109. All Organizations
  110. </Link>
  111. </CommandItem>
  112. </CommandGroup>
  113. {organizationCreationEnabled && (
  114. <>
  115. <CommandSeparator />
  116. <CommandGroup>
  117. <CommandItem className="cursor-pointer w-full" onSelect={() => onClose()}>
  118. <Link href="/new" className="flex items-center gap-2 w-full">
  119. <Plus size={14} strokeWidth={1.5} />
  120. <p>New organization</p>
  121. </Link>
  122. </CommandItem>
  123. </CommandGroup>
  124. </>
  125. )}
  126. </CommandList>
  127. </Command>
  128. )
  129. }