Files
Verso/services/web/frontend/js/features/subscription/components/dashboard/reactivate-subscription.tsx
T
Rebeka DekanyandCopybot aebff54a6b Improvement to OLButton loading labels (#28659)
* Create eslint rule for requiring loadingLabel prop when isLoading is specified on OLButton

* Add `loadingLabel` props for OLButton components with `isLoading`

* Clarify loading label and button loading state

GitOrigin-RevId: 89279d5b4c346f9c3b67a59d0db822a2ff04314a
2025-09-26 08:05:41 +00:00

42 lines
1.2 KiB
TypeScript

import { useTranslation } from 'react-i18next'
import { postJSON } from '../../../../infrastructure/fetch-json'
import { reactivateSubscriptionUrl } from '../../data/subscription-url'
import useAsync from '../../../../shared/hooks/use-async'
import { useLocation } from '../../../../shared/hooks/use-location'
import getMeta from '../../../../utils/meta'
import { debugConsole } from '@/utils/debugging'
import OLButton from '@/shared/components/ol/ol-button'
function ReactivateSubscription() {
const { t } = useTranslation()
const { isLoading, isSuccess, runAsync } = useAsync()
const location = useLocation()
const handleReactivate = () => {
runAsync(postJSON(reactivateSubscriptionUrl)).catch(debugConsole.error)
}
if (isSuccess) {
location.reload()
}
// Don't show the button to reactivate the subscription for managed users
if (getMeta('ol-cannot-reactivate-subscription')) {
return null
}
return (
<OLButton
variant="primary"
disabled={isLoading || isSuccess}
onClick={handleReactivate}
isLoading={isLoading}
loadingLabel={t('reactivating')}
>
{t('reactivate_subscription')}
</OLButton>
)
}
export default ReactivateSubscription