AddIntegrationDropdown.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { ChevronDown } from 'lucide-react'
  2. import Image from 'next/image'
  3. import {
  4. Button,
  5. cn,
  6. DropdownMenu,
  7. DropdownMenuContent,
  8. DropdownMenuItem,
  9. DropdownMenuLabel,
  10. DropdownMenuSeparator,
  11. DropdownMenuTrigger,
  12. } from 'ui'
  13. import {
  14. getIntegrationTypeIcon,
  15. getIntegrationTypeLabel,
  16. INTEGRATION_TYPES,
  17. } from './ThirdPartyAuthForm.utils'
  18. interface AddIntegrationDropdownProps {
  19. buttonText?: string
  20. align?: 'end' | 'center'
  21. type?: 'primary' | 'default'
  22. open?: boolean
  23. onOpenChange?: (open: boolean) => void
  24. onSelectIntegrationType: (type: INTEGRATION_TYPES) => void
  25. }
  26. const ProviderDropdownItem = ({
  27. disabled,
  28. type,
  29. onSelectIntegrationType,
  30. }: {
  31. disabled?: boolean
  32. type: INTEGRATION_TYPES
  33. onSelectIntegrationType: (type: INTEGRATION_TYPES) => void
  34. }) => {
  35. return (
  36. <DropdownMenuItem
  37. key={type}
  38. onClick={() => onSelectIntegrationType(type)}
  39. className={cn('flex items-center gap-x-2 p-2', disabled && 'cursor-not-allowed')}
  40. disabled={disabled}
  41. >
  42. <Image src={getIntegrationTypeIcon(type)} width={16} height={16} alt={`${type} icon`} />
  43. <span>{getIntegrationTypeLabel(type)}</span>
  44. </DropdownMenuItem>
  45. )
  46. }
  47. export const AddIntegrationDropdown = ({
  48. type = 'primary',
  49. align = 'end',
  50. open,
  51. onOpenChange,
  52. onSelectIntegrationType,
  53. }: AddIntegrationDropdownProps) => {
  54. return (
  55. <DropdownMenu open={open} onOpenChange={onOpenChange}>
  56. <DropdownMenuTrigger asChild>
  57. <Button type={type} iconRight={<ChevronDown />}>
  58. Add provider
  59. </Button>
  60. </DropdownMenuTrigger>
  61. <DropdownMenuContent align={align} className="w-56">
  62. <DropdownMenuLabel>Select provider</DropdownMenuLabel>
  63. <DropdownMenuSeparator />
  64. <ProviderDropdownItem type="firebase" onSelectIntegrationType={onSelectIntegrationType} />
  65. <ProviderDropdownItem type="clerk" onSelectIntegrationType={onSelectIntegrationType} />
  66. <ProviderDropdownItem type="workos" onSelectIntegrationType={onSelectIntegrationType} />
  67. <ProviderDropdownItem type="auth0" onSelectIntegrationType={onSelectIntegrationType} />
  68. <ProviderDropdownItem type="awsCognito" onSelectIntegrationType={onSelectIntegrationType} />
  69. </DropdownMenuContent>
  70. </DropdownMenu>
  71. )
  72. }