DiscordCTACard.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { AnimatePresence, motion } from 'framer-motion'
  2. import Link from 'next/link'
  3. import router from 'next/router'
  4. import { useEffect, useState } from 'react'
  5. import SVG from 'react-inlinesvg'
  6. import { Button } from 'ui'
  7. import { NO_ORG_MARKER } from './SupportForm.utils'
  8. import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
  9. interface DiscordCTACardProps {
  10. organizationSlug?: string | null
  11. }
  12. export const DiscordCTACard = ({ organizationSlug }: DiscordCTACardProps) => {
  13. const { data: organizations } = useOrganizationsQuery()
  14. const [isVisible, setIsVisible] = useState(false)
  15. const selectedOrg = organizations?.find((org) => org.slug === organizationSlug)
  16. const isFreePlan = selectedOrg?.plan.id === 'free'
  17. useEffect(() => {
  18. const timer = setTimeout(() => setIsVisible(true), 800)
  19. return () => clearTimeout(timer)
  20. }, [])
  21. return (
  22. <AnimatePresence>
  23. {isVisible && isFreePlan && organizationSlug !== NO_ORG_MARKER && (
  24. <motion.aside
  25. initial={{ height: 0, opacity: 0 }}
  26. animate={{ height: 'auto', opacity: 1 }}
  27. exit={{ height: 0, opacity: 0 }}
  28. className="w-full overflow-hidden border border-transparent rounded-md relative"
  29. style={{
  30. background: '#404EED',
  31. borderColor: 'color-mix(in srgb, #404EED 95%, #000000)',
  32. }}
  33. >
  34. <div className="flex items-center p-6">
  35. {/* Decorative background */}
  36. <div
  37. className="absolute inset-0 opacity-20 md:opacity-30"
  38. style={{
  39. backgroundImage: `url(${router.basePath}/img/support/discord-bg-small.jpg)`,
  40. backgroundSize: '75%',
  41. backgroundPosition: '112% 50%',
  42. backgroundRepeat: 'no-repeat',
  43. maskImage: 'linear-gradient(to left, rgba(0,0,0,1) 10%, rgba(0,0,0,0) 100%)',
  44. WebkitMaskImage: 'linear-gradient(to left, rgba(0,0,0,1) 10%, rgba(0,0,0,0) 100%)',
  45. }}
  46. />
  47. {/* Content */}
  48. <div className="relative z-10">
  49. <div className="flex flex-col gap-3">
  50. <div>
  51. <h5 className="text-sm font-medium text-white">Ask the Discord community</h5>
  52. <p className="text-sm text-white/75">
  53. Many code-related questions are answered within minutes.
  54. </p>
  55. </div>
  56. <Link href="https://discord.supabase.com" target="_blank" rel="noreferrer">
  57. <Button
  58. size="tiny"
  59. type="secondary"
  60. icon={
  61. <SVG src={`${router.basePath}/img/discord-icon.svg`} className="h-4 w-4" />
  62. }
  63. className="bg-white hover:bg-white/90" // Force white button on all color schemes
  64. >
  65. <span style={{ color: '#404EED' }}>Ask on Discord</span>
  66. </Button>
  67. </Link>
  68. </div>
  69. </div>
  70. </div>
  71. </motion.aside>
  72. )}
  73. </AnimatePresence>
  74. )
  75. }