Commit 7be4e921 authored by TJHeeringa's avatar TJHeeringa

Some cleanup

parent 3b96e9ea
......@@ -24,10 +24,10 @@ const Member = (props) => {
const [modalOpen, setModalOpen] = useState(false);
const onCancelButtonClick = () => setModalOpen(true);
const onCancel = () => {setModalOpen(false)};
const onCancel = () => setModalOpen(false);
const onConfirm = () => {
setModalOpen(false);
alerthandler.handleAlertHandler("blue", "This function doesn't work yet.")
alerthandler.handleAlertHandler("blue", "This function doesn't work yet.");
// This function should do a delete call to the membership
};
......
import "react-simple-tree-menu/dist/main.css";
import "./Groups.css";
import Container from "@material-ui/core/Container";
import { Helper } from "App/Helper";
import PropTypes from "prop-types";
import React, { Component } from "react";
import { NavLink, withRouter } from "react-router-dom";
import TreeMenu from "react-simple-tree-menu";
import { Button } from "reactstrap";
import CardGrid from "../../../Components/Card/CardGrid";
import GroupCard from "../../../Components/Card/GroupCardV2";
import Block from "../../../Components/PageLayout/Content/Block";
import PageContent from "../../../Components/PageLayout/Content/Content";
import Sushi from "../../../../img/Sushi-11-me.jpg"; // Import using relative path
import { GroupRouter } from "./GroupRouter";
class Boards extends Component {
constructor(props) {
super(props);
this.state = {
boards: [],
tree: [],
hide_board_parent: true
};
}
boardArrayToTree(board_array) {
let board_parent = board_array.filter((board)=>{return board.parent_group === null;})[0];
let boards = board_array.filter((board)=>{return board.parent_group !== null;});
if (this.state.hide_board_parent) {
return boards.map((board, index)=>{return {key: index+1, label:board.full_name, slug: board.slug};});
} else {
return [{
key: 1,
label: board_parent.full_name,
slug: board_parent.slug,
nodes: boards.map((board, index)=>{return {key: index+1, label:board.full_name, slug: board.slug};})
}];
}
}
componentDidMount() {
Helper.api_callv3({
url: "/groups?limit=1000&board_group=true&association__slug="+this.props.association.slug,
method: "GET",
on_succes: (data)=>{this.setState({boards: data.results, tree: this.boardArrayToTree(data.results)});},
on_failure: ()=>{},
});
}
currentBoardSlug(data) {
let current_board = data.find(board => board.current_board === true);
if (current_board && current_board.hasOwnProperty("slug")){
return current_board.slug;
}
return "";
}
boardToGroupCard = (board) => ({
title: board.full_name,
photo: board.photo || Sushi,
path: "boards/" + board.slug
});
render() {
const { association } = this.props;
let path = this.props.path+"/boards";
return (
<div>
<GroupRouter
groups={this.state.boards}
path={path}
association={association}
board_page={true}
/>
{ this.props.location.pathname === path &&
<Container>
<Block className={"mt-20"}>
<h4>BOARDS</h4>
<hr className={"box-title-separator"}/>
<NavLink to = {path +"/" + this.currentBoardSlug(this.state.boards)} >
current board
</NavLink>
<br/>
<hr className={"box-title-separator"}/>
<TreeMenu
data={this.state.tree}
debounceTime={125}
onClickItem={({ key, label, ...props }) => {
this.props.history.push("boards/"+props.slug);
}}
initialOpenNodes={["1"]}
/>
<NavLink to={path + "/add"} className={"addGroupBtnLink"}>
<Button color={"primary"} outline block className={"mt-20"}>
Add a new board
</Button>
</NavLink>
</Block>
<CardGrid
component={GroupCard}
card_grid={this.state.boards.map(board=>this.boardToGroupCard(board))}
chunk_size={4}
/>
</Container>
};
</div>
);
}
}
Boards.propTypes = {
association: PropTypes.object.isRequired
};
export const BoardsWithRouter = withRouter(Boards);
import { Helper } from "App/Helper";
import {AvField, AvForm} from "availity-reactstrap-validation";
import React, { Component } from "react";
import { Button } from "reactstrap";
import { v4 as uuidv4 } from "uuid";
import {AlertHandlerContext} from "../../../Contexts/AlertHandler";
export class GroupInfoForm extends Component {
constructor(props) {
super(props);
this.state = {
group: this.props.group,
photo: null,
logo: null,
board: this.props.board !== undefined ? this.props.board : false
};
}
handleGroupChange = (field, value) => {
this.props.handleGroupChange(field, value);
};
handleValidSubmit = (event, values) => {
let group = this.state.group;
this.state.photo !== null ? (group.photo = this.state.photo) : (delete group.photo);
this.state.logo !== null ? (group.logo = this.state.logo) : (delete group.logo);
this.patchGroupSettings(group);
};
patchGroupSettings(group){
return Helper.api_call(this.props.group.url, "PATCH", group, "form-data",
(group) => {
group.logo !== null && this.handleGroupChange("logo", group.logo);
group.photo !== null && this.handleGroupChange("photo", group.photo);
this.context.handleAlertHandler("green", "Save successful");
},
()=>{this.context.handleAlertHandler("red", "Save failed");}
);
}
render() {
return (
<AvForm id={"groupsettingsform"} onValidSubmit={this.handleValidSubmit} ref={c => (this.form = c)}>
<AvField
type={"text"}
name={"full_name"}
label={"Full name"}
value={this.state.group.full_name}
onChange={(event)=>this.handleGroupChange("full_name",event.target.value)}
/>
<AvField
type={"text"}
name={"short_name"}
label={"Short name"}
value={this.state.group.short_name}
onChange={(event)=>this.handleGroupChange("short_name",event.target.value)}
/>
<AvField
type={"text"}
name={"alternate_name"}
label={"Alternate name"}
value={this.state.group.alternate_name}
onChange={(event)=>this.handleGroupChange("alternate_name",event.target.value)}
/>
<AvField
type={"number"}
name={"number"}
label={"Number"}
value={this.state.group.number}
onChange={(event)=>this.handleGroupChange("number",event.target.value)}
/>
<AvField
type={"text"}
name={"motto"}
label={"Creed"}
value={this.state.group.motto}
onChange={(event)=>this.handleGroupChange("motto",event.target.value)}
/>
<AvField
type={"textarea"}
name={"description"}
label={"Description"}
value={this.state.group.description}
onChange={(event)=>this.handleGroupChange("description",event.target.value)}
/>
<AvField
type={"date"}
name={"founding_date"}
label={"Founding Date"}
value={this.state.group.founding_date}
onChange={(event)=>this.handleGroupChange("founding_date",event.target.value)}
/>
<AvField
type={"date"}
name={"dissolution_date"}
label={"Dissolution Date"}
value={this.state.group.dissolution_date}
onChange={(event)=>this.handleGroupChange("dissolution_date",event.target.value)}
/>
<AvField
type={"email"}
name={"email"}
label={"Email"}
value={this.state.group.email}
onChange={(event)=>this.handleGroupChange("email",event.target.value)}
/>
{ !this.state.board &&
<AvField
type={"select"}
name={"parent_group"}
label={"Parent Group"}
value={this.state.group.parent_group}
onChange={(event)=>this.handleGroupChange("parent_group",event.target.value)}
>
<option value={null}></option>
{ this.props.groups.map(potential_parent_group=>
<option key={uuidv4()} value={potential_parent_group.url}>{ potential_parent_group.full_name }</option>
) }
</AvField>
}
<AvField
type={"file"}
name={"logo"}
label={"Logo"}
onChange={(event)=>this.setState({logo: event.target.files[0]})}
/>
<AvField
type={"file"}
name={"photo"}
label={"Photo"}
onChange={(event)=>this.setState({photo: event.target.files[0]})}
/>
{ /* <FormText color="muted">
This is some placeholder block-level help text for the above input.
It's a bit lighter and easily wraps to a new line.
</FormText>*/ }
<Button color={"primary"} outline block type={"submit"}>Update settings</Button>
</AvForm>
);
}
}
GroupInfoForm.contextType = AlertHandlerContext;
\ No newline at end of file
import "react-simple-tree-menu/dist/main.css";
import "../Board/Groups.css";
import "./Groups.css";
import { makeStyles, useTheme, withStyles } from "@material-ui/core/styles";
import { Helper } from "App/Helper";
import { makeStyles, useTheme } from "@material-ui/core/styles";
import PropTypes from "prop-types";
import React, { Component } from "react";
import React from "react";
import { Route , useLocation, withRouter } from "react-router-dom";
import { useGet } from "restful-react";
......@@ -62,58 +61,6 @@ const Committees = ({ association, path }) => {
}
};
export class Committees2 extends Component {
constructor(props) {
super(props);
this.state = {
committees: []
};
}
componentDidMount() {
this.getGroups();
}
getGroups = () => {
return Helper.api_callv3({
url: "/groups?board_group=false&association__slug="+this.props.association.slug,
method: "GET",
on_succes: (data)=>{this.setState({committees: data.results.filter(committee=>committee.parent_group === null)});}
});
};
committeeToGroupCard = (committee) => ({
title: committee.full_name,
photo: committee.photo,
path: "committees/" + committee.slug
});
render() {
let path = this.props.path + "/committees";
let { committees } = this.state;
let groupcards = committees ? committees.map(committee=>this.committeeToGroupCard(committee)) : [];
console.log(committees, groupcards);
return (
<>
<MyCommitteesRouter
groups={this.state.committees}
path={path}
association={this.props.association}
/>
{ this.props.location.pathname === path &&
<PageContent title={"Groups and Committees"}>
<CardGrid
component={GroupCard}
card_grid={groupcards}
chunk_size={4}
/>
</PageContent>
}
</>
);
}
}
const MyCommitteesRouter = ({groups, path}) => {
return (
<>
......@@ -140,4 +87,4 @@ MyCommitteesRouter.propTypes = {
path: PropTypes.string.isRequired
};
export const MyCommitteesWithRouter = withRouter(Committees);
\ No newline at end of file
export const MyCommittees = Committees;
\ No newline at end of file
......@@ -2,7 +2,7 @@ import BoardInfo from "App/Pages/Association/AssociationBoardInfo";
import { AssociationInfoWithRouter } from "App/Pages/Association/AssociationInfo";
import Member from "App/Pages/Association/Home/member";
import { CalendarWithRouter } from "App/Pages/Calendar/Calendar";
import { MyCommitteesWithRouter } from "App/Pages/Groups/Member/Committees";
import { MyCommittees } from "App/Pages/Groups/Member/Committees";
import { AssociationProfileWithRouter } from "App/Pages/Profile/AssociationProfile";
import MembershipEnd from "App/Pages/Profile/MembershipEnd";
import PropTypes from "prop-types";
......@@ -62,7 +62,7 @@ const MemberRoutes = (props) => {
<Route
path={path+"/committees"}
render={() =>
<MyCommitteesWithRouter
<MyCommittees
committees={committees}
association={association}
association_membership={association_membership}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment