Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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