diff --git a/platform/src/common/components/Collocation/DeviceStatus/Table/DataTable.jsx b/platform/src/common/components/Collocation/DeviceStatus/Table/DataTable.jsx index b26d20d979..311f13087c 100644 --- a/platform/src/common/components/Collocation/DeviceStatus/Table/DataTable.jsx +++ b/platform/src/common/components/Collocation/DeviceStatus/Table/DataTable.jsx @@ -45,6 +45,7 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { const [collocationInput, setCollocationInput] = useState({ devices: null, batchId: '', + batchName: '', }); const [skip, setSkip] = useState(true); const [clickedRowIndex, setClickedRowIndex] = useState(null); @@ -107,17 +108,17 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { // This function is to delete batch const deleteBatch = async () => { - const { device, batchId } = collocationInput; + const { device, batchId, batchName } = collocationInput; const data = { batchId: batchId, }; - createAxiosInstance() + await createAxiosInstance() .delete(DELETE_COLLOCATION_DEVICE, { params: data }) .then((response) => { - dispatch(getDeviceStatusSummary()); setVisible(false); - setSuccessMessage(`Succesfully deleted batch ${batchId}`); + dispatch(getDeviceStatusSummary()); + setSuccessMessage(`Succesfully deleted batch ${batchName}`); }) .catch((error) => { setVisible(false); @@ -127,18 +128,18 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { // This function is to delete device const deleteDevice = async () => { - const { device, batchId } = collocationInput; + const { device, batchId, batchName } = collocationInput; const data = { batchId: batchId, devices: device, }; - createAxiosInstance() + await createAxiosInstance() .delete(DELETE_COLLOCATION_DEVICE, { params: data }) .then((response) => { - dispatch(getDeviceStatusSummary()); setVisibleDeleteDevice(false); - setSuccessMessage(`Succesfully deleted device ${device}`); + dispatch(getDeviceStatusSummary()); + setSuccessMessage(`Succesfully deleted device ${device} from batch ${batchName}`); }) .catch((error) => { setVisibleDeleteDevice(false); @@ -163,7 +164,7 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { ]); const handleItemClick = (id, device, index) => { - const { device_name, batch_id } = device; + const { device_name, batch_id, batch_name } = device; switch (id) { case 1: openMonitorReport(device_name, batch_id, index); @@ -173,6 +174,7 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { setCollocationInput({ device: device_name, batchId: batch_id, + batchName: batch_name, }); break; case 3: @@ -180,6 +182,7 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => { setCollocationInput({ device: device_name, batchId: batch_id, + batchName: batch_name, }); break; default: @@ -337,9 +340,9 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => {
deleteBatch()} closeModal={() => setVisible(false)} - description={`Are you sure you want to delete this collocation batch ${collocationInput.batchId}?`} + description={`Are you sure you want to delete this collocation batch ${collocationInput.batchName}?`} confirmButton='Delete' />
@@ -363,7 +366,7 @@ const DataTable = ({ filteredData, collocationDevices, isLoading }) => {
deleteDevice()} closeModal={() => setVisibleDeleteDevice(false)} description={`Are you sure you want to delete ${collocationInput.device} from the collocation batch?`} confirmButton='Delete' diff --git a/platform/src/common/components/Modal/Modal.jsx b/platform/src/common/components/Modal/Modal.jsx index 7d89f1ba29..379f98bb53 100644 --- a/platform/src/common/components/Modal/Modal.jsx +++ b/platform/src/common/components/Modal/Modal.jsx @@ -1,20 +1,19 @@ import React, { useState } from 'react'; - import Close from '@/icons/Actions/close.svg'; -import Exclamation from '@/icons/Actions/exclamation.svg'; -import Image from 'next/image'; +import Button from '@/components/Button'; const Modal = ({ description, confirmButton, handleConfirm, display, closeModal }) => { const [loading, setLoading] = useState(false); + console.log(loading); const handleClick = async () => { setLoading(true); try { await handleConfirm(); } catch (error) { throw error; - } finally { - setLoading(false); } + + setLoading(false); }; return ( @@ -40,28 +39,26 @@ const Modal = ({ description, confirmButton, handleConfirm, display, closeModal

{description}

-
+
{confirmButton && ( - + {loading ? 'Loading...' : 'Delete'} + )} - +
diff --git a/platform/src/core/urls/deviceMonitoring.js b/platform/src/core/urls/deviceMonitoring.js index 70cdc5c34e..9d2b24623e 100644 --- a/platform/src/core/urls/deviceMonitoring.js +++ b/platform/src/core/urls/deviceMonitoring.js @@ -5,4 +5,4 @@ const BASE_DEVICE_MONITORING_URL = stripTrailingSlash(process.env.NEXT_PUBLIC_AP export const COLLOCATION = `${BASE_DEVICE_MONITORING_URL}/monitor/collocation`; -export const DELETE_COLLOCATION_DEVICE = `${COLLOCATION}?TOKEN=${NEXT_PUBLIC_API_TOKEN}`; +export const DELETE_COLLOCATION_DEVICE = `${COLLOCATION}`;