-
Notifications
You must be signed in to change notification settings - Fork 0
/
cadastrar.js
41 lines (35 loc) · 1.47 KB
/
cadastrar.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
// Formulário de cadastro de novo paciente
const newClientForm = document.querySelector('.newClientForm')
newClientForm.addEventListener('submit', (event) => {
event.preventDefault()
const loginType = 'paciente'
const registredAt = new Date()
const nomeCompleto = event.target[0].value
const endereçoCompleto = event.target[1].value
const telefone = event.target[2].value
const email = event.target[3].value
const nascimento = new Date(event.target[4].value)
const registredAccount = localStorage.getItem(`nutripuc:account[${email}]`, email)
if (registredAccount) {
window.alert('Este e-mail já foi registrado')
return
}
if (!nomeCompleto || !endereçoCompleto || !telefone || !email) {
window.alert('Nenhum campo do formulário deve estar vazio')
return
}
console.log('está rodando')
localStorage.setItem(`nutripuc:account[${email}]`, email)
localStorage.setItem(`nutripuc:account[${email}]-loginType`, loginType)
localStorage.setItem(`nutripuc:account[${email}]-nomeCompleto`, nomeCompleto)
localStorage.setItem(
`nutripuc:account[${email}]-registerDate`,
registredAt.toLocaleDateString('pt-BR', { day: '2-digit', month: 'long', year: 'numeric' })
)
localStorage.setItem(`nutripuc:account[${email}]-phone`, telefone)
localStorage.setItem(
`nutripuc:account[${email}]-birthDate`,
nascimento.toLocaleDateString('pt-BR', { weekday: 'long', day: '2-digit', month: 'long' })
)
window.location.assign('./clients.html')
})