import getMeta from '@/utils/meta' import { FetchError, postJSON } from '@/infrastructure/fetch-json' import { useTranslation, Trans } from 'react-i18next' import { Card, Row, Col } from 'react-bootstrap' import IconButton from '@/features/ui/components/bootstrap-5/icon-button' import Button from '@/features/ui/components/bootstrap-5/button' import UpgradeSubscriptionPlanDetails from './upgrade-subscription-plan-details' import RequestStatus from '../request-status' import UpgradeSummary, { SubscriptionChange, } from './upgrade-subscription-upgrade-summary' import { debugConsole } from '@/utils/debugging' import { sendMB } from '../../../../infrastructure/event-tracking' import handleStripePaymentAction from '@/features/subscription/util/handle-stripe-payment-action' import { useState } from 'react' function UpgradeSubscription() { const { t } = useTranslation() const groupName = getMeta('ol-groupName') const preview = getMeta('ol-subscriptionChangePreview') as SubscriptionChange const [isError, setIsError] = useState(false) const [isLoading, setIsLoading] = useState(false) const [isSuccess, setIsSuccess] = useState(false) const onSubmit = async () => { sendMB('flex-upgrade-form', { action: 'click-upgrade-button', }) setIsLoading(true) try { await postJSON('/user/subscription/group/upgrade-subscription') sendMB('flex-upgrade-success') setIsSuccess(true) } catch (error) { const { handled } = await handleStripePaymentAction(error as FetchError) if (handled) { sendMB('flex-upgrade-success') setIsSuccess(true) return } debugConsole.error(error) sendMB('flex-upgrade-error') setIsError(true) } finally { setIsLoading(false) } } if (isSuccess) { return ( ) } if (isError) { return ( { sendMB('flex-upgrade-form', { action: 'click-get-in-touch-link', }) }} />, ]} /> } /> ) } return (

{groupName || t('group_subscription')}

{t('upgrade_your_subscription')}

, /* eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key */ , ]} />

sendMB('flex-add-users')} > {t('add_more_licenses_to_my_plan')}
) } export default UpgradeSubscription