Skip to content

Commit

Permalink
Mulig å velge "Alle grupper"
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus committed Nov 10, 2020
1 parent 8d1f7c8 commit 2d49067
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
17 changes: 15 additions & 2 deletions src/BackOffice/CreateNewEvent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 === ""),
Expand Down Expand Up @@ -370,7 +379,11 @@ const CreateNewEvent = ({

{newSubeventPage && (
<EventWithPosts
selectedGroups={groups.sort(groupComparator)}
selectedGroups={
groups.includes("all") ?
availableGroups.filter(group => group !== "all").sort(groupComparator) :
groups.sort(groupComparator)
}
posts={posts}
setPosts={setPosts}
postTime={postTime}
Expand Down
11 changes: 7 additions & 4 deletions src/BackOffice/form-fields/GroupPicker.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import { Form, Checkbox } from "semantic-ui-react";
import ErrorLabel from "../ErrorLabel";

Expand All @@ -11,7 +11,8 @@ const GroupPicker = ({
editing,
}) => {
const redStar = <span style={{ color: "red" }}>*</span>;
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 });
Expand All @@ -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 (
Expand Down

0 comments on commit 2d49067

Please sign in to comment.