Skip to content

Commit 53f9cb1

Browse files
authored
feat: added logic to display hotjar survey widget (#120)
1 parent ba4f0da commit 53f9cb1

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/components/HotjarSurvey/index.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { useEffect } from 'react';
2+
import { useGlobalState, useStepInfo, useAssessmentStepConfig } from 'hooks/app';
3+
import { stepNames, stepStates } from 'constants';
4+
5+
export const HotjarSurvey = () => {
6+
const configInfo = useAssessmentStepConfig();
7+
const stepInfo = useStepInfo();
8+
const isSelfRequired = configInfo.settings[stepNames.self].required;
9+
const isPeerRequired = configInfo.settings[stepNames.peer].required;
10+
const stepState = useGlobalState(stepNames.self).activeStepState;
11+
12+
let isShowSurvey = false;
13+
/*
14+
Hotjar survey widget will show for the following scenarios:
15+
1. ORA is configured with self AND NOT peer assessment.
16+
After completing self assessment survey will render (xblock)
17+
2. ORA is configured with self AND peer assessment. Survey
18+
will render when learner completed their assignments
19+
*/
20+
if (isSelfRequired && !isPeerRequired) {
21+
isShowSurvey = (stepState === stepStates.done);
22+
} else if (isPeerRequired && stepInfo[stepNames.peer] != null) {
23+
const stepConfigInfo = configInfo.settings[stepNames.peer];
24+
const { minNumberToGrade } = stepConfigInfo;
25+
const { numberOfAssessmentsCompleted } = stepInfo[stepNames.peer];
26+
27+
isShowSurvey = (minNumberToGrade === numberOfAssessmentsCompleted);
28+
}
29+
30+
useEffect(() => {
31+
if (isShowSurvey && window.hj) {
32+
window.hj('event', 'lms_openassessment_survey');
33+
}
34+
});
35+
return (
36+
<div id="openassessment_hotjar" />
37+
);
38+
};
39+
40+
export default HotjarSurvey;

src/views/XBlockView/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Prompt from 'components/Prompt';
77
import Rubric from 'components/Rubric';
88
import Instructions from 'components/Instructions';
99
import StatusAlert from 'components/StatusAlert';
10+
import HotjarSurvey from 'components/HotjarSurvey';
1011

1112
import StatusRow from './StatusRow';
1213
import Actions from './Actions';
@@ -31,6 +32,7 @@ export const XBlockView = () => {
3132
<ProgressBar />
3233
<StatusRow />
3334
<StatusAlert />
35+
<HotjarSurvey />
3436
<Instructions />
3537
<Actions />
3638
{prompts.map(prompt => <Prompt key={prompt} prompt={prompt} />)}

0 commit comments

Comments
 (0)