feat: SaaS price plan frontend (#1683)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
32
web/app/components/billing/usage-info/apps-info.tsx
Normal file
32
web/app/components/billing/usage-info/apps-info.tsx
Normal file
@@ -0,0 +1,32 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ChatBot } from '../../base/icons/src/vender/line/communication'
|
||||
import UsageInfo from '../usage-info'
|
||||
import { useProviderContext } from '@/context/provider-context'
|
||||
|
||||
type Props = {
|
||||
className?: string
|
||||
}
|
||||
|
||||
const AppsInfo: FC<Props> = ({
|
||||
className,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { plan } = useProviderContext()
|
||||
const {
|
||||
usage,
|
||||
total,
|
||||
} = plan
|
||||
return (
|
||||
<UsageInfo
|
||||
className={className}
|
||||
Icon={ChatBot}
|
||||
name={t('billing.plansCommon.buildApps')}
|
||||
usage={usage.buildApps}
|
||||
total={total.buildApps}
|
||||
/>
|
||||
)
|
||||
}
|
||||
export default React.memo(AppsInfo)
|
||||
75
web/app/components/billing/usage-info/index.tsx
Normal file
75
web/app/components/billing/usage-info/index.tsx
Normal file
@@ -0,0 +1,75 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { InfoCircle } from '../../base/icons/src/vender/line/general'
|
||||
import ProgressBar from '../progress-bar'
|
||||
import { NUM_INFINITE } from '../config'
|
||||
import Tooltip from '@/app/components/base/tooltip'
|
||||
|
||||
type Props = {
|
||||
className?: string
|
||||
Icon: any
|
||||
name: string
|
||||
tooltip?: string
|
||||
usage: number
|
||||
total: number
|
||||
unit?: string
|
||||
}
|
||||
|
||||
const LOW = 50
|
||||
const MIDDLE = 80
|
||||
|
||||
const UsageInfo: FC<Props> = ({
|
||||
className,
|
||||
Icon,
|
||||
name,
|
||||
tooltip,
|
||||
usage,
|
||||
total,
|
||||
unit = '',
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const percent = usage / total * 100
|
||||
const color = (() => {
|
||||
if (percent < LOW)
|
||||
return '#155EEF'
|
||||
|
||||
if (percent < MIDDLE)
|
||||
return '#F79009'
|
||||
|
||||
return '#F04438'
|
||||
})()
|
||||
return (
|
||||
<div className={className}>
|
||||
<div className='flex justify-between h-5 items-center'>
|
||||
<div className='flex items-center'>
|
||||
<Icon className='w-4 h-4 text-gray-700' />
|
||||
<div className='mx-1 leading-5 text-sm font-medium text-gray-700'>{name}</div>
|
||||
{tooltip && (
|
||||
<Tooltip htmlContent={<div className='w-[180px]'>
|
||||
{tooltip}
|
||||
</div>} selector='config-var-tooltip'>
|
||||
<InfoCircle className='w-[14px] h-[14px] text-gray-400' />
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<div className='flex items-center leading-[18px] text-[13px] font-normal'>
|
||||
<div style={{
|
||||
color: percent < LOW ? '#344054' : color,
|
||||
}}>{usage}{unit}</div>
|
||||
<div className='mx-1 text-gray-300'>/</div>
|
||||
<div className='text-gray-500'>{total === NUM_INFINITE ? t('billing.plansCommon.unlimited') : `${total}${unit}`}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className='mt-2'>
|
||||
<ProgressBar
|
||||
percent={percent}
|
||||
color={color}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
export default React.memo(UsageInfo)
|
||||
34
web/app/components/billing/usage-info/vector-space-info.tsx
Normal file
34
web/app/components/billing/usage-info/vector-space-info.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
'use client'
|
||||
import type { FC } from 'react'
|
||||
import React from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ArtificialBrain } from '../../base/icons/src/vender/line/development'
|
||||
import UsageInfo from '../usage-info'
|
||||
import { useProviderContext } from '@/context/provider-context'
|
||||
|
||||
type Props = {
|
||||
className?: string
|
||||
}
|
||||
|
||||
const VectorSpaceInfo: FC<Props> = ({
|
||||
className,
|
||||
}) => {
|
||||
const { t } = useTranslation()
|
||||
const { plan } = useProviderContext()
|
||||
const {
|
||||
usage,
|
||||
total,
|
||||
} = plan
|
||||
return (
|
||||
<UsageInfo
|
||||
className={className}
|
||||
Icon={ArtificialBrain}
|
||||
name={t('billing.plansCommon.vectorSpace')}
|
||||
tooltip={t('billing.plansCommon.vectorSpaceTooltip') as string}
|
||||
usage={usage.vectorSpace}
|
||||
total={total.vectorSpace}
|
||||
unit='MB'
|
||||
/>
|
||||
)
|
||||
}
|
||||
export default React.memo(VectorSpaceInfo)
|
||||
Reference in New Issue
Block a user