diff --git a/src/pages/CreateEvent/index.js b/src/pages/CreateEvent/index.js index 73b0ce4..44e994d 100644 --- a/src/pages/CreateEvent/index.js +++ b/src/pages/CreateEvent/index.js @@ -1,84 +1,105 @@ -import { Field, Form, Formik } from "formik"; +import { useFormik } from "formik"; import { useRef, useState } from "react"; import { Stack } from "react-bootstrap"; import { Map } from "../../components/Map"; import { searchLocation } from "../../utils/map/searchLocation"; import { fromLonLat, toLonLat } from "ol/proj"; import { useHistory } from "react-router"; +import { API_CLIENT } from "../../constants"; import styles from "./index.module.scss"; export const CreateEvent = () => { const mapSearchBox = useRef(null); + const mapSearchBtn = useRef(null); let [center, setCenter] = useState(fromLonLat([18.667, 54.35])); const [zoom, setZoom] = useState(15); const history = useHistory(); + const formik = useFormik({ + initialValues: { + name: "", + type: 0, + time: "0", + date: "0", + description: "", + }, + onSubmit: (data) => { + const cords = toLonLat([center[0], center[1]]); + const rqObj = { + name: data.name, + type: parseInt(data.type), + description: data.description, + lon: cords[0], + lat: cords[1], + time: new Date(`${data.date} ${data.time}`).getTime(), + }; + API_CLIENT.createEvent(rqObj); + history.push("/"); + }, + }); return (