import './style.css'; import { userStore } from './userStore'; // import { User } from './types'; // Add notification container const notificationContainer = document.createElement('div'); notificationContainer.className = 'fixed top-4 right-4 z-50 space-y-2'; document.body.appendChild(notificationContainer); // Notification handler userStore.onNotification((message, type) => { const notification = document.createElement('div'); notification.className = `p-4 rounded-lg shadow-lg ${ type === 'success' ? 'bg-green-500' : 'bg-red-500' } text-white`; notification.textContent = message; notificationContainer.appendChild(notification); // Remove notification after 3 seconds setTimeout(() => { notification.remove(); }, 3000); }); document.querySelector('#app')!.innerHTML = `

Add User

User List

Name Email Phone Platform

Send Message

`; function updateUserList() { const userTableBody = document.getElementById('userTableBody')!; const userList = document.getElementById('userList')!; const users = userStore.getUsers(); // Update table view userTableBody.innerHTML = users.map(user => ` ${user.name} ${user.email} ${user.phone} ${user.platform} `).join(''); // Update message form checkboxes userList.innerHTML = users.map(user => `
`).join(''); } document.getElementById('userForm')?.addEventListener('submit', (e) => { e.preventDefault(); const formData = new FormData(e.target as HTMLFormElement); const user = { name: formData.get('name') as string, email: formData.get('email') as string, phone: formData.get('phone') as string, platform: formData.get('platform') as 'email' | 'sms' }; userStore.addUser(user); updateUserList(); (e.target as HTMLFormElement).reset(); }); document.getElementById('messageForm')?.addEventListener('submit', async (e) => { e.preventDefault(); const formData = new FormData(e.target as HTMLFormElement); const messageType = formData.get('messageType') as 'email' | 'sms'; const message = formData.get('message') as string; const selectedUsers = Array.from(document.querySelectorAll('#userList input[type="checkbox"]:checked')) .map(checkbox => checkbox.value); if (selectedUsers.length === 0) { alert('Please select at least one user'); return; } const submitButton = document.getElementById('submitButton') as HTMLButtonElement; submitButton.disabled = true; // ... submitButton.disabled = false; try { await userStore.sendMessage(selectedUsers, messageType, message); (e.target as HTMLFormElement).reset(); } finally { submitButton.disabled = false; submitButton.textContent = 'Send Message'; } }); updateUserList();