index.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import useSWR from 'swr'
  6. import {
  7. RiExternalLinkLine,
  8. } from '@remixicon/react'
  9. import PlanComp from '../plan'
  10. import { ReceiptList } from '../../base/icons/src/vender/line/financeAndECommerce'
  11. import { fetchBillingUrl } from '@/service/billing'
  12. import { useAppContext } from '@/context/app-context'
  13. import { useProviderContext } from '@/context/provider-context'
  14. const Billing: FC = () => {
  15. const { t } = useTranslation()
  16. const { isCurrentWorkspaceManager } = useAppContext()
  17. const { enableBilling } = useProviderContext()
  18. const { data: billingUrl } = useSWR(
  19. (!enableBilling || !isCurrentWorkspaceManager) ? null : ['/billing/invoices'],
  20. () => fetchBillingUrl().then(data => data.url),
  21. )
  22. return (
  23. <div>
  24. <PlanComp loc={'billing-page'} />
  25. {enableBilling && isCurrentWorkspaceManager && billingUrl && (
  26. <a className='mt-5 flex px-6 justify-between h-12 items-center bg-gray-50 rounded-xl cursor-pointer' href={billingUrl} target='_blank' rel='noopener noreferrer'>
  27. <div className='flex items-center'>
  28. <ReceiptList className='w-4 h-4 text-gray-700' />
  29. <div className='ml-2 text-sm font-normal text-gray-700'>{t('billing.viewBilling')}</div>
  30. </div>
  31. <RiExternalLinkLine className='w-3 h-3' />
  32. </a>
  33. )}
  34. </div>
  35. )
  36. }
  37. export default React.memo(Billing)