Skip to content

Commit

Permalink
feat: updated the custom expiration model design and truly blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
jajjibhai008 committed Oct 17, 2024
1 parent 7b28c5b commit 5396302
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
44 changes: 32 additions & 12 deletions src/components/expired-subscription-modal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import {
StandardModal, useToggle,
useToggle, AlertModal, Button, ActionRow,
} from '@openedx/paragon';
import { Link } from 'react-router-dom';
import { useSubscriptions } from '../app/data';

const ExpiredSubscriptionModal = () => {
const { data: { customerAgreement } } = useSubscriptions();
const [isOpen, ,close] = useToggle(true);
const [isOpen] = useToggle(true);
if (!customerAgreement?.hasCustomLicenseExpirationMessaging) {
return null;
}
const onClickHandler = () => {
let url = customerAgreement?.urlForButtonInModal;

if (url) {
// Check if the URL starts with 'http://' or 'https://'
if (!url.startsWith('http://') && !url.startsWith('https://')) {
// Prepend 'https://' if the URL is missing the protocol
url = `https://${url}`;
}

// Navigate to the full URL
window.open(url, '_blank'); // Opening in a new tab
}
};
return (
<StandardModal
<AlertModal
title={customerAgreement?.modalHeaderText}
isOpen={isOpen}
className="d-flex justify-content-center align-items-center text-wrap text-right "
hasCloseButton
onClose={close}
onClose={() => {}}
isBlocking
footerNode={(
<ActionRow>
<Button
onClick={onClickHandler}
>
{customerAgreement?.buttonLabelInModal}
</Button>
</ActionRow>
)}
>
<p className="text-center">
{customerAgreement?.expiredSubscriptionModalMessaging}
<Link className="text-decoration-none" to={customerAgreement?.urlForExpiredModal}> {customerAgreement?.hyperLinkTextForExpiredModal}</Link>
</p>
</StandardModal>
{/* eslint-disable-next-line react/no-danger */}
<div dangerouslySetInnerHTML={{ __html: customerAgreement?.expiredSubscriptionModalMessaging }} />
</AlertModal>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ describe('<ExpiredSubscriptionModal />', () => {
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: false,
modalHeaderText: null,
buttonLabelInModal: null,
expiredSubscriptionModalMessaging: null,
urlForExpiredModal: null,
hyperLinkTextForExpiredModal: null,
urlForButtonInModal: null,
},
},
});
Expand All @@ -33,18 +34,18 @@ describe('<ExpiredSubscriptionModal />', () => {
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: true,
expiredSubscriptionModalMessaging: 'Your subscription has expired.',
urlForExpiredModal: '/renew',
hyperLinkTextForExpiredModal: 'Click here to renew',
modalHeaderText: 'Expired Subscription',
buttonLabelInModal: 'Continue Learning',
expiredSubscriptionModalMessaging: '<p>Your subscription has expired.</p>',
urlForButtonInModal: '/renew',
},
},
});

renderWithRouter(<ExpiredSubscriptionModal />);

expect(screen.getByText('Your subscription has expired.')).toBeInTheDocument();
expect(screen.getByText('Click here to renew')).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Click here to renew' })).toHaveAttribute('href', '/renew');
expect(screen.getByText('Expired Subscription')).toBeInTheDocument();
expect(screen.getByText('Continue Learning')).toBeInTheDocument();
});

test('does not renderwithrouter modal if no customer agreement data is present', () => {
Expand All @@ -53,19 +54,21 @@ describe('<ExpiredSubscriptionModal />', () => {
expect(container).toBeEmptyDOMElement();
});

test('renderwithrouters close button in modal', () => {
test('Close button (cross) should not be available, making the modal truly blocking', () => {
useSubscriptions.mockReturnValue({
data: {
customerAgreement: {
hasCustomLicenseExpirationMessaging: true,
expiredSubscriptionModalMessaging: 'Subscription expired',
urlForExpiredModal: '/renew',
hyperLinkTextForExpiredModal: 'Renew',
modalHeaderText: 'Expired Subscription',
buttonLabelInModal: 'Continue Learning',
expiredSubscriptionModalMessaging: '<p>Your subscription has expired.</p>',
urlForButtonInModal: '/renew',
},
},
});

renderWithRouter(<ExpiredSubscriptionModal />);
expect(screen.getByRole('button', { name: /close/i })).toBeInTheDocument();
// expect(screen.queryByRole('button', { name: /close/i })).not.toBeInTheDocument();
expect(screen.queryByLabelText(/close/i)).not.toBeInTheDocument();
});
});

0 comments on commit 5396302

Please sign in to comment.