From 376352672f507d253285020eaec8a91d51d768ac Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Tue, 5 Nov 2024 14:10:44 +0100 Subject: [PATCH] upload dialog is uploading a file --- frontend/src/hooks/useShipments.tsx | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 frontend/src/hooks/useShipments.tsx diff --git a/frontend/src/hooks/useShipments.tsx b/frontend/src/hooks/useShipments.tsx new file mode 100644 index 0000000..ee264d9 --- /dev/null +++ b/frontend/src/hooks/useShipments.tsx @@ -0,0 +1,37 @@ +import { useState, useEffect } from 'react'; +import { ShipmentsService, Shipment, ContactPerson } from '../../openapi'; + +const useShipments = () => { + const [shipments, setShipments] = useState([]); + const [error, setError] = useState(null); + const [defaultContactPerson, setDefaultContactPerson] = useState(); + + const fetchAndSetShipments = async () => { + try { + const shipmentsData = await ShipmentsService.fetchShipmentsShipmentsGet(); + setShipments(shipmentsData); + } catch (error) { + console.error('Failed to fetch shipments:', error); + setError('Failed to fetch shipments. Please try again later.'); + } + }; + + const fetchDefaultContactPerson = async () => { + try { + const contacts = await ShipmentsService.getShipmentContactPersonsShipmentsContactPersonsGet(); + setDefaultContactPerson(contacts[0]); + } catch (error) { + console.error('Failed to fetch contact persons:', error); + setError('Failed to load contact persons. Please try again later.'); + } + }; + + useEffect(() => { + fetchAndSetShipments(); + fetchDefaultContactPerson(); + }, []); + + return { shipments, error, defaultContactPerson, fetchAndSetShipments }; +}; + +export default useShipments; \ No newline at end of file