-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
394 lines (332 loc) · 13.6 KB
/
Copy pathapp.js
File metadata and controls
394 lines (332 loc) · 13.6 KB
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
// ========================
// EMAILJS CONFIGURATION
// ========================
document.addEventListener('DOMContentLoaded', function() {
console.log('🚀 Inicializando website Catálise Estudos...');
// Inicializar EmailJS
emailjs.init("YlgyKX0_nVeBbDxA4");
console.log('✅ EmailJS inicializado com sucesso');
// ========================
// FUNÇÕES DE EMAIL
// ========================
function enviarAgendamento(formData) {
console.log('📧 Enviando agendamento...', formData);
const templateParams = {
from_name: formData.nome,
from_email: formData.email,
to_name: 'Professor Hugo',
materia: formData.materia,
modalidade: formData.modalidade,
message: `
🎓 NOVA SOLICITAÇÃO DE AGENDAMENTO
👤 Nome: ${formData.nome}
📧 Email: ${formData.email}
📞 Telefone: ${formData.telefone || 'Não fornecido'}
📚 Matéria: ${formData.materia}
🎯 Modalidade: ${formData.modalidade}
💬 Mensagem do aluno:
${formData.mensagem || 'Sem mensagem adicional'}
---
Enviado através do website Catálise Estudos
Data: ${new Date().toLocaleDateString('pt-PT')} às ${new Date().toLocaleTimeString('pt-PT')}
`.trim()
};
return emailjs.send('service_nooo1v5', 'template_g99r5xc', templateParams);
}
function enviarContacto(formData) {
console.log('📧 Enviando contacto...', formData);
const templateParams = {
from_name: formData.nome,
from_email: formData.email,
to_name: 'Professor Hugo',
materia: formData.materia,
modalidade: 'Contacto Geral',
message: `
📞 NOVA MENSAGEM DE CONTACTO
👤 Nome: ${formData.nome}
📧 Email: ${formData.email}
📞 Telefone: ${formData.telefone || 'Não fornecido'}
📚 Matéria de Interesse: ${formData.materia}
💬 Mensagem:
${formData.mensagem}
---
Enviado através do website Catálise Estudos
Data: ${new Date().toLocaleDateString('pt-PT')} às ${new Date().toLocaleTimeString('pt-PT')}
`.trim()
};
return emailjs.send('service_nooo1v5', 'template_g99r5xc', templateParams);
}
// ========================
// ELEMENTOS DOM
// ========================
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('nav-toggle');
const navMenu = document.getElementById('nav-menu');
const navLinks = document.querySelectorAll('.nav-link');
const scheduleModal = document.getElementById('schedule-modal');
const agendarBtns = document.querySelectorAll('#agendar-btn, #hero-cta');
const closeModal = document.getElementById('close-modal');
const contactForm = document.getElementById('contact-form');
const scheduleForm = document.getElementById('schedule-form');
const saberMaisBtn = document.getElementById('saber-mais');
console.log('📋 Elementos encontrados:', {
navbar: !!navbar,
navToggle: !!navToggle,
navMenu: !!navMenu,
scheduleModal: !!scheduleModal,
agendarBtns: agendarBtns.length,
closeModal: !!closeModal,
contactForm: !!contactForm,
scheduleForm: !!scheduleForm
});
// ========================
// NAVEGAÇÃO
// ========================
// Mobile Navigation Toggle
if (navToggle && navMenu) {
navToggle.addEventListener('click', function() {
navToggle.classList.toggle('active');
navMenu.classList.toggle('active');
if (navMenu.classList.contains('active')) {
document.body.style.overflow = 'hidden';
} else {
document.body.style.overflow = '';
}
});
}
// Close mobile menu when clicking on a link
navLinks.forEach(link => {
link.addEventListener('click', function() {
if (navToggle && navMenu) {
navToggle.classList.remove('active');
navMenu.classList.remove('active');
document.body.style.overflow = '';
}
});
});
// Navbar scroll effects
window.addEventListener('scroll', function() {
if (navbar) {
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
}
});
// Smooth scrolling
navLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href').substring(1);
const targetSection = document.getElementById(targetId);
if (targetSection) {
const offsetTop = targetSection.offsetTop - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// Saber Mais button
if (saberMaisBtn) {
saberMaisBtn.addEventListener('click', function() {
const servicesSection = document.getElementById('servicos');
if (servicesSection) {
const offsetTop = servicesSection.offsetTop - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
}
// ========================
// MODAL FUNCTIONALITY
// ========================
function openModal() {
console.log('📱 Abrindo modal...');
if (scheduleModal) {
scheduleModal.classList.remove('hidden');
document.body.style.overflow = 'hidden';
const firstInput = scheduleModal.querySelector('input');
if (firstInput) {
setTimeout(() => firstInput.focus(), 100);
}
}
}
function closeModalHandler() {
console.log('📱 Fechando modal...');
if (scheduleModal) {
scheduleModal.classList.add('hidden');
document.body.style.overflow = '';
if (scheduleForm) {
scheduleForm.reset();
}
}
}
// Modal event listeners
agendarBtns.forEach(btn => {
if (btn) {
btn.addEventListener('click', function(e) {
e.preventDefault();
console.log('🎯 Botão agendar clicado');
openModal();
});
}
});
if (closeModal) {
closeModal.addEventListener('click', function(e) {
e.preventDefault();
closeModalHandler();
});
}
if (scheduleModal) {
scheduleModal.addEventListener('click', function(e) {
if (e.target === scheduleModal) {
closeModalHandler();
}
});
}
// Close with Escape key
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && scheduleModal && !scheduleModal.classList.contains('hidden')) {
closeModalHandler();
}
});
// ========================
// FORM SUBMISSIONS
// ========================
// Schedule Form (Modal)
if (scheduleForm) {
scheduleForm.addEventListener('submit', function(e) {
e.preventDefault();
console.log('📝 Formulário de agendamento submetido');
const formData = {
nome: document.getElementById('modal-nome')?.value.trim() || '',
email: document.getElementById('modal-email')?.value.trim() || '',
telefone: document.getElementById('modal-telefone')?.value.trim() || '',
materia: document.getElementById('modal-materia')?.value || '',
modalidade: document.getElementById('modal-modalidade')?.value || '',
mensagem: document.getElementById('modal-mensagem')?.value.trim() || ''
};
console.log('📋 Dados coletados:', formData);
// Validação
if (!formData.nome) {
alert('❌ Por favor, preencha o seu nome.');
document.getElementById('modal-nome')?.focus();
return;
}
if (!formData.email) {
alert('❌ Por favor, preencha o seu email.');
document.getElementById('modal-email')?.focus();
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
alert('❌ Por favor, introduza um email válido.');
document.getElementById('modal-email')?.focus();
return;
}
if (!formData.materia) {
alert('❌ Por favor, selecione uma matéria.');
document.getElementById('modal-materia')?.focus();
return;
}
if (!formData.modalidade) {
alert('❌ Por favor, selecione uma modalidade.');
document.getElementById('modal-modalidade')?.focus();
return;
}
// Loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalHTML = submitBtn.innerHTML;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Enviando...';
submitBtn.disabled = true;
// Send email
enviarAgendamento(formData)
.then(function(response) {
console.log('✅ Agendamento enviado com sucesso:', response);
alert('✅ Pedido de agendamento enviado com sucesso!\n\nO Professor Hugo entrará em contacto brevemente através do email ou telefone fornecido.');
scheduleForm.reset();
closeModalHandler();
})
.catch(function(error) {
console.error('❌ Erro ao enviar agendamento:', error);
alert('❌ Ocorreu um erro ao enviar o pedido.\n\nPor favor, contacte diretamente:\n📞 +351 933 237 805\n📧 chemreaction@outlook.com');
})
.finally(function() {
submitBtn.innerHTML = originalHTML;
submitBtn.disabled = false;
});
});
}
// Contact Form
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
console.log('📝 Formulário de contacto submetido');
const formData = {
nome: document.getElementById('nome')?.value.trim() || '',
email: document.getElementById('email')?.value.trim() || '',
telefone: document.getElementById('telefone')?.value.trim() || '',
materia: document.getElementById('materia')?.value || '',
mensagem: document.getElementById('mensagem')?.value.trim() || ''
};
console.log('📋 Dados de contacto coletados:', formData);
// Validação
if (!formData.nome) {
alert('❌ Por favor, preencha o seu nome.');
document.getElementById('nome')?.focus();
return;
}
if (!formData.email) {
alert('❌ Por favor, preencha o seu email.');
document.getElementById('email')?.focus();
return;
}
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
alert('❌ Por favor, introduza um email válido.');
document.getElementById('email')?.focus();
return;
}
if (!formData.materia) {
alert('❌ Por favor, selecione uma matéria.');
document.getElementById('materia')?.focus();
return;
}
if (!formData.mensagem) {
alert('❌ Por favor, escreva uma mensagem.');
document.getElementById('mensagem')?.focus();
return;
}
// Loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalHTML = submitBtn.innerHTML;
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Enviando...';
submitBtn.disabled = true;
// Send email
enviarContacto(formData)
.then(function(response) {
console.log('✅ Contacto enviado com sucesso:', response);
alert('✅ Mensagem enviada com sucesso!\n\nO Professor Hugo entrará em contacto brevemente.');
contactForm.reset();
})
.catch(function(error) {
console.error('❌ Erro ao enviar contacto:', error);
alert('❌ Ocorreu um erro ao enviar a mensagem.\n\nPor favor, contacte diretamente:\n📞 +351 933 237 805\n📧 chemreaction@outlook.com');
})
.finally(function() {
submitBtn.innerHTML = originalHTML;
submitBtn.disabled = false;
});
});
}
// ========================
// FINALIZAÇÃO
// ========================
console.log('✅ Website Catálise Estudos inicializado com sucesso!');
console.log('📧 EmailJS funcionando - Formulários prontos para uso');
});