diff --git a/src/pages/admin/admin.js b/src/pages/admin/admin.js index f38cc1b5d2f7bbb29a8d1e8e8d8d1315d4703f37..6f003a5c2eb5362b8828e3e4e311274c1040abe3 100644 --- a/src/pages/admin/admin.js +++ b/src/pages/admin/admin.js @@ -78,10 +78,25 @@ const AdminPageView = () => { // Fetch locations from the server const loadLocations = async () => { - const response = await fetch("/api/locations"); - const data = await response.json(); - - setLocations(data); + try { + const baseUrl = process.env.REACT_APP_LOCATION_SERVICE_ENDPOINT; + const response = await fetch(`${baseUrl}/location/parking-locations/all`, { + method: "GET", + headers: { + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + }); + const data = await response.json(); + setLocations(data); + } + catch (error) { + toast({ + title: error.message ?? "Failed to add location.", + status: "error", + duration: 2000, + isClosable: true, + }); + } }; // Add a new location @@ -276,6 +291,16 @@ const AdminPageView = () => { } /> </FormControl> + <FormControl id="city"> + <FormLabel>City</FormLabel> + <Input + type="text" + value={newLocation.city} + onChange={(e) => + setNewLocation({ ...newLocation, city: e.target.value }) + } + /> + </FormControl> <FormControl id="street_address"> <FormLabel>Street Address</FormLabel> <Input @@ -286,13 +311,13 @@ const AdminPageView = () => { } /> </FormControl> - <FormControl id="city"> - <FormLabel>City</FormLabel> + <FormControl id="postcode"> + <FormLabel>Postcode</FormLabel> <Input type="text" - value={newLocation.city} + value={newLocation.postcode} onChange={(e) => - setNewLocation({ ...newLocation, city: e.target.value }) + setNewLocation({ ...newLocation, postcode: e.target.value }) } /> </FormControl>