[WIFI-13257] Fixed configure notification when command is pending

Signed-off-by: Charles <charles.bourque96@gmail.com>
This commit is contained in:
Charles
2024-01-02 12:55:19 -05:00
parent 88cb945760
commit f8ddf88b8c
4 changed files with 71 additions and 19 deletions

4
package-lock.json generated
View File

@@ -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",

View File

@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "3.0.0(4)",
"version": "3.0.0(5)",
"description": "",
"private": true,
"main": "index.tsx",

View File

@@ -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();
},
});

View File

@@ -174,12 +174,37 @@ export const useGetEventQueue = () => {
};
const configureDevice = (serialNumber: string) => async (configuration: Record<string, unknown>) =>
axiosGw.post<unknown>(`device/${serialNumber}/configure`, {
when: 0,
UUID: 1,
serialNumber,
configuration,
});
axiosGw
.post<unknown>(`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<string, unknown>;
errorCode: number;
errorText: string;
executed: number;
executionTime: number;
lastTry: number;
results: Record<string, unknown>;
serialNumber: string;
status: string;
submitted: number;
submittedBy: string;
waitingForFile: number;
when: number;
}>,
);
export const useConfigureDevice = ({ serialNumber }: { serialNumber: string }) => {
const queryClient = useQueryClient();