From 4a1007a6a44df372181edc1d49035c280323dd0c Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 22 Oct 2020 13:23:18 +0200 Subject: [PATCH] Add editing for new subevents --- src/BackOffice/AddPost.jsx | 9 +-- src/BackOffice/CreateNewEvent.jsx | 101 ++++++++++++++++-------------- src/BackOffice/EditableEvent.jsx | 10 +++ src/BackOffice/EventWithPosts.js | 2 +- 4 files changed, 67 insertions(+), 55 deletions(-) diff --git a/src/BackOffice/AddPost.jsx b/src/BackOffice/AddPost.jsx index b5894a2..80f11f8 100644 --- a/src/BackOffice/AddPost.jsx +++ b/src/BackOffice/AddPost.jsx @@ -40,14 +40,7 @@ const AddPost = ({ address: address, googleMaps: googleMaps, }), - [ - id, - title, - startGroup, - address, - googleMaps, - timeOnEveryPost, - ], + [id, title, startGroup, address, googleMaps], ); diff --git a/src/BackOffice/CreateNewEvent.jsx b/src/BackOffice/CreateNewEvent.jsx index e64cd66..5f2ece4 100644 --- a/src/BackOffice/CreateNewEvent.jsx +++ b/src/BackOffice/CreateNewEvent.jsx @@ -25,6 +25,7 @@ const CreateNewEvent = ({ addressSuggestions, }) => { // Denne syntaksen pakker ut existingEvent inn i alle variablene som står under. Ved å ha = "" bak så gir vi default-verdier til disse + const { title_NO = "", title_EN = "", @@ -51,19 +52,19 @@ const CreateNewEvent = ({ /** Her er syntaxen til subeventene */ const [posts, setPosts] = useState( - [ - { - id: uuid(), - title: "", - startGroup: "", - address: "", - googleMaps: "", - timeOnEveryPost: "" - } - ] - ); - const [postTime, setPostTime] = useState(0); - + existingEvent.posts + ? existingEvent.posts + : [ + { + id: uuid(), + title: "", + startGroup: "", + address: "", + googleMaps: "", + }, + ] + ); + const [postTime, setPostTime] = useState(existingEvent.post_time ? existingEvent.post_time : 0); /** *************************************************************************** */ @@ -140,9 +141,9 @@ const CreateNewEvent = ({ if (formIsValid) { setSubmitting(true); const isMentorBoard = availableGroups.indexOf("all") >= 0; - + if (newSubeventPage) { - fixOrderOnPosts() + fixOrderOnPosts(); } const event = { @@ -198,27 +199,28 @@ const CreateNewEvent = ({ }; /** State som sier om vi øsnker et event med subevents, for å kunne få opp en ny side */ - const [newSubeventPage, setNewSubeventPage] = useState(false); + const [newSubeventPage, setNewSubeventPage] = useState( + editing && existingEvent.posts.length > 0 ? true : false + ); const fixOrderOnPosts = () => { - const getGroupOrder = () => { const order = []; - posts.forEach(post => order.unshift(post.startGroup)); + posts.forEach((post) => order.unshift(post.startGroup)); return order; - } + }; const assignGroupOrder = () => { const groupOrder = getGroupOrder(); - posts.forEach(post => { - while(groupOrder[0] !== post.startGroup) { - groupOrder.push(groupOrder.shift()); - } - post.order = [...groupOrder]; - }); - } + posts.forEach((post) => { + while (groupOrder[0] !== post.startGroup) { + groupOrder.push(groupOrder.shift()); + } + post.order = [...groupOrder]; + }); + }; assignGroupOrder(); - } + }; return (
@@ -238,16 +240,17 @@ const CreateNewEvent = ({ Legg til et nytt event. Felter merket med {redStar} er obligatoriske.
- { /** *********************************************************** **/} - {//TODO: For å endre til at data blir sendt til databasen så uncomment linje 237, og kommenter ut linjen over **/ + {/** *********************************************************** **/} + { + //TODO: For å endre til at data blir sendt til databasen så uncomment linje 237, og kommenter ut linjen over **/ }
- { /** *********************************************************** **/} + {/** *********************************************************** **/} {/** TITTEL **/} + + /************* NEW SUBEVENTS********************** */ )} {/** for å få opp muligheten for å lage subevents **/} - {!editing && ( - newSubeventPage === false ? setNewSubeventPage(true) : setNewSubeventPage(false)} - /> - )} + defaultChecked={newSubeventPage} + onChange={() => + newSubeventPage === false + ? setNewSubeventPage(true) + : setNewSubeventPage(false) + } + /> {newSubeventPage && ( + selectedGroups={groups} + posts={posts} + setPosts={setPosts} + errors={errors} + setErrors={setErrors} + postTime={postTime} + setPostTime={setPostTime} + /> )} {/** CANCEL OG SUBMIT KNAPPER **/} @@ -363,8 +372,8 @@ const CreateNewEvent = ({ className="full-width margin-bottom-small margin-top-medium" content="Avbryt" /> - -