Skip to content

Commit

Permalink
Merge pull request #872 from openedx/mashal-m/paragon-modal-deprecation
Browse files Browse the repository at this point in the history
refactor: migrate off paragon modal deprecated migration
  • Loading branch information
feanil authored Feb 8, 2024
2 parents 2193013 + 37a8719 commit 1b3c6f7
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ const CodeAssignmentModalWrapper = (props) => (
</MemoryRouter>
);
/* eslint-enable react/prop-types */

describe('CodeAssignmentModal component', () => {
it('displays a modal', () => {
render(<CodeAssignmentModalWrapper />);
Expand Down
78 changes: 41 additions & 37 deletions src/components/CodeAssignmentModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { reduxForm, SubmissionError } from 'redux-form';
import {
Button, Modal, Form, Spinner,
Button, Icon, ModalDialog, ActionRow, Form,

Check failure on line 5 in src/components/CodeAssignmentModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Icon' is defined but never used
} from '@edx/paragon';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';

Expand Down Expand Up @@ -40,7 +40,6 @@ export class BaseCodeAssignmentModal extends React.Component {
super(props);

this.errorMessageRef = React.createRef();
this.modalRef = React.createRef();

this.state = {
mode: MODAL_TYPES.assign,
Expand All @@ -54,14 +53,6 @@ export class BaseCodeAssignmentModal extends React.Component {
this.getNumberOfSelectedCodes = this.getNumberOfSelectedCodes.bind(this);
}

componentDidMount() {
const { current: { firstFocusableElement } } = this.modalRef;

if (firstFocusableElement) {
firstFocusableElement.focus();
}
}

componentDidUpdate(prevProps) {
const {
submitFailed,
Expand Down Expand Up @@ -376,7 +367,7 @@ export class BaseCodeAssignmentModal extends React.Component {
>
Notify learners by email
</Form.Checkbox>
{ notify && (
{notify && (
<EmailTemplateForm
emailTemplateType={MODAL_TYPES.assign}
fields={getAssignmentModalFields(formatMessage)}
Expand Down Expand Up @@ -405,33 +396,46 @@ export class BaseCodeAssignmentModal extends React.Component {
} = this.state;

return (
<Modal
ref={this.modalRef}
dialogClassName="code-assignment"
title={this.renderTitle()}
body={this.renderBody()}
buttons={[
<Button
key="assign-submit-btn"
disabled={submitting}
onClick={handleSubmit(this.handleModalSubmit)}
data-testid={SUBMIT_BUTTON_TEST_ID}
>
<>
{mode === MODAL_TYPES.assign && submitting && <Spinner animation="border" className="mr-2" variant="light" size="sm" />}
{`Assign ${isBulkAssign ? 'Codes' : 'Code'}`}
</>
</Button>,
<SaveTemplateButton
key="save-assign-template-btn"
templateType={MODAL_TYPES.assign}
setMode={this.setMode}
handleSubmit={handleSubmit}
/>,
]}
<ModalDialog
isOpen
size="lg"
onClose={onClose}
open
/>
className="code-assignment"
hasCloseButton
>
<ModalDialog.Header>
<ModalDialog.Title>
{this.renderTitle()}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body>
{this.renderBody()}
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="link">
Cancel
</ModalDialog.CloseButton>
<Button
key="assign-submit-btn"
disabled={submitting}
onClick={handleSubmit(this.handleModalSubmit)}
data-testid={SUBMIT_BUTTON_TEST_ID}
>
<>
{mode === MODAL_TYPES.assign && submitting && <Spinner animation="border" className="mr-2" variant="light" size="sm" />}

Check failure on line 426 in src/components/CodeAssignmentModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

Expected indentation of 16 space characters but found 14

Check failure on line 426 in src/components/CodeAssignmentModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined

Check failure on line 426 in src/components/CodeAssignmentModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined
{`Assign ${isBulkAssign ? 'Codes' : 'Code'}`}
</>
</Button>,
<SaveTemplateButton
key="save-assign-template-btn"
templateType={MODAL_TYPES.assign}
setMode={this.setMode}
handleSubmit={handleSubmit}
/>,
</ActionRow>
</ModalDialog.Footer>
</ModalDialog>
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ const CodeReminderModalWrapper = (props) => (
</MemoryRouter>
);
/* eslint-enable react/prop-types */

describe('CodeReminderModal component', () => {
it('displays a modal', () => {
render(<CodeReminderModalWrapper />);

expect(screen.getByText(initialProps.title)).toBeInTheDocument();
});
it('displays an error', () => {
Expand Down
76 changes: 42 additions & 34 deletions src/components/CodeReminderModal/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React from 'react';
import PropTypes from 'prop-types';
import { reduxForm, SubmissionError } from 'redux-form';
import { Button, Modal, Spinner } from '@edx/paragon';
import {
Button, Icon, ModalDialog, ActionRow,

Check failure on line 5 in src/components/CodeReminderModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Icon' is defined but never used
} from '@edx/paragon';
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n';

import SaveTemplateButton from '../../containers/SaveTemplateButton';
Expand All @@ -28,7 +30,6 @@ export class BaseCodeReminderModal extends React.Component {
super(props);

this.errorMessageRef = React.createRef();
this.modalRef = React.createRef();

this.state = {
mode: REMIND_MODE,
Expand All @@ -39,14 +40,6 @@ export class BaseCodeReminderModal extends React.Component {
this.getNumberOfSelectedCodes = this.getNumberOfSelectedCodes.bind(this);
}

componentDidMount() {
const { current: { firstFocusableElement } } = this.modalRef;

if (firstFocusableElement) {
firstFocusableElement.focus();
}
}

componentDidUpdate(prevProps) {
const {
submitFailed,
Expand Down Expand Up @@ -217,31 +210,46 @@ export class BaseCodeReminderModal extends React.Component {
} = this.state;

return (
<Modal
ref={this.modalRef}
dialogClassName="code-reminder"
title={this.renderTitle()}
body={this.renderBody()}
buttons={[
<Button
key="remind-submit-btn"
disabled={submitting}
className="code-remind-save-btn"
onClick={handleSubmit(this.handleModalSubmit)}
>
{mode === REMIND_MODE && submitting && <Spinner animation="border" variant="primary" size="sm" />}
Remind
</Button>,
<SaveTemplateButton
key="save-remind-template-btn"
templateType={REMIND_MODE}
setMode={this.setMode}
handleSubmit={handleSubmit}
/>,
]}
<ModalDialog
isOpen
size="lg"
onClose={onClose}
open
/>
className="code-reminder"
hasCloseButton
>
<ModalDialog.Header>
<ModalDialog.Title>
{this.renderTitle()}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body>
{this.renderBody()}
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="link">
Cancel
</ModalDialog.CloseButton>
<Button
key="remind-submit-btn"
disabled={submitting}
className="code-remind-save-btn"
onClick={handleSubmit(this.handleModalSubmit)}
>
<>
{mode === REMIND_MODE && submitting && <Spinner animation="border" variant="primary" size="sm" />}

Check failure on line 240 in src/components/CodeReminderModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined

Check failure on line 240 in src/components/CodeReminderModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined
Remind
</>
</Button>,
<SaveTemplateButton
key="save-remind-template-btn"
templateType={REMIND_MODE}
setMode={this.setMode}
handleSubmit={handleSubmit}
/>,
</ActionRow>
</ModalDialog.Footer>
</ModalDialog>
);
}
}
Expand Down
85 changes: 45 additions & 40 deletions src/components/CodeRevokeModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import { Field, reduxForm, SubmissionError } from 'redux-form';
import {
Button, Modal, Spinner,
Button, Icon, ModalDialog, ActionRow,

Check failure on line 5 in src/components/CodeRevokeModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Icon' is defined but never used
} from '@edx/paragon';
import { Info } from '@edx/paragon/icons';

Expand Down Expand Up @@ -30,7 +30,6 @@ class CodeRevokeModal extends React.Component {
super(props);

this.errorMessageRef = React.createRef();
this.modalRef = React.createRef();

this.state = {
mode: MODAL_TYPES.revoke,
Expand All @@ -42,14 +41,6 @@ class CodeRevokeModal extends React.Component {
this.handleModalSubmit = this.handleModalSubmit.bind(this);
}

componentDidMount() {
const { current: { firstFocusableElement } } = this.modalRef;

if (firstFocusableElement) {
firstFocusableElement.focus();
}
}

componentDidUpdate(prevProps) {
const {
submitFailed,
Expand Down Expand Up @@ -177,11 +168,11 @@ class CodeRevokeModal extends React.Component {
<>
{submitFailed
&& (
<ModalError
title={ERROR_MESSAGE_TITLES[mode]}
errors={error}
ref={this.errorMessageRef}
/>
<ModalError
title={ERROR_MESSAGE_TITLES[mode]}
errors={error}
ref={this.errorMessageRef}
/>
)}
<div className="assignment-details mb-4">
{(isBulkRevoke && data.selectedCodes.length > 0) && <p className="bulk-selected-codes">{displaySelectedCodes(data.selectedCodes.length)}</p>}
Expand Down Expand Up @@ -228,32 +219,46 @@ class CodeRevokeModal extends React.Component {
} = this.state;

return (
<Modal
ref={this.modalRef}
dialogClassName="code-revoke"
title={this.renderTitle()}
body={this.renderBody()}
buttons={[
<Button
key="revoke-submit-btn"
disabled={submitting}
className="code-revoke-save-btn"
onClick={handleSubmit(this.handleModalSubmit)}
>
{mode === MODAL_TYPES.revoke && submitting && <Spinner animation="border" className="mr-2" variant="primary" size="sm" />}
Revoke
</Button>,
<SaveTemplateButton
key="save-revoke-template-btn"
templateType={MODAL_TYPES.revoke}
setMode={this.setMode}
handleSubmit={handleSubmit}
disabled={doNotEmail}
/>,
]}
<ModalDialog
isOpen
onClose={onClose}
open
/>
className="code-revoke"
hasCloseButton
>
<ModalDialog.Header>
<ModalDialog.Title>
{this.renderTitle()}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body>
{this.renderBody()}
</ModalDialog.Body>
<ModalDialog.Footer>
<ActionRow>
<ModalDialog.CloseButton variant="link">
Close
</ModalDialog.CloseButton>
<Button
key="revoke-submit-btn"
disabled={submitting}
className="code-revoke-save-btn"
onClick={handleSubmit(this.handleModalSubmit)}
>
<>
{mode === MODAL_TYPES.revoke && submitting && <Spinner animation="border" className="mr-2" variant="primary" size="sm" />}

Check failure on line 248 in src/components/CodeRevokeModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined

Check failure on line 248 in src/components/CodeRevokeModal/index.jsx

View workflow job for this annotation

GitHub Actions / tests

'Spinner' is not defined
Revoke
</>
</Button>,
<SaveTemplateButton
key="save-revoke-template-btn"
templateType={MODAL_TYPES.revoke}
setMode={this.setMode}
handleSubmit={handleSubmit}
disabled={doNotEmail}
/>,
</ActionRow>
</ModalDialog.Footer>
</ModalDialog>
);
}
}
Expand Down
Loading

0 comments on commit 1b3c6f7

Please sign in to comment.