import { Box, Button, Collapse, FormControl, FormErrorMessage, FormLabel, HStack, Icon, InputGroup, InputRightAddon, NumberDecrementStepper, NumberIncrementStepper, NumberInput, NumberInputField, NumberInputStepper, Radio, RadioGroup, Stack, Switch, Tab, TabList, TabPanel, TabPanels, Tabs, Tooltip, } from '@chakra-ui/react'; import { useQuery } from '@tanstack/react-query'; import { __ } from '@wordpress/i18n'; import React, { useState } from 'react'; import { Controller, useFormContext, useWatch } from 'react-hook-form'; import { BiInfoCircle } from 'react-icons/bi'; import FormControlTwoCol from '../../../../assets/js/back-end/components/common/FormControlTwoCol'; import { infoIconStyles, tabListStyles, tabStyles, } from '../../../../assets/js/back-end/config/styles'; import http from '../../../../assets/js/back-end/utils/http'; import { convertMinutesToHours } from '../../../../assets/js/back-end/utils/math'; import { CustomChakraRadio } from '../../../../assets/js/getting-started/components/CustomChakraRadio'; import h5pUrls from '../../constants/urls'; interface Props { defaultValues?: any; } const H5PQuizSettings: React.FC = ({ defaultValues = {} }) => { const { control, setValue, formState: { errors }, } = useFormContext(); const quizId = defaultValues?.id; const fullPointsQuery = useQuery<{ full_points: number }>({ queryKey: [`${quizId}h5pFullPoints`, quizId], queryFn: () => http({ path: h5pUrls.h5pQuizzes + '/' + quizId + '/full-points', method: 'post', }), enabled: false, }); const [hours, minutes] = convertMinutesToHours(defaultValues?.duration || 0); const [attemptsDisplayValue, setAttemptsDisplayValue] = useState( defaultValues?.attempts_allowed && defaultValues.attempts_allowed !== 0 ? '1' : '0', ); // questions_display_per_page: 0 = "From Global Settings", any other value = "Set Individually" const defaultDisplayPerPage = !defaultValues?.questions_display_per_page || defaultValues.questions_display_per_page === 0 ? '0' : '1'; const watchDisplayPerPage = useWatch({ name: 'questions_display_per_page_mode', defaultValue: defaultDisplayPerPage, control, }); const watchPassType = useWatch({ name: 'pass_mark_type', defaultValue: defaultValues?.pass_mark_type || 'point', control, }); const isPassPercent = 'percentage' === watchPassType; return ( {__('General', 'learning-management-system')} {__('Display', 'learning-management-system')} {/* General tab */} {/* Full Points */} {__('Full Points', 'learning-management-system')} ( )} /> {/* Pass Points */} {__('Pass', 'learning-management-system')}{' '} {isPassPercent ? __('Percent', 'learning-management-system') : __('Points', 'learning-management-system')} ( )} /> {/* Time limit */} {__('Time limit', 'learning-management-system')} ( {__('Hours', 'learning-management-system')} )} /> {errors?.duration_hour && (errors.duration_hour.message as string)} ( {__('Minutes', 'learning-management-system')} )} /> {errors?.duration_minute && (errors.duration_minute.message as string)} {/* Attempts Allowed */} {__('Attempts Allowed', 'learning-management-system')} setValue('attempts_allowed', e.target.value) } > {__('No limit', 'learning-management-system')} setValue( 'attempts_allowed', defaultValues?.attempts_allowed || 5, ) } > {__('Limit', 'learning-management-system')} {/* Number of Attempts */} {__('Number of Attempts', 'learning-management-system')} ( {__('Attempts', 'learning-management-system')} )} /> {errors?.attempts_allowed && (errors.attempts_allowed.message as string)} {/* Display tab */} {/* Questions Per Page */} {__('Questions Per Page', 'learning-management-system')} ( {__( 'From Global Settings', 'learning-management-system', )} {__( 'Set Individually', 'learning-management-system', )} )} /> ( )} /> {errors?.questions_display_per_page_custom && (errors.questions_display_per_page_custom .message as string)} {/* Randomize Questions */} {__('Randomize Questions', 'learning-management-system')} ( )} /> {/* Show Result */} {__('Show Result', 'learning-management-system')} ( )} /> ); }; export default H5PQuizSettings;