diff --git a/src/index.jsx b/src/index.jsx index ff282888..f825f7fd 100755 --- a/src/index.jsx +++ b/src/index.jsx @@ -9,7 +9,6 @@ import { APP_READY, initialize, subscribe, - getConfig, mergeConfig, } from '@edx/frontend-platform'; @@ -20,7 +19,6 @@ import messages from './i18n'; import configureStore from './store'; import { NotFoundPage } from './components'; import { OrdersAndSubscriptionsPage } from './orders-and-subscriptions'; -import { ManageSubscriptionsPage } from './subscriptions'; import './index.scss'; @@ -52,12 +50,6 @@ subscribe(APP_READY, () => {
- {getConfig().ENABLE_B2C_SUBSCRIPTIONS?.toLowerCase() === 'true' ? ( - } - /> - ) : null} } /> } /> } /> diff --git a/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.jsx b/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.jsx index e598feb7..09b80a77 100644 --- a/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.jsx +++ b/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.jsx @@ -64,18 +64,11 @@ const OrdersAndSubscriptionsPage = () => { {(text) =>

{text}

}
- - {(text) => {text}} - diff --git a/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.test.jsx b/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.test.jsx index 30e90ad2..87be6546 100644 --- a/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.test.jsx +++ b/src/orders-and-subscriptions/OrdersAndSubscriptionsPage.test.jsx @@ -17,19 +17,13 @@ const { const testHeadings = (hasSections = true, hasSubscriptions = true) => { if (hasSections && hasSubscriptions) { // Assert the main heading is present - expect(getByText('My orders and subscriptions')).toBeInTheDocument(); - expect( - getByText('Manage your program subscriptions and view your order history.'), - ).toBeInTheDocument(); + expect(getByText('My order history')).toBeInTheDocument(); // Assert Subscription and Order History sections are rendered expect(getByText('Subscriptions')).toBeInTheDocument(); expect(getByText('Order History')).toBeInTheDocument(); } else if (!hasSections && !hasSubscriptions) { // Assert only Order History section is rendered - expect(queryByText('My orders and subscriptions')).toBeNull(); - expect( - queryByText('Manage your program subscriptions and view your order history.'), - ).toBeNull(); + expect(queryByText('My order history')).toBeNull(); expect(getByText('Order History')).toBeInTheDocument(); expect(queryByText('Subscriptions')).toBeNull(); } @@ -38,10 +32,7 @@ const testHeadings = (hasSections = true, hasSubscriptions = true) => { const testHeadingsLoading = (hasSections = true, hasSubscriptions = true) => { if (!hasSections && !hasSubscriptions) { // Assert loading, nothing is rendered - expect(queryByText('My orders and subscriptions')).toBeNull(); - expect( - queryByText('Manage your program subscriptions and view your order history.'), - ).toBeNull(); + expect(queryByText('My order history')).toBeNull(); expect(queryByText('Subscriptions')).toBeNull(); expect(queryByText('Order History')).toBeNull(); } @@ -51,19 +42,13 @@ const testHeadingsError = (hasSections = true, hasSubscriptions = true) => { if (!hasSections && !hasSubscriptions) { // Error with no subscriptions // Assert only Order History sections is rendered - expect(queryByText('My orders and subscriptions')).toBeNull(); - expect( - queryByText('Manage your program subscriptions and view your order history.'), - ).toBeNull(); + expect(queryByText('My order history')).toBeNull(); expect(queryByText('Subscriptions')).toBeNull(); expect(getByText('Order History')).toBeInTheDocument(); } else if (hasSections && hasSubscriptions) { // Error but has subscriptions // Assert the main heading is present - expect(getByText('My orders and subscriptions')).toBeInTheDocument(); - expect( - getByText('Manage your program subscriptions and view your order history.'), - ).toBeInTheDocument(); + expect(getByText('My order history')).toBeInTheDocument(); // Assert Subscription and Order History sections are rendered expect(getByText('Subscriptions')).toBeInTheDocument(); expect(getByText('Order History')).toBeInTheDocument(); diff --git a/src/store/__mocks__/mockEmptyStore.js b/src/store/__mocks__/mockEmptyStore.js index 9969ab10..97450d2b 100644 --- a/src/store/__mocks__/mockEmptyStore.js +++ b/src/store/__mocks__/mockEmptyStore.js @@ -13,7 +13,6 @@ module.exports = { loading: false, loadingError: false, subscriptions: [], - stripeCustomerPortalURL: null, stripeError: false, stripeLoading: false, shouldShowSubscriptionsSection: true, diff --git a/src/store/__mocks__/subscriptions.mockStore.js b/src/store/__mocks__/subscriptions.mockStore.js index 6839134f..3c7bdcc6 100644 --- a/src/store/__mocks__/subscriptions.mockStore.js +++ b/src/store/__mocks__/subscriptions.mockStore.js @@ -4,7 +4,6 @@ module.exports = { loadingError: false, stripeLoading: false, stripeError: false, - stripeCustomerPortalURL: null, shouldShowSubscriptionsSection: true, subscriptions: [ { diff --git a/src/subscriptions/ManageSubscriptionsPage.jsx b/src/subscriptions/ManageSubscriptionsPage.jsx deleted file mode 100644 index 858684a7..00000000 --- a/src/subscriptions/ManageSubscriptionsPage.jsx +++ /dev/null @@ -1,81 +0,0 @@ -import React, { useEffect } from 'react'; -import { useDispatch, useSelector } from 'react-redux'; -import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; -import { Button } from '@edx/paragon'; - -import { PageLoading, SupportLink } from '../components'; - -import { fetchStripeCustomerPortalURL } from './actions'; -import { subscriptionsSelector } from './selectors'; -import messages from './ManageSubscriptionsPage.messages'; - -const ManageSubscriptionsPage = () => { - const { formatMessage } = useIntl(); - const dispatch = useDispatch(); - const { stripeCustomerPortalURL, stripeError } = useSelector( - subscriptionsSelector, - ); - - const buttonLabel = formatMessage( - messages['ecommerce.order.history.manage.subscriptions.button'], - ); - - useEffect(() => { - dispatch(fetchStripeCustomerPortalURL()); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); - - useEffect(() => { - if (stripeCustomerPortalURL) { - window.location.href = stripeCustomerPortalURL; - } - }, [stripeCustomerPortalURL]); - - const renderLoading = () => ( - - ); - - const renderError = () => ( -
-
- - {(text) =>

{text}

} -
- {buttonLabel}, - }} - > - {(text) =>

{text}

} -
- , - }} - /> - -
-
- ); - - return stripeError ? renderError() : renderLoading(); -}; - -export default ManageSubscriptionsPage; diff --git a/src/subscriptions/ManageSubscriptionsPage.messages.js b/src/subscriptions/ManageSubscriptionsPage.messages.js deleted file mode 100644 index d15e030b..00000000 --- a/src/subscriptions/ManageSubscriptionsPage.messages.js +++ /dev/null @@ -1,17 +0,0 @@ -import { defineMessages } from '@edx/frontend-platform/i18n'; - -const messages = defineMessages({ - 'ecommerce.order.history.manage.subscriptions.button': { - id: 'ecommerce.order.history.manage.subscriptions.button', - defaultMessage: 'Orders and subscriptions', - description: - 'Button label to navigate to the orders and subscriptions page.', - }, - 'ecommerce.order.history.manage.subscriptions.loading': { - id: 'ecommerce.order.history.manage.subscriptions.loading', - defaultMessage: 'Loading manage subscriptions...', - description: 'Message when loading the manage subscriptions page.', - }, -}); - -export default messages; diff --git a/src/subscriptions/ManageSubscriptionsPage.test.jsx b/src/subscriptions/ManageSubscriptionsPage.test.jsx deleted file mode 100644 index f00f7ec4..00000000 --- a/src/subscriptions/ManageSubscriptionsPage.test.jsx +++ /dev/null @@ -1,64 +0,0 @@ -/* eslint-disable global-require */ -import React from 'react'; -import { act, render, screen } from '../testing'; - -import ManageSubscriptionsPage from './ManageSubscriptionsPage'; - -const storeMocks = require('../store/__mocks__/mockEmptyStore'); - -const { getByText, getAllByText } = screen; - -describe('', () => { - describe('Renders correctly in various states', () => { - it('navigates when url is fetched correctly', () => { - const storeMocksWithURL = { - ...storeMocks, - subscriptions: { - ...storeMocks.subscriptions, - stripeCustomerPortalURL: 'http://edx.org', - }, - }; - - const mockHrefSetter = jest.fn(); - delete window.location; - window.location = { - ...window.location, - set href(url) { - mockHrefSetter(url); - }, - }; - - jest.useFakeTimers(); - - render(, storeMocksWithURL); - - act(() => { - jest.runAllTimers(); - }); - expect(mockHrefSetter).toHaveBeenCalledWith('http://edx.org'); - expect(getByText('Loading manage subscriptions...')).toBeInTheDocument(); - }); - - it('renders loading when url is being fetched', () => { - render(, storeMocks); - - expect(getByText('Loading manage subscriptions...')).toBeInTheDocument(); - }); - - it('renders error ui when fetching url fails', () => { - const storeMocksWithError = { - ...storeMocks, - subscriptions: { - ...storeMocks.subscriptions, - stripeError: true, - }, - }; - - render(, storeMocksWithError); - - expect(getByText('Something went wrong')).toBeInTheDocument(); - expect(getByText('contact support')).toBeInTheDocument(); - expect(getAllByText('Orders and subscriptions')).toHaveLength(2); - }); - }); -}); diff --git a/src/subscriptions/Subscriptions.jsx b/src/subscriptions/Subscriptions.jsx index ef777f4f..52cb8e30 100644 --- a/src/subscriptions/Subscriptions.jsx +++ b/src/subscriptions/Subscriptions.jsx @@ -1,16 +1,13 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { useDispatch, useSelector } from 'react-redux'; -import { sendTrackEvent } from '@edx/frontend-platform/analytics'; import { FormattedMessage, useIntl } from '@edx/frontend-platform/i18n'; -import { StatefulButton } from '@edx/paragon'; -import { Launch, SpinnerSimple } from '@edx/paragon/icons'; import { BasicAlert } from '../components'; import SubscriptionCardsView from './SubscriptionCardsView'; import SubscriptionUpsell from './SubscriptionUpsell'; -import { clearStripeError, fetchStripeCustomerPortalURL } from './actions'; +import { clearStripeError } from './actions'; import { subscriptionsSelector } from './selectors'; import messages from './Subscriptions.messages'; @@ -20,9 +17,7 @@ const Subscriptions = () => { const dispatch = useDispatch(); const { subscriptions, - stripeCustomerPortalURL, stripeError, - stripeLoading, } = useSelector(subscriptionsSelector); const hasSubscriptions = subscriptions.length > 0; const activeCount = subscriptions.filter( @@ -35,29 +30,10 @@ const Subscriptions = () => { 2: 'ecommerce.order.history.subscriptions.subtitle.multiple', }[Math.min(activeCount, 2)]; - const buttonLabel = formatMessage( - messages['ecommerce.order.history.subscriptions.manage.button'], - ); - - const handleManageSubscriptionsClick = () => { - sendTrackEvent('edx.bi.user.subscription.order-page.manage.clicked'); - dispatch(fetchStripeCustomerPortalURL()); - }; - const handeAlertClose = () => { dispatch(clearStripeError()); }; - useEffect(() => { - if (stripeCustomerPortalURL) { - window.open(stripeCustomerPortalURL, '_blank', 'noopener,noreferrer'); - } - }, [stripeCustomerPortalURL]); - - const renderSpinner = () => ( -
{SpinnerSimple()}
- ); - const renderEmpty = () => ( <> { {formatMessage(messages[subtitle], { activeCount, - buttonLabel: {buttonLabel}, })} - diff --git a/src/subscriptions/Subscriptions.messages.js b/src/subscriptions/Subscriptions.messages.js index 828610ab..3b76b2d5 100644 --- a/src/subscriptions/Subscriptions.messages.js +++ b/src/subscriptions/Subscriptions.messages.js @@ -4,26 +4,21 @@ const messages = defineMessages({ 'ecommerce.order.history.subscriptions.subtitle.zero': { id: 'ecommerce.order.history.subscriptions.subtitle.zero', defaultMessage: - 'You do not have an active subscription. To view your past receipts, click {buttonLabel}.', + 'You do not have an active subscription. To view your past receipts, please contact support.', description: 'Subtitle for zero active subscriptions', }, 'ecommerce.order.history.subscriptions.subtitle.one': { id: 'ecommerce.order.history.subscriptions.subtitle.one', defaultMessage: - 'You have {activeCount} active subscription. To view your receipts, change your payment method or cancel your subscription, click {buttonLabel}.', + 'You have {activeCount} active subscription. To view your receipts, please contact support.', description: 'Subtitle for one active subscriptions ', }, 'ecommerce.order.history.subscriptions.subtitle.multiple': { id: 'ecommerce.order.history.subscriptions.subtitle.multiple', defaultMessage: - 'You have {activeCount} active subscriptions. To view your receipts, change your payment method or cancel your subscription, click {buttonLabel}.', + 'You have {activeCount} active subscriptions. To view your receipts, please contact support.', description: 'Subtitle for multiple subscriptions', }, - 'ecommerce.order.history.subscriptions.manage.button': { - id: 'ecommerce.order.history.subscriptions.manage.button', - defaultMessage: 'Manage my subscriptions', - description: 'Button text for managing subscriptions.', - }, }); export default messages; diff --git a/src/subscriptions/Subscriptions.test.jsx b/src/subscriptions/Subscriptions.test.jsx index 7ee5afe6..32ac4063 100644 --- a/src/subscriptions/Subscriptions.test.jsx +++ b/src/subscriptions/Subscriptions.test.jsx @@ -19,7 +19,6 @@ jest.mock('@edx/frontend-platform', () => ({ const { getByText, getByTestId, - getAllByText, getAllByTestId, queryByText, queryByTestId, @@ -38,10 +37,10 @@ describe('', () => { it('Renders appropriate subscription heading', () => { expect(getByText('Subscriptions')).toBeInTheDocument(); expect(getByTestId('subscription-subtitle').textContent).toMatch( - /You have 2 active subscriptions\. To view your receipts, change your payment method or cancel your subscription, click.*Manage my subscriptions/, + /You have 2 active subscriptions\. To view your receipts, please contact support/, ); - // Assert the button is rendered - expect(getAllByText('Manage my subscriptions')).toHaveLength(2); + // Assert the button is not rendered + expect(queryByText('Manage my subscriptions')).toBeNull(); }); it('Renders subscription cards', () => { @@ -147,10 +146,10 @@ describe('', () => { it('Renders appropriate subscription heading', () => { expect(getByText('Subscriptions')).toBeInTheDocument(); expect(getByTestId('subscription-subtitle').textContent).toMatch( - /You do not have an active subscription\. To view your past receipts, click.*Manage my subscriptions/, + /You do not have an active subscription\. To view your past receipts, please contact support/, ); - // Assert the button is rendered - expect(getAllByText('Manage my subscriptions')).toHaveLength(2); + // Assert the button is not rendered + expect(queryByText('Manage my subscriptions')).toBeNull(); }); it('Render subscription cards', () => { diff --git a/src/subscriptions/actions.js b/src/subscriptions/actions.js index 5b5c531b..94a0aa22 100644 --- a/src/subscriptions/actions.js +++ b/src/subscriptions/actions.js @@ -1,9 +1,6 @@ import { createRoutine } from 'redux-saga-routines'; export const fetchSubscriptions = createRoutine('FETCH_SUBSCRIPTIONS'); -export const fetchStripeCustomerPortalURL = createRoutine( - 'FETCH_STRIPE_CUSTOMER_PORTAL_URL', -); export const clearStripeError = () => ({ type: 'CLEAR_STRIPE_ERROR', diff --git a/src/subscriptions/index.js b/src/subscriptions/index.js index d9aeb95a..b51acb36 100644 --- a/src/subscriptions/index.js +++ b/src/subscriptions/index.js @@ -1,5 +1,4 @@ import Subscriptions from './Subscriptions'; -import ManageSubscriptionsPage from './ManageSubscriptionsPage'; import { fetchSubscriptions } from './actions'; import reducer from './reducer'; import saga from './saga'; @@ -11,5 +10,4 @@ export { reducer, saga, storeName, - ManageSubscriptionsPage, }; diff --git a/src/subscriptions/reducer.js b/src/subscriptions/reducer.js index 72cb4e61..9a2aa42b 100644 --- a/src/subscriptions/reducer.js +++ b/src/subscriptions/reducer.js @@ -1,10 +1,9 @@ -import { fetchStripeCustomerPortalURL, fetchSubscriptions } from './actions'; +import { fetchSubscriptions } from './actions'; export const initialState = { loading: true, loadingError: false, subscriptions: [], - stripeCustomerPortalURL: null, stripeError: false, stripeLoading: false, shouldShowSubscriptionsSection: true, @@ -33,27 +32,6 @@ const subscriptionsReducer = (state = initialState, action = {}) => { ...state, loading: false, }; - case fetchStripeCustomerPortalURL.TRIGGER: - return { - ...state, - stripeLoading: true, - stripeCustomerPortalURL: null, - }; - case fetchStripeCustomerPortalURL.SUCCESS: - return { - ...state, - stripeCustomerPortalURL: action.payload, - }; - case fetchStripeCustomerPortalURL.FAILURE: - return { - ...state, - stripeError: true, - }; - case fetchStripeCustomerPortalURL.FULFILL: - return { - ...state, - stripeLoading: false, - }; case 'CLEAR_STRIPE_ERROR': return { ...state, diff --git a/src/subscriptions/saga.js b/src/subscriptions/saga.js index 4d0b3f58..21b53eeb 100644 --- a/src/subscriptions/saga.js +++ b/src/subscriptions/saga.js @@ -1,9 +1,7 @@ import { put, takeLatest, call } from 'redux-saga/effects'; -import { createFetchHandler } from '../utils'; - -import { fetchSubscriptions, fetchStripeCustomerPortalURL, hideSubscriptionSection } from './actions'; -import { getSubscriptions, getStripeCustomerPortalURL } from './service'; +import { fetchSubscriptions, hideSubscriptionSection } from './actions'; +import getSubscriptions from './service'; function* handleFetchSubscriptions() { try { @@ -27,15 +25,6 @@ function* handleFetchSubscriptions() { } } -const handleFetchStripeCustomerPortalURL = createFetchHandler( - fetchStripeCustomerPortalURL, - getStripeCustomerPortalURL, -); - export default function* subscriptionSaga() { yield takeLatest(fetchSubscriptions.TRIGGER, handleFetchSubscriptions); - yield takeLatest( - fetchStripeCustomerPortalURL.TRIGGER, - handleFetchStripeCustomerPortalURL, - ); } diff --git a/src/subscriptions/service.js b/src/subscriptions/service.js index eb75d7c4..6b86f9ec 100644 --- a/src/subscriptions/service.js +++ b/src/subscriptions/service.js @@ -3,7 +3,7 @@ import { getConfig } from '@edx/frontend-platform'; const createURL = (url) => `${getConfig().SUBSCRIPTIONS_BASE_URL}/api/v1${url}`; -export async function getSubscriptions() { +export default async function getSubscriptions() { const httpClient = getAuthenticatedHttpClient(); const stripeUserSubscriptionsUrl = createURL('/stripe-user-subscriptions/'); @@ -19,13 +19,3 @@ export async function getSubscriptions() { : subscription.subscription_state?.toLowerCase(), })); } - -export async function getStripeCustomerPortalURL() { - const httpClient = getAuthenticatedHttpClient(); - - const stripePortalURL = createURL('/stripe-portal/'); - - const { data } = await httpClient.post(stripePortalURL); - - return data.portal_url; -}