From a86abebdd4847d8217e0c2049e83b1873cde503d Mon Sep 17 00:00:00 2001 From: GRZ4NA Date: Sun, 3 Oct 2021 21:44:52 +0200 Subject: [PATCH] update event list after creating a record --- src/pages/CreateEvent/index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/CreateEvent/index.js b/src/pages/CreateEvent/index.js index 44e994d..a4c784a 100644 --- a/src/pages/CreateEvent/index.js +++ b/src/pages/CreateEvent/index.js @@ -1,14 +1,15 @@ import { useFormik } from "formik"; -import { useRef, useState } from "react"; +import { useRef, useState, useContext } 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 { API_CLIENT, EVENT_CONTEXT } from "../../constants"; import styles from "./index.module.scss"; export const CreateEvent = () => { + const context = useContext(EVENT_CONTEXT); const mapSearchBox = useRef(null); const mapSearchBtn = useRef(null); let [center, setCenter] = useState(fromLonLat([18.667, 54.35])); @@ -32,8 +33,12 @@ export const CreateEvent = () => { lat: cords[1], time: new Date(`${data.date} ${data.time}`).getTime(), }; - API_CLIENT.createEvent(rqObj); - history.push("/"); + API_CLIENT.createEvent(rqObj).then(() => { + API_CLIENT.getEvents().then((r) => { + context.updateEvents(r); + history.push("/"); + }); + }); }, });