Last active
December 17, 2018 19:49
-
-
Save wendelnascimento/bb6a19c882b3ae629d562189149cb7af to your computer and use it in GitHub Desktop.
Shawee subscription script
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
// First we get the form instance and add an listener for the submit event | |
var form = document.querySelector('.form'); | |
form.addEventListener('submit', function(e) { | |
e.preventDefault(); | |
var serialized = $('#submitForm').serializeArray(); | |
var btnSend = document.querySelector('.btn-send'); | |
btnSend.setAttribute('disabled', ''); | |
btnSend.setAttribute('style', 'cursor: not-allowed'); | |
// then we build the POST request to shawee API with all the variables to fill in the participant profile | |
fetch('https://api.shawee.io/api/graphql', { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
query: | |
'mutation ($person: AddPerson!, $participant: AddParticipant!) {\n addPersonAsAParticipant(person: $person, participant: $participant) {\n name\n email\n phone\n __typename\n }\n}\n', | |
variables: { | |
person: { | |
name: serialized[0].value, | |
email: serialized[1].value, | |
cpf: serialized[2].value, | |
phone: serialized[3].value, | |
linkedin: serialized[4].value, | |
github: serialized[5].value, | |
facebook: serialized[6].value, | |
}, | |
participant: { | |
hackathonId: hackathonId, | |
roleId: serialized[7].value, | |
}, | |
}, | |
operationName: null, | |
}), | |
}).then(function() { | |
e.target.classList.add('invisible'); | |
var feedback = document.querySelector('.feedback'); | |
feedback.classList.remove('invisible'); | |
var modalTitle = document.querySelector('.modal-header-title'); | |
modalTitle.innerText = 'Success!'; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment