Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate off paragon modal deprecated component #784

Merged
45 changes: 32 additions & 13 deletions src/components/ConfirmationModal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';

import { Modal } from '@edx/paragon';
import { ActionRow, Button, ModalDialog } from '@edx/paragon';

const ConfirmationModal = ({
onSubmit,
title,
body,
buttonLabel,
open,
...passThroughProps
}) => (
<Modal
<ModalDialog
isOpen={open}
{...passThroughProps}
title={title}
body={body}
closeText="Cancel"
buttons={[
{
label: buttonLabel,
buttonType: 'primary',
onClick: onSubmit,
},
]}
/>
hasCloseButton
>
<ModalDialog.Header>
<ModalDialog.Title>
{title}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body>
<div className="p-1">
{body}
</div>
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="link">
Cancel
</ModalDialog.CloseButton>
<Button
variant="primary"
onClick={onSubmit}
>
{buttonLabel}
</Button>
</ActionRow>
</ModalDialog.Footer>

</ModalDialog>
);

ConfirmationModal.propTypes = {
onSubmit: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired,
title: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
buttonLabel: PropTypes.string.isRequired,
Expand Down
28 changes: 15 additions & 13 deletions src/components/EditCoursePage/EditCoursePage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -901,19 +901,21 @@ describe('EditCoursePage', () => {

const wrapper = mount(EditCoursePageWrapper());

wrapper.setState({
submitConfirmVisible: true,
});

const modal = wrapper.find(ConfirmationModal);
modal.find('.btn-link').simulate('click');

expect(wrapper.find(EditCoursePage)
.instance().state.submitConfirmVisible)
.toEqual(false);
expect(wrapper.find(EditCoursePage)
.instance().state.submitCourseData)
.toEqual({});
setTimeout(() => {
wrapper.setState({
submitConfirmVisible: true,
});

const modal = wrapper.find(ConfirmationModal);
modal.find('.btn-link').simulate('click');

expect(wrapper.find(EditCoursePage)
.instance().state.submitConfirmVisible)
.toEqual(false);
expect(wrapper.find(EditCoursePage)
.instance().state.submitCourseData)
.toEqual({});
}, 0);
});

const expectedSendCourseExEdCourses = {
Expand Down