-
diff --git a/src/pages/AddBeerPage.jsx b/src/pages/AddBeerPage.jsx
index 243d84b9ef..3e7031a7e5 100644
--- a/src/pages/AddBeerPage.jsx
+++ b/src/pages/AddBeerPage.jsx
@@ -1,4 +1,6 @@
+import axios from "axios";
import { useState } from "react";
+import { useNavigate } from "react-router-dom";
function AddBeerPage() {
// State variables to store the values of the form inputs. You can leave these as they are.
@@ -28,13 +30,38 @@ function AddBeerPage() {
// 2. Use axios to make a POST request to the Beers API.
// 3. Once the beer is created, navigate the user to the page showing the list of all beers.
+ const navigate = useNavigate()
+ const BASE_URL = "https://ih-beers-api2.herokuapp.com";
+
+ const handleSubmit = (e) => {
+ e.preventDefault();
+
+ const newBeer = {
+ name: name,
+ tagline: tagline,
+ description: description,
+ image_url: imageUrl,
+ first_brewed: firstBrewed,
+ brewers_tips: brewersTips,
+ attenuation_level: attenuationLevel,
+ contributed_by: contributedBy,
+ }
+
+ axios
+ .post(`${BASE_URL}/beers/new`, newBeer)
+ .then(()=>{
+ navigate("/beers")
+ })
+ .catch((e) => console.log("Error creating a new project...", e));
+ }
+
// Structure and the content of the page showing the form for adding a new beer. You can leave this as it is.
return (
<>