reactivate-subscription.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 '@/shared/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. loadingLabel={t('reactivating')}
  30. >
  31. {t('reactivate_subscription')}
  32. </OLButton>
  33. )
  34. }
  35. export default ReactivateSubscription