-
Notifications
You must be signed in to change notification settings - Fork 1
/
guest_invite.html
310 lines (289 loc) · 10.1 KB
/
guest_invite.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Samagra Event - Guest Invite</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.css"
/>
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="./style.css" />
<style>
.form-container {
max-height: 80vh;
overflow-y: auto;
}
.button-container {
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<section>
<div class="swiper">
<div class="swiper-wrapper">
<div class="swiper-slide">
<div class="gradient"></div>
<div class="form-container">
<div class="flex-container ">
<div class="flex-item-left">
<form class="form-content" id="inviteForm">
<h2 class="head">Create Event</h2>
<!-- <div class="form-group">
<label for="guestCount">Guest Count</label>
<input
type="number"
id="guestCount"
name="guestCount"
placeholder="Guest Count"
required
/>
</div> -->
<div class="form-group">
<label for="adminEmail">Admin Email</label>
<input
type="email"
id="adminEmail"
name="adminEmail"
placeholder="Admin Email"
required
/>
</div>
<div class="form-group">
<label for="documentHash">Document Hash</label>
<input
type="text"
id="documentHash"
name="documentHash"
placeholder="Document Hash"
required
/>
</div>
<div class="form-group">
<label for="identifier">Identifier</label>
<input
type="text"
id="identifier"
name="identifier"
placeholder="Identifier"
required
/>
</div>
<div class="button-container">
<button
type="button"
class="gradient-button"
id="inviteSubmit"
onclick="createAdmin()"
>
Create Event
</button>
</div>
</form>
</div>
<div class="flex-item-right" id="inviteid">
<div class="vertical"></div>
<h2 class="head">Guest List</h2>
<form class="form-content" id="inviteFormdata">
<div id="guestInputs">
<div class="guest-input">
<div class="form-group guestnam">
<label for="guestName">Guest Name</label>
<input
type="text"
id="guestName_0"
name="guestName[]"
placeholder="Guest Name"
required
/>
</div>
<div class="form-group guestfrom">
<label for="guestEmail">Guest Email</label>
<input
type="email"
id="guestEmail_0"
name="guestEmail[]"
placeholder="Guest Email"
required
/>
</div>
</div>
</div>
<div class="guest-input">
<div class="form-group guestnam">
<label for="guestName">Guest Name</label>
<input
type="text"
id="guestName_1"
name="guestName[]"
placeholder="Guest Name"
required
/>
</div>
<div class="form-group guestfrom">
<label for="guestEmail">Guest Email</label>
<input
type="email"
id="guestEmail_1"
name="guestEmail[]"
placeholder="Guest Email"
required
/>
</div>
</div>
<div class="guest-input">
<div class="form-group guestnam">
<label for="guestName">Guest Name</label>
<input
type="text"
id="guestName_2"
name="guestName[]"
placeholder="Guest Name"
required
/>
</div>
<div class="form-group guestfrom">
<label for="guestEmail">Guest Email</label>
<input
type="email"
id="guestEmail_2"
name="guestEmail[]"
placeholder="Guest Email"
required
/>
</div>
</div>
<div class="button-container">
<button
type="button"
class="gradient-button"
id="inviteSend"
onclick="sendInvite()"
>
Send Invite
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
<script>
let guestCount = 0;
function addGuestInput() {
const guestInputs = document.getElementById("guestInputs")
const guestInputDiv = document.createElement("div")
guestInputDiv.className = "guest-input"
guestInputDiv.innerHTML = `
<br / >
<div class="form-group">
<label for="guestName">Guest Name</label>
<input type="text" id="guestName_${guestCount}" name="guestName[]" placeholder="Guest Name" required />
</div>
<div class="form-group">
<label for="guestEmail">Guest Email</label>
<input type="email" id="guestEmail_${guestCount}" name="guestEmail[]" placeholder="Guest Email" required />
</div>
<br />
`
guestInputs.appendChild(guestInputDiv)
}
function highlightinvite(index) {
const guestInputDiv = document.getElementById("inviteid");
guestInputDiv.classList.remove("hide");
guestInputDiv.classList.add("visible");
}
function createAdmin() {
document.getElementById("inviteSubmit").disabled = true;
const form = document.getElementById("inviteForm")
const formData = new FormData(form)
const data = {
email: formData.get("adminEmail"),
identifier: formData.get("identifier"),
document_hash: formData.get("documentHash"),
witnessCount: 3,
}
fetch("https://api.demo.dhiway.com/api/v1/dmp/create", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
if(response.status === 200){
alert("Event Created Successfully!")
document.getElementById("inviteSubmit").disabled = false;
highlightinvite()
console.log("Success:", data)
}
})
.catch((error) => {
document.getElementById("inviteSubmit").disabled = false;
console.error("Error:", error)
})
}
function sendInvite() {
document.getElementById("inviteSend").disabled = true;
const form = document.getElementById("inviteFormdata")
const formData = new FormData(form)
const formmain = document.getElementById("inviteForm")
const formDatamain = new FormData(formmain)
const guests = []
const names = formData.getAll('guestName[]');
const emails = formData.getAll('guestEmail[]');
for (let i = 0; i < names.length; i++) {
const guest = {
name: names[i],
email: emails[i]
};
guests.push(guest);
}
// for (const entry of formData.entries()) {
// if (entry[0].startsWith("guestName")) {
// const index = entry[0].split("[")[1].split("]")[0]
// const guest = {
// name: entry[1],
// email: formData.get(`guestEmail[${index}]`),
// }
// console.log("here",guest);
// guests.push(guest)
// }
// }
const data = {
recipients: guests,
document_hash: formDatamain.get("documentHash"),
identifier: formDatamain.get("identifier"),
}
fetch("https://api.demo.dhiway.com/api/v1/dmp/sendMail", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then((response) => {
if (!response.ok) {
throw new Error("Network response was not ok")
}
alert("Invite sent successfully!")
document.getElementById("inviteSend").disabled = false;
form.reset() // Reset the form after successful submission
})
.catch((error) => {
document.getElementById("inviteSend").disabled = false;
console.error(
"There was a problem with your fetch operation:",
error
)
})
}
</script>
</body>
</html>