diff --git a/package-lock.json b/package-lock.json index a557a6f..96cacab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ucentral-client", - "version": "3.0.0(4)", + "version": "3.0.0(5)", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ucentral-client", - "version": "3.0.0(4)", + "version": "3.0.0(5)", "license": "ISC", "dependencies": { "@chakra-ui/anatomy": "^2.1.1", diff --git a/package.json b/package.json index 4def4d0..5d838c9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucentral-client", - "version": "3.0.0(4)", + "version": "3.0.0(5)", "description": "", "private": true, "main": "index.tsx", diff --git a/src/components/Modals/ConfigureModal/index.tsx b/src/components/Modals/ConfigureModal/index.tsx index d2e9ff9..c8889f7 100644 --- a/src/components/Modals/ConfigureModal/index.tsx +++ b/src/components/Modals/ConfigureModal/index.tsx @@ -59,16 +59,43 @@ const _ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps) => { try { const config = JSON.parse(newConfig); configure.mutate(config, { - onSuccess: () => { - toast({ - id: `configure-success-${serialNumber}`, - title: t('common.success'), - description: t('controller.configure.success'), - status: 'success', - duration: 5000, - isClosable: true, - position: 'top-right', - }); + onSuccess: (data) => { + if (data.errorCode === 0) { + toast({ + id: `configure-success-${serialNumber}`, + title: t('common.success'), + description: + data.status === 'pending' + ? 'Command is pending! It will execute once the device connects' + : t('controller.configure.success'), + status: 'success', + duration: 5000, + isClosable: true, + position: 'top-right', + }); + modalProps.onClose(); + } else if (data.errorCode === 1) { + toast({ + id: `configure-warning-${serialNumber}`, + title: 'Warning', + description: `${data?.errorText ?? 'Unknown Warning'}`, + status: 'warning', + duration: 5000, + isClosable: true, + position: 'top-right', + }); + modalProps.onClose(); + } else { + toast({ + id: `config-error-${serialNumber}`, + title: t('common.error'), + description: `${data?.errorText ?? 'Unknown Error'} (Code ${data.errorCode})`, + status: 'error', + duration: 5000, + isClosable: true, + position: 'top-right', + }); + } modalProps.onClose(); }, }); diff --git a/src/hooks/Network/Commands.ts b/src/hooks/Network/Commands.ts index 5f14e4b..035baf6 100644 --- a/src/hooks/Network/Commands.ts +++ b/src/hooks/Network/Commands.ts @@ -174,12 +174,37 @@ export const useGetEventQueue = () => { }; const configureDevice = (serialNumber: string) => async (configuration: Record) => - axiosGw.post(`device/${serialNumber}/configure`, { - when: 0, - UUID: 1, - serialNumber, - configuration, - }); + axiosGw + .post(`device/${serialNumber}/configure`, { + when: 0, + UUID: 1, + serialNumber, + configuration, + }) + .then( + (res) => + res.data as Partial<{ + UUID: string; + attachFile: number; + command: string; + completed: number; + custom: number; + deferred: boolean; + details: Record; + errorCode: number; + errorText: string; + executed: number; + executionTime: number; + lastTry: number; + results: Record; + serialNumber: string; + status: string; + submitted: number; + submittedBy: string; + waitingForFile: number; + when: number; + }>, + ); export const useConfigureDevice = ({ serialNumber }: { serialNumber: string }) => { const queryClient = useQueryClient();