import React from "react"; import axios from "axios"; import { Form, Button } from "react-bootstrap"; import { useState } from 'react'; import './event-creation.css'; import Cookies from "universal-cookie"; import NavBar from '../nav-bar/nav-bar'; const cookies = new Cookies(); export default function EventCreation() { // initial state const [event_name, setEventName] = useState(""); const [event_date, setEventDate] = useState(""); const [event_budget, setEventBudget] = useState(""); const owner_email = cookies.get("TOKEN_AND_EMAIL")[1]; let handleSubmit = async (e) => { e.preventDefault(); // set configurations console.log("in handle submit for event creation"); console.log(event_name); console.log(owner_email); const configuration = { method: "post", url: "http://localhost:3001/event-creation", data: { event_name, event_date, event_budget, owner_email, }, }; console.log("frontend event creation, email:", owner_email); // make the API call axios(configuration) .then((result) => { window.localStorage.setItem("curr_event", event_name); var new_event = { event_name: event_name }; // no other events, user making first one if (window.localStorage.getItem("events") === "no events") { window.localStorage.setItem("events", JSON.stringify([new_event])); } // has other events, user adding another event else { var events = JSON.parse(window.localStorage.getItem("events")); events.push(new_event); window.localStorage.setItem("events", JSON.stringify(events)); } window.localStorage.setItem('event_date', JSON.stringify(event_date)); window.localStorage.setItem('invitees', JSON.stringify([])); window.localStorage.setItem('spent_desc', JSON.stringify([])); window.localStorage.setItem("curr_event_spent", parseInt(0)) window.localStorage.setItem("curr_event_budget", event_budget) window.localStorage.setItem("attendees", 0) window.location.href = "./event-dashboard"; }) .catch((error) => { error = new Error(); }); }; return (
); };