Skip to content

Commit

Permalink
refactor: migrate off paragon modal deprecated component (#784)
Browse files Browse the repository at this point in the history
* refactor: migrate off paragon modal deprecated component

* refactor: updated unit tests

---------

Co-authored-by: Bilal Qamar <[email protected]>
  • Loading branch information
Mashal-m and BilalQamar95 authored May 5, 2023
1 parent 371d7de commit 2e877fc
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
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

0 comments on commit 2e877fc

Please sign in to comment.