Skip to content

Instantly share code, notes, and snippets.

@sankita15
Last active December 27, 2019 11:07
Show Gist options
  • Save sankita15/c39380e47da9e6774114a5be5e4adb6b to your computer and use it in GitHub Desktop.
Save sankita15/c39380e47da9e6774114a5be5e4adb6b to your computer and use it in GitHub Desktop.
Guest Invitation Page
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