41 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

'use client'
import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import useSWR from 'swr'
2024-06-20 11:05:08 +08:00
import {
2025-03-07 11:56:20 +08:00
RiArrowRightUpLine,
2024-06-20 11:05:08 +08:00
} from '@remixicon/react'
import PlanComp from '../plan'
2025-03-07 11:56:20 +08:00
import Divider from '@/app/components/base/divider'
import { fetchBillingUrl } from '@/service/billing'
import { useAppContext } from '@/context/app-context'
import { useProviderContext } from '@/context/provider-context'
const Billing: FC = () => {
const { t } = useTranslation()
const { isCurrentWorkspaceManager } = useAppContext()
const { enableBilling } = useProviderContext()
const { data: billingUrl } = useSWR(
(!enableBilling || !isCurrentWorkspaceManager) ? null : ['/billing/invoices'],
() => fetchBillingUrl().then(data => data.url),
)
return (
<div>
2023-12-05 15:05:05 +08:00
<PlanComp loc={'billing-page'} />
{enableBilling && isCurrentWorkspaceManager && billingUrl && (
2025-03-07 11:56:20 +08:00
<>
<Divider className='my-4' />
<a className='system-xs-medium flex cursor-pointer items-center text-text-accent-light-mode-only' href={billingUrl} target='_blank' rel='noopener noreferrer'>
2025-03-07 11:56:20 +08:00
<span className='pr-0.5'>{t('billing.viewBilling')}</span>
<RiArrowRightUpLine className='h-4 w-4' />
2025-03-07 11:56:20 +08:00
</a>
</>
)}
</div>
)
}
export default React.memo(Billing)