reactivate-subscription.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { useTranslation } from 'react-i18next'
  2. import { postJSON } from '../../../../infrastructure/fetch-json'
  3. import { reactivateSubscriptionUrl } from '../../data/subscription-url'
  4. import useAsync from '../../../../shared/hooks/use-async'
  5. import { useLocation } from '../../../../shared/hooks/use-location'
  6. import getMeta from '../../../../utils/meta'
  7. import { debugConsole } from '@/utils/debugging'
  8. import OLButton from '@/features/ui/components/ol/ol-button'
  9. function ReactivateSubscription() {
  10. const { t } = useTranslation()
  11. const { isLoading, isSuccess, runAsync } = useAsync()
  12. const location = useLocation()
  13. const handleReactivate = () => {
  14. runAsync(postJSON(reactivateSubscriptionUrl)).catch(debugConsole.error)
  15. }
  16. if (isSuccess) {
  17. location.reload()
  18. }
  19. // Don't show the button to reactivate the subscription for managed users
  20. if (getMeta('ol-cannot-reactivate-subscription')) {
  21. return null
  22. }
  23. return (
  24. <OLButton
  25. variant="primary"
  26. disabled={isLoading || isSuccess}
  27. onClick={handleReactivate}
  28. isLoading={isLoading}
  29. >
  30. {t('reactivate_subscription')}
  31. </OLButton>
  32. )
  33. }
  34. export default ReactivateSubscription