Skip to content

Commit 3b7239d

Browse files
feat: added product tour to notify all learners (#783)
* feat: added product tour to notify all learners * fix: removed unused function
1 parent 7ebdf1b commit 3b7239d

File tree

4 files changed

+30
-17
lines changed

4 files changed

+30
-17
lines changed

src/discussions/data/hooks.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,6 @@ export const useUserPostingEnabled = () => {
224224
return (isPostingEnabled || isPrivileged);
225225
};
226226

227-
function camelToConstant(string) {
228-
return string.replace(/[A-Z]/g, (match) => `_${match}`).toUpperCase();
229-
}
230-
231227
export const useTourConfiguration = () => {
232228
const intl = useIntl();
233229
const dispatch = useDispatch();
@@ -252,7 +248,7 @@ export const useTourConfiguration = () => {
252248
enabled: tour && Boolean(tour.enabled && tour.showTour && !enableInContextSidebar),
253249
onDismiss: () => handleOnDismiss(tour.id),
254250
onEnd: () => handleOnEnd(tour.id),
255-
checkpoints: tourCheckpoints(intl)[camelToConstant(tour.tourName)],
251+
checkpoints: tourCheckpoints(intl)[tour.tourName],
256252
}
257253
))
258254
), [tours, enableInContextSidebar]);

src/discussions/posts/post-editor/PostEditor.jsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
selectNonCoursewareTopics as inContextNonCourseware,
4444
} from '../../in-context-topics/data/selectors';
4545
import { selectCoursewareTopics, selectNonCoursewareIds, selectNonCoursewareTopics } from '../../topics/data/selectors';
46+
import { updateUserDiscussionsTourByName } from '../../tours/data';
4647
import {
4748
discussionsPath, formikCompatibleHandler, isFormikFieldInvalid, useCommentsPagePath,
4849
} from '../../utils';
@@ -91,6 +92,21 @@ const PostEditor = ({
9192
editReasonCode: Yup.string().required(intl.formatMessage(messages.editReasonCodeError)),
9293
};
9394

95+
const enableNotifyAllLearnersTour = useCallback((enabled) => {
96+
const data = {
97+
enabled,
98+
tourName: 'notify_all_learners',
99+
};
100+
dispatch(updateUserDiscussionsTourByName(data));
101+
}, []);
102+
103+
useEffect(() => {
104+
enableNotifyAllLearnersTour(true);
105+
return () => {
106+
enableNotifyAllLearnersTour(false);
107+
};
108+
}, []);
109+
94110
const canSelectCohort = useCallback((tId) => {
95111
// If the user isn't privileged, they can't edit the cohort.
96112
// If the topic is being edited the cohort can't be changed.
@@ -427,6 +443,7 @@ const PostEditor = ({
427443
<Form.Group>
428444
<Form.Checkbox
429445
name="notifyAllLearners"
446+
id="notify-learners"
430447
checked={values.notifyAllLearners}
431448
onChange={handleChange}
432449
onBlur={handleBlur}

src/discussions/tours/constants.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import messages from './messages';
77
*/
88
export default function tourCheckpoints(intl) {
99
return {
10-
EXAMPLE_TOUR: [
10+
notify_all_learners: [
1111
{
12-
title: intl.formatMessage(messages.exampleTourTitle),
13-
body: intl.formatMessage(messages.exampleTourBody),
14-
target: '#example-tour-target',
12+
title: intl.formatMessage(messages.notifyAllLearnersTourTitle),
13+
body: intl.formatMessage(messages.notifyAllLearnersTourBody),
14+
target: '#notify-learners',
1515
placement: 'bottom',
1616
},
1717
],

src/discussions/tours/messages.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ const messages = defineMessages({
1616
defaultMessage: 'Okay',
1717
description: 'Action to end current tour',
1818
},
19-
exampleTourTitle: {
20-
id: 'tour.example.title',
21-
defaultMessage: 'Example Tour',
22-
description: 'Title for example tour',
19+
notifyAllLearnersTourTitle: {
20+
id: 'tour.title.notifyAllLearners',
21+
defaultMessage: 'Let your learners know.',
22+
description: 'Title of the tour to notify all learners',
2323
},
24-
exampleTourBody: {
25-
id: 'tour.example.body',
26-
defaultMessage: 'This is an example tour',
27-
description: 'Body for example tour',
24+
notifyAllLearnersTourBody: {
25+
id: 'tour.body.notifyAllLearners',
26+
defaultMessage: 'Check this box to notify all learners.',
27+
description: 'Body of the tour to notify all learners',
2828
},
2929
});
3030

0 commit comments

Comments
 (0)