VIN Numbers can be decoded.

This commit is contained in:
Roland 2023-06-11 12:31:56 -06:00
parent e5fe1b6bb9
commit f2a4eb930c
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
8 changed files with 195 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import {useContext, useEffect, useRef, useState} from "react";
import {
fetchDecoded,
fetchDomains,
fetchFilesProgress,
filesSearch,
@ -928,3 +929,29 @@ export const useUploadFile = () => {
return {files, setFiles: handleFilesChange, progresses, destination, setDestination, doClear, doUpload}
}
export const useVINDecoder = (defaultVINNumber = '') => {
const [value, setValue] = useState(defaultVINNumber);
// The response vin from the API.
const [vin, setVin] = useState(null);
const localFetchDecoded = async () => {
if (!value) {
return;
}
try {
const vin = await fetchDecoded(value);
setVin(vin);
} catch (e) {
console.error('Failed to decode VIN number');
setVin(null);
}
}
useEffect(() => {
localFetchDecoded();
}, [value]);
return {value, setValue, vin}
}