1
1
import DialogActions from "@mui/material/DialogActions" ;
2
- import { makeStyles } from "@mui/styles " ;
3
- import { ReactNode , FC , PropsWithChildren } from "react" ;
2
+ import { type Interpolation , type Theme } from "@emotion/react " ;
3
+ import { type FC , type PropsWithChildren , type ReactNode } from "react" ;
4
4
import {
5
5
Dialog ,
6
6
DialogActionButtons ,
7
7
DialogActionButtonsProps ,
8
8
} from "../Dialog" ;
9
- import { ConfirmDialogType } from "../types" ;
10
- import Checkbox from "@mui/material/Checkbox" ;
11
- import FormControlLabel from "@mui/material/FormControlLabel" ;
12
- import { Stack } from "@mui/system" ;
9
+ import type { ConfirmDialogType } from "../types" ;
13
10
14
11
interface ConfirmDialogTypeConfig {
15
12
confirmText : ReactNode ;
@@ -58,8 +55,8 @@ export interface ConfirmDialogProps
58
55
readonly title : string ;
59
56
}
60
57
61
- const useStyles = makeStyles ( ( theme ) => ( {
62
- dialogWrapper : {
58
+ const styles = {
59
+ dialogWrapper : ( theme ) => ( {
63
60
"& .MuiPaper-root" : {
64
61
background : theme . palette . background . paper ,
65
62
border : `1px solid ${ theme . palette . divider } ` ,
@@ -69,19 +66,19 @@ const useStyles = makeStyles((theme) => ({
69
66
"& .MuiDialogActions-spacing" : {
70
67
padding : `0 ${ theme . spacing ( 5 ) } ${ theme . spacing ( 5 ) } ` ,
71
68
} ,
72
- } ,
73
- dialogContent : {
69
+ } ) ,
70
+ dialogContent : ( theme ) => ( {
74
71
color : theme . palette . text . secondary ,
75
72
padding : theme . spacing ( 5 ) ,
76
- } ,
77
- dialogTitle : {
73
+ } ) ,
74
+ dialogTitle : ( theme ) => ( {
78
75
margin : 0 ,
79
76
marginBottom : theme . spacing ( 2 ) ,
80
77
color : theme . palette . text . primary ,
81
78
fontWeight : 400 ,
82
79
fontSize : theme . spacing ( 2.5 ) ,
83
- } ,
84
- dialogDescription : {
80
+ } ) ,
81
+ dialogDescription : ( theme ) => ( {
85
82
color : theme . palette . text . secondary ,
86
83
lineHeight : "160%" ,
87
84
fontSize : 16 ,
@@ -97,8 +94,8 @@ const useStyles = makeStyles((theme) => ({
97
94
"& > p" : {
98
95
margin : theme . spacing ( 1 , 0 ) ,
99
96
} ,
100
- } ,
101
- } ) ) ;
97
+ } ) ,
98
+ } satisfies Record < string , Interpolation < Theme > > ;
102
99
103
100
/**
104
101
* Quick-use version of the Dialog component with slightly alternative styles,
@@ -117,8 +114,6 @@ export const ConfirmDialog: FC<PropsWithChildren<ConfirmDialogProps>> = ({
117
114
title,
118
115
type = "info" ,
119
116
} ) => {
120
- const styles = useStyles ( { type } ) ;
121
-
122
117
const defaults = CONFIRM_DIALOG_DEFAULTS [ type ] ;
123
118
124
119
if ( typeof hideCancel === "undefined" ) {
@@ -127,16 +122,14 @@ export const ConfirmDialog: FC<PropsWithChildren<ConfirmDialogProps>> = ({
127
122
128
123
return (
129
124
< Dialog
130
- className = { styles . dialogWrapper }
125
+ css = { styles . dialogWrapper }
131
126
onClose = { onClose }
132
127
open = { open }
133
128
data-testid = "dialog"
134
129
>
135
- < div className = { styles . dialogContent } >
136
- < h3 className = { styles . dialogTitle } > { title } </ h3 >
137
- { description && (
138
- < div className = { styles . dialogDescription } > { description } </ div >
139
- ) }
130
+ < div css = { styles . dialogContent } >
131
+ < h3 css = { styles . dialogTitle } > { title } </ h3 >
132
+ { description && < div css = { styles . dialogDescription } > { description } </ div > }
140
133
</ div >
141
134
142
135
< DialogActions >
@@ -154,169 +147,3 @@ export const ConfirmDialog: FC<PropsWithChildren<ConfirmDialogProps>> = ({
154
147
</ Dialog >
155
148
) ;
156
149
} ;
157
-
158
- export interface ScheduleDialogProps extends ConfirmDialogProps {
159
- readonly inactiveWorkspacesToGoDormant : number ;
160
- readonly inactiveWorkspacesToGoDormantInWeek : number ;
161
- readonly dormantWorkspacesToBeDeleted : number ;
162
- readonly dormantWorkspacesToBeDeletedInWeek : number ;
163
- readonly updateDormantWorkspaces : ( confirm : boolean ) => void ;
164
- readonly updateInactiveWorkspaces : ( confirm : boolean ) => void ;
165
- readonly dormantValueChanged : boolean ;
166
- readonly deletionValueChanged : boolean ;
167
- }
168
-
169
- export const ScheduleDialog : FC < PropsWithChildren < ScheduleDialogProps > > = ( {
170
- cancelText,
171
- confirmLoading,
172
- disabled = false ,
173
- hideCancel,
174
- onClose,
175
- onConfirm,
176
- type,
177
- open = false ,
178
- title,
179
- inactiveWorkspacesToGoDormant,
180
- inactiveWorkspacesToGoDormantInWeek,
181
- dormantWorkspacesToBeDeleted,
182
- dormantWorkspacesToBeDeletedInWeek,
183
- updateDormantWorkspaces,
184
- updateInactiveWorkspaces,
185
- dormantValueChanged,
186
- deletionValueChanged,
187
- } ) => {
188
- const styles = useScheduleStyles ( { type } ) ;
189
-
190
- const defaults = CONFIRM_DIALOG_DEFAULTS [ "delete" ] ;
191
-
192
- if ( typeof hideCancel === "undefined" ) {
193
- hideCancel = defaults . hideCancel ;
194
- }
195
-
196
- const showDormancyWarning =
197
- dormantValueChanged &&
198
- ( inactiveWorkspacesToGoDormant > 0 ||
199
- inactiveWorkspacesToGoDormantInWeek > 0 ) ;
200
- const showDeletionWarning =
201
- deletionValueChanged &&
202
- ( dormantWorkspacesToBeDeleted > 0 ||
203
- dormantWorkspacesToBeDeletedInWeek > 0 ) ;
204
-
205
- return (
206
- < Dialog
207
- className = { styles . dialogWrapper }
208
- onClose = { onClose }
209
- open = { open }
210
- data-testid = "dialog"
211
- >
212
- < div className = { styles . dialogContent } >
213
- < h3 className = { styles . dialogTitle } > { title } </ h3 >
214
- < >
215
- { showDormancyWarning && (
216
- < >
217
- < h4 > { "Dormancy Threshold" } </ h4 >
218
- < Stack direction = "row" spacing = { 5 } >
219
- < div className = { styles . dialogDescription } > { `
220
- This change will result in ${ inactiveWorkspacesToGoDormant } workspaces being immediately transitioned to the dormant state and ${ inactiveWorkspacesToGoDormantInWeek } over the next seven days. To prevent this, do you want to reset the inactivity period for all template workspaces?` } </ div >
221
- < FormControlLabel
222
- sx = { {
223
- marginTop : 2 ,
224
- } }
225
- control = {
226
- < Checkbox
227
- size = "small"
228
- onChange = { ( e ) => {
229
- updateInactiveWorkspaces ( e . target . checked ) ;
230
- } }
231
- />
232
- }
233
- label = "Reset"
234
- />
235
- </ Stack >
236
- </ >
237
- ) }
238
-
239
- { showDeletionWarning && (
240
- < >
241
- < h4 > { "Dormancy Auto-Deletion" } </ h4 >
242
- < Stack direction = "row" spacing = { 5 } >
243
- < div
244
- className = { styles . dialogDescription }
245
- > { `This change will result in ${ dormantWorkspacesToBeDeleted } workspaces being immediately deleted and ${ dormantWorkspacesToBeDeletedInWeek } over the next 7 days. To prevent this, do you want to reset the dormancy period for all template workspaces?` } </ div >
246
- < FormControlLabel
247
- sx = { {
248
- marginTop : 2 ,
249
- } }
250
- control = {
251
- < Checkbox
252
- size = "small"
253
- onChange = { ( e ) => {
254
- updateDormantWorkspaces ( e . target . checked ) ;
255
- } }
256
- />
257
- }
258
- label = "Reset"
259
- />
260
- </ Stack >
261
- </ >
262
- ) }
263
- </ >
264
- </ div >
265
-
266
- < DialogActions >
267
- < DialogActionButtons
268
- cancelText = { cancelText }
269
- confirmDialog
270
- confirmLoading = { confirmLoading }
271
- confirmText = "Submit"
272
- disabled = { disabled }
273
- onCancel = { ! hideCancel ? onClose : undefined }
274
- onConfirm = { onConfirm || onClose }
275
- type = "delete"
276
- />
277
- </ DialogActions >
278
- </ Dialog >
279
- ) ;
280
- } ;
281
-
282
- const useScheduleStyles = makeStyles ( ( theme ) => ( {
283
- dialogWrapper : {
284
- "& .MuiPaper-root" : {
285
- background : theme . palette . background . paper ,
286
- border : `1px solid ${ theme . palette . divider } ` ,
287
- width : "100%" ,
288
- maxWidth : theme . spacing ( 125 ) ,
289
- } ,
290
- "& .MuiDialogActions-spacing" : {
291
- padding : `0 ${ theme . spacing ( 5 ) } ${ theme . spacing ( 5 ) } ` ,
292
- } ,
293
- } ,
294
- dialogContent : {
295
- color : theme . palette . text . secondary ,
296
- padding : theme . spacing ( 5 ) ,
297
- } ,
298
- dialogTitle : {
299
- margin : 0 ,
300
- marginBottom : theme . spacing ( 2 ) ,
301
- color : theme . palette . text . primary ,
302
- fontWeight : 400 ,
303
- fontSize : theme . spacing ( 2.5 ) ,
304
- } ,
305
- dialogDescription : {
306
- color : theme . palette . text . secondary ,
307
- lineHeight : "160%" ,
308
- fontSize : 16 ,
309
-
310
- "& strong" : {
311
- color : theme . palette . text . primary ,
312
- } ,
313
-
314
- "& p:not(.MuiFormHelperText-root)" : {
315
- margin : 0 ,
316
- } ,
317
-
318
- "& > p" : {
319
- margin : theme . spacing ( 1 , 0 ) ,
320
- } ,
321
- } ,
322
- } ) ) ;
0 commit comments