mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ui.git
				synced 2025-10-31 18:57:59 +00:00 
			
		
		
		
	fixed OUI Upload
This commit is contained in:
		| @@ -1,8 +1,11 @@ | |||||||
| import React from 'react'; | import React, { useState } from 'react'; | ||||||
| import { useMutation, useLazyQuery, gql } from '@apollo/client'; | import { useQuery, useMutation, useLazyQuery, gql } from '@apollo/client'; | ||||||
| import { notification } from 'antd'; | import { notification } from 'antd'; | ||||||
| import { Manufacturer as ManufacturerPage } from '@tip-wlan/wlan-cloud-ui-library'; | import { Manufacturer as ManufacturerPage } from '@tip-wlan/wlan-cloud-ui-library'; | ||||||
| import { OUI_UPLOAD } from 'graphql/mutations'; |  | ||||||
|  | import { AUTH_TOKEN } from 'constants/index'; | ||||||
|  | import { GET_API_URL } from 'graphql/queries'; | ||||||
|  | import { getItem } from 'utils/localStorage'; | ||||||
|  |  | ||||||
| const GET_OUI = gql` | const GET_OUI = gql` | ||||||
|   query GetOui($oui: String!) { |   query GetOui($oui: String!) { | ||||||
| @@ -27,7 +30,13 @@ const UPDATE_OUI = gql` | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
| `; | `; | ||||||
|  |  | ||||||
|  | const token = getItem(AUTH_TOKEN); | ||||||
|  |  | ||||||
| const System = () => { | const System = () => { | ||||||
|  |   const [loadingFileUpload, setLoadingFileUpload] = useState(false); | ||||||
|  |  | ||||||
|  |   const { data: apiUrl } = useQuery(GET_API_URL); | ||||||
|   const [updateOUI] = useMutation(UPDATE_OUI); |   const [updateOUI] = useMutation(UPDATE_OUI); | ||||||
|   const [searchOUI, { data }] = useLazyQuery(GET_OUI, { |   const [searchOUI, { data }] = useLazyQuery(GET_OUI, { | ||||||
|     onError: () => { |     onError: () => { | ||||||
| @@ -46,7 +55,6 @@ const System = () => { | |||||||
|     }, |     }, | ||||||
|     fetchPolicy: 'no-cache', |     fetchPolicy: 'no-cache', | ||||||
|   }); |   }); | ||||||
|   const [fileUpload] = useMutation(OUI_UPLOAD); |  | ||||||
|  |  | ||||||
|   const handleUpdateOUI = (oui, manufacturerAlias, manufacturerName) => { |   const handleUpdateOUI = (oui, manufacturerAlias, manufacturerName) => { | ||||||
|     updateOUI({ |     updateOUI({ | ||||||
| @@ -74,33 +82,54 @@ const System = () => { | |||||||
|     searchOUI({ variables: { oui } }); |     searchOUI({ variables: { oui } }); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const handleFileUpload = (fileName, file) => |   const handleFileUpload = (fileName, file) => { | ||||||
|     fileUpload({ variables: { fileName, file } }) |     if (apiUrl?.getApiUrl) { | ||||||
|       .then(resp => { |       setLoadingFileUpload(true); | ||||||
|         if (resp?.ouiUpload?.success) { |  | ||||||
|           notification.success({ |       fetch(`${apiUrl?.getApiUrl}portal/manufacturer/oui/upload?fileName=${fileName}`, { | ||||||
|             message: 'Success', |         method: 'POST', | ||||||
|             description: 'File successfully uploaded.', |         headers: { | ||||||
|           }); |           Authorization: token ? `Bearer ${token.access_token}` : '', | ||||||
|         } else { |           'Content-Type': 'application/octet-stream', | ||||||
|  |         }, | ||||||
|  |         body: file, | ||||||
|  |       }) | ||||||
|  |         .then(response => response.json()) | ||||||
|  |         .then(resp => { | ||||||
|  |           if (resp?.success) { | ||||||
|  |             notification.success({ | ||||||
|  |               message: 'Success', | ||||||
|  |               description: 'File successfully uploaded.', | ||||||
|  |             }); | ||||||
|  |           } else { | ||||||
|  |             notification.error({ | ||||||
|  |               message: 'Error', | ||||||
|  |               description: 'File could not be uploaded.', | ||||||
|  |             }); | ||||||
|  |           } | ||||||
|  |         }) | ||||||
|  |         .catch(() => { | ||||||
|           notification.error({ |           notification.error({ | ||||||
|             message: 'Error', |             message: 'Error', | ||||||
|             description: 'File could not be uploaded.', |             description: 'File could not be uploaded.', | ||||||
|           }); |           }); | ||||||
|         } |  | ||||||
|       }) |  | ||||||
|       .catch(() => |  | ||||||
|         notification.error({ |  | ||||||
|           message: 'Error', |  | ||||||
|           description: 'File could not be uploaded.', |  | ||||||
|         }) |         }) | ||||||
|       ); |         .finally(() => setLoadingFileUpload(false)); | ||||||
|  |     } else { | ||||||
|  |       notification.error({ | ||||||
|  |         message: 'Error', | ||||||
|  |         description: 'File could not be uploaded.', | ||||||
|  |       }); | ||||||
|  |     } | ||||||
|  |   }; | ||||||
|  |  | ||||||
|   return ( |   return ( | ||||||
|     <ManufacturerPage |     <ManufacturerPage | ||||||
|       onSearchOUI={handleSearchOUI} |       onSearchOUI={handleSearchOUI} | ||||||
|       onUpdateOUI={handleUpdateOUI} |       onUpdateOUI={handleUpdateOUI} | ||||||
|       returnedOUI={data && data.getOui} |       returnedOUI={data && data.getOui} | ||||||
|       fileUpload={handleFileUpload} |       fileUpload={handleFileUpload} | ||||||
|  |       loadingFileUpload={loadingFileUpload} | ||||||
|     /> |     /> | ||||||
|   ); |   ); | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -1,5 +1,11 @@ | |||||||
| import { gql } from '@apollo/client'; | import { gql } from '@apollo/client'; | ||||||
|  |  | ||||||
|  | export const GET_API_URL = gql` | ||||||
|  |   query GetApiUrl { | ||||||
|  |     getApiUrl | ||||||
|  |   } | ||||||
|  | `; | ||||||
|  |  | ||||||
| export const GET_ALL_LOCATIONS = gql` | export const GET_ALL_LOCATIONS = gql` | ||||||
|   query GetAllLocations($customerId: ID!) { |   query GetAllLocations($customerId: ID!) { | ||||||
|     getAllLocations(customerId: $customerId) { |     getAllLocations(customerId: $customerId) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sean Macfarlane
					Sean Macfarlane