From e7f71f6a8da2720efebb0edd04626a238c5c8715 Mon Sep 17 00:00:00 2001
From: Marcus Tonge <mt01158@surrey.ac.uk>
Date: Sat, 22 Apr 2023 11:18:47 +0100
Subject: [PATCH] Added postcode to create on admin page

---
 src/pages/admin/admin.js | 41 ++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)

diff --git a/src/pages/admin/admin.js b/src/pages/admin/admin.js
index f38cc1b..6f003a5 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>
-- 
GitLab