IntegrationCard.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { BadgeCheck } from 'lucide-react'
  2. import Image from 'next/image'
  3. import Link from 'next/link'
  4. import { Badge, Card, CardContent, cn } from 'ui'
  5. import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
  6. import { IntegrationDefinition } from './Integrations.constants'
  7. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  8. type IntegrationCardProps = IntegrationDefinition & {
  9. isInstalled?: boolean
  10. featured?: boolean
  11. image?: string
  12. }
  13. const INTEGRATION_CARD_STYLE = cn(
  14. 'w-full h-full bg-surface-100 hover:bg-surface-200 hover:border-strong',
  15. 'border border-border rounded-md ease-out duration-200 transition-all'
  16. )
  17. export const IntegrationLoadingCard = () => {
  18. return (
  19. <div className={cn(INTEGRATION_CARD_STYLE, 'pl-5 pr-6 py-3 gap-3 inline-flex h-[110px]')}>
  20. <div className="w-10 h-10 relative">
  21. <ShimmeringLoader className="w-full h-full bg-foreground-light border rounded-md" />
  22. </div>
  23. <div className="grow basis-0 w-full flex flex-col justify-between items-start gap-y-2">
  24. <div className="w-full flex-col justify-start items-start gap-y-1 flex">
  25. <ShimmeringLoader className="w-3/4 py-2.5" />
  26. <ShimmeringLoader className="w-full py-2.5" />
  27. </div>
  28. </div>
  29. </div>
  30. )
  31. }
  32. export const IntegrationCard = ({
  33. id,
  34. listingId,
  35. status,
  36. name,
  37. icon,
  38. description,
  39. isInstalled,
  40. featured = false,
  41. image,
  42. }: IntegrationCardProps) => {
  43. const { data: project } = useSelectedProjectQuery()
  44. const shouldShowOfficialBadge = !listingId
  45. if (featured) {
  46. return (
  47. <Link href={`/project/${project?.ref}/integrations/${id}/overview`} className="h-full">
  48. <Card className="h-full">
  49. {/* Full-width image/icon at the top */}
  50. <div className="w-full h-24 bg-surface-400 rounded-t-md flex items-center justify-center overflow-hidden relative">
  51. {image ? (
  52. <Image
  53. fill
  54. src={image}
  55. alt={`${name} integration`}
  56. className="w-full h-full object-cover invert dark:invert-0"
  57. objectFit="cover"
  58. />
  59. ) : (
  60. <div className="w-12 h-12 text-foreground relative">
  61. {icon({ className: 'w-full h-full text-foreground' })}
  62. </div>
  63. )}
  64. </div>
  65. <CardContent className="p-6 px-4">
  66. <div className="flex-col justify-start items-center text-center gap-y-0.5 flex">
  67. <h3>{name}</h3>
  68. <p className="text-foreground-light text-sm line-clamp-3">{description}</p>
  69. <div className="flex items-center gap-x-1 mt-4">
  70. {status && <Badge variant="warning">{status}</Badge>}
  71. {shouldShowOfficialBadge && <Badge>Official</Badge>}
  72. </div>
  73. </div>
  74. </CardContent>
  75. </Card>
  76. </Link>
  77. )
  78. }
  79. return (
  80. <Link href={`/project/${project?.ref}/integrations/${id}/overview`} className="h-full">
  81. <Card className="h-full">
  82. <CardContent className="flex flex-col p-4 @2xl:p-6 h-full">
  83. <div className="flex items-start justify-between mb-4">
  84. <div className="shrink-0 w-10 h-10 relative bg-white border rounded-md flex items-center justify-center">
  85. {icon()}
  86. </div>
  87. {isInstalled && (
  88. <div className="flex items-center gap-x-1">
  89. <BadgeCheck size={14} className="text-brand-link" />
  90. <span className="text-brand-link text-xs">Installed</span>
  91. </div>
  92. )}
  93. </div>
  94. <div className="flex-col justify-start items-start gap-y-0.5 flex flex-1">
  95. <h3 className="text-foreground text-sm">{name}</h3>
  96. <p className="text-foreground-light text-xs flex-1">{description}</p>
  97. <div className="flex items-center gap-x-1 mt-4">
  98. {status && <Badge variant="warning">{status}</Badge>}
  99. {shouldShowOfficialBadge && <Badge>Official</Badge>}
  100. </div>
  101. </div>
  102. </CardContent>
  103. </Card>
  104. </Link>
  105. )
  106. }