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

fix: fixes incorrect status reporting for self step and #151

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 20 additions & 10 deletions src/components/HotjarSurvey/index.jsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import React, { useEffect } from 'react';
import { useGlobalState, useStepInfo, useAssessmentStepConfig } from 'hooks/app';

import {
useGlobalState,
useStepInfo,
useAssessmentStepConfig,
useAssessmentStepOrder,
useStepState,
} from 'hooks/app';
import { stepNames, stepStates } from 'constants';

export const HotjarSurvey = () => {
const configInfo = useAssessmentStepConfig();
const assessmentStepConfig = useAssessmentStepConfig();
const stepInfo = useStepInfo();
const isSelfRequired = configInfo.settings[stepNames.self].required;
const isPeerRequired = configInfo.settings[stepNames.peer].required;
const stepState = useGlobalState(stepNames.self).activeStepState;
const assessmentStepOrder = useAssessmentStepOrder();
const isSelfRequired = assessmentStepOrder.includes(stepNames.self);
const isPeerRequired = assessmentStepOrder.includes(stepNames.peer);
const isSelfDone = useStepState({ step: stepNames.self }) === stepStates.done;

const globalState = useGlobalState();

let isShowSurvey = false;

/*
Hotjar survey widget will show for the following scenarios:
1. ORA is configured with self AND NOT peer assessment.
Expand All @@ -18,13 +29,12 @@ export const HotjarSurvey = () => {
will render when learner completed their assignments
*/
if (isSelfRequired && !isPeerRequired) {
isShowSurvey = (stepState === stepStates.done);
} else if (isPeerRequired && stepInfo[stepNames.peer] != null) {
const stepConfigInfo = configInfo.settings[stepNames.peer];
isShowSurvey = isSelfDone;
} else if (isPeerRequired && globalState.activeStepName === stepNames.peer && stepInfo[stepNames.peer] != null) {
const stepConfigInfo = assessmentStepConfig.settings[stepNames.peer];
const { minNumberToGrade } = stepConfigInfo;
const { numberOfAssessmentsCompleted } = stepInfo[stepNames.peer];

isShowSurvey = (minNumberToGrade === numberOfAssessmentsCompleted);
isShowSurvey = isSelfDone && (minNumberToGrade === numberOfAssessmentsCompleted);
}

useEffect(() => {
Expand Down
3 changes: 1 addition & 2 deletions src/data/services/lms/hooks/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export const useStepState = ({ step = null } = {}) => {
if (stepName === stepNames.studentTraining && trainingStepIsCompleted) {
return stepStates.done;
}

if (activeStepName === stepNames.peer && stepInfo?.peer) {
if (step === stepNames.peer && stepInfo?.peer) {
const config = stepConfig[stepNames.peer];
const { numberOfAssessmentsCompleted, numberOfReceivedAssessments } = stepInfo.peer;
const { minNumberToGrade, minNumberToBeGradedBy } = config;
Expand Down