fixed question modal and form
This commit is contained in:
parent
00d49635d8
commit
8d81c12fbe
@ -12,12 +12,12 @@ import {
|
|||||||
|
|
||||||
import { useOpenaiGenerateQuestion } from "../../hooks/questions/useOpenaiGenerateQuestion";
|
import { useOpenaiGenerateQuestion } from "../../hooks/questions/useOpenaiGenerateQuestion";
|
||||||
import type { QuestionPayload } from "../../api/questionsApi";
|
import type { QuestionPayload } from "../../api/questionsApi";
|
||||||
|
import { useCategories } from "../../hooks/categories/useCategories";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
onGenerated: (question: QuestionPayload) => void;
|
onGenerated: (question: QuestionPayload) => void;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const GenerateQuestionModal = ({ open, onClose, onGenerated }: Props) => {
|
const GenerateQuestionModal = ({ open, onClose, onGenerated }: Props) => {
|
||||||
@ -28,6 +28,7 @@ const GenerateQuestionModal = ({ open, onClose, onGenerated }: Props) => {
|
|||||||
const [language, setLanguage] = useState<"en" | "sr" | "hu" | "ru">("en");
|
const [language, setLanguage] = useState<"en" | "sr" | "hu" | "ru">("en");
|
||||||
const [difficulty, setDifficulty] = useState(5);
|
const [difficulty, setDifficulty] = useState(5);
|
||||||
const [prompt, setPrompt] = useState("");
|
const [prompt, setPrompt] = useState("");
|
||||||
|
const { data: categories } = useCategories();
|
||||||
|
|
||||||
const handleGenerate = () => {
|
const handleGenerate = () => {
|
||||||
if (!categoryId || !prompt.trim()) return;
|
if (!categoryId || !prompt.trim()) return;
|
||||||
@ -69,14 +70,29 @@ const GenerateQuestionModal = ({ open, onClose, onGenerated }: Props) => {
|
|||||||
<MenuItem value="text">Text</MenuItem>
|
<MenuItem value="text">Text</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
|
|
||||||
<TextField
|
{/* <TextField
|
||||||
label="Category ID"
|
label="Category ID"
|
||||||
type="number"
|
type="number"
|
||||||
value={categoryId}
|
value={categoryId}
|
||||||
onChange={(e) => setCategoryId(Number(e.target.value))}
|
onChange={(e) => setCategoryId(Number(e.target.value))}
|
||||||
fullWidth
|
fullWidth
|
||||||
sx={{ mb: 2 }}
|
sx={{ mb: 2 }}
|
||||||
/>
|
/> */}
|
||||||
|
<TextField
|
||||||
|
select
|
||||||
|
label="Category"
|
||||||
|
value={categoryId}
|
||||||
|
onChange={(e) => setCategoryId(Number(e.target.value))}
|
||||||
|
fullWidth
|
||||||
|
required
|
||||||
|
sx={{ mb: 3 }}
|
||||||
|
>
|
||||||
|
{categories?.map((cat) => (
|
||||||
|
<MenuItem key={cat.id} value={cat.id}>
|
||||||
|
{cat.name}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
|
|
||||||
<TextField
|
<TextField
|
||||||
select
|
select
|
||||||
|
|||||||
@ -130,7 +130,7 @@ const QuestionForm = () => {
|
|||||||
difficulty,
|
difficulty,
|
||||||
category_id: Number(categoryId),
|
category_id: Number(categoryId),
|
||||||
variants: type === "text" ? [] : variants,
|
variants: type === "text" ? [] : variants,
|
||||||
correct_answers: correctAnswers,
|
correct_answers: type === "text" ? [textAnswer]: correctAnswers,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isUpdate && id) {
|
if (isUpdate && id) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user