index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. loc?: 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. loc,
  40. }) => {
  41. const { t } = useTranslation()
  42. const { setShowPricingModal } = useModalContext()
  43. const handleClick = () => {
  44. if (_onClick)
  45. _onClick()
  46. else
  47. (setShowPricingModal as any)()
  48. }
  49. const onClick = () => {
  50. if (loc && (window as any).gtag) {
  51. (window as any).gtag('event', 'click_upgrade_btn', {
  52. loc,
  53. event_callback: handleClick,
  54. })
  55. }
  56. else {
  57. handleClick()
  58. }
  59. }
  60. if (isPlain)
  61. return <PlainBtn onClick={onClick} className={className} />
  62. return (
  63. <div
  64. className={cn(
  65. s.upgradeBtn,
  66. className,
  67. isFull ? 'justify-center' : 'px-3',
  68. size === 'lg' ? 'h-10' : 'h-9',
  69. 'relative flex items-center cursor-pointer border rounded-[20px] border-[#0096EA] text-white',
  70. )}
  71. onClick={onClick}
  72. >
  73. <GoldCoin className='mr-1 w-3.5 h-3.5' />
  74. <div className='text-xs font-normal'>{t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}</div>
  75. <Sparkles
  76. className='absolute -right-1 -top-2 w-4 h-5 bg-cover'
  77. />
  78. </div>
  79. )
  80. }
  81. export default React.memo(UpgradeBtn)