diff --git a/smart-hut/src/components/HostModal.js b/smart-hut/src/components/HostModal.js index 8867b47..789c484 100644 --- a/smart-hut/src/components/HostModal.js +++ b/smart-hut/src/components/HostModal.js @@ -1,43 +1,71 @@ import React, { Component } from "react"; -import { Button, Header, Modal, Icon, Responsive } from "semantic-ui-react"; +import { + Button, + Header, + Modal, + Icon, + Form, + Responsive, + Dropdown, +} from "semantic-ui-react"; import { connect } from "react-redux"; -import { RemoteService } from "../remote"; +import { RemoteService, Forms } from "../remote"; import { appActions } from "../storeActions"; //import { update } from "immutability-helper"; class HostModal extends Component { constructor(props) { super(props); - this.state = this.initialState; + this.state = { guests: [], users: [] }; + this.props + .fetchGuests() + .then(() => { + this.setState({ + ...this.state, + guests: this.props.guests.map((u) => u.id), + }); + }) + .catch(console.error); + + Forms.fetchAllUsers() + .then((users) => + this.setState({ + ...this.state, + users: users.map((u) => ({ + key: u.id, + text: `@${u.username} (${u.name})`, + value: u.id, + })), + }) + ) + .catch(console.error); + + this.saveGuestSettings = this.saveGuestSettings.bind(this); + this.closeModal = this.closeModal.bind(this); + this.openModal = this.openModal.bind(this); + this.setGuests = this.setGuests.bind(this); this.saveGuestSettings = this.saveGuestSettings.bind(this); } - get initialState() { - return { - //INITIAL STATE HERE - }; + setGuests(_, guests) { + this.setState({ guests: guests.value }); } - setInitialState() { - this.setState(this.initialState); - } - - changeSomething = (event) => { - let nam = event.target.name; - let val = event.target.value; - this.setState({ [nam]: val }); - }; - - closeModal = (e) => { + closeModal() { this.setState({ openModal: false }); - }; + } - openModal = (e) => { + openModal() { this.setState({ openModal: true }); - }; + } - saveGuestSettings() {} + saveGuestSettings() { + this.props + .updateGuests(this.state.guests) + .then(this.closeModal) + .catch(console.error); + } render() { return ( @@ -49,17 +77,10 @@ class HostModal extends Component { - {this.type === "new" ? ( - - ) : ( - - )} + @@ -68,6 +89,22 @@ class HostModal extends Component {

Spaghetti!

+ +
+ + + + +
+