index.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import UpgradeBtn from '../upgrade-btn'
  5. import { Plan } from '../type'
  6. import cn from '@/utils/classnames'
  7. import { useProviderContext } from '@/context/provider-context'
  8. type Props = {
  9. onClick: () => void
  10. }
  11. const HeaderBillingBtn: FC<Props> = ({
  12. onClick,
  13. }) => {
  14. const { plan, enableBilling, isFetchedPlan } = useProviderContext()
  15. const {
  16. type,
  17. } = plan
  18. const name = (() => {
  19. if (type === Plan.professional)
  20. return 'pro'
  21. return type
  22. })()
  23. const classNames = (() => {
  24. if (type === Plan.professional)
  25. return 'border-[#E0F2FE] hover:border-[#B9E6FE] bg-[#E0F2FE] text-[#026AA2]'
  26. if (type === Plan.team)
  27. return 'border-[#E0EAFF] hover:border-[#C7D7FE] bg-[#E0EAFF] text-[#3538CD]'
  28. return ''
  29. })()
  30. if (!enableBilling || !isFetchedPlan)
  31. return null
  32. if (type === Plan.sandbox)
  33. return <UpgradeBtn onClick={onClick} isShort />
  34. return (
  35. <div onClick={onClick} className={cn(classNames, 'flex items-center h-[22px] px-2 rounded-md border text-xs font-semibold uppercase cursor-pointer')}>
  36. {name}
  37. </div>
  38. )
  39. }
  40. export default React.memo(HeaderBillingBtn)