1
1
"use client" ;
2
2
3
- import { Question } from "@/lib/schemas/question-schema" ;
3
+ import {
4
+ CategoryEnum ,
5
+ CategoryEnumArray ,
6
+ ComplexityEnum ,
7
+ ComplexityEnumArray ,
8
+ Question ,
9
+ } from "@/lib/schemas/question-schema" ;
4
10
import { useEffect , useState } from "react" ;
5
11
import { Input } from "@/components/ui/input" ;
6
12
import {
@@ -19,6 +25,7 @@ import {
19
25
DialogFooter ,
20
26
DialogHeader ,
21
27
} from "@/components/ui/dialog" ;
28
+ import { MultiSelect } from "@/components/ui/multi-select" ;
22
29
23
30
interface QuestionFormModalProps {
24
31
showModal : boolean ;
@@ -33,8 +40,8 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
33
40
const initialQuestionState : Question = {
34
41
id : "" ,
35
42
title : "" ,
36
- category : "" ,
37
- complexity : "easy " ,
43
+ categories : [ ] ,
44
+ complexity : "Easy " ,
38
45
description : "" ,
39
46
} ;
40
47
@@ -85,15 +92,19 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
85
92
</ DialogHeader >
86
93
< div >
87
94
< Label > Category</ Label >
88
- < Input
89
- id = "category"
90
- value = { question . category }
95
+ < MultiSelect
91
96
className = "mt-2"
92
- onChange = { ( e ) =>
93
- setQuestion ( { ...question , category : e . target . value } )
97
+ defaultValue = { question . categories as string [ ] }
98
+ options = { CategoryEnumArray . map ( ( category ) => ( {
99
+ label : category ,
100
+ value : category ,
101
+ } ) ) }
102
+ onValueChange = { ( v ) =>
103
+ setQuestion ( {
104
+ ...question ,
105
+ categories : v as CategoryEnum [ ] ,
106
+ } )
94
107
}
95
- disabled = { ! props . isAdmin }
96
- required
97
108
/>
98
109
</ div >
99
110
@@ -103,7 +114,7 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
103
114
{ props . isAdmin ? (
104
115
< Select
105
116
value = { question . complexity }
106
- onValueChange = { ( e ) =>
117
+ onValueChange = { ( e : ComplexityEnum ) =>
107
118
setQuestion ( { ...question , complexity : e } )
108
119
}
109
120
disabled = { ! props . isAdmin }
@@ -112,19 +123,18 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
112
123
< SelectValue placeholder = "Select complexity" />
113
124
</ SelectTrigger >
114
125
< SelectContent >
115
- < SelectItem value = "easy" > Easy</ SelectItem >
116
- < SelectItem value = "medium" > Medium</ SelectItem >
117
- < SelectItem value = "hard" > Hard</ SelectItem >
126
+ { ComplexityEnumArray . map ( ( complexity ) => (
127
+ < SelectItem value = { complexity } >
128
+ { complexity }
129
+ </ SelectItem >
130
+ ) ) }
118
131
</ SelectContent >
119
132
</ Select >
120
133
) : (
121
134
< Input
122
135
id = "complexity"
123
136
value = { question . complexity }
124
- onChange = { ( e ) =>
125
- setQuestion ( { ...question , complexity : e . target . value } )
126
- }
127
- disabled = { ! props . isAdmin }
137
+ disabled
128
138
/>
129
139
) }
130
140
</ div >
0 commit comments