Skip to content

Commit

Permalink
Merge pull request #205 from stephb9959/main
Browse files Browse the repository at this point in the history
[WIFI-13257] Fixed configure notification when command is pending
  • Loading branch information
BourqueCharles authored Jan 2, 2024
2 parents 301581d + f8ddf88 commit fedb60f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ucentral-client",
"version": "3.0.0(4)",
"version": "3.0.0(5)",
"description": "",
"private": true,
"main": "index.tsx",
Expand Down
47 changes: 37 additions & 10 deletions src/components/Modals/ConfigureModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});
Expand Down
37 changes: 31 additions & 6 deletions src/hooks/Network/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit fedb60f

Please sign in to comment.