index.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import cn from 'classnames'
  6. import { GoldCoin } from '../../base/icons/src/vender/solid/FinanceAndECommerce'
  7. import { Sparkles } from '../../base/icons/src/public/billing'
  8. import s from './style.module.css'
  9. import { useModalContext } from '@/context/modal-context'
  10. type Props = {
  11. className?: string
  12. isFull?: boolean
  13. size?: 'md' | 'lg'
  14. isPlain?: boolean
  15. isShort?: boolean
  16. onClick?: () => void
  17. gaEventName?: string
  18. }
  19. const PlainBtn = ({ className, onClick }: { className?: string; onClick: () => void }) => {
  20. const { t } = useTranslation()
  21. return (
  22. <div
  23. className={cn(className, 'flex items-center h-8 px-3 rounded-lg border border-gray-200 bg-white shadow-sm cursor-pointer')}
  24. onClick={onClick}
  25. >
  26. <div className='leading-[18px] text-[13px] font-medium text-gray-700'>
  27. {t('billing.upgradeBtn.plain')}
  28. </div>
  29. </div>
  30. )
  31. }
  32. const UpgradeBtn: FC<Props> = ({
  33. className,
  34. isPlain = false,
  35. isFull = false,
  36. isShort = false,
  37. size = 'md',
  38. onClick: _onClick,
  39. gaEventName,
  40. }) => {
  41. const { t } = useTranslation()
  42. const { setShowPricingModal } = useModalContext()
  43. const onClick = () => {
  44. if (gaEventName)
  45. (window as any).dataLayer.push({ event: gaEventName })
  46. if (_onClick)
  47. _onClick()
  48. else
  49. (setShowPricingModal as any)()
  50. }
  51. if (isPlain)
  52. return <PlainBtn onClick={onClick} className={className} />
  53. return (
  54. <div
  55. className={cn(
  56. s.upgradeBtn,
  57. className,
  58. isFull ? 'justify-center' : 'px-3',
  59. size === 'lg' ? 'h-10' : 'h-9',
  60. 'relative flex items-center cursor-pointer border rounded-[20px] border-[#0096EA] text-white',
  61. )}
  62. onClick={onClick}
  63. >
  64. <GoldCoin className='mr-1 w-3.5 h-3.5' />
  65. <div className='text-xs font-normal'>{t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}</div>
  66. <Sparkles
  67. className='absolute -right-1 -top-2 w-4 h-5 bg-cover'
  68. />
  69. </div>
  70. )
  71. }
  72. export default React.memo(UpgradeBtn)