Skip to content
This repository was archived by the owner on Sep 23, 2021. It is now read-only.

Commit cfb55c7

Browse files
committed
refactor(devices): use the new Confirmation component
Signed-off-by: Gianfranco Manganiello <gmanganiello@teclib.com>
1 parent 00cf9e1 commit cfb55c7

File tree

3 files changed

+64
-34
lines changed

3 files changed

+64
-34
lines changed

src/containers/Applications/components/ApplicationsList.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export default class ApplicationsList extends PureComponent {
266266
* handle delete selected application
267267
* @function handleSelectionChanged
268268
* @param {object} eventObject
269+
* @async
269270
*/
270271
handleDelete = async (isOK) => {
271272
try {

src/containers/Devices/components/DevicesList.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export default class DevicesList extends PureComponent {
8484
page: 1,
8585
count: 15,
8686
},
87+
hideContentDialog: true,
88+
8789
}
8890
}
8991

@@ -258,12 +260,19 @@ export default class DevicesList extends PureComponent {
258260
}
259261

260262
/**
261-
* handle delete to selected device
262-
* @function handleDelete
263+
* Show the content dialog
264+
* @function showContentDialog
265+
*/
266+
showContentDialog = () => this.setState({ hideContentDialog: false })
267+
268+
/**
269+
* handle delete selected devices
270+
* @function handleSelectionChanged
271+
* @param {object} eventObject
272+
* @async
263273
*/
264-
handleDelete = async () => {
274+
handleDelete = async (isOK) => {
265275
try {
266-
const isOK = await Confirmation.isOK(this.contentDialog)
267276
if (isOK) {
268277
const itemListToDelete = this.props.selectedItems.map(item => ({
269278
id: item['PluginFlyvemdmAgent.id'],
@@ -369,7 +378,7 @@ export default class DevicesList extends PureComponent {
369378
label={I18n.t('commons.delete')}
370379
priority={0}
371380
disabled={this.props.selectedItems.length === 0}
372-
onClick={this.handleDelete}
381+
onClick={this.showContentDialog}
373382
/>
374383
)
375384

@@ -469,9 +478,19 @@ export default class DevicesList extends PureComponent {
469478
</ReactWinJS.ToolBar>
470479
{listComponent}
471480
<Confirmation
481+
hideDialog={this.state.hideContentDialog}
472482
title={I18n.t('devices.delete')}
473483
message={`${this.props.selectedItems.length} ${I18n.t('devices.title')}`}
474-
reference={(el) => { this.contentDialog = el }}
484+
isOK={() => {
485+
this.setState({ hideContentDialog: true }, () => {
486+
this.handleDelete(true)
487+
})
488+
}}
489+
cancel={() => {
490+
this.setState({ hideContentDialog: true }, () => {
491+
this.handleDelete(false)
492+
})
493+
}}
475494
/>
476495
</React.Fragment>
477496
)

src/containers/Devices/components/Sections/Main.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default class Main extends PureComponent {
5454
update: this.props.update,
5555
data: undefined,
5656
sendingPing: false,
57+
hideContentDialog: true,
5758
}
5859
}
5960

@@ -108,39 +109,42 @@ export default class Main extends PureComponent {
108109
}
109110
}
110111

112+
/**
113+
* Show the content dialog
114+
* @function showContentDialog
115+
*/
116+
showContentDialog = () => this.setState({ hideContentDialog: false })
117+
118+
111119
/**
112120
* handle delete selected device
113-
* @async
114121
* @function handleRefresh
115122
*/
116123
handleDelete = async () => {
117-
const isOK = await Confirmation.isOK(this.contentDialog)
118-
if (isOK) {
119-
this.setState({
120-
isLoading: true,
121-
})
124+
this.setState({
125+
isLoading: true,
126+
})
122127

123-
this.props.glpi.deleteItem({
124-
itemtype: itemtype.PluginFlyvemdmAgent,
125-
id: this.state.id,
126-
})
127-
.then(() => {
128-
this.props.toast.setNotification({
129-
title: I18n.t('commons.success'),
130-
body: I18n.t('notifications.device_successfully_removed'),
131-
type: 'success',
132-
})
133-
this.props.changeSelectionMode(false)
134-
this.props.history.push(`${publicURL}/app/devices`)
135-
this.props.changeAction('reload')
136-
})
137-
.catch((error) => {
138-
this.props.toast.setNotification(this.props.handleMessage({
139-
type: 'alert',
140-
message: error,
141-
}))
128+
this.props.glpi.deleteItem({
129+
itemtype: itemtype.PluginFlyvemdmAgent,
130+
id: this.state.id,
131+
})
132+
.then(() => {
133+
this.props.toast.setNotification({
134+
title: I18n.t('commons.success'),
135+
body: I18n.t('notifications.device_successfully_removed'),
136+
type: 'success',
142137
})
143-
}
138+
this.props.changeSelectionMode(false)
139+
this.props.history.push(`${publicURL}/app/devices`)
140+
this.props.changeAction('reload')
141+
})
142+
.catch((error) => {
143+
this.props.toast.setNotification(this.props.handleMessage({
144+
type: 'alert',
145+
message: error,
146+
}))
147+
})
144148
}
145149

146150
/**
@@ -266,7 +270,7 @@ export default class Main extends PureComponent {
266270
<Icon
267271
iconName="Delete"
268272
style={{ marginRight: '20px', fontSize: '20px' }}
269-
onClick={this.handleDelete}
273+
onClick={this.showContentDialog}
270274
/>
271275
</div>
272276
</div>
@@ -289,9 +293,15 @@ export default class Main extends PureComponent {
289293
</div>
290294

291295
<Confirmation
296+
hideDialog={this.state.hideContentDialog}
292297
title={I18n.t('devices.delete')}
293298
message={this.state.data.name}
294-
reference={(el) => { this.contentDialog = el }}
299+
isOK={() => {
300+
this.setState({ hideContentDialog: true }, () => {
301+
this.handleDelete()
302+
})
303+
}}
304+
cancel={() => this.setState({ hideContentDialog: true })}
295305
/>
296306
</ContentPane>
297307
)

0 commit comments

Comments
 (0)