Skip to content

Commit

Permalink
fix: Making sure email setting model opens when emailSettingsModal.op…
Browse files Browse the repository at this point in the history
…en is true
  • Loading branch information
zwidekalanga committed Aug 7, 2024
1 parent 01ceb41 commit 1850887
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ export const getScreenReaderText = (str) => (
);

const BaseCourseCard = ({
hasEmailsEnabled: defaultHasEmailsEnabled,
title,
dropdownMenuItems: customDropdownMenuItem,
canUnenroll,
Expand All @@ -148,7 +147,6 @@ const BaseCourseCard = ({
const intl = useIntl();
const { LEARNER_SUPPORT_PACED_COURSE_MODE_URL } = getConfig();
const { data: enterpriseCustomer } = useEnterpriseCustomer();
const [hasEmailsEnabled, setHasEmailsEnabled] = useState(defaultHasEmailsEnabled);
const [emailSettingsModal, setEmailSettingsModal] = useState({
open: false,
options: {},
Expand Down Expand Up @@ -189,9 +187,7 @@ const BaseCourseCard = ({
setEmailSettingsModal((prevState) => ({
...prevState,
open: true,
options: {
hasEmailsEnabled,
},
options: {},
}));
sendEnterpriseTrackEvent(
enterpriseCustomer.uuid,
Expand All @@ -203,7 +199,7 @@ const BaseCourseCard = ({
const getDropdownMenuItems = () => {
const firstMenuItems = [];
const lastMenuItems = [];
if (hasEmailsEnabled !== null && !isExecutiveEducation2UCourse) {
if (!isExecutiveEducation2UCourse) {
firstMenuItems.push({
key: 'email-settings',
type: 'button',
Expand Down Expand Up @@ -267,11 +263,8 @@ const BaseCourseCard = ({
}));
};

const handleEmailSettingsModalOnClose = (newValue) => {
const handleEmailSettingsModalOnClose = () => {
resetModals();
if (hasEmailsEnabled !== undefined) {
setHasEmailsEnabled(newValue);
}
};

const handleUnenrollModalOnClose = () => {
Expand Down Expand Up @@ -341,19 +334,14 @@ const BaseCourseCard = ({
);
};

const renderEmailSettingsModal = () => {
if (!hasEmailsEnabled) {
return null;
}
return (
<EmailSettingsModal
{...emailSettingsModal.options}
courseRunId={courseRunId}
onClose={handleEmailSettingsModalOnClose}
open={emailSettingsModal.open}
/>
);
};
const renderEmailSettingsModal = () => (
<EmailSettingsModal
{...emailSettingsModal.options}
courseRunId={courseRunId}
onClose={handleEmailSettingsModalOnClose}
open={emailSettingsModal.open}
/>
);

const renderAdditionalInfoOutline = () => {
if (type !== COURSE_STATUSES.requested) {
Expand Down Expand Up @@ -635,7 +623,6 @@ BaseCourseCard.propTypes = {
children: PropTypes.node,
startDate: PropTypes.string,
endDate: PropTypes.string,
hasEmailsEnabled: PropTypes.bool,
canUnenroll: PropTypes.bool,
microMastersTitle: PropTypes.string,
orgName: PropTypes.string,
Expand All @@ -659,7 +646,6 @@ BaseCourseCard.defaultProps = {
children: null,
startDate: null,
endDate: null,
hasEmailsEnabled: null,
canUnenroll: null,
microMastersTitle: null,
orgName: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ describe('<BaseCourseCard />', () => {
it('handles email settings modal close/cancel', async () => {
userEvent.click(screen.getByTestId('modal-footer-btn', { name: 'Close' }));
await waitFor(() => {
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
const dialogElement = screen.queryByRole('dialog');

if (dialogElement) {
expect(dialogElement).not.toHaveClass('show');
}
});
});
});
Expand Down

0 comments on commit 1850887

Please sign in to comment.