index.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 Button from '@/app/components/base/button'
  7. import { SparklesSoft } from '@/app/components/base/icons/src/public/common'
  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 UpgradeBtn: FC<Props> = ({
  19. isPlain = false,
  20. isShort = false,
  21. onClick: _onClick,
  22. loc,
  23. }) => {
  24. const { t } = useTranslation()
  25. const { setShowPricingModal } = useModalContext()
  26. const handleClick = () => {
  27. if (_onClick)
  28. _onClick()
  29. else
  30. (setShowPricingModal as any)()
  31. }
  32. const onClick = () => {
  33. handleClick()
  34. if (loc && (window as any).gtag) {
  35. (window as any).gtag('event', 'click_upgrade_btn', {
  36. loc,
  37. })
  38. }
  39. }
  40. if (isPlain) {
  41. return (
  42. <Button onClick={onClick}>
  43. {t('billing.upgradeBtn.plain')}
  44. </Button>
  45. )
  46. }
  47. return (
  48. <PremiumBadge
  49. size="m"
  50. color="blue"
  51. allowHover={true}
  52. onClick={onClick}
  53. >
  54. <SparklesSoft className='flex items-center py-[1px] pl-[3px] w-3.5 h-3.5 text-components-premium-badge-indigo-text-stop-0' />
  55. <div className='system-xs-medium'>
  56. <span className='p-1'>
  57. {t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}
  58. </span>
  59. </div>
  60. </PremiumBadge>
  61. )
  62. }
  63. export default React.memo(UpgradeBtn)