1
- import React from 'react' ;
1
+ import React , { useState } from 'react' ;
2
2
import {
3
3
Dialog ,
4
4
DialogContent ,
@@ -7,14 +7,17 @@ import {
7
7
DialogTitle ,
8
8
} from '../ui/dialog' ;
9
9
import { Button } from '../ui/button' ;
10
- import { getDifficultyString } from '@/lib/utils' ;
11
- import { ProblemDialogData } from '@/types/types' ;
10
+ import { Problem } from '@/types/types' ;
11
+ import { Textarea } from '../ui/textarea' ;
12
+ import { Input } from '../ui/input' ;
13
+ import { FilterSelect } from '@/app/(main)/components/filter/FilterSelect' ;
14
+ import { TopicsPopover } from '@/app/(main)/components/filter/TopicsPopover' ;
12
15
13
16
type Props = {
14
17
isOpen : boolean ;
15
18
onClose : ( ) => void ;
16
- problem : ProblemDialogData | null ;
17
- requestCallback : ( ) => void ;
19
+ problem : Problem ;
20
+ requestCallback : ( problem : Problem ) => void ;
18
21
requestTitle : string ;
19
22
} ;
20
23
@@ -25,25 +28,76 @@ function ProblemInputDialog({
25
28
requestCallback,
26
29
requestTitle,
27
30
} : Props ) {
31
+ const [ problemData , setProblemData ] = useState < Problem > ( problem ) ;
32
+
33
+ const handleSubmit = async ( ) => {
34
+ requestCallback ( problemData ) ;
35
+ } ;
36
+
28
37
if ( ! problem ) return null ;
29
38
30
39
return (
31
40
< Dialog open = { isOpen } onOpenChange = { onClose } >
32
41
< DialogContent className = "bg-black" >
33
42
< DialogHeader >
34
- < DialogTitle > { problem . title } </ DialogTitle >
35
- < DialogDescription >
36
- Difficulty: { getDifficultyString ( problem . difficulty ) }
37
- </ DialogDescription >
43
+ < DialogTitle > Edit Question</ DialogTitle >
44
+ < DialogDescription />
38
45
</ DialogHeader >
39
- < div className = "mt-4" >
40
- < h3 className = "mb-2 text-lg font-semibold" > Description:</ h3 >
41
- < p > { problem . description } </ p >
42
- </ div >
43
- < div className = "mt-6 flex justify-end" >
44
- < Button variant = "secondary" onClick = { requestCallback } >
45
- { requestTitle }
46
- </ Button >
46
+ < div className = "space-y-4" >
47
+ < div className = "space-y-2" >
48
+ < p > Description</ p >
49
+ < Input
50
+ name = "title"
51
+ placeholder = "Question Title"
52
+ defaultValue = { problemData . title }
53
+ onChange = { ( e ) => {
54
+ setProblemData ( { ...problemData , title : e . target . value } ) ;
55
+ } }
56
+ required
57
+ />
58
+ </ div >
59
+ < div className = "space-y-2" >
60
+ < p > Difficulty</ p >
61
+ < FilterSelect
62
+ placeholder = "difficulty"
63
+ options = { [
64
+ { value : '1' , label : 'Easy' } ,
65
+ { value : '2' , label : 'Medium' } ,
66
+ { value : '3' , label : 'Hard' } ,
67
+ ] }
68
+ onChange = { ( value ) => {
69
+ setProblemData ( { ...problemData , difficulty : Number ( value ) } ) ;
70
+ } }
71
+ value = { String ( problemData . difficulty ) }
72
+ />
73
+ </ div >
74
+ < div className = "space-y-2" >
75
+ < p > Description</ p >
76
+ < Textarea
77
+ name = "description"
78
+ placeholder = "Question Description"
79
+ defaultValue = { problemData . description }
80
+ onChange = { ( e ) => {
81
+ setProblemData ( { ...problemData , description : e . target . value } ) ;
82
+ } }
83
+ className = "min-h-[100px]"
84
+ required
85
+ />
86
+ </ div >
87
+ < div className = "space-y-2" >
88
+ < p > Topics</ p >
89
+ < TopicsPopover
90
+ selectedTopics = { problemData . tags }
91
+ onChange = { ( value ) => {
92
+ setProblemData ( { ...problemData , tags : value } ) ;
93
+ } }
94
+ />
95
+ </ div >
96
+ < div className = "mt-2 flex justify-end" >
97
+ < Button variant = "secondary" onClick = { handleSubmit } >
98
+ { requestTitle }
99
+ </ Button >
100
+ </ div >
47
101
</ div >
48
102
</ DialogContent >
49
103
</ Dialog >
0 commit comments