2023-12-03 22:10:16 +08:00
|
|
|
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
2025-02-17 17:05:13 +08:00
|
|
|
import PremiumBadge from '../../base/premium-badge'
|
|
|
|
import { SparklesSoft } from '@/app/components/base/icons/src/public/common'
|
2024-07-09 15:05:40 +08:00
|
|
|
import cn from '@/utils/classnames'
|
2023-12-03 22:10:16 +08:00
|
|
|
import { useModalContext } from '@/context/modal-context'
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
className?: string
|
|
|
|
isFull?: boolean
|
|
|
|
size?: 'md' | 'lg'
|
|
|
|
isPlain?: boolean
|
|
|
|
isShort?: boolean
|
|
|
|
onClick?: () => void
|
2023-12-05 15:05:05 +08:00
|
|
|
loc?: string
|
2023-12-03 22:10:16 +08:00
|
|
|
}
|
|
|
|
|
2023-12-04 18:16:59 +08:00
|
|
|
const PlainBtn = ({ className, onClick }: { className?: string; onClick: () => void }) => {
|
2023-12-03 22:10:16 +08:00
|
|
|
const { t } = useTranslation()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={cn(className, 'flex items-center h-8 px-3 rounded-lg border border-gray-200 bg-white shadow-sm cursor-pointer')}
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
<div className='leading-[18px] text-[13px] font-medium text-gray-700'>
|
|
|
|
{t('billing.upgradeBtn.plain')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const UpgradeBtn: FC<Props> = ({
|
|
|
|
className,
|
|
|
|
isPlain = false,
|
|
|
|
isShort = false,
|
2023-12-04 18:16:59 +08:00
|
|
|
onClick: _onClick,
|
2023-12-05 15:05:05 +08:00
|
|
|
loc,
|
2023-12-03 22:10:16 +08:00
|
|
|
}) => {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { setShowPricingModal } = useModalContext()
|
2023-12-05 15:05:05 +08:00
|
|
|
const handleClick = () => {
|
2023-12-04 18:16:59 +08:00
|
|
|
if (_onClick)
|
|
|
|
_onClick()
|
|
|
|
else
|
|
|
|
(setShowPricingModal as any)()
|
|
|
|
}
|
2023-12-05 15:05:05 +08:00
|
|
|
const onClick = () => {
|
2023-12-11 16:36:58 +08:00
|
|
|
handleClick()
|
2023-12-05 15:05:05 +08:00
|
|
|
if (loc && (window as any).gtag) {
|
|
|
|
(window as any).gtag('event', 'click_upgrade_btn', {
|
|
|
|
loc,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2023-12-03 22:10:16 +08:00
|
|
|
|
|
|
|
if (isPlain)
|
2023-12-04 18:16:59 +08:00
|
|
|
return <PlainBtn onClick={onClick} className={className} />
|
2023-12-03 22:10:16 +08:00
|
|
|
|
|
|
|
return (
|
2025-02-17 17:05:13 +08:00
|
|
|
<PremiumBadge
|
|
|
|
size="m"
|
|
|
|
color="blue"
|
|
|
|
allowHover={true}
|
2023-12-04 18:16:59 +08:00
|
|
|
onClick={onClick}
|
2023-12-03 22:10:16 +08:00
|
|
|
>
|
2025-02-17 17:05:13 +08:00
|
|
|
<SparklesSoft className='flex items-center py-[1px] pl-[3px] w-3.5 h-3.5 text-components-premium-badge-indigo-text-stop-0' />
|
|
|
|
<div className='system-xs-medium'>
|
|
|
|
<span className='p-1'>
|
|
|
|
{t(`billing.upgradeBtn.${isShort ? 'encourageShort' : 'encourage'}`)}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</PremiumBadge>
|
2023-12-03 22:10:16 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
export default React.memo(UpgradeBtn)
|