reactivate-subscription.tsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. function ReactivateSubscription() {
  9. const { t } = useTranslation()
  10. const { isLoading, isSuccess, runAsync } = useAsync()
  11. const location = useLocation()
  12. const handleReactivate = () => {
  13. runAsync(postJSON(reactivateSubscriptionUrl)).catch(debugConsole.error)
  14. }
  15. if (isSuccess) {
  16. location.reload()
  17. }
  18. // Don't show the button to reactivate the subscription for managed users
  19. if (getMeta('ol-cannot-reactivate-subscription')) {
  20. return null
  21. }
  22. return (
  23. <button
  24. type="button"
  25. className="btn btn-primary"
  26. disabled={isLoading || isSuccess}
  27. onClick={handleReactivate}
  28. >
  29. {t('reactivate_subscription')}
  30. </button>
  31. )
  32. }
  33. export default ReactivateSubscription