index.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. RiArrowRightUpLine,
  8. } from '@remixicon/react'
  9. import PlanComp from '../plan'
  10. import Divider from '@/app/components/base/divider'
  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. <>
  27. <Divider className='my-4' />
  28. <a className='flex items-center text-text-accent-light-mode-only system-xs-medium cursor-pointer' href={billingUrl} target='_blank' rel='noopener noreferrer'>
  29. <span className='pr-0.5'>{t('billing.viewBilling')}</span>
  30. <RiArrowRightUpLine className='w-4 h-4' />
  31. </a>
  32. </>
  33. )}
  34. </div>
  35. )
  36. }
  37. export default React.memo(Billing)