-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (69 loc) · 2.68 KB
/
script.js
File metadata and controls
81 lines (69 loc) · 2.68 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
document.addEventListener('DOMContentLoaded', function () {
const loginForm = document.getElementById('loginForm');
const resultDiv = document.getElementById('result');
loginForm.addEventListener('submit', async function (e) {
e.preventDefault();
const apiKey = document.getElementById('apiKey').value;
try {
const response = await fetch('https://standupparo-apis.vercel.app/api/company-name', {
method: 'GET',
headers: {
'x-api-key': apiKey
}
});
if (response.ok) {
const data = await response.json();
localStorage.setItem('apiKey', apiKey);
localStorage.setItem('companyName', data.companyName);
try {
const devsResponse = await fetch('https://standupparo-apis.vercel.app/api/devs', {
method: 'GET',
headers: {
'x-api-key': apiKey
}
});
if (devsResponse.ok) {
const devs = await devsResponse.json();
localStorage.setItem('developers', JSON.stringify(devs));
console.log('Dati degli sviluppatori precaricati con successo');
}
} catch (error) {
console.error('Errore nel precaricare i dati degli sviluppatori:', error);
}
try {
const meetingsResponse = await fetch('https://standupparo-apis.vercel.app/api/stand-ups', {
method: 'GET',
headers: {
'x-api-key': apiKey
}
});
if (meetingsResponse.ok) {
const meetings = await meetingsResponse.json();
localStorage.setItem('api_meetings', JSON.stringify(meetings));
const savedMeetings = JSON.parse(localStorage.getItem('meetings')) || [];
meetings.forEach(apiMeeting => {
const existingMeeting = savedMeetings.find(m => m.date === apiMeeting.date);
if (!existingMeeting) {
savedMeetings.push({
...apiMeeting,
plannedDurationMins: apiMeeting.plannedDurationMins || 0,
standUpsInfo: apiMeeting.notes || []
});
}
});
localStorage.setItem('meetings', JSON.stringify(savedMeetings));
console.log('Dati dei meeting precaricati con successo');
}
} catch (error) {
console.error('Errore nel precaricare i dati dei meeting:', error);
}
window.location.href = 'dashboard.html';
} else {
resultDiv.innerText = 'API Key non valida o errore nella richiesta.';
}
} catch (error) {
resultDiv.innerText = 'Errore di rete.';
console.error('Errore:', error);
}
});
});