overleaf/services/web/frontend/js/features/subscription/components/dashboard/personal-subscription.tsx

94 lines
2.7 KiB
TypeScript
Raw Normal View History

import { Trans, useTranslation } from 'react-i18next'
import { RecurlySubscription } from '../../../../../../types/subscription/dashboard/subscription'
import { ActiveSubscription } from './states/active/active'
import { CanceledSubscription } from './states/canceled'
import { ExpiredSubscription } from './states/expired'
import { useSubscriptionDashboardContext } from '../../context/subscription-dashboard-context'
import PersonalSubscriptionRecurlySyncEmail from './personal-subscription-recurly-sync-email'
[web] Migrate `/user/subscription` to BS5 (#20513) * [web] Initialize BS5 in subscription page * [web] Update subscription-dashboard.tsx for BS5 * [web] Update row-link.tsx for BS5 * [web] Update modals * [web] Add `btn` to `btn-inline-link` classes * [web] Update circle change-to-group circle price element * [web] Replace `list-item-with-margin-bottom` with `mb-3` * [web] Update form elements to BS5 * [web] Use `useContactUsModal` * [web] Adjust tables margin/padding, and more * [web] Update change-to-group-modal.tsx * [web] Add gap to subscription buttons * [web] Remove subscription page colspan for md and above * [web] Use Notification component * [web] Update "leave group" buttons * [web] Fix tests: add `ol-user` meta tag * [web] Nest .hover-highlight in #subscription-dashboard-root * [web] Update to OLRow/OLCol * [web] Update to OLButtons * [web] Update to OLFormGroup * [web] Naming: use BSversion prefix * [web] Set CancelSubscriptionButton as ghost directly in component * [web] Set "Plan" font size * [web] Simplify cancel-subscription buttons * [web] Remove `--neutral-10` ModalFooter background * [web] Simplify circle styles * [web] Center discount badge * [web] Update fieldset label * [web] Add `<ul>` around RowLink * [web] Define SCSS for row-link component * [web] Remove some use of utility classes * [web] Revert and update `fieldset` changes (fixes tests) * [web] Fixup some more OLButtons * [web] Fixup use of OLRow/OLCol * [web] Reduce spacing below "legend-as-label" * [web] Use h5 instead of small in OLModalTitle * [web] Revert OLCol removal on lg screens I had removed them by mistake because I wasn't using the proper breakpoints * [web] Add backdrop to nested modal ContactUsModal * [web] Don't prefill project URL in ContactUsModal * [web] Fix lint * [web] Share `className` prop in BS5 and BS3 modals * [web] Set sub-title font sans serif (BS3) * [web] Update remaining Alerts to OLNotification GitOrigin-RevId: 7fd975ae3e992cebfaf71d4e182f8e13ec886d09
2024-09-30 05:49:18 -04:00
import OLNotification from '@/features/ui/components/ol/ol-notification'
function PastDueSubscriptionAlert({
subscription,
}: {
subscription: RecurlySubscription
}) {
const { t } = useTranslation()
return (
[web] Migrate `/user/subscription` to BS5 (#20513) * [web] Initialize BS5 in subscription page * [web] Update subscription-dashboard.tsx for BS5 * [web] Update row-link.tsx for BS5 * [web] Update modals * [web] Add `btn` to `btn-inline-link` classes * [web] Update circle change-to-group circle price element * [web] Replace `list-item-with-margin-bottom` with `mb-3` * [web] Update form elements to BS5 * [web] Use `useContactUsModal` * [web] Adjust tables margin/padding, and more * [web] Update change-to-group-modal.tsx * [web] Add gap to subscription buttons * [web] Remove subscription page colspan for md and above * [web] Use Notification component * [web] Update "leave group" buttons * [web] Fix tests: add `ol-user` meta tag * [web] Nest .hover-highlight in #subscription-dashboard-root * [web] Update to OLRow/OLCol * [web] Update to OLButtons * [web] Update to OLFormGroup * [web] Naming: use BSversion prefix * [web] Set CancelSubscriptionButton as ghost directly in component * [web] Set "Plan" font size * [web] Simplify cancel-subscription buttons * [web] Remove `--neutral-10` ModalFooter background * [web] Simplify circle styles * [web] Center discount badge * [web] Update fieldset label * [web] Add `<ul>` around RowLink * [web] Define SCSS for row-link component * [web] Remove some use of utility classes * [web] Revert and update `fieldset` changes (fixes tests) * [web] Fixup some more OLButtons * [web] Fixup use of OLRow/OLCol * [web] Reduce spacing below "legend-as-label" * [web] Use h5 instead of small in OLModalTitle * [web] Revert OLCol removal on lg screens I had removed them by mistake because I wasn't using the proper breakpoints * [web] Add backdrop to nested modal ContactUsModal * [web] Don't prefill project URL in ContactUsModal * [web] Fix lint * [web] Share `className` prop in BS5 and BS3 modals * [web] Set sub-title font sans serif (BS3) * [web] Update remaining Alerts to OLNotification GitOrigin-RevId: 7fd975ae3e992cebfaf71d4e182f8e13ec886d09
2024-09-30 05:49:18 -04:00
<OLNotification
type="error"
content={
<>
{t('account_has_past_due_invoice_change_plan_warning')}{' '}
<a
href={subscription.recurly.accountManagementLink}
target="_blank"
rel="noreferrer noopener"
>
{t('view_your_invoices')}
</a>
</>
}
/>
)
}
function PersonalSubscriptionStates({
subscription,
}: {
subscription: RecurlySubscription
}) {
const { t } = useTranslation()
const state = subscription?.recurly.state
if (state === 'active') {
return <ActiveSubscription subscription={subscription} />
} else if (state === 'canceled') {
return <CanceledSubscription subscription={subscription} />
} else if (state === 'expired') {
return <ExpiredSubscription subscription={subscription} />
} else {
return <>{t('problem_with_subscription_contact_us')}</>
}
}
function PersonalSubscription() {
const { t } = useTranslation()
const { personalSubscription, recurlyLoadError } =
useSubscriptionDashboardContext()
if (!personalSubscription) return null
if (!('recurly' in personalSubscription)) {
return (
<p>
<Trans
i18nKey="please_contact_support_to_makes_change_to_your_plan"
components={[<a href="/contact" />]} // eslint-disable-line react/jsx-key, jsx-a11y/anchor-has-content
/>
</p>
)
}
return (
<>
{personalSubscription.recurly.account.has_past_due_invoice._ ===
'true' && (
<PastDueSubscriptionAlert subscription={personalSubscription} />
)}
<PersonalSubscriptionStates
subscription={personalSubscription as RecurlySubscription}
/>
{recurlyLoadError && (
[web] Migrate `/user/subscription` to BS5 (#20513) * [web] Initialize BS5 in subscription page * [web] Update subscription-dashboard.tsx for BS5 * [web] Update row-link.tsx for BS5 * [web] Update modals * [web] Add `btn` to `btn-inline-link` classes * [web] Update circle change-to-group circle price element * [web] Replace `list-item-with-margin-bottom` with `mb-3` * [web] Update form elements to BS5 * [web] Use `useContactUsModal` * [web] Adjust tables margin/padding, and more * [web] Update change-to-group-modal.tsx * [web] Add gap to subscription buttons * [web] Remove subscription page colspan for md and above * [web] Use Notification component * [web] Update "leave group" buttons * [web] Fix tests: add `ol-user` meta tag * [web] Nest .hover-highlight in #subscription-dashboard-root * [web] Update to OLRow/OLCol * [web] Update to OLButtons * [web] Update to OLFormGroup * [web] Naming: use BSversion prefix * [web] Set CancelSubscriptionButton as ghost directly in component * [web] Set "Plan" font size * [web] Simplify cancel-subscription buttons * [web] Remove `--neutral-10` ModalFooter background * [web] Simplify circle styles * [web] Center discount badge * [web] Update fieldset label * [web] Add `<ul>` around RowLink * [web] Define SCSS for row-link component * [web] Remove some use of utility classes * [web] Revert and update `fieldset` changes (fixes tests) * [web] Fixup some more OLButtons * [web] Fixup use of OLRow/OLCol * [web] Reduce spacing below "legend-as-label" * [web] Use h5 instead of small in OLModalTitle * [web] Revert OLCol removal on lg screens I had removed them by mistake because I wasn't using the proper breakpoints * [web] Add backdrop to nested modal ContactUsModal * [web] Don't prefill project URL in ContactUsModal * [web] Fix lint * [web] Share `className` prop in BS5 and BS3 modals * [web] Set sub-title font sans serif (BS3) * [web] Update remaining Alerts to OLNotification GitOrigin-RevId: 7fd975ae3e992cebfaf71d4e182f8e13ec886d09
2024-09-30 05:49:18 -04:00
<OLNotification
type="warning"
content={<strong>{t('payment_provider_unreachable_error')}</strong>}
/>
)}
<hr />
<PersonalSubscriptionRecurlySyncEmail />
</>
)
}
export default PersonalSubscription