index.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import PremiumBadge from '../../base/premium-badge'
  6. import { SparklesSoft } from '@/app/components/base/icons/src/public/common'
  7. import cn from '@/utils/classnames'
  8. import { useModalContext } from '@/context/modal-context'
  9. type Props = {
  10. className?: string
  11. isFull?: boolean
  12. size?: 'md' | 'lg'
  13. isPlain?: boolean
  14. isShort?: boolean
  15. onClick?: () => void
  16. loc?: string
  17. }
  18. const PlainBtn = ({ className, onClick }: { className?: string; onClick: () => void }) => {
  19. const { t } = useTranslation()
  20. return (
  21. <div
  22. className={cn(className, 'flex items-center h-8 px-3 rounded-lg border border-gray-200 bg-white shadow-sm cursor-pointer')}
  23. onClick={onClick}
  24. >
  25. <div className='leading-[18px] text-[13px] font-medium text-gray-700'>
  26. {t('billing.upgradeBtn.plain')}
  27. </div>
  28. </div>
  29. )
  30. }
  31. const UpgradeBtn: FC<Props> = ({
  32. className,
  33. isPlain = false,
  34. isShort = false,
  35. onClick: _onClick,
  36. loc,
  37. }) => {
  38. const { t } = useTranslation()
  39. const { setShowPricingModal } = useModalContext()
  40. const handleClick = () => {
  41. if (_onClick)
  42. _onClick()
  43. else
  44. (setShowPricingModal as any)()
  45. }
  46. const onClick = () => {
  47. handleClick()
  48. if (loc && (window as any).gtag) {
  49. (window as any).gtag('event', 'click_upgrade_btn', {
  50. loc,
  51. })
  52. }
  53. }
  54. if (isPlain)
  55. return <PlainBtn onClick={onClick} className={className} />
  56. return (
  57. <PremiumBadge
  58. size="m"
  59. color="blue"
  60. allowHover={true}
  61. onClick={onClick}
  62. >
  63. <SparklesSoft className='flex items-center py-[1px] pl-[3px] w-3.5 h-3.5 text-components-premium-badge-indigo-text-stop-0' />
  64. <div className='system-xs-medium'>
  65. <span className='p-1'>
  66. {t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}
  67. </span>
  68. </div>
  69. </PremiumBadge>
  70. )
  71. }
  72. export default React.memo(UpgradeBtn)