You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { useRouter } from 'next/navigation'
  6. import {
  7. RiBook2Line,
  8. RiFileEditLine,
  9. RiGraduationCapLine,
  10. RiGroupLine,
  11. } from '@remixicon/react'
  12. import { Plan, SelfHostedPlan } from '../type'
  13. import VectorSpaceInfo from '../usage-info/vector-space-info'
  14. import AppsInfo from '../usage-info/apps-info'
  15. import UpgradeBtn from '../upgrade-btn'
  16. import { useProviderContext } from '@/context/provider-context'
  17. import { useAppContext } from '@/context/app-context'
  18. import Button from '@/app/components/base/button'
  19. import UsageInfo from '@/app/components/billing/usage-info'
  20. import VerifyStateModal from '@/app/education-apply/verify-state-modal'
  21. import { EDUCATION_VERIFYING_LOCALSTORAGE_ITEM } from '@/app/education-apply/constants'
  22. import { useEducationVerify } from '@/service/use-education'
  23. import { useModalContextSelector } from '@/context/modal-context'
  24. import { Enterprise, Professional, Sandbox, Team } from './assets'
  25. type Props = {
  26. loc: string
  27. }
  28. const PlanComp: FC<Props> = ({
  29. loc,
  30. }) => {
  31. const { t } = useTranslation()
  32. const router = useRouter()
  33. const { userProfile } = useAppContext()
  34. const { plan, enableEducationPlan, allowRefreshEducationVerify, isEducationAccount } = useProviderContext()
  35. const isAboutToExpire = allowRefreshEducationVerify
  36. const {
  37. type,
  38. } = plan
  39. const {
  40. usage,
  41. total,
  42. } = plan
  43. const [showModal, setShowModal] = React.useState(false)
  44. const { mutateAsync } = useEducationVerify()
  45. const setShowAccountSettingModal = useModalContextSelector(s => s.setShowAccountSettingModal)
  46. const handleVerify = () => {
  47. mutateAsync().then((res) => {
  48. localStorage.removeItem(EDUCATION_VERIFYING_LOCALSTORAGE_ITEM)
  49. router.push(`/education-apply?token=${res.token}`)
  50. setShowAccountSettingModal(null)
  51. }).catch(() => {
  52. setShowModal(true)
  53. })
  54. }
  55. return (
  56. <div className='relative rounded-2xl border-[0.5px] border-effects-highlight-lightmode-off bg-background-section-burn'>
  57. <div className='p-6 pb-2'>
  58. {plan.type === Plan.sandbox && (
  59. <Sandbox />
  60. )}
  61. {plan.type === Plan.professional && (
  62. <Professional />
  63. )}
  64. {plan.type === Plan.team && (
  65. <Team />
  66. )}
  67. {(plan.type as any) === SelfHostedPlan.enterprise && (
  68. <Enterprise />
  69. )}
  70. <div className='mt-1 flex items-center'>
  71. <div className='grow'>
  72. <div className='mb-1 flex items-center gap-1'>
  73. <div className='system-md-semibold-uppercase text-text-primary'>{t(`billing.plans.${type}.name`)}</div>
  74. <div className='system-2xs-medium-uppercase rounded-[5px] border border-divider-deep px-1 py-0.5 text-text-tertiary'>{t('billing.currentPlan')}</div>
  75. </div>
  76. <div className='system-xs-regular text-util-colors-gray-gray-600'>{t(`billing.plans.${type}.for`)}</div>
  77. </div>
  78. <div className='flex shrink-0 items-center gap-1'>
  79. {enableEducationPlan && (!isEducationAccount || isAboutToExpire) && (
  80. <Button variant='ghost' onClick={handleVerify}>
  81. <RiGraduationCapLine className='mr-1 h-4 w-4' />
  82. {t('education.toVerified')}
  83. </Button>
  84. )}
  85. {(plan.type as any) !== SelfHostedPlan.enterprise && (
  86. <UpgradeBtn
  87. className='shrink-0'
  88. isPlain={type === Plan.team}
  89. isShort
  90. loc={loc}
  91. />
  92. )}
  93. </div>
  94. </div>
  95. </div>
  96. {/* Plan detail */}
  97. <div className='grid grid-cols-3 content-start gap-1 p-2'>
  98. <AppsInfo />
  99. <UsageInfo
  100. Icon={RiGroupLine}
  101. name={t('billing.usagePage.teamMembers')}
  102. usage={usage.teamMembers}
  103. total={total.teamMembers}
  104. />
  105. <UsageInfo
  106. Icon={RiBook2Line}
  107. name={t('billing.usagePage.documentsUploadQuota')}
  108. usage={usage.documentsUploadQuota}
  109. total={total.documentsUploadQuota}
  110. />
  111. <VectorSpaceInfo />
  112. <UsageInfo
  113. Icon={RiFileEditLine}
  114. name={t('billing.usagePage.annotationQuota')}
  115. usage={usage.annotatedResponse}
  116. total={total.annotatedResponse}
  117. />
  118. </div>
  119. <VerifyStateModal
  120. showLink
  121. email={userProfile.email}
  122. isShow={showModal}
  123. title={t('education.rejectTitle')}
  124. content={t('education.rejectContent')}
  125. onConfirm={() => setShowModal(false)}
  126. onCancel={() => setShowModal(false)}
  127. />
  128. </div>
  129. )
  130. }
  131. export default React.memo(PlanComp)