ToggleSpendCapButton.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Link from 'next/link'
  2. import { PropsWithChildren } from 'react'
  3. import { Button } from 'ui'
  4. import { SupportLink } from '@/components/interfaces/Support/SupportLink'
  5. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  6. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  7. interface ToggleSpendCapButtonProps {
  8. action?: 'disable' | 'enable'
  9. type?: 'default' | 'primary'
  10. }
  11. export const ToggleSpendCapButton = ({
  12. action = 'disable',
  13. type = 'default',
  14. children,
  15. }: PropsWithChildren<ToggleSpendCapButtonProps>) => {
  16. const { data: organization } = useSelectedOrganizationQuery()
  17. const slug = organization?.slug ?? '_'
  18. const { billingAll } = useIsFeatureEnabled(['billing:all'])
  19. const subject = `Enquiry to ${action} spend cap for organization`
  20. const message = `Name: ${organization?.name}\nSlug: ${organization?.slug}`
  21. const href = billingAll ? `/org/${slug}/billing?panel=costControl` : ''
  22. const linkChildren = children || `${action} spend cap`
  23. const link = billingAll ? (
  24. <Link href={href} className="capitalize">
  25. {linkChildren}
  26. </Link>
  27. ) : (
  28. <SupportLink queryParams={{ orgSlug: slug, category: 'Plan_upgrade', subject, message }}>
  29. {linkChildren}
  30. </SupportLink>
  31. )
  32. return (
  33. <Button type={type} asChild>
  34. {link}
  35. </Button>
  36. )
  37. }