2023-01-26 11:48:30 -05:00
|
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { Subscription } from '../../../../../../types/subscription/dashboard/subscription'
|
2023-01-31 10:56:34 -05:00
|
|
|
import { ActiveSubscription } from './states/active/active'
|
|
|
|
import { CanceledSubscription } from './states/canceled'
|
|
|
|
import { ExpiredSubscription } from './states/expired'
|
2023-01-26 12:01:54 -05:00
|
|
|
import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
|
2023-01-26 11:48:30 -05:00
|
|
|
|
|
|
|
function PastDueSubscriptionAlert({
|
|
|
|
subscription,
|
|
|
|
}: {
|
|
|
|
subscription: Subscription
|
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="alert alert-danger" role="alert">
|
|
|
|
{t('account_has_past_due_invoice_change_plan_warning')}{' '}
|
|
|
|
<a
|
|
|
|
href={subscription.recurly.accountManagementLink}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer noopener"
|
|
|
|
>
|
|
|
|
{t('view_your_invoices')}
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function PersonalSubscriptionStates({
|
|
|
|
subscription,
|
|
|
|
}: {
|
|
|
|
subscription: Subscription
|
|
|
|
}) {
|
|
|
|
const { t } = useTranslation()
|
2023-01-31 10:56:34 -05:00
|
|
|
const state = subscription?.recurly?.state
|
2023-01-26 11:48:30 -05:00
|
|
|
|
|
|
|
if (state === 'active') {
|
2023-01-31 10:56:34 -05:00
|
|
|
return <ActiveSubscription subscription={subscription} />
|
2023-01-26 11:48:30 -05:00
|
|
|
} else if (state === 'canceled') {
|
2023-01-31 10:56:34 -05:00
|
|
|
return <CanceledSubscription subscription={subscription} />
|
2023-01-26 11:48:30 -05:00
|
|
|
} else if (state === 'expired') {
|
2023-01-31 10:56:34 -05:00
|
|
|
return <ExpiredSubscription subscription={subscription} />
|
2023-01-26 11:48:30 -05:00
|
|
|
} else {
|
|
|
|
return <>{t('problem_with_subscription_contact_us')}</>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-07 10:38:04 -05:00
|
|
|
function PersonalSubscription() {
|
2023-01-26 12:01:54 -05:00
|
|
|
const { t } = useTranslation()
|
2023-02-07 10:38:12 -05:00
|
|
|
const { personalSubscription, recurlyLoadError } =
|
2023-01-26 12:01:54 -05:00
|
|
|
useSubscriptionDashboardContext()
|
2023-01-26 11:48:30 -05:00
|
|
|
|
2023-02-07 10:38:04 -05:00
|
|
|
if (!personalSubscription) return null
|
2023-01-26 11:48:30 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2023-02-07 10:38:04 -05:00
|
|
|
{personalSubscription.recurly.account.has_past_due_invoice._ ===
|
|
|
|
'true' && (
|
|
|
|
<PastDueSubscriptionAlert subscription={personalSubscription} />
|
2023-01-26 11:48:30 -05:00
|
|
|
)}
|
2023-02-07 10:38:04 -05:00
|
|
|
<PersonalSubscriptionStates subscription={personalSubscription} />
|
2023-01-26 12:01:54 -05:00
|
|
|
{recurlyLoadError && (
|
|
|
|
<div className="alert alert-warning" role="alert">
|
|
|
|
<strong>{t('payment_provider_unreachable_error')}</strong>
|
|
|
|
</div>
|
|
|
|
)}
|
2023-01-31 10:42:52 -05:00
|
|
|
<hr />
|
2023-01-26 11:48:30 -05:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default PersonalSubscription
|