From fade650aadd9a0fad187390b08a0305f84207371 Mon Sep 17 00:00:00 2001 From: Mica <25252229+MicaLovesKPOP@users.noreply.github.com> Date: Sun, 6 Oct 2024 21:18:41 +0200 Subject: [PATCH] Update webform.html --- webform.html | 66 ++++++++++++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/webform.html b/webform.html index 35e1d7e..d2da3bd 100644 --- a/webform.html +++ b/webform.html @@ -40,40 +40,46 @@

Submit an Issue

fetchLastUpdatedTime(); -document.getElementById('issueForm').addEventListener('submit', async function(event) { +const form = document.getElementById('issueForm'); +const titleInput = document.getElementById('title'); +const bodyInput = document.getElementById('body'); + +form.addEventListener('submit', async (event) => { event.preventDefault(); - const name = document.getElementById('name').value; - const title = document.getElementById('title').value; - const body = document.getElementById('body').value; - const time = document.getElementById('lastUpdatedTime').textContent; + const title = titleInput.value; + const body = bodyInput.value; + + try { + const url = `https://api.github.com/repos/MicaLovesKPOP/CrashdayBugTracking/dispatches`; + const headers = { + 'Content-Type': 'application/json' + }; + const data = { + 'event_type': 'create-issue', + 'client_payload': { + 'title': title, + 'body': body + } + }; -try { - const response = await fetch(`https://api.github.com/repos/MicaLovesKPOP/CrashdayBugTracking/issues`, { - method: 'POST', - headers: { - 'Accept': 'application/vnd.github.v3+json', - 'Content-Type': 'application/json', - 'Authorization': `Bearer github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru` - }, - body: JSON.stringify({ - title: title, - body: `**Submitted by:** ${name}\n\n**Last Updated Time:** ${time}\n\n${body}` - }) - }); + const response = await fetch(url, { + method: 'POST', + headers: headers, + body: JSON.stringify(data) + }); - if (response.ok) { - alert('Issue created successfully!'); - } else { - console.error(`Failed to create issue: ${response.status} ${response.statusText}`); - console.error(`Response data: ${await response.text()}`); - console.error(`API Token: ${'github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru'}`); - alert(`Failed to create issue: ${response.status} ${response.statusText}`); + if (response.ok) { + console.log('Issue created successfully!'); + alert('Issue created successfully!'); + } else { + console.error(`Failed to create issue: ${response.status} ${response.statusText}`); + console.error(`Response data: ${await response.text()}`); + alert(`Failed to create issue: ${response.status} ${response.statusText}`); + } + } catch (error) { + console.error(`Error creating issue: ${error.message}`); + alert(`Error creating issue: ${error.message}`); } -} catch (error) { - console.error(`Error creating issue: ${error.message}`); - console.error(`API Token: ${'github_pat_11AGAVDBI08q9sEhSguOGw_wLRh3TAiyXbVpVGAEqDeBs69NDLmobDCTjtDzgNDHMk5VUFREJnQ1K7ru'}`); - alert(`Error creating issue: ${error.message}`); -} });