From 2d490678f8460144eb24922c0424dd5454f6fcb2 Mon Sep 17 00:00:00 2001 From: Magnus Date: Tue, 10 Nov 2020 14:34:31 +0100 Subject: [PATCH] =?UTF-8?q?Mulig=20=C3=A5=20velge=20"Alle=20grupper"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BackOffice/CreateNewEvent.jsx | 17 +++++++++++++++-- src/BackOffice/form-fields/GroupPicker.jsx | 11 +++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/BackOffice/CreateNewEvent.jsx b/src/BackOffice/CreateNewEvent.jsx index f45a2d4..4e6cc77 100644 --- a/src/BackOffice/CreateNewEvent.jsx +++ b/src/BackOffice/CreateNewEvent.jsx @@ -138,7 +138,16 @@ const CreateNewEvent = ({ ) === -1, link: (linkTextEN.length !== 0 || linkTextNO.length !== 0) && !link, groups: groups.length === 0, - postGroupsAssigned: newSubeventPage && groups.some(group => !posts.map(post => post.startGroup).includes(group)), + postGroupsAssigned: newSubeventPage && ( + groups.includes("all") ? + availableGroups + .filter(group => group !== "all") + .some(group => !posts.map(post => post.startGroup) + .includes(group)) : + groups + .some(group => !posts.map(post => post.startGroup) + .includes(group)) + ), postStartTime: newSubeventPage && (startTimeHourPosts.length !== 2 || startTimeMinutePosts.length !== 2), postTime: newSubeventPage && postTime.length === 0, postTitle: newSubeventPage && posts.some(post => post.title === ""), @@ -370,7 +379,11 @@ const CreateNewEvent = ({ {newSubeventPage && ( group !== "all").sort(groupComparator) : + groups.sort(groupComparator) + } posts={posts} setPosts={setPosts} postTime={postTime} diff --git a/src/BackOffice/form-fields/GroupPicker.jsx b/src/BackOffice/form-fields/GroupPicker.jsx index 8565dd1..3c128fb 100644 --- a/src/BackOffice/form-fields/GroupPicker.jsx +++ b/src/BackOffice/form-fields/GroupPicker.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React from "react"; import { Form, Checkbox } from "semantic-ui-react"; import ErrorLabel from "../ErrorLabel"; @@ -11,7 +11,8 @@ const GroupPicker = ({ editing, }) => { const redStar = *; - const [allGroupsSelected, setAllGroupsSelected] = useState(false); //groups.indexOf("all") >= 0; + const allGroupsSelected = groups.indexOf("all") >= 0; + //const [allGroupsSelected, setAllGroupsSelected] = useState(false); const handleCheckbox = (group) => { setErrors({ ...errors, groups: false }); @@ -21,9 +22,11 @@ const GroupPicker = ({ } else { setGroups(["duplicate"]); } - } else if (group === "all") { + } else if (group === "all" && groups.indexOf("all") === -1) { + setGroups(["all"]); + /* } else if (group === "all") { setAllGroupsSelected(!allGroupsSelected); - setGroups(allGroupsSelected ? [] : [...availableGroups]); + setGroups(allGroupsSelected ? [] : [...availableGroups]);*/ } else if (groups.indexOf(group) >= 0) { setGroups(groups.filter((g) => g !== group)); } else if (