1
- import React , { useState , useContext , useEffect } from 'react'
1
+ import React , { useState } from 'react'
2
2
import Box from '@material-ui/core/Box'
3
3
import { Link } from 'react-router-dom'
4
4
import {
@@ -20,14 +20,14 @@ import GluuInputRow from 'Routes/Apps/Gluu/GluuInputRow'
20
20
import GluuTypeAheadWithAdd from 'Routes/Apps/Gluu/GluuTypeAheadWithAdd'
21
21
import { FormControlLabel , Radio , RadioGroup } from '@material-ui/core'
22
22
import GluuTypeAheadForDn from 'Routes/Apps/Gluu/GluuTypeAheadForDn'
23
- import { ThemeContext } from 'Context/theme/themeContext'
24
23
import applicationStyle from 'Routes/Apps/Gluu/styles/applicationstyle'
24
+ import { deleteUMAResource } from 'Plugins/auth-server/redux/actions/UMAResourceActions'
25
+ import GluuDialog from 'Routes/Apps/Gluu/GluuDialog'
26
+ import { buildPayload } from 'Utils/PermChecker'
25
27
const DOC_CATEGORY = 'openid_client'
26
28
27
- function ClientCibaParUmaPanel ( { client, umaResources, scripts, formik } ) {
29
+ function ClientCibaParUmaPanel ( { client, dispatch , umaResources, scripts, formik } ) {
28
30
const { t } = useTranslation ( )
29
- const theme = useContext ( ThemeContext )
30
- const selectedTheme = theme . state . theme
31
31
const claim_uri_id = 'claim_uri_id'
32
32
const cibaDeliveryModes = [ 'poll' , 'push' , 'ping' ]
33
33
const claimRedirectURI = [ ]
@@ -44,6 +44,7 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
44
44
const [ selectedUMA , setSelectedUMA ] = useState ( )
45
45
const [ scopeExpression , setScopeExpression ] = useState ( )
46
46
const [ showScopeSection , setShowScopeSection ] = useState ( 'scope' )
47
+ const [ confirmModal , setConfirmModal ] = useState ( false )
47
48
48
49
const rptScripts = scripts
49
50
. filter ( ( item ) => item . scriptType == 'UMA_RPT_CLAIMS' )
@@ -53,12 +54,25 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
53
54
const handleUMADetail = ( uma ) => {
54
55
if ( ! isEmpty ( uma ) ) {
55
56
setSelectedUMA ( uma )
56
- setScopeExpression ( JSON . parse ( uma . scopeExpression ) ?. data )
57
+ if ( ! isEmpty ( uma . scopeExpression ) ) {
58
+ setScopeExpression ( JSON . parse ( uma . scopeExpression ) ?. data )
59
+ }
57
60
}
58
61
59
62
setOpen ( true )
60
63
}
61
64
65
+ const handleDeleteUMA = ( uma ) => {
66
+ setSelectedUMA ( uma )
67
+ setConfirmModal ( true )
68
+ }
69
+
70
+ const onDeletionConfirmed = ( message ) => {
71
+ buildPayload ( { } , message , selectedUMA . id )
72
+ dispatch ( deleteUMAResource ( selectedUMA . id ) )
73
+ setConfirmModal ( false )
74
+ }
75
+
62
76
return (
63
77
< Container >
64
78
< h2 > { t ( `titles.CIBA` ) } </ h2 >
@@ -156,10 +170,24 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
156
170
< Col sm = { 9 } >
157
171
{ umaResources . length > 0 && umaResources ?. map ( uma => {
158
172
return (
159
- < Box key = { uma . id } >
173
+ < Box key = { uma . id } className = "mb-2" >
160
174
< Box display = "flex" >
161
- < Box className = "common-link cursor-pointer" onClick = { ( ) => handleUMADetail ( uma ) } >
162
- { uma . id }
175
+ < Box width = "40%" >
176
+ < a href = "javascript:;" className = "common-link cursor-pointer" onClick = { ( ) => handleUMADetail ( uma ) } >
177
+ { uma . id }
178
+ </ a >
179
+ </ Box >
180
+ < Box width = "50%" className = "text-dark" >
181
+ { uma . name }
182
+ </ Box >
183
+ < Box width = "10%" >
184
+ < Button
185
+ color = "danger"
186
+ size = "sm"
187
+ onClick = { ( ) => handleDeleteUMA ( uma ) }
188
+ >
189
+ < span className = "font-weight-bold" > X</ span >
190
+ </ Button >
163
191
</ Box >
164
192
</ Box >
165
193
</ Box >
@@ -247,15 +275,15 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
247
275
</ React . Fragment >
248
276
) : (
249
277
< React . Fragment >
250
- { ! isEmpty ( scopeExpression ) && scopeExpression . map ( ( expression , key ) => (
278
+ { ! isEmpty ( scopeExpression ) ? scopeExpression . map ( ( expression , key ) => (
251
279
< Box key = { key } >
252
280
< Box display = "flex" >
253
281
< a href = { expression } target = "_blank" alt = "scope expression" className = "common-link" rel = "noreferrer" >
254
282
{ expression }
255
283
</ a >
256
284
</ Box >
257
285
</ Box >
258
- ) ) }
286
+ ) ) : '-' }
259
287
</ React . Fragment >
260
288
) }
261
289
</ Col >
@@ -289,14 +317,23 @@ function ClientCibaParUmaPanel({ client, umaResources, scripts, formik }) {
289
317
</ ModalBody >
290
318
< ModalFooter >
291
319
< Button
292
- color = { `primary-${ selectedTheme } ` }
293
- style = { applicationStyle . buttonStyle }
294
- onClick = { ( ) => setOpen ( ! open ) }
320
+ color = "danger"
321
+ onClick = { ( ) => handleDeleteUMA ( selectedUMA ) }
295
322
>
296
- { t ( 'actions.close ' ) }
323
+ { t ( 'actions.delete ' ) }
297
324
</ Button >
298
325
</ ModalFooter >
299
326
</ Modal >
327
+ { selectedUMA && (
328
+ < GluuDialog
329
+ row = { selectedUMA }
330
+ name = { selectedUMA ?. name }
331
+ handler = { ( ) => setConfirmModal ( ! confirmModal ) }
332
+ modal = { confirmModal }
333
+ subject = "uma resources"
334
+ onAccept = { onDeletionConfirmed }
335
+ />
336
+ ) }
300
337
</ Container >
301
338
)
302
339
}
@@ -308,5 +345,5 @@ const mapStateToProps = (state) => {
308
345
scope : state . scopeReducer . item ,
309
346
}
310
347
}
311
- export default connect ( mapStateToProps ) ( ClientCibaParUmaPanel )
312
348
349
+ export default connect ( mapStateToProps ) ( ClientCibaParUmaPanel )
0 commit comments