Created
July 17, 2018 21:55
-
-
Save wendelnascimento/685640324fb18bbb8df56682798c7ab8 to your computer and use it in GitHub Desktop.
Subscribe to a shawee hackathon using jquery ajax
This file contains hidden or 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
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'); | |
jQuery.ajax({ | |
url: 'https://api.shawee.io/api/graphql', | |
type: 'POST', | |
contentType: "application/json", | |
dataType: "json", | |
data: { | |
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, | |
}, | |
}).done(function() { | |
e.target.classList.add('invisible'); | |
var feedback = document.querySelector('.feedback'); | |
feedback.classList.remove('invisible'); | |
var modalTitle = document.querySelector('.modal-header-title'); | |
modalTitle.innerText = 'Inscrição feita com sucesso!'; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment