Skip to content

Commit

Permalink
Add editing for new subevents
Browse files Browse the repository at this point in the history
  • Loading branch information
MathiasSJacobsen committed Oct 22, 2020
1 parent a59a052 commit 4a1007a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 55 deletions.
9 changes: 1 addition & 8 deletions src/BackOffice/AddPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@ const AddPost = ({
address: address,
googleMaps: googleMaps,
}),
[
id,
title,
startGroup,
address,
googleMaps,
timeOnEveryPost,
],
[id, title, startGroup, address, googleMaps],
);


Expand Down
101 changes: 55 additions & 46 deletions src/BackOffice/CreateNewEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
Expand All @@ -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);

/** *************************************************************************** */

Expand Down Expand Up @@ -140,9 +141,9 @@ const CreateNewEvent = ({
if (formIsValid) {
setSubmitting(true);
const isMentorBoard = availableGroups.indexOf("all") >= 0;

if (newSubeventPage) {
fixOrderOnPosts()
fixOrderOnPosts();
}

const event = {
Expand Down Expand Up @@ -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 (
<div className="flex-column create-event-wrapper">
Expand All @@ -238,16 +240,17 @@ const CreateNewEvent = ({
Legg til et nytt event. Felter merket med {redStar} er
obligatoriske.
</div>
{ /** *********************************************************** **/}
{//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 **/
}
<Form
className="create-event-form"
//onSubmit={readyForDatabase}
//onSubmit={readyForDatabase}
onSubmit={submit}
loading={!availableGroups || submitting}
>
{ /** *********************************************************** **/}
{/** *********************************************************** **/}

{/** TITTEL **/}
<TitleFields
Expand Down Expand Up @@ -333,27 +336,33 @@ const CreateNewEvent = ({
className="full-width margin-bottom-small margin-top-small"
content="Legg til hendelser"
/>

/************* NEW SUBEVENTS********************** */
)}

{/** for å få opp muligheten for å lage subevents **/}
{!editing && (
<Checkbox

<Checkbox
label={`Lag et arrangement med subeventes`}
className="group-checkbox full-width margin-top-medium"
onChange={() => newSubeventPage === false ? setNewSubeventPage(true) : setNewSubeventPage(false)}
/>
)}
defaultChecked={newSubeventPage}
onChange={() =>
newSubeventPage === false
? setNewSubeventPage(true)
: setNewSubeventPage(false)
}
/>

{newSubeventPage && (
<EventWithPosts
selectedGroups={groups}
posts={posts}
setPosts={setPosts}
errors={errors}
setErrors={setErrors}
postTime={postTime}
setPostTime={setPostTime}
/>
selectedGroups={groups}
posts={posts}
setPosts={setPosts}
errors={errors}
setErrors={setErrors}
postTime={postTime}
setPostTime={setPostTime}
/>
)}

{/** CANCEL OG SUBMIT KNAPPER **/}
Expand All @@ -363,8 +372,8 @@ const CreateNewEvent = ({
className="full-width margin-bottom-small margin-top-medium"
content="Avbryt"
/>
<Button

<Button
primary
type="submit"
className="full-width margin-bottom-large"
Expand Down
10 changes: 10 additions & 0 deletions src/BackOffice/EditableEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const CheckLabel = ({ check, label }) => {
);
};



const EditableEvent = ({ event, canManage, deleteCallback, editCallback }) => {
let [lang, setLang] = useState("NO");
const changeLanguage = () => setLang(lang === "NO" ? "EN" : "NO");
Expand Down Expand Up @@ -69,6 +71,12 @@ const EditableEvent = ({ event, canManage, deleteCallback, editCallback }) => {
Beskrivelse: {description}
</label>
)}
{showDescription && (
event.posts.map(post => (
<label className="editable-event-info-label" key={post.id}>
{post.title}
</label>
)))}

<div className="flex-row bottom-row">
{hasAddress && (
Expand All @@ -83,6 +91,8 @@ const EditableEvent = ({ event, canManage, deleteCallback, editCallback }) => {
{!allFieldsEnglish && (
<CheckLabel check={allFieldsEnglish} label="Mangler oversettelse" />
)}


<FontAwesomeIcon
className="show-description-icon icon"
icon={showDescription ? faAngleDoubleUp : faAngleDoubleDown}
Expand Down
2 changes: 1 addition & 1 deletion src/BackOffice/EventWithPosts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useState } from "react";
import React from "react";
import AddPost from "./AddPost";
import AddEventButton from "./AddEventButton";
import uuid from "react-uuid";
Expand Down

0 comments on commit 4a1007a

Please sign in to comment.