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.

button.tsx 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { useMemo } from 'react'
  2. import { SelfHostedPlan } from '../../../type'
  3. import { AwsMarketplaceDark, AwsMarketplaceLight } from '@/app/components/base/icons/src/public/billing'
  4. import { RiArrowRightLine } from '@remixicon/react'
  5. import cn from '@/utils/classnames'
  6. import { useTranslation } from 'react-i18next'
  7. import useTheme from '@/hooks/use-theme'
  8. import { Theme } from '@/types/app'
  9. const BUTTON_CLASSNAME = {
  10. [SelfHostedPlan.community]: 'text-text-primary bg-components-button-tertiary-bg hover:bg-components-button-tertiary-bg-hover',
  11. [SelfHostedPlan.premium]: 'text-background-default bg-saas-background-inverted hover:bg-saas-background-inverted-hover',
  12. [SelfHostedPlan.enterprise]: 'text-text-primary-on-surface bg-saas-dify-blue-static hover:bg-saas-dify-blue-static-hover',
  13. }
  14. type ButtonProps = {
  15. plan: SelfHostedPlan
  16. handleGetPayUrl: () => void
  17. }
  18. const Button = ({
  19. plan,
  20. handleGetPayUrl,
  21. }: ButtonProps) => {
  22. const { t } = useTranslation()
  23. const { theme } = useTheme()
  24. const i18nPrefix = `billing.plans.${plan}`
  25. const isPremiumPlan = plan === SelfHostedPlan.premium
  26. const AwsMarketplace = useMemo(() => {
  27. return theme === Theme.light ? AwsMarketplaceLight : AwsMarketplaceDark
  28. }, [theme])
  29. return (
  30. <button type="button"
  31. className={cn(
  32. 'system-xl-semibold flex items-center gap-x-2 py-3 pl-5 pr-4',
  33. BUTTON_CLASSNAME[plan],
  34. isPremiumPlan && 'py-2',
  35. )}
  36. onClick={handleGetPayUrl}
  37. >
  38. <div className='flex grow items-center gap-x-2'>
  39. <span>{t(`${i18nPrefix}.btnText`)}</span>
  40. {isPremiumPlan && (
  41. <span className='pb-px pt-[7px]'>
  42. <AwsMarketplace className='h-6' />
  43. </span>
  44. )}
  45. </div>
  46. <RiArrowRightLine className='size-5 shrink-0' />
  47. </button>
  48. )
  49. }
  50. export default React.memo(Button)