index.tsx 1.5 KB

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