();
-
- useEffect(() => {
- logtail.info("Trying to receive all restaurants from /api/restaurants");
-
- axios
- .get("/api/restaurants")
- .then((response) => {
- logtail.info("Received " + response.data.length + " restaurants");
- setRestaurants(response.data);
- })
- .catch((error) => {
- logtail.error(error.message, {
- error: error,
- });
- setError(error);
- console.error(error.message);
- });
- }, []);
-
- if (error) {
- return (
-
-
- Sorry, we encountered an error loading the restaurants. Please try
- again later.
-
- {error.message}
-
- );
- }
-
- return (
-
- {restaurants.length === 0 ? (
-
- ) : (
-
- )}
-
- );
-}
diff --git a/frontend/src/pages/UpdateRestaurantPage.tsx b/frontend/src/pages/UpdateRestaurantPage.tsx
new file mode 100644
index 0000000..738ffdf
--- /dev/null
+++ b/frontend/src/pages/UpdateRestaurantPage.tsx
@@ -0,0 +1,69 @@
+import { useNavigate, useParams } from "react-router-dom";
+import { NewRestaurantDTOType } from "../model/Restaurant.ts";
+import axios from "axios";
+import DefaultPageTemplate from "./templates/DefaultPageTemplate/DefaultPageTemplate.tsx";
+import RestaurantForm from "../components/RestaurantForm/RestaurantForm.tsx";
+import { logtail } from "../logger.ts";
+import { useRestaurant } from "../data/restaurantData.ts";
+import AlertBox from "../components/AlertBox/AlertBox.tsx";
+import { mutate } from "swr";
+
+export default function UpdateRestaurantPage() {
+ const navigate = useNavigate();
+ const { id: paramId } = useParams<{ id: string }>();
+ const id = paramId ?? "";
+ const { restaurant, isLoading, isError } = useRestaurant(id);
+
+ if (isLoading) {
+ return (
+
+ Restaurant is currently loading. Please wait.
+
+ );
+ }
+
+ if (isError) {
+ return (
+
+
+ Sorry, we encountered an error loading the restaurants. Please try
+ again later.
+
+ {isError.message}
+
+ );
+ }
+
+ if (!restaurant) {
+ logtail.error(`There was an error displaying restaurant with ID ${id}`);
+ return Error;
+ }
+
+ function handleEditRestaurant(formData: NewRestaurantDTOType) {
+ logtail.info("Trying to update data for restaurant with ID " + id);
+
+ axios
+ .put(`/api/restaurants/${id}`, formData)
+ .then(() => {
+ logtail.info(`Updated data of restaurant with ID ${id}`);
+ mutate(`/api/restaurants/${id}`);
+ mutate("/api/restaurants");
+ navigate(`/restaurants/${id}`);
+ })
+ .catch((error) => {
+ logtail.error(error.message, {
+ error: error,
+ });
+ window.console.error(error.message);
+ });
+ }
+
+ return (
+
+
+
+ );
+}
diff --git a/frontend/src/pages/ViewRestaurantPage.tsx b/frontend/src/pages/ViewRestaurantPage.tsx
new file mode 100644
index 0000000..040fe1a
--- /dev/null
+++ b/frontend/src/pages/ViewRestaurantPage.tsx
@@ -0,0 +1,60 @@
+import { useNavigate, useParams } from "react-router-dom";
+import DefaultPageTemplate from "./templates/DefaultPageTemplate/DefaultPageTemplate.tsx";
+import axios from "axios";
+
+import Button from "../components/Button/Button.tsx";
+import ButtonLink from "../components/ButtonLink/ButtonLink.tsx";
+import { useRestaurant } from "../data/restaurantData.ts";
+import { logtail } from "../logger.ts";
+import AlertBox from "../components/AlertBox/AlertBox.tsx";
+import { mutate } from "swr";
+
+export default function ViewRestaurantPage() {
+ const navigate = useNavigate();
+ const { id: paramId } = useParams<{ id: string }>();
+ const id = paramId ?? "";
+ const { restaurant, isLoading, isError } = useRestaurant(id);
+
+ if (isLoading) {
+ return (
+
+ Restaurant is currently loading. Please wait.
+
+ );
+ }
+
+ if (isError) {
+ return (
+
+
+ Sorry, we encountered an error loading the restaurants. Please try
+ again later.
+
+ {isError.message}
+
+ );
+ }
+
+ if (!restaurant) {
+ logtail.error(`There was an error displaying restaurant with ID ${id}`);
+ return Error;
+ }
+
+ function deleteRestaurantById() {
+ axios.delete(`/api/restaurants/${id}`).then(() => {
+ mutate("/api/restaurants");
+ navigate("/");
+ });
+ }
+
+ return (
+
+ {restaurant.city}
+ Edit
+ Back
+
+
+ );
+}
diff --git a/frontend/src/pages/templates/DefaultPageTemplate/DefaultPageTemplate.tsx b/frontend/src/pages/templates/DefaultPageTemplate/DefaultPageTemplate.tsx
index 37954ba..b61e6b0 100644
--- a/frontend/src/pages/templates/DefaultPageTemplate/DefaultPageTemplate.tsx
+++ b/frontend/src/pages/templates/DefaultPageTemplate/DefaultPageTemplate.tsx
@@ -10,7 +10,7 @@ type DefaultPageTemplateProps = {
export default function DefaultPageTemplate({
children,
pageTitle,
-}: DefaultPageTemplateProps) {
+}: Readonly) {
return (
<>