Skip to content

Commit 9228d01

Browse files
authored
feat: course banner slot (#559)
1 parent 1104c58 commit 9228d01

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

src/containers/CourseCard/components/CourseCardBanners/__snapshots__/index.test.jsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ exports[`CourseCardBanners render with isEnrolled false 1`] = `
88
<RelatedProgramsBanner
99
cardId="test-card-id"
1010
/>
11-
<CourseBanner
11+
<CourseBannerSlot
1212
cardId="test-card-id"
1313
/>
1414
<EntitlementBanner
@@ -25,7 +25,7 @@ exports[`CourseCardBanners renders default CourseCardBanners 1`] = `
2525
<RelatedProgramsBanner
2626
cardId="test-card-id"
2727
/>
28-
<CourseBanner
28+
<CourseBannerSlot
2929
cardId="test-card-id"
3030
/>
3131
<EntitlementBanner

src/containers/CourseCard/components/CourseCardBanners/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33

44
import { reduxHooks } from 'hooks';
55

6-
import CourseBanner from './CourseBanner';
6+
import CourseBannerSlot from 'plugin-slots/CourseBannerSlot';
77
import CertificateBanner from './CertificateBanner';
88
import CreditBanner from './CreditBanner';
99
import EntitlementBanner from './EntitlementBanner';
@@ -14,7 +14,7 @@ export const CourseCardBanners = ({ cardId }) => {
1414
return (
1515
<div className="course-card-banners" data-testid="CourseCardBanners">
1616
<RelatedProgramsBanner cardId={cardId} />
17-
<CourseBanner cardId={cardId} />
17+
<CourseBannerSlot cardId={cardId} />
1818
<EntitlementBanner cardId={cardId} />
1919
{isEnrolled && <CertificateBanner cardId={cardId} />}
2020
{isEnrolled && <CreditBanner cardId={cardId} />}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Course Card Action Slot
2+
3+
### Slot ID: `course_banner_slot`
4+
### Props:
5+
* `cardId`
6+
7+
## Description
8+
9+
This slot is used for replacing or adding content for the `CourseBanner` component. This banner is rendered as a child of the `CourseCard`.
10+
11+
The default CourseBanner looks like this when audit access has expired for the course:
12+
![Screenshot of the default CourseBanner when audit access has expired](./images/course_banner_slot_default.png)
13+
14+
## Example
15+
16+
The following `env.config.jsx` will render a custom implemenation of a CourseBanner under every `CourseCard`.
17+
18+
![Screenshot of custom banner added under CourseCard](./images/course_banner_slot_default.png)
19+
20+
```js
21+
import { DIRECT_PLUGIN, PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
22+
23+
const config = {
24+
pluginSlots: {
25+
course_banner_slot: {
26+
keepDefault: false,
27+
plugins: [
28+
{
29+
op: PLUGIN_OPERATIONS.Insert,
30+
widget: {
31+
id: 'custom_course_banner',
32+
type: DIRECT_PLUGIN,
33+
priority: 60,
34+
RenderWidget: ({ cardId }) => (
35+
<Alert variant="info" className="mb-0">
36+
Course banner for course with {cardId}
37+
</Alert>
38+
),
39+
},
40+
},
41+
],
42+
},
43+
},
44+
}
45+
46+
export default config;
47+
```
90.4 KB
Loading
87.2 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { PluginSlot } from '@openedx/frontend-plugin-framework';
4+
import CourseBanner from 'containers/CourseCard/components/CourseCardBanners/CourseBanner';
5+
6+
const CourseBannerSlot = ({ cardId }) => (
7+
<PluginSlot
8+
id="course_banner_slot"
9+
pluginProps={{
10+
cardId,
11+
}}
12+
>
13+
<CourseBanner
14+
cardId={cardId}
15+
/>
16+
</PluginSlot>
17+
);
18+
19+
CourseBannerSlot.propTypes = {
20+
cardId: PropTypes.string.isRequired,
21+
};
22+
23+
export default CourseBannerSlot;

0 commit comments

Comments
 (0)