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

feat: add progress certificate status plugin slot #1551

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { useEffect } from 'react';
import { useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { sendTrackEvent } from '@edx/frontend-platform/analytics';
import { getAuthenticatedUser } from '@edx/frontend-platform/auth';
import {
FormattedDate, FormattedMessage, injectIntl, intlShape,
} from '@edx/frontend-platform/i18n';
import { FormattedDate, FormattedMessage, useIntl } from '@edx/frontend-platform/i18n';

import { Button, Card } from '@openedx/paragon';
import { getConfig } from '@edx/frontend-platform';
Expand All @@ -13,8 +11,10 @@ import { COURSE_EXIT_MODES, getCourseExitMode } from '../../../courseware/course
import { DashboardLink, IdVerificationSupportLink, ProfileLink } from '../../../shared/links';
import { requestCert } from '../../data/thunks';
import messages from './messages';
import ProgressCertificateStatusSlot from '../../../plugin-slots/ProgressCertificateStatusSlot';

const CertificateStatus = ({ intl }) => {
const CertificateStatus = () => {
const intl = useIntl();
const {
courseId,
} = useSelector(state => state.courseHome);
Expand Down Expand Up @@ -215,7 +215,6 @@ const CertificateStatus = ({ intl }) => {
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

if (!certCase) {
return null;
}
Expand Down Expand Up @@ -243,32 +242,32 @@ const CertificateStatus = ({ intl }) => {
return (
<section data-testid="certificate-status-component" className="text-dark-700 mb-4">
<Card className="bg-light-200 raised-card">
<Card.Header title={header} />
<Card.Section className="small text-gray-700">
{body}
</Card.Section>
<Card.Footer>
{buttonText && (buttonLocation || buttonAction) && (
<Button
variant="outline-brand"
onClick={() => {
logCertificateStatusButtonClicked(certStatus);
if (buttonAction) { buttonAction(); }
}}
href={buttonLocation}
block
>
{buttonText}
</Button>
)}
</Card.Footer>
<ProgressCertificateStatusSlot courseId={courseId}>
<div id={`${certCase}_certificate_status`}>
<Card.Header title={header} />
<Card.Section className="small text-gray-700">
{body}
</Card.Section>
<Card.Footer>
{buttonText && (buttonLocation || buttonAction) && (
<Button
variant="outline-brand"
onClick={() => {
logCertificateStatusButtonClicked(certStatus);
if (buttonAction) { buttonAction(); }
}}
href={buttonLocation}
block
>
{buttonText}
</Button>
)}
</Card.Footer>
</div>
</ProgressCertificateStatusSlot>
</Card>
</section>
);
};

CertificateStatus.propTypes = {
intl: intlShape.isRequired,
};

export default injectIntl(CertificateStatus);
export default CertificateStatus;
53 changes: 53 additions & 0 deletions src/plugin-slots/ProgressCertificateStatusSlot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Unit Title Slot

### Slot ID: `progress_certificate_status_slot`
### Props:
* `courseId`

## Description

This slot is used for modify the content in the CertificateStatus in the progress page for specific enrollment tracks.

## Example

The following `env.config.jsx` will render the `RenderWidget.props.id` of the course as `<p>` element.

### Default content
![Certificate Status slot with default content](./screenshot_default.png)

### Replaced with custom component
![Default content id showing in trigger slot](./screenshot_custom.png)

```js
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';

const modifyWidget = (widget) => {
const { RenderWidget } = widget;
if (RenderWidget.props.id.includes('upgrade')) {
widget.RenderWidget = (
<div className='m-3'>
<h3>Upgrade certificate</h3>
<p>{RenderWidget.props.id}</p>
</div>
)
}

return widget;
}

const config = {
pluginSlots: {
progress_certificate_status_slot: {
keepDefault: true,
plugins: [{
op: PLUGIN_OPERATIONS.Modify,
widgetId: 'default_contents',
// Insert custom content top modify certificate status
fn: modifyWidget,
}],
}
},
}

export default config;
```
18 changes: 18 additions & 0 deletions src/plugin-slots/ProgressCertificateStatusSlot/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import PropTypes from 'prop-types';
import { PluginSlot } from '@openedx/frontend-plugin-framework';

const ProgressCertificateStatusSlot = ({ courseId, children }) => (
<PluginSlot
id="progress_certificate_status_slot"
pluginProps={{ courseId }}
>
{children}
</PluginSlot>
);

ProgressCertificateStatusSlot.propTypes = {
courseId: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
};

export default ProgressCertificateStatusSlot;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading