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
@@ -89,15 +96,19 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
89
96
</ DialogHeader >
90
97
< div >
91
98
< Label > Category</ Label >
92
- < Input
93
- id = "category"
94
- value = { question . category }
99
+ < MultiSelect
95
100
className = "mt-2"
96
- onChange = { ( e ) =>
97
- setQuestion ( { ...question , category : e . target . value } )
101
+ defaultValue = { question . categories as string [ ] }
102
+ options = { CategoryEnumArray . map ( ( category ) => ( {
103
+ label : category ,
104
+ value : category ,
105
+ } ) ) }
106
+ onValueChange = { ( v ) =>
107
+ setQuestion ( {
108
+ ...question ,
109
+ categories : v as CategoryEnum [ ] ,
110
+ } )
98
111
}
99
- disabled = { ! props . isAdmin }
100
- required
101
112
/>
102
113
</ div >
103
114
@@ -107,7 +118,7 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
107
118
{ props . isAdmin ? (
108
119
< Select
109
120
value = { question . complexity }
110
- onValueChange = { ( e ) =>
121
+ onValueChange = { ( e : ComplexityEnum ) =>
111
122
setQuestion ( { ...question , complexity : e } )
112
123
}
113
124
disabled = { ! props . isAdmin }
@@ -116,19 +127,18 @@ const QuestionFormModal: React.FC<QuestionFormModalProps> = ({ ...props }) => {
116
127
< SelectValue placeholder = "Select complexity" />
117
128
</ SelectTrigger >
118
129
< SelectContent >
119
- < SelectItem value = "easy" > Easy</ SelectItem >
120
- < SelectItem value = "medium" > Medium</ SelectItem >
121
- < SelectItem value = "hard" > Hard</ SelectItem >
130
+ { ComplexityEnumArray . map ( ( complexity ) => (
131
+ < SelectItem key = { complexity } value = { complexity } >
132
+ { complexity }
133
+ </ SelectItem >
134
+ ) ) }
122
135
</ SelectContent >
123
136
</ Select >
124
137
) : (
125
138
< Input
126
139
id = "complexity"
127
140
value = { question . complexity }
128
- onChange = { ( e ) =>
129
- setQuestion ( { ...question , complexity : e . target . value } )
130
- }
131
- disabled = { ! props . isAdmin }
141
+ disabled
132
142
/>
133
143
) }
134
144
</ div >
0 commit comments