2
2
3
3
import * as z from "zod" ;
4
4
import { FieldValues } from "react-hook-form" ;
5
- import { Modal , Box , Typography , IconButton } from "@mui/material" ;
6
- import { grey } from "@mui/material/colors" ;
7
- import CloseIcon from "@mui/icons-material/Close" ;
8
5
import { CODE_ITEM_TYPE , CODEITEMS_API_ENDPOINT , Label } from "@/types" ;
9
6
import { useUpdateLabel , useCreateLabel , fetchOneCodeItem } from "@/api" ;
10
- import { Form } from "../Form" ;
11
- import { Button } from "../buttons" ;
12
- import { TextInput } from "../inputs" ;
13
7
import { useQuery , useQueryClient } from "@tanstack/react-query" ;
14
8
import { useParams } from "next/navigation" ;
9
+ import { EditLabelModal } from "../labels" ;
15
10
16
11
interface EditCodeItemLabelModalProps {
17
12
isOpen : boolean ;
@@ -23,6 +18,7 @@ interface EditCodeItemLabelModalProps {
23
18
const schema = z . object ( {
24
19
name : z . string ( ) . min ( 1 , { message : "Required" } ) ,
25
20
color : z . string ( ) ,
21
+ text_color : z . string ( ) ,
26
22
} ) ;
27
23
28
24
export const EditCodeItemLabelModal = ( {
@@ -48,6 +44,7 @@ export const EditCodeItemLabelModal = ({
48
44
...editedLabel ,
49
45
name : data . name ,
50
46
color : data . color ,
47
+ text_color : data . text_color ,
51
48
} ) ;
52
49
53
50
await queryClient . invalidateQueries ( {
@@ -61,6 +58,7 @@ export const EditCodeItemLabelModal = ({
61
58
name : data . name ,
62
59
color : data . color ,
63
60
type : CODE_ITEM_TYPE ,
61
+ text_color : data . text_color ,
64
62
} ) ;
65
63
66
64
await queryClient . invalidateQueries ( {
@@ -73,83 +71,15 @@ export const EditCodeItemLabelModal = ({
73
71
} ;
74
72
75
73
return (
76
- < Modal
77
- open = { isOpen }
74
+ < EditLabelModal
75
+ onSaveLabel = { onSaveLabel }
76
+ editedLabel = { editedLabel }
77
+ isLoadingUpdate = { isLoadingUpdate }
78
+ isOpen = { isOpen }
79
+ isPending = { isPending }
78
80
onClose = { onClose }
79
- slotProps = { {
80
- backdrop : {
81
- invisible : true ,
82
- } ,
83
- } }
84
- >
85
- < Box
86
- sx = { {
87
- position : "absolute" ,
88
- top : "50%" ,
89
- left : "50%" ,
90
- transform : "translate(-50%, -50%)" ,
91
- minWidth : 300 ,
92
- bgcolor : "background.paper" ,
93
- boxShadow : 24 ,
94
- p : 4 ,
95
- borderRadius : 2 ,
96
- } }
97
- >
98
- < Typography variant = "h6" component = "h2" sx = { { mb : 2 } } >
99
- { editedLabel ? "Edit label" : "Create label" }
100
- </ Typography >
101
-
102
- < IconButton
103
- aria-label = "close"
104
- onClick = { onClose }
105
- sx = { {
106
- position : "absolute" ,
107
- right : 8 ,
108
- top : 8 ,
109
- } }
110
- >
111
- < CloseIcon />
112
- </ IconButton >
113
-
114
- < Form schema = { schema } onSubmit = { onSaveLabel } sx = { { height : 1 } } >
115
- < TextInput
116
- fullWidth
117
- label = "Label Name"
118
- name = "name"
119
- defaultValue = { editedLabel ?. name }
120
- required
121
- />
122
-
123
- < Typography sx = { { mt : 2 , mb : 1 } } > Label Color</ Typography >
124
-
125
- < Box >
126
- < TextInput
127
- name = "color"
128
- type = "color"
129
- fullWidth
130
- variant = "standard"
131
- defaultValue = { editedLabel ?. color || label ?. color || grey [ 100 ] }
132
- inputProps = { {
133
- sx : {
134
- height : "53.15px" ,
135
- p : 0 ,
136
- cursor : "pointer" ,
137
- borderRadius : 2 ,
138
- } ,
139
- } }
140
- />
141
- </ Box >
142
-
143
- < Button
144
- variant = "contained"
145
- type = "submit"
146
- sx = { { mt : 3 } }
147
- isLoading = { isPending || isLoadingUpdate }
148
- >
149
- Save
150
- </ Button >
151
- </ Form >
152
- </ Box >
153
- </ Modal >
81
+ schema = { schema }
82
+ label = { label }
83
+ />
154
84
) ;
155
85
} ;
0 commit comments