Skip to content

Instantly share code, notes, and snippets.

@syamjayaraj
Created August 7, 2018 18:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syamjayaraj/c2b3fddc170d8d65c51b527ae6691ff2 to your computer and use it in GitHub Desktop.
Save syamjayaraj/c2b3fddc170d8d65c51b527ae6691ff2 to your computer and use it in GitHub Desktop.
addDonor = (name, mobile, group) => {
if(this.state.name != null && this.state.mobile != null && this.state.group != null){
fetch('https://blood-donors-db.firebaseio.com/donors.json', {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"name": name,
"mobile": mobile,
"group": group,
}),
})
.then((response) => response.json())
.then((responseData) => {
if(responseData.name != null ){
this.setState({
name: null,
mobile: null,
group: null,
isSubmited: true,
})
}
else{
Alert.alert(
'Oops !',
'Something went wrong',
[
{text: 'OK', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
],
{ cancelable: false }
)
}
})
.done();
}
else{
Alert.alert(
'Oops !',
'You forgot some field. Please fill it before submitting',
[
{text: 'OK', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
],
{ cancelable: false }
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment