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-09-27 05:45:49 -04:00
|
|
|
import { debugConsole } from '@/utils/debugging'
|
2024-09-30 05:49:18 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
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 = () => {
|
2023-09-27 05:45:49 -04:00
|
|
|
runAsync(postJSON(reactivateSubscriptionUrl)).catch(debugConsole.error)
|
2023-02-28 04:48:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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 (
|
2024-09-30 05:49:18 -04:00
|
|
|
<OLButton
|
|
|
|
variant="primary"
|
2023-02-28 04:48:48 -05:00
|
|
|
disabled={isLoading || isSuccess}
|
|
|
|
onClick={handleReactivate}
|
2024-09-30 05:49:18 -04:00
|
|
|
isLoading={isLoading}
|
2023-02-28 04:48:48 -05:00
|
|
|
>
|
|
|
|
{t('reactivate_subscription')}
|
2024-09-30 05:49:18 -04:00
|
|
|
</OLButton>
|
2023-02-28 04:48:48 -05:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ReactivateSubscription
|