| 
1 | 1 | import React, {Component} from 'react';  | 
 | 2 | +import {Link} from 'react-router-dom';  | 
2 | 3 | 
 
  | 
3 | 4 | class newConversationForm extends Component {  | 
 | 5 | +    constructor(props){  | 
 | 6 | +        super(props)  | 
 | 7 | +        this.state = {  | 
 | 8 | +        title: "",  | 
 | 9 | +        topic: "",  | 
 | 10 | +        // conversationIsPrivate: false  | 
 | 11 | +        }  | 
 | 12 | +    }     | 
 | 13 | + | 
 | 14 | +    // ADD PARTICIPANTS AS WELL  | 
 | 15 | + | 
 | 16 | +    handleCreateConversation = () => {  | 
 | 17 | +        console.log(this.state)  | 
 | 18 | +        const conversation = this.state  | 
 | 19 | +        console.log(JSON.stringify({conversation:conversation}))  | 
 | 20 | +       fetch('http://localhost:3000/conversations', {  | 
 | 21 | +           method: 'POST',  | 
 | 22 | +           headers: {  | 
 | 23 | +            Authorization: `Bearer ${localStorage.getItem("token")}`,  | 
 | 24 | +            "Content-type": "application/json"  | 
 | 25 | +         },  | 
 | 26 | +           body: JSON.stringify(conversation)  | 
 | 27 | +         }).then(res => res.json())  | 
 | 28 | +         .then(json => console.log(json))  | 
 | 29 | +       //   grab json and set active conversation  | 
 | 30 | +       // push history to messageContainer view  | 
 | 31 | +         this.props.history.push('/home')  | 
 | 32 | +       }  | 
 | 33 | + | 
 | 34 | +       onAddConversation = (conversation) => {  | 
 | 35 | +        console.log("ONADDCONVERSATION BEING CALLED")  | 
 | 36 | +        console.log(conversation)  | 
 | 37 | +      this.conversationChannel.send({  | 
 | 38 | +        title: conversation.title,  | 
 | 39 | +        topic: conversation.topic,  | 
 | 40 | +        user_id: localStorage.getItem("token")  | 
 | 41 | +      })  | 
 | 42 | +    }  | 
 | 43 | + | 
 | 44 | +    handleTitle = e => {  | 
 | 45 | +        this.setState({title: e.target.value})  | 
 | 46 | +    }  | 
 | 47 | + | 
 | 48 | +    handleTopic = e => {  | 
 | 49 | +        this.setState({topic: e.target.value})  | 
 | 50 | +    }  | 
 | 51 | + | 
 | 52 | +    // handleIsPrivate = e => {  | 
 | 53 | +    //     this.setState(prevState => ({conversationIsPrivate: !prevState.conversationIsPrivate}))  | 
 | 54 | +    // }  | 
 | 55 | + | 
 | 56 | +    handleSubmit = e => {  | 
 | 57 | +        e.preventDefault()  | 
 | 58 | +        this.handleCreateConversation(this.state)  | 
 | 59 | +    }  | 
4 | 60 | 
 
  | 
5 |  | -          | 
6 | 61 |     render() {  | 
7 | 62 |         return (  | 
8 | 63 |             <div>  | 
9 | 64 |                 <h3>Create a conversation</h3>  | 
10 |  | -                <form onSubmit={this.props.handleNewConversation}>  | 
 | 65 | +                <Link to='/home'>Back</Link>  | 
 | 66 | +                <form onSubmit={this.handleSubmit}>  | 
11 | 67 |                     <label>Title</label>  | 
12 |  | -                    <input></input><br></br>  | 
 | 68 | +                    <input value={this.state.title} onChange={this.handleTitle}></input><br></br>  | 
13 | 69 |                     <label>Topic</label>  | 
14 |  | -                    <input></input><br></br>  | 
15 |  | -                    <label>Private?</label>  | 
16 |  | -                    <input type="radio"></input><br></br>  | 
 | 70 | +                    <input value={this.state.topic} onChange={this.handleTopic}></input><br></br>  | 
 | 71 | +                    {/* <label>Private?</label>  | 
 | 72 | +                    <input type="radio" value={this.state.conversationIsPrivate} onChange={this.handleIsPrivate}></input><br></br> */}  | 
17 | 73 |                     <button type="submit">Submit</button>  | 
18 | 74 |                 </form>  | 
19 | 75 |             </div>  | 
 | 
0 commit comments