28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
// initials.js
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
function getInitials(firstName, lastName) {
|
|
if (firstName && lastName) {
|
|
return firstName.charAt(0) + lastName.charAt(0);
|
|
}
|
|
return 'N/A';
|
|
}
|
|
|
|
fetchUserData()
|
|
.then(data => {
|
|
if (data.error) {
|
|
document.getElementById('user-name').textContent = 'Guest';
|
|
document.getElementById('profile-picture').textContent = 'G';
|
|
} else {
|
|
const firstName = data.firstname || 'N/A';
|
|
const lastName = data.lastname || 'N/A';
|
|
document.getElementById('user-name').textContent = firstName + ' ' + lastName;
|
|
document.getElementById('profile-picture').textContent = getInitials(firstName, lastName);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error fetching user data:', error);
|
|
document.getElementById('user-name').textContent = 'Error loading user data';
|
|
document.getElementById('profile-picture').textContent = 'E';
|
|
});
|
|
});
|