|
| 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; |
0 commit comments