Skip to content

Commit

Permalink
implemented similar registerBeforeNext and onComplete functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkarimoff committed Jan 4, 2024
1 parent 0268dae commit 60e6076
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions lib/interviewer/containers/ProtocolScreen.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
import React from 'react';
import React, { useState } from 'react';
import Stage from './Stage';
import { AnimatePresence, motion } from 'framer-motion';
import { getCurrentStage } from '../selectors/session';
import { useSelector } from 'react-redux';
import Navigation from '../components/Navigation';

const registerBeforeNext = () => {
// console.log('TODO: implement registerBeforeNext lib/interviewer/containers/ProtocolScreen.js');
};
const ProtocolScreen = (props) => {
const currentStage = useSelector(getCurrentStage);
const [beforeNextFunctions, setBeforeNextFunctions] = useState({});
const [pendingStage, setPendingStage] = useState(-1);
const [pendingDirection, setPendingDirection] = useState(1);

const onComplete = () => {
// console.log('TODO: implement onComplete lib/interviewer/containers/ProtocolScreen.js');
};
const onComplete = (directionOverride) => {
const { goToNext } = props;
const nextDirection = directionOverride || pendingDirection;

const ProtocolScreen = () => {
const currentStage = useSelector(getCurrentStage);
const navigate =
pendingStage === -1
? () => goToNext(nextDirection)
: () => goToStage(pendingStage);

setPendingStage(-1);
setPendingDirection(1);
navigate();
};

const registerBeforeNext = (beforeNext, stageId) => {
if (beforeNext === null) return;

setBeforeNextFunctions((prevFunctions) => ({
...prevFunctions,
[stageId]: beforeNext,
}));
};

const goToStage = (index) => {
const { isSkipped, openDialog, goToStage } = props;
if (isSkipped(index)) {
openDialog({
type: 'Warning',
title: 'Show this stage?',
confirmLabel: 'Show Stage',
onConfirm: () => goToStage(index),
message: (
<p>
Your skip logic settings would normally prevent this stage from
being shown in this interview. Do you want to show it anyway?
</p>
),
});
} else {
goToStage(index);
}
};

if (!currentStage) {
return null;
Expand Down

0 comments on commit 60e6076

Please sign in to comment.