Skip to content

Instantly share code, notes, and snippets.

@syamjayaraj syamjayaraj/App.js
Created Aug 7, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.