Skip to content
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
15 changes: 14 additions & 1 deletion src/components/TrainingFailed.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Text } from '@mantine/core';
import { useEffect } from 'react';
import { useStorageEngine } from '../storage/storageEngineHooks';

export function TrainingFailed() {
const { storageEngine } = useStorageEngine();

useEffect(() => {
if (storageEngine) {
storageEngine.rejectCurrentParticipant('Failed training')
.catch(() => {
console.error('Failed to reject participant who failed training');
});
}
}, [storageEngine]);

return (
<Text>
Thank you for participating. Unfortunately you have didn&apos;t answer the training correctly, which means you are not eligible to participate in the study. You may close this window now.
Thank you for participating. Unfortunately you didn&apos;t answer the training correctly, which means you are not eligible to participate in the study. You may close this window now.
</Text>
);
}
17 changes: 4 additions & 13 deletions src/components/response/ResponseBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,19 +256,10 @@
message = `You didn't answer this question correctly after ${trainingAttempts} attempts. ${allowFailedTraining ? 'You can continue to the next question.' : 'Unfortunately you have not met the criteria for continuing this study.'}`;

// If the user has failed the training, wait 5 seconds and redirect to a fail page
if (!allowFailedTraining && storageEngine) {
storageEngine.rejectCurrentParticipant('Failed training')
.then(() => {
setTimeout(() => {
navigate('./../__trainingFailed');
}, 5000);
})
.catch(() => {
console.error('Failed to reject participant who failed training');
setTimeout(() => {
navigate('./../__trainingFailed');
}, 5000);
});
if (!allowFailedTraining) {
setTimeout(() => {
navigate('./../__trainingFailed');
}, 5000);
}
} else if (trainingAttempts - newAttemptsUsed === 1) {
message = 'Please try again. You have 1 attempt left.';
Expand Down Expand Up @@ -299,7 +290,7 @@
),
);
}
}, [attemptsUsed, allResponsesWithDefaults, config, hasCorrectAnswerFeedback, trainingAttempts, allowFailedTraining, storageEngine, navigate, identifier, storeDispatch, alertConfig, saveIncorrectAnswer, trialValidation]);

Check warning on line 293 in src/components/response/ResponseBlock.tsx

View workflow job for this annotation

GitHub Actions / lint / lint

React Hook useCallback has an unnecessary dependency: 'storageEngine'. Either exclude it or remove the dependency array

const nextOnEnter = config?.nextOnEnter ?? studyConfig.uiConfig.nextOnEnter;

Expand Down
6 changes: 6 additions & 0 deletions src/storage/engines/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,12 @@ export abstract class StorageEngine {
if (!this.currentParticipantId || this.participantData === undefined) {
throw new Error('Participant not initialized');
}

// Don't save further answers if participant is rejected
if (this.participantData.rejected) {
return;
}

// Update the local copy of the participant data
this.participantData = {
...this.participantData,
Expand Down
Loading