-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
163 lines (143 loc) · 3.78 KB
/
main.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
157
158
159
160
161
162
163
let participantes = [
{
nome: "Diego Fernandes",
email: "[email protected]",
dataInscricao: new Date(2024, 2, 1, 19, 23),
dataCheckIn: new Date(2024, 2, 1, 20, 20)
},
{
nome: "Mayk Brito",
email: "[email protected]",
dataInscricao: new Date(2024, 2, 23, 19, 23),
dataCheckIn: new Date(2024, 2, 25, 20, 20)
},
{
nome: "Ana Souza",
email: "[email protected]",
dataInscricao: new Date(2024, 0, 3, 19, 23),
dataCheckIn: new Date(2024, 0, 4, 20, 20)
},
{
nome: "João Silva",
email: "[email protected]",
dataInscricao: new Date(2023, 11, 4, 19, 23),
dataCheckIn: null
},
{
nome: "Maria Oliveira",
email: "[email protected]",
dataInscricao: new Date(2023, 10, 5, 19, 23),
dataCheckIn: new Date(2023, 10, 6, 20, 20)
},
{
nome: "Pedro Santos",
email: "[email protected]",
dataInscricao: new Date(2023, 9, 6, 19, 23),
dataCheckIn: new Date(2023, 9, 7, 20, 20)
},
{
nome: "Carla Lima",
email: "[email protected]",
dataInscricao: new Date(2023, 8, 7, 19, 23),
dataCheckIn: new Date(2023, 8, 8, 20, 20)
},
{
nome: "Lucas Sousa",
email: "[email protected]",
dataInscricao: new Date(2023, 7, 8, 19, 23),
dataCheckIn: new Date(2023, 7, 9, 20, 20)
},
{
nome: "Paula Costa",
email: "[email protected]",
dataInscricao: new Date(2023, 6, 9, 19, 23),
dataCheckIn: new Date(2023, 6, 10, 20, 20)
},
{
nome: "Gabriel Almeida",
email: "[email protected]",
dataInscricao: new Date(2023, 5, 10, 19, 23),
dataCheckIn: new Date(2023, 5, 11, 20, 20)
}
];
const criarNovoParticipante = (participante) => {
const dataInscricao = dayjs(Date.now())
.to(participante.dataInscricao)
let dataCheckIn = dayjs(Date.now())
.to(participante.dataCheckIn)
//condicição do check in
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)
}
// substituir informacao do HTML
document
.querySelector('tbody')
.innerHTML = output
}
atualizarLista(participantes)
const adicionarParticipante = (event) =>{
event.preventDefault()
const dadosDoFormulario = new FormData(event.target)
const participante = {
nome: dadosDoFormulario.get('nome'),
email: dadosDoFormulario.get('email'),
dataInscricao: new Date(),
dataCheckIn: null
}
// verificar se o participante ja foi cadastrado
const participanteExiste = participantes.find((p) => {
return p.email == participante.email
})
if(participanteExiste){
alert('Email já cadastrado!')
return
}
participantes = [participante, ...participantes]
atualizarLista(participantes)
// limpar formulario após enviar
event.target.querySelector('[name= "nome"]').value = ""
event.target.querySelector('[name="email"]').value = ""
}
const fazerCheckIn = (event) => {
// confirmar se realmente quer fazer o check-in
const mensagemConfirmacao = 'Tem certeza que deseja fazer o check-in?'
if(confirm(mensagemConfirmacao)== false){
return
}
// encontrar o participante dentro da lista
const participante = participantes.find((p) => {
return p.email == event.target.dataset.email
})
//atualizar o check-in do participante
participante.dataCheckIn = new Date()
//atualizar a lista de participantes
atualizarLista(participantes)
}