Skip to content

Commit

Permalink
frontend: pass requestBody to showResponseStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaw3d committed Oct 28, 2024
1 parent 1c78544 commit f9b266d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions faucet-frontend/src/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// @ts-check

function showResponseStatus(status) {
function showResponseStatus(error, status, requestBody) {
document.querySelector('#request-form').style.display = 'none';
document.querySelector('#response-display').style.display = 'block';
document.querySelector('#response-display-text').textContent = status;
if (error) {
document.querySelector('#response-display-text').textContent = error;
} else {
document.querySelector('#response-display-text').textContent = status;
if (requestBody.get('paratime') === 'emerald') {}
if (requestBody.get('paratime') === 'sapphire') {}
}
}
function showLoading(bool) {
document.querySelector('#request-form-submit').disabled = bool;
Expand Down Expand Up @@ -31,21 +37,22 @@ document.querySelector('#request-form').addEventListener('submit', (event) => {
/** @type {HTMLFormElement} */
(event.currentTarget);
const url = form.action;
const requestBody = new URLSearchParams(new FormData(form))

fetch(url, {
method: 'POST',
body: new URLSearchParams(new FormData(form)),
body: requestBody,
headers: {
Accept: 'application/json',
},
})
.then(response => response.json())
.then((responseJson) => {
showLoading(false);
showResponseStatus(responseJson.result);
showResponseStatus(null, responseJson.result, requestBody);
}, (error) => {
showLoading(false);
showResponseStatus(error);
showResponseStatus(error, null, requestBody);
});

// Only prevent native form POST if no errors were thrown until `fetch`
Expand Down

0 comments on commit f9b266d

Please sign in to comment.