Last active
December 27, 2019 11:07
-
-
Save sankita15/c39380e47da9e6774114a5be5e4adb6b to your computer and use it in GitHub Desktop.
Guest Invitation Page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
export default class GuestInvitation extends React.Component { | |
constructor(props){ | |
super(props); | |
this.state = { | |
name: '', | |
message: '' | |
} | |
} | |
handleNameChange = (value) => { | |
this.setState({ | |
name: value | |
}) | |
}; | |
handleInvitation() { | |
const { name } = this.state; | |
fetch(`/api/invite/${name}`, { | |
headers: { | |
ContentType: "application/json" | |
}, | |
method: 'POST' | |
}) | |
.then(res => (res.ok ? res.json() : Promise.reject(res.status))) | |
.then(message => this.setState({ message })) | |
.catch(e => console.warn(e)); | |
} | |
render() { | |
const { message } = this.state; | |
return( | |
<div> | |
<input | |
onChange={(e) => this.handleNameChange(e.target.value)} | |
placeholder="Enter Your Name For Invitation" /> | |
<button onClick={() => this.handleInvitation()}>Attend</button> | |
{ | |
message !== '' ? message : null | |
} | |
</div> | |
) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment