2024-05-08 09:43:25 -04:00
|
|
|
import { FetchError, postJSON } from '@/infrastructure/fetch-json'
|
|
|
|
import Notification from '@/shared/components/notification'
|
|
|
|
import useAsync from '@/shared/hooks/use-async'
|
|
|
|
import { debugConsole } from '@/utils/debugging'
|
|
|
|
import getMeta from '@/utils/meta'
|
|
|
|
import { Dispatch, SetStateAction, useCallback } from 'react'
|
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { InviteViewTypes } from './group-invite'
|
2024-09-30 05:48:56 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2024-05-08 09:43:25 -04:00
|
|
|
|
|
|
|
export default function HasIndividualRecurlySubscription({
|
|
|
|
setView,
|
|
|
|
}: {
|
|
|
|
setView: Dispatch<SetStateAction<InviteViewTypes>>
|
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const {
|
|
|
|
runAsync,
|
|
|
|
isLoading: isCancelling,
|
|
|
|
isError,
|
|
|
|
} = useAsync<never, FetchError>()
|
|
|
|
|
|
|
|
const cancelPersonalSubscription = useCallback(() => {
|
|
|
|
runAsync(
|
|
|
|
postJSON('/user/subscription/cancel', {
|
|
|
|
body: {
|
|
|
|
_csrf: getMeta('ol-csrfToken'),
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.then(() => {
|
|
|
|
setView('invite')
|
|
|
|
})
|
|
|
|
.catch(debugConsole.error)
|
|
|
|
}, [runAsync, setView])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{isError && (
|
|
|
|
<Notification
|
|
|
|
type="error"
|
|
|
|
content={t('something_went_wrong_canceling_your_subscription')}
|
|
|
|
className="my-3"
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className="text-center">
|
|
|
|
<p>{t('cancel_personal_subscription_first')}</p>
|
|
|
|
<p>
|
2024-09-30 05:48:56 -04:00
|
|
|
<OLButton
|
|
|
|
variant="secondary"
|
2024-05-08 09:43:25 -04:00
|
|
|
disabled={isCancelling}
|
|
|
|
onClick={() => setView('invite')}
|
|
|
|
>
|
|
|
|
{t('not_now')}
|
2024-09-30 05:48:56 -04:00
|
|
|
</OLButton>
|
2024-05-08 09:43:25 -04:00
|
|
|
|
2024-09-30 05:48:56 -04:00
|
|
|
<OLButton
|
|
|
|
variant="primary"
|
2024-05-08 09:43:25 -04:00
|
|
|
disabled={isCancelling}
|
2024-09-30 05:48:56 -04:00
|
|
|
onClick={() => cancelPersonalSubscription()}
|
2024-05-08 09:43:25 -04:00
|
|
|
>
|
|
|
|
{t('cancel_your_subscription')}
|
2024-09-30 05:48:56 -04:00
|
|
|
</OLButton>
|
2024-05-08 09:43:25 -04:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|