'use client' import type { FC, ReactNode } from 'react' import React from 'react' import { useTranslation } from 'react-i18next' import { RiArrowRightUpLine, RiBrain2Line, RiCheckLine, RiQuestionLine } from '@remixicon/react' import { SelfHostedPlan } from '../type' import { contactSalesUrl, getStartedWithCommunityUrl, getWithPremiumUrl } from '../config' import Toast from '../../base/toast' import Tooltip from '../../base/tooltip' import { Asterisk, AwsMarketplace, Azure, Buildings, Diamond, GoogleCloud } from '../../base/icons/src/public/billing' import type { PlanRange } from './select-plan-range' import cn from '@/utils/classnames' import { useAppContext } from '@/context/app-context' type Props = { plan: SelfHostedPlan planRange: PlanRange canPay: boolean } const KeyValue = ({ label, tooltip, textColor, tooltipIconColor }: { icon: ReactNode; label: string; tooltip?: string; textColor: string; tooltipIconColor: string }) => { return (
{label}
{tooltip && (
)}
) } const style = { [SelfHostedPlan.community]: { icon: , title: 'text-text-primary', price: 'text-text-primary', priceTip: 'text-text-tertiary', description: 'text-util-colors-gray-gray-600', bg: 'border-effects-highlight-lightmode-off bg-background-section-burn', btnStyle: 'bg-components-button-secondary-bg hover:bg-components-button-secondary-bg-hover border-[0.5px] border-components-button-secondary-border text-text-primary', values: 'text-text-secondary', tooltipIconColor: 'text-text-tertiary', }, [SelfHostedPlan.premium]: { icon: , title: 'text-text-primary', price: 'text-text-primary', priceTip: 'text-text-tertiary', description: 'text-text-warning', bg: 'border-effects-highlight bg-background-section-burn', btnStyle: 'bg-third-party-aws hover:bg-third-party-aws-hover border border-components-button-primary-border text-text-primary-on-surface shadow-xs', values: 'text-text-secondary', tooltipIconColor: 'text-text-tertiary', }, [SelfHostedPlan.enterprise]: { icon: , title: 'text-text-primary-on-surface', price: 'text-text-primary-on-surface', priceTip: 'text-text-primary-on-surface', description: 'text-text-primary-on-surface', bg: 'border-effects-highlight bg-[#155AEF] text-text-primary-on-surface', btnStyle: 'bg-white bg-opacity-96 hover:opacity-85 border-[0.5px] border-components-button-secondary-border text-[#155AEF] shadow-xs', values: 'text-text-primary-on-surface', tooltipIconColor: 'text-text-primary-on-surface', }, } const SelfHostedPlanItem: FC = ({ plan, }) => { const { t } = useTranslation() const isFreePlan = plan === SelfHostedPlan.community const isPremiumPlan = plan === SelfHostedPlan.premium const i18nPrefix = `billing.plans.${plan}` const isEnterprisePlan = plan === SelfHostedPlan.enterprise const { isCurrentWorkspaceManager } = useAppContext() const features = t(`${i18nPrefix}.features`, { returnObjects: true }) as string[] const handleGetPayUrl = () => { // 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 } return (
{isEnterprisePlan &&
} {isEnterprisePlan &&
}
{style[plan].icon}
{t(`${i18nPrefix}.name`)}
{t(`${i18nPrefix}.description`)}
{t(`${i18nPrefix}.price`)}
{!isFreePlan && {t(`${i18nPrefix}.priceTip`)} }
{t(`${i18nPrefix}.btnText`)} {isPremiumPlan && <>
}
{t(`${i18nPrefix}.includesTitle`)}
{features.map(v => } label={v} />)}
{isPremiumPlan &&
{t('billing.plans.premium.comingSoon')}
}
) } export default React.memo(SelfHostedPlanItem)