-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
156 lines (129 loc) · 3.66 KB
/
app.js
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
let participantes = [
{
nome: "Diego Fernandes",
email: "[email protected]",
dataInscricao: new Date(2023, 4, 20, 19, 23),
dataCheckIn: null
},
{
nome: "Mayk Brito",
email: "[email protected]",
dataInscricao: new Date(2023, 11, 4, 19, 23),
dataCheckIn: new Date(2023, 11, 5, 20, 20)
},
{
nome: "Maria Silva",
email: "[email protected]",
dataInscricao: new Date(2023, 9, 6, 19, 23),
dataCheckIn: new Date(2023, 4, 21, 10, 0)
},
{
nome: "João Souza",
email: "[email protected]",
dataInscricao: new Date(2023, 0, 5, 8, 0),
dataCheckIn: null
},
{
nome: "Fernanda Lima",
email: "[email protected]",
dataInscricao: new Date(2023, 3, 16, 11, 45),
dataCheckIn: new Date(2023, 4, 21, 10, 0)
},
{
nome: "Lucas Santos",
email: "[email protected]",
dataInscricao: new Date(2023, 4, 20, 17, 10),
dataCheckIn: null
},
{
nome: "Ana Oliveira",
email: "[email protected]",
dataInscricao: new Date(2023, 2, 1, 19, 23),
dataCheckIn: new Date(2023, 5, 10, 19, 23)
},
{
nome: "Pedro Carvalho",
email: "[email protected]",
dataInscricao: new Date(2023, 7, 12, 14, 20),
dataCheckIn: null
},
{
nome: "Camila Oliveira",
email: "[email protected]",
dataInscricao: new Date(2023, 8, 8, 18, 45),
dataCheckIn: new Date(2023, 8, 9, 9, 0)
},
{
nome: "Gustavo Santos",
email: "[email protected]",
dataInscricao: new Date(2023, 9, 25, 20, 5),
dataCheckIn: new Date(2023, 9, 26, 8, 45)
}
];
const criarNovoParticipante = (participante) => {
const dataInscricao = dayjs(Date.now()).to(participante.dataInscricao)
let dataCheckIn = dayjs(Date.now()).to(participante.dataCheckIn)
if(participante.dataCheckIn == null) {
dataCheckIn = `
<button
data-email="${participante.email}"
onclick="fazerCheckIn(event)"
>
Confirmar check-in
</button>
`
}
return `
<tr>
<td>
<strong>
${participante.nome}
</strong>
<br>
<small>
${participante.email}
</small>
</td>
<td>${dataInscricao}</td>
<td>${dataCheckIn}</td>
</tr>
`
}
const atualizarLista = (participantes) => {
let output = ""
for(let participante of participantes) {
output = output + criarNovoParticipante(participante)
}
document.querySelector('tbody').innerHTML = output
}
atualizarLista(participantes)
const adicionarParticipante = (event) => {
event.preventDefault()
const formData = new FormData(event.target)
const participante = {
nome: formData.get('nome'),
email: formData.get('email'),
dataInscricao: new Date(),
dataCheckIn: null
}
const participanteExiste = participantes.find((p) => p.email == participante.email
)
if (participanteExiste) {
alert('Email já cadastrado!')
return
}
participantes = [participante, ...participantes]
atualizarLista(participantes)
event.target.querySelector('[name="nome"]').value = ""
event.targe.querySelector('[name="email"]').value = ""
}
const fazerCheckIn = (event) => {
const mensagemConfirmacao = confirm('Tem certeza que deseja fazer o check-in?')
if(confirm(mensagemConfirmacao) == false) {
return
}
const participante = participantes.find((p)=> p.email == event.target.dataset.email
)
participante.dataCheckIn = new Date()
atualizarLista(participantes)
}