'use client' import type { FC } from 'react' import React, { useCallback } from 'react' import { useTranslation } from 'react-i18next' import { SelfHostedPlan } from '../../../type' import { contactSalesUrl, getStartedWithCommunityUrl, getWithPremiumUrl } from '../../../config' import Toast from '../../../../base/toast' import cn from '@/utils/classnames' import { useAppContext } from '@/context/app-context' import Button from './button' import List from './list' import { Azure, GoogleCloud } from '@/app/components/base/icons/src/public/billing' import { Community, Enterprise, EnterpriseNoise, Premium, PremiumNoise } from '../../assets' const STYLE_MAP = { [SelfHostedPlan.community]: { icon: , bg: '', noise: null, }, [SelfHostedPlan.premium]: { icon: , bg: 'bg-billing-plan-card-premium-bg opacity-10', noise: (
), }, [SelfHostedPlan.enterprise]: { icon: , bg: 'bg-billing-plan-card-enterprise-bg opacity-10', noise: (
), }, } type SelfHostedPlanItemProps = { plan: SelfHostedPlan } const SelfHostedPlanItem: FC = ({ plan, }) => { const { t } = useTranslation() const i18nPrefix = `billing.plans.${plan}` const isFreePlan = plan === SelfHostedPlan.community const isPremiumPlan = plan === SelfHostedPlan.premium const isEnterprisePlan = plan === SelfHostedPlan.enterprise const { isCurrentWorkspaceManager } = useAppContext() const handleGetPayUrl = useCallback(() => { // Only workspace manager can buy plan if (!isCurrentWorkspaceManager) { Toast.notify({ type: 'error', message: t('billing.buyPermissionDeniedTip'), className: 'z-[1001]', }) return } if (isFreePlan) { window.location.href = getStartedWithCommunityUrl return } if (isPremiumPlan) { window.location.href = getWithPremiumUrl return } if (isEnterprisePlan) window.location.href = contactSalesUrl }, [isCurrentWorkspaceManager, isFreePlan, isPremiumPlan, isEnterprisePlan, t]) return (
{/* Noise Effect */} {STYLE_MAP[plan].noise}
{STYLE_MAP[plan].icon}
{t(`${i18nPrefix}.name`)}
{t(`${i18nPrefix}.description`)}
{/* Price */}
{t(`${i18nPrefix}.price`)}
{!isFreePlan && ( {t(`${i18nPrefix}.priceTip`)} )}
{isPremiumPlan && (
{t('billing.plans.premium.comingSoon')}
)}
) } export default React.memo(SelfHostedPlanItem)