2023-02-28 04:48:48 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { postJSON } from '../../../../infrastructure/fetch-json'
|
|
|
|
import { reactivateSubscriptionUrl } from '../../data/subscription-url'
|
|
|
|
import useAsync from '../../../../shared/hooks/use-async'
|
2023-03-16 08:32:48 -04:00
|
|
|
import { useLocation } from '../../../../shared/hooks/use-location'
|
2023-07-20 06:14:12 -04:00
|
|
|
import getMeta from '../../../../utils/meta'
|
2023-02-28 04:48:48 -05:00
|
|
|
|
|
|
|
function ReactivateSubscription() {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const { isLoading, isSuccess, runAsync } = useAsync()
|
2023-03-16 08:32:48 -04:00
|
|
|
const location = useLocation()
|
2023-02-28 04:48:48 -05:00
|
|
|
|
|
|
|
const handleReactivate = () => {
|
|
|
|
runAsync(postJSON(reactivateSubscriptionUrl)).catch(console.error)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSuccess) {
|
2023-03-16 08:32:48 -04:00
|
|
|
location.reload()
|
2023-02-28 04:48:48 -05:00
|
|
|
}
|
|
|
|
|
2023-07-20 06:14:12 -04:00
|
|
|
// Don't show the button to reactivate the subscription for managed users
|
|
|
|
if (getMeta('ol-cannot-reactivate-subscription')) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
2023-02-28 04:48:48 -05:00
|
|
|
return (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-primary"
|
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
onClick={handleReactivate}
|
|
|
|
>
|
|
|
|
{t('reactivate_subscription')}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReactivateSubscription
|