reactivate-subscription.tsx 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // unless they are a managed group admin (who should be able to reactivate their own subscription)
  21. if (
  22. getMeta('ol-cannot-reactivate-subscription') &&
  23. !getMeta('ol-isManagedGroupAdmin')
  24. ) {
  25. return null
  26. }
  27. return (
  28. <OLButton
  29. variant="primary"
  30. disabled={isLoading || isSuccess}
  31. onClick={handleReactivate}
  32. isLoading={isLoading}
  33. loadingLabel={t('reactivating')}
  34. >
  35. {t('reactivate_subscription')}
  36. </OLButton>
  37. )
  38. }
  39. export default ReactivateSubscription