-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webform.html
86 lines (73 loc) · 2.65 KB
/
webform.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Submit Issue</title>
</head>
<body>
<p><small><span id="lastUpdatedTime"></span></small></p>
<h1>Submit an Issue</h1>
<form id="issueForm">
<label for="name">Your Name:</label>
<input type="text" id="name" name="name" required>
<label for="title">Title:</label>
<input type="text" id="title" name="title" required>
<label for="body">Description:</label>
<textarea id="body" name="body" required></textarea>
<button type="submit">Submit</button>
</form>
<script>
async function fetchLastUpdatedTime() {
const response = await fetch('https://micaloveskpop.github.io/crashdayhub/webform.html');
const lastModified = response.headers.get('Last-Modified');
const lastUpdatedDate = new Date(lastModified);
const formattedDateTime = lastUpdatedDate.getFullYear().toString().slice(2) +
String(lastUpdatedDate.getMonth() + 1).padStart(2, '0') +
String(lastUpdatedDate.getDate()).padStart(2, '0') +
String(lastUpdatedDate.getHours()).padStart(2, '0') +
String(lastUpdatedDate.getMinutes()).padStart(2, '0') +
String(lastUpdatedDate.getSeconds()).padStart(2, '0');
document.getElementById('lastUpdatedTime').textContent = formattedDateTime;
}
fetchLastUpdatedTime();
const form = document.getElementById('issueForm');
const titleInput = document.getElementById('title');
const bodyInput = document.getElementById('body');
form.addEventListener('submit', async (event) => {
event.preventDefault();
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
}
};
const response = await fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify(data)
});
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}`);
}
});
</script>
</body>
</html>