index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 PlanComp from '../plan'
  7. import { ReceiptList } from '../../base/icons/src/vender/line/financeAndECommerce'
  8. import { LinkExternal01 } from '../../base/icons/src/vender/line/general'
  9. import { fetchBillingUrl } from '@/service/billing'
  10. import { useAppContext } from '@/context/app-context'
  11. import { useProviderContext } from '@/context/provider-context'
  12. const Billing: FC = () => {
  13. const { t } = useTranslation()
  14. const { isCurrentWorkspaceManager } = useAppContext()
  15. const { enableBilling } = useProviderContext()
  16. const { data: billingUrl } = useSWR(
  17. (!enableBilling || !isCurrentWorkspaceManager) ? null : ['/billing/invoices'],
  18. () => fetchBillingUrl().then(data => data.url),
  19. )
  20. return (
  21. <div>
  22. <PlanComp loc={'billing-page'} />
  23. {enableBilling && isCurrentWorkspaceManager && billingUrl && (
  24. <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'>
  25. <div className='flex items-center'>
  26. <ReceiptList className='w-4 h-4 text-gray-700' />
  27. <div className='ml-2 text-sm font-normal text-gray-700'>{t('billing.viewBilling')}</div>
  28. </div>
  29. <LinkExternal01 className='w-3 h-3' />
  30. </a>
  31. )}
  32. </div>
  33. )
  34. }
  35. export default React.memo(Billing)