From 7a9fddf6dae4d957c09aea5124f1da32bee79587 Mon Sep 17 00:00:00 2001 From: shamalka Date: Fri, 11 Oct 2019 13:37:04 +0530 Subject: [PATCH] Disenroll device --- .../src/components/Devices/BulkActionBar.js | 2 +- .../src/components/Devices/DevicesTable.js | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/BulkActionBar.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/BulkActionBar.js index 5b4f49e6ed5..ca1d51a83a4 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/BulkActionBar.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/BulkActionBar.js @@ -50,7 +50,7 @@ class BulkActionBar extends React.Component { }; onConfirmDisenroll = () => { - //TODO: Implement disenrollment function + this.props.disenrollDevice(); }; onDeviceGroupCall = () => { diff --git a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js index fd87a6a7e16..62cb0c9f148 100644 --- a/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js +++ b/components/device-mgt/io.entgra.device.mgt.ui/react-app/src/components/Devices/DevicesTable.js @@ -233,6 +233,47 @@ class DeviceTable extends React.Component { }); }; + disenrollDevice = () => { + const config = this.props.context; + this.setState({loading: true}); + + const deviceData = this.state.selectedRows[0]; + + //send request to the invoker + axios.delete( + window.location.origin + config.serverConfig.invoker.uri + + config.serverConfig.invoker.deviceMgt + + "/devices/type/" + deviceData.type + "/id/" + deviceData.deviceIdentifier, + {headers: {'Content-Type': 'application/json'}} + + ).then(res => { + if (res.status === 200) { + this.fetch(); + notification["success"]({ + message: "Done", + duration: 4, + description: + "Successfully disenrolled the device.", + }); + } + }).catch((error) => { + if (error.hasOwnProperty("response") && error.response.status === 401) { + //todo display a popop with error + message.error('You are not logged in'); + window.location.href = window.location.origin + '/entgra/login'; + } else { + notification["error"]({ + message: "There was a problem", + duration: 0, + description: + "Error occurred while trying to disenroll devices.", + }); + } + + this.setState({loading: false}); + }); + }; + addDevicesToGroup = (groupId) => { const config = this.props.context; this.setState({loading: true}); @@ -384,6 +425,7 @@ class DeviceTable extends React.Component {