Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/assets/images/edx-enterprise.svg

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/Disclaimer/BillingDetailsDisclaimer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { FormattedMessage } from '@edx/frontend-platform/i18n';
import dayjs from 'dayjs';

import { usePurchaseSummaryPricing } from '@/components/app/data';
import { DATE_FORMAT, SUBSCRIPTION_TRIAL_LENGTH_DAYS } from '@/components/app/data/constants';
import { SHORT_MONTH_DATE_FORMAT, SUBSCRIPTION_TRIAL_LENGTH_DAYS } from '@/components/app/data/constants';
import { DisplayPrice } from '@/components/DisplayPrice';

const BillingDetailsDisclaimer = () => {
const { yearlySubscriptionCostForQuantity } = usePurchaseSummaryPricing();
const trialEndDate = dayjs().add(SUBSCRIPTION_TRIAL_LENGTH_DAYS, 'days').format(DATE_FORMAT);
const trialEndDate = dayjs().add(SUBSCRIPTION_TRIAL_LENGTH_DAYS, 'days').format(SHORT_MONTH_DATE_FORMAT);
return (
<p className="font-weight-light">
<FormattedMessage
Expand Down
86 changes: 86 additions & 0 deletions src/components/StatefulButton/StatefulProvisioningButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { defineMessages, useIntl } from '@edx/frontend-platform/i18n';
import { Icon, StatefulButton } from '@openedx/paragon';
import { ArrowForward, SpinnerSimple } from '@openedx/paragon/icons';
import classNames from 'classnames';
import { useEffect, useState } from 'react';

import { useBFFSuccess, usePolledCheckoutIntent } from '@/components/app/data';

const variants = {
default: 'secondary',
pending: 'secondary',
error: 'secondary',
success: 'secondary',
};

const buttonMessages = defineMessages({
pending: {
id: 'checkout.billingDetailsSuccess.statefulProvisioningButton.creating_account.',
defaultMessage: 'Creating your account',
description: 'Button label when processing subscription',
},
error: {
id: 'checkout.billingDetailsSuccess.statefulProvisioningButton.still_provisioning',
defaultMessage: 'Still provisioning…',
description: 'Button label when a transient error occurred but the system is still attempting to provision',
},
success: {
id: 'checkout.billingDetails.statefulProvisioningButton.success',
defaultMessage: 'Go to dashboard',
description: 'Button label when system creates account successfully',
},
});

const StatefulProvisioningButton = () => {
const { data: polledCheckoutIntent } = usePolledCheckoutIntent();
const { data: successContext } = useBFFSuccess();
const { checkoutIntent } = successContext || {};
const [statefulButtonState, setStatefulButtonState] = useState('pending');
const intl = useIntl();
const onClickHandler = () => {
if (statefulButtonState === 'success' && checkoutIntent?.adminPortalUrl) {
window.location.href = checkoutIntent?.adminPortalUrl;
}
};

useEffect(() => {
if (polledCheckoutIntent) {
setStatefulButtonState('pending');
if (polledCheckoutIntent?.state === 'fulfilled') {
setStatefulButtonState('success');
}
if (['errored_provisioning', 'errored_stripe_checkout'].includes(polledCheckoutIntent?.state)) {
setStatefulButtonState('error');
}
}
}, [polledCheckoutIntent]);

const props = {
labels: {
pending: intl.formatMessage(buttonMessages.pending),
error: intl.formatMessage(buttonMessages.error),
success: intl.formatMessage(buttonMessages.success),
},
icons: {
pending: <Icon src={SpinnerSimple} className="icon-spin" />,
success: <Icon src={ArrowForward} className="ml-2" />,
},
type: 'submit',
variant: variants[statefulButtonState],
disabledStates: ['default', 'pending', 'error'],
state: statefulButtonState,
onClick: onClickHandler,
};

return (
<StatefulButton
className={classNames('mx-auto d-block w-auto', {
'reverse-stateful-provisioning-success': statefulButtonState === 'success',
'disabled-opacity': ['default', 'pending', 'error'].includes(statefulButtonState),
})}
{...props}
/>
);
};

export default StatefulProvisioningButton;
1 change: 1 addition & 0 deletions src/components/StatefulButton/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as StatefulPurchaseButton } from './StatefulPurchaseButton';
export { default as StatefulSubscribeButton } from './StatefulSubscribeButton';
export { default as StatefulProvisioningButton } from './StatefulProvisioningButton';
Loading
Loading