diff --git a/frontend/src/hooks/car-hooks/useCars.ts b/frontend/src/hooks/car-hooks/useCars.ts deleted file mode 100644 index f7ce7f2..0000000 --- a/frontend/src/hooks/car-hooks/useCars.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { Car } from "../../types/datatypes.ts"; -import { BackendMessage } from "../../types/response.types.ts"; - -import { useEffect, useState, useCallback } from "react"; -import { fetchWithAuth } from "../../utils/fetch.tsx"; -import useFetchWithAuthExports from "../context-hooks/useFetchWithAuthExports.ts"; - -const useCars = (driverId: string) => { - const [data, setData] = useState(null); - const [error, setError] = useState(null); - const [loading, setLoading] = useState(false); - const { auth, refresh, navigate } = useFetchWithAuthExports(); - - const fetchCars = useCallback(async () => { - setLoading(true); - try { - const response = await fetchWithAuth( - navigate, - refresh, - auth, - `/car/get?driverId=${driverId}`, - "get", - ); - - if (!response.ok) { - const error: BackendMessage = await response.json(); - setError(error); - } else { - const cars: Car[] = await response.json(); - setData(cars); - } - } catch (err) { - console.error("Unexpected error:", err); - setError({ message: "An unexpected error occurred" } as BackendMessage); - } finally { - setLoading(false); - } - }, [driverId, fetchWithAuth]); - - useEffect(() => { - if (driverId) { - fetchCars(); - } - }, [driverId, fetchCars]); - - return { data, error, loading, fetchCars }; -}; - -export default useCars; diff --git a/package-lock.json b/package-lock.json index a7d569a..be7aa19 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.14", "globals": "^15.13.0", + "husky": "^9.1.7", "prettier": "^3.4.2", "typescript-eslint": "^8.17.0" } @@ -2593,6 +2594,21 @@ "node": ">= 0.4" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/ignore": { "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", diff --git a/package.json b/package.json index 73f745b..5f7f058 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "eslint-plugin-react-hooks": "^5.0.0", "eslint-plugin-react-refresh": "^0.4.14", "globals": "^15.13.0", + "husky": "^9.1.7", "prettier": "^3.4.2", "typescript-eslint": "^8.17.0" }