mirror of
				https://github.com/optim-enterprises-bv/OptimCloud-gw-ui.git
				synced 2025-10-30 17:57:46 +00:00 
			
		
		
		
	[WIFI-13257] Fixed configure notification when command is pending
Signed-off-by: Charles <charles.bourque96@gmail.com>
This commit is contained in:
		
							
								
								
									
										4
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										4
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							| @@ -1,12 +1,12 @@ | |||||||
| { | { | ||||||
|   "name": "ucentral-client", |   "name": "ucentral-client", | ||||||
|   "version": "3.0.0(4)", |   "version": "3.0.0(5)", | ||||||
|   "lockfileVersion": 3, |   "lockfileVersion": 3, | ||||||
|   "requires": true, |   "requires": true, | ||||||
|   "packages": { |   "packages": { | ||||||
|     "": { |     "": { | ||||||
|       "name": "ucentral-client", |       "name": "ucentral-client", | ||||||
|       "version": "3.0.0(4)", |       "version": "3.0.0(5)", | ||||||
|       "license": "ISC", |       "license": "ISC", | ||||||
|       "dependencies": { |       "dependencies": { | ||||||
|         "@chakra-ui/anatomy": "^2.1.1", |         "@chakra-ui/anatomy": "^2.1.1", | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "ucentral-client", |   "name": "ucentral-client", | ||||||
|   "version": "3.0.0(4)", |   "version": "3.0.0(5)", | ||||||
|   "description": "", |   "description": "", | ||||||
|   "private": true, |   "private": true, | ||||||
|   "main": "index.tsx", |   "main": "index.tsx", | ||||||
|   | |||||||
| @@ -59,17 +59,44 @@ const _ConfigureModal = ({ serialNumber, modalProps }: ConfigureModalProps) => { | |||||||
|     try { |     try { | ||||||
|       const config = JSON.parse(newConfig); |       const config = JSON.parse(newConfig); | ||||||
|       configure.mutate(config, { |       configure.mutate(config, { | ||||||
|         onSuccess: () => { |         onSuccess: (data) => { | ||||||
|  |           if (data.errorCode === 0) { | ||||||
|             toast({ |             toast({ | ||||||
|               id: `configure-success-${serialNumber}`, |               id: `configure-success-${serialNumber}`, | ||||||
|               title: t('common.success'), |               title: t('common.success'), | ||||||
|             description: t('controller.configure.success'), |               description: | ||||||
|  |                 data.status === 'pending' | ||||||
|  |                   ? 'Command is pending! It will execute once the device connects' | ||||||
|  |                   : t('controller.configure.success'), | ||||||
|               status: 'success', |               status: 'success', | ||||||
|               duration: 5000, |               duration: 5000, | ||||||
|               isClosable: true, |               isClosable: true, | ||||||
|               position: 'top-right', |               position: 'top-right', | ||||||
|             }); |             }); | ||||||
|             modalProps.onClose(); |             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(); | ||||||
|         }, |         }, | ||||||
|       }); |       }); | ||||||
|     } catch (e) { |     } catch (e) { | ||||||
|   | |||||||
| @@ -174,12 +174,37 @@ export const useGetEventQueue = () => { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| const configureDevice = (serialNumber: string) => async (configuration: Record<string, unknown>) => | const configureDevice = (serialNumber: string) => async (configuration: Record<string, unknown>) => | ||||||
|   axiosGw.post<unknown>(`device/${serialNumber}/configure`, { |   axiosGw | ||||||
|  |     .post<unknown>(`device/${serialNumber}/configure`, { | ||||||
|       when: 0, |       when: 0, | ||||||
|       UUID: 1, |       UUID: 1, | ||||||
|       serialNumber, |       serialNumber, | ||||||
|       configuration, |       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 }) => { | export const useConfigureDevice = ({ serialNumber }: { serialNumber: string }) => { | ||||||
|   const queryClient = useQueryClient(); |   const queryClient = useQueryClient(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Charles
					Charles