Merge pull request #4

add the confirmation dialog before finishing a test
This commit is contained in:
Dawid Wysokiński 2021-05-25 18:08:05 +02:00 committed by GitHub
commit 41ddf9c31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -36,6 +36,8 @@ export interface TestProps {
qualification: Qualification;
}
const MIN_QUESTIONS_REQUIRED_TO_SHOW_CONFIRMATION = 2;
const Test = ({ initialQuestions, qualification }: TestProps) => {
const headingRef = useRef<HTMLSpanElement | null>(null);
const [isFetching, setIsFetching] = useState(false);
@ -123,10 +125,17 @@ const Test = ({ initialQuestions, qualification }: TestProps) => {
};
const handleFinish = () => {
if (
initialQuestions.length >= MIN_QUESTIONS_REQUIRED_TO_SHOW_CONFIRMATION &&
!window.confirm('Czy na pewno chcesz zakończyć test?')
) {
return;
}
setEndedAt(new Date());
setCurrentTab(currentTab => currentTab + 1);
setReviewMode(true);
};
return (
<Section>
{isFetching && <FixedSpinner />}