Skip to content

Commit 82efcb3

Browse files
authored
Sincronização dos dados no perfil do voluntário
1 parent 945f23a commit 82efcb3

File tree

2 files changed

+103
-101
lines changed

2 files changed

+103
-101
lines changed

fj-tech/src/js/voluntarios/lista.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,10 @@ document.getElementById("corpoTabelaDeListagemDeVoluntarios").addEventListener("
164164
const idVoluntarioPerfil = event.target.closest("tr").id;
165165

166166
const docVoluntario = voluntarioSnapshot.docs.find((doc) => doc.id === idVoluntarioPerfil);
167-
const inscricaoVoluntario = getDoc(doc(docVoluntario, 'festival', edicaoAtualFestival), data_inscricao);
167+
const inscricaoVoluntario = doc(docVoluntario.ref, 'festival', edicaoAtualFestival).data_inscricao;
168168
const dataInscricaoVoluntario = new Date(inscricaoVoluntario * 1000).toLocaleDateString('pt-BR');
169169

170+
//console.log("Dados do voluntário: ", docVoluntario.data());
170171
document.getElementById("docVoluntarioPerfil").innerHTML = `ID: ${docVoluntario.id} | Voluntário desde ${dataInscricaoVoluntario}`;
171172
});
172173

@@ -179,9 +180,6 @@ document.getElementById("corpoTabelaDeListagemDeVoluntarios").addEventListener("
179180

180181
document.getElementById("nomeVoluntarioGerenciado").innerText = `${docVoluntario.data().nome_completo_voluntario}`;
181182
document.getElementById("gestaoRecusosVoluntarioNoFestival").innerText = `${docVoluntario.id}`;
182-
183-
// Adiciona o código de credencial previamente cadastrado
184-
document.getElementById("codigoCredencial").value = getDoc(doc(voluntarioDoc.ref, 'festival', edicaoAtualFestival)).data().codigo_credencial_voluntario;
185183
});
186184

187185
/**

fj-tech/src/js/voluntarios/perfil.mjs

Lines changed: 101 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,108 +7,112 @@ import './lista.mjs';
77
/**
88
* Identifica o id do voluntário cujo perfil será exibido
99
*/
10-
document.querySelectorAll("tr").forEach((tr) => {
11-
tr.addEventListener("click", async () => {
12-
const idPerfilVoluntario = tr.id;
13-
14-
/**
15-
* Exibe as informações mais relevantes do voluntário na tela de perfil
16-
*/
17-
const docRef = doc(db, "voluntario", idPerfilVoluntario);
18-
const perfil = await getDoc(docRef);
19-
20-
if (perfil.exists()) {
21-
//console.log("Document data:", perfil.data());
22-
23-
/**
24-
* Dados Pessoais
25-
*/
26-
document.getElementById("nomeCompletoDoVoluntario").value = perfil.data().nome_completo_voluntario;
27-
document.getElementById("cpfDoVoluntario").value = perfil.data().cpf_voluntario;
28-
document.getElementById("emailDoVoluntario").value = perfil.data().contato.email_voluntario;
29-
document.getElementById("telefoneDoVoluntario").value = perfil.data().contato.celular_voluntario;
30-
31-
(perfil.data().sexo_voluntario === "Masculino")
32-
? document.getElementById("sexoMasculino").checked = true
33-
: document.getElementById("sexoFeminino").checked = true;
34-
35-
perfil.data().faixa_etaria_voluntario.forEach((faixaEtaria) => {
36-
document.getElementById("faixaEtariaDoVoluntario").value += faixaEtaria;
37-
});
38-
39-
/**
40-
* Contato de Emergência
41-
*/
42-
document.getElementById("nomeContatoDoVoluntario").value = perfil.data().contato.emergencia.nome_contato_emergencia;
43-
document.getElementById("telefoneContatoDoVoluntario").value = perfil.data().contato.emergencia.telefone_contato_emergencia;
44-
45-
/**
46-
* Endereço do Voluntário
47-
*/
48-
document.getElementById("cepDoVoluntario").setAttribute("readonly", true);
49-
document.getElementById("cepDoVoluntario").value = perfil.data().endereco.cep;
50-
51-
document.getElementById("enderecoDoVoluntario").value = perfil.data().endereco.logradouro;
52-
document.getElementById("bairroDoVoluntario").value = perfil.data().endereco.bairro;
53-
document.getElementById("cidadeDoVoluntario").value = perfil.data().endereco.cidade;
54-
document.getElementById("estadoDoVoluntario").value = perfil.data().endereco.estado;
10+
document.getElementById("corpoTabelaDeListagemDeVoluntarios").addEventListener("click", () => {
11+
document.querySelectorAll("tr").forEach((tr) => {
12+
tr.addEventListener("click", async () => {
13+
const idPerfilVoluntario = tr.id;
5514

5615
/**
57-
* Dados Adicionais
16+
* Exibe as informações mais relevantes do voluntário na tela de perfil
5817
*/
59-
document.getElementById("ascendente").setAttribute("hidden", true);
60-
if (perfil.data().descendencia_voluntario.descendente_japones === true) {
61-
document.getElementById("descendenteSim").checked = true;
62-
document.getElementById("ascendente").removeAttribute("hidden");
18+
const docRef = doc(db, "voluntario", idPerfilVoluntario);
19+
const perfil = await getDoc(docRef);
20+
21+
if (perfil.exists()) {
22+
// Limpa os campos do modal de perfil do voluntário se houver algum valor
23+
clearInputData();
24+
//console.log("Document data:", perfil.data());
25+
26+
/**
27+
* Dados Pessoais
28+
*/
29+
document.getElementById("nomeCompletoDoVoluntario").value = perfil.data().nome_completo_voluntario;
30+
document.getElementById("cpfDoVoluntario").value = perfil.data().cpf_voluntario;
31+
document.getElementById("emailDoVoluntario").value = perfil.data().contato.email_voluntario;
32+
document.getElementById("telefoneDoVoluntario").value = perfil.data().contato.celular_voluntario;
33+
34+
(perfil.data().dados_pessoais.sexo_voluntario === "Masculino")
35+
? document.getElementById("sexoMasculino").checked = true
36+
: document.getElementById("sexoFeminino").checked = true;
37+
38+
perfil.data().dados_pessoais.faixa_etaria.forEach((faixaEtaria) => {
39+
document.getElementById("faixaEtariaDoVoluntario").value += faixaEtaria;
40+
});
41+
42+
/**
43+
* Contato de Emergência
44+
*/
45+
document.getElementById("nomeContatoDoVoluntario").value = perfil.data().contato.emergencia.nome_contato_emergencia;
46+
document.getElementById("telefoneContatoDoVoluntario").value = perfil.data().contato.emergencia.telefone_contato_emergencia;
47+
48+
/**
49+
* Endereço do Voluntário
50+
*/
51+
document.getElementById("cepDoVoluntario").setAttribute("readonly", true);
52+
document.getElementById("cepDoVoluntario").value = perfil.data().endereco.cep;
53+
54+
document.getElementById("enderecoDoVoluntario").value = perfil.data().endereco.logradouro;
55+
document.getElementById("bairroDoVoluntario").value = perfil.data().endereco.bairro;
56+
document.getElementById("cidadeDoVoluntario").value = perfil.data().endereco.cidade;
57+
document.getElementById("estadoDoVoluntario").value = perfil.data().endereco.estado;
58+
59+
/**
60+
* Dados Adicionais
61+
*/
62+
document.getElementById("ascendente").setAttribute("hidden", true);
63+
if (perfil.data().dados_pessoais.descendencia.possui_descendencia_japonesa === true) {
64+
document.getElementById("descendenteSim").checked = true;
65+
document.getElementById("ascendente").removeAttribute("hidden");
66+
} else {
67+
document.getElementById("descendenteNao").checked = true;
68+
document.getElementById("ascendente").setAttribute("hidden", true);
69+
}
70+
71+
perfil.data().dados_pessoais.descendencia.ascendencia_voluntario.forEach((ascendencia) => {
72+
document.getElementById("ascendenciaDoVoluntarioDescendente").value += ascendencia;
73+
});
74+
75+
// Idiomas
76+
// Conhecimento em Ingl~Es
77+
document.getElementById("idiomaVoluntarioIngles").removeAttribute("checked", true);
78+
(perfil.data().carreira.escolaridade.conhecimento_linguas.idioma_ingles === true)
79+
? document.getElementById("idiomaVoluntarioIngles").checked = true
80+
: document.getElementById("idiomaVoluntarioIngles").removeAttribute("checked");
81+
// Conhecimento em Japonês
82+
document.getElementById("idiomaVoluntarioJapones").removeAttribute("checked", true);
83+
(perfil.data().carreira.escolaridade.conhecimento_linguas.idioma_japones === true)
84+
? document.getElementById("idiomaVoluntarioJapones").checked = true
85+
: document.getElementById("idiomaVoluntarioJapones").removeAttribute("checked");
86+
// Conhecimento em Espanhol
87+
document.getElementById("idiomaVoluntarioEspanhol").removeAttribute("checked", true);
88+
(perfil.data().carreira.escolaridade.conhecimento_linguas.idioma_espanhol === true)
89+
? document.getElementById("idiomaVoluntarioEspanhol").checked = true
90+
: document.getElementById("idiomaVoluntarioEspanhol").removeAttribute("checked");
91+
92+
// Conhecimento em Libras
93+
(perfil.data().carreira.escolaridade.conhecimento_linguas.linguagem_de_sinais_brasileira === true)
94+
? document.getElementById("conhecimentoLibrasSim").checked = true
95+
: document.getElementById("conhecimentoLibrasNao").checked = true;
96+
97+
// Treinamento em Primeiros Socorros
98+
(perfil.data().treinamento_primeiros_socorros === true)
99+
? document.getElementById("treinamentoSim").checked = true
100+
: document.getElementById("treinamentoNao").checked = true;
101+
102+
// Escolaridade
103+
perfil.data().carreira.escolaridade.nivel_escolaridade.forEach((nivelEscolaridade) => {
104+
document.getElementById("nivelEscolaridadeVoluntario").value += nivelEscolaridade;
105+
});
106+
107+
// Trabalho
108+
(perfil.data().carreira.profissao.trabalha_atualmente === true)
109+
? document.getElementById("trabalhaSim").checked = true
110+
: document.getElementById("trabalhaNao").checked = true;
63111
} else {
64-
document.getElementById("descendenteNao").checked = true;
112+
// perfil.data() retornará undefined
113+
console.log("Não foi possível encontrar o perfil deste voluntário.");
65114
}
66-
67-
perfil.data().descendencia_voluntario.ascendencia_voluntario.forEach((ascendencia) => {
68-
document.getElementById("ascendenciaDoVoluntarioDescendente").value += ascendencia;
69-
});
70-
71-
// Idiomas
72-
// Conhecimento em Ingl~Es
73-
document.getElementById("idiomaVoluntarioIngles").removeAttribute("checked", true);
74-
(perfil.data().escolaridade_voluntario.conhecimento_voluntario.idioma_ingles === true)
75-
? document.getElementById("idiomaVoluntarioIngles").setAttribute("checked", true)
76-
: document.getElementById("idiomaVoluntarioIngles").removeAttribute("checked");
77-
// Conhecimento em Japonês
78-
document.getElementById("idiomaVoluntarioJapones").removeAttribute("checked", true);
79-
(perfil.data().escolaridade_voluntario.conhecimento_voluntario.idioma_japones === true)
80-
? document.getElementById("idiomaVoluntarioJapones").setAttribute("checked", true)
81-
: document.getElementById("idiomaVoluntarioJapones").removeAttribute("checked");
82-
// Conhecimento em Espanhol
83-
document.getElementById("idiomaVoluntarioEspanhol").removeAttribute("checked", true);
84-
(perfil.data().escolaridade_voluntario.conhecimento_voluntario.idioma_espanhol === true)
85-
? document.getElementById("idiomaVoluntarioEspanhol").setAttribute("checked", true)
86-
: document.getElementById("idiomaVoluntarioEspanhol").removeAttribute("checked");
87-
88-
// Conhecimento em Libras
89-
(perfil.data().escolaridade_voluntario.conhecimento_voluntario.linguagem_libras === true)
90-
? document.getElementById("conhecimentoLibrasSim").checked = true
91-
: document.getElementById("conhecimentoLibrasNao").checked = true;
92-
93-
// Treinamento em Primeiros Socorros
94-
(perfil.data().escolaridade_voluntario.treinamento_primeiros_socorros === true)
95-
? document.getElementById("treinamentoSim").checked = true
96-
: document.getElementById("treinamentoNao").checked = true;
97-
98-
// Escolaridade
99-
perfil.data().escolaridade_voluntario.nivel_escolaridade_voluntario.forEach((nivelEscolaridade) => {
100-
document.getElementById("nivelEscolaridadeVoluntario").value += nivelEscolaridade;
101-
});
102-
103-
// Trabalho
104-
(perfil.data().carreira_voluntario.trabalha_atualmente === true)
105-
? document.getElementById("trabalhaSim").checked = true
106-
: document.getElementById("trabalhaNao").checked = true;
107-
} else {
108-
// perfil.data() retornará undefined
109-
console.log("Não foi possível encontrar o perfil deste voluntário.");
110-
}
111-
115+
});
112116
});
113117
});
114118

0 commit comments

Comments
 (0)