index.tsx 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { GoldCoin } from '../../base/icons/src/vender/solid/FinanceAndECommerce'
  6. import { Sparkles } from '../../base/icons/src/public/billing'
  7. import s from './style.module.css'
  8. import cn from '@/utils/classnames'
  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. handleClick()
  51. if (loc && (window as any).gtag) {
  52. (window as any).gtag('event', 'click_upgrade_btn', {
  53. loc,
  54. })
  55. }
  56. }
  57. if (isPlain)
  58. return <PlainBtn onClick={onClick} className={className} />
  59. return (
  60. <div
  61. className={cn(
  62. s.upgradeBtn,
  63. className,
  64. isFull ? 'justify-center' : 'px-3',
  65. size === 'lg' ? 'h-10' : 'h-9',
  66. 'relative flex items-center cursor-pointer border rounded-[20px] border-[#0096EA] text-white',
  67. )}
  68. onClick={onClick}
  69. >
  70. <GoldCoin className='mr-1 w-3.5 h-3.5' />
  71. <div className='text-xs font-normal'>{t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}</div>
  72. <Sparkles
  73. className='absolute -right-1 -top-2 w-4 h-5 bg-cover'
  74. />
  75. </div>
  76. )
  77. }
  78. export default React.memo(UpgradeBtn)