PHP Classes

File: front-pessoas/js/components/UsersList.js

Recommend this page to a friend!
  Classes of Rodrigo Faustino   App MFE   front-pessoas/js/components/UsersList.js   Download  
File: front-pessoas/js/components/UsersList.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: App MFE
Single-page application with micro-frontends
Author: By
Last change:
Date: 10 hours ago
Size: 1,994 bytes
 

Contents

Class file image Download
class UsersList { constructor(fetchService, updateUserForm, refreshUsersList) { this.fetchService = fetchService; this.updateUserForm = updateUserForm; this.refreshUsersList = refreshUsersList; } async render() { const users = await this.fetchService.fetch('/users'); let usersHtml = '<h2>Usuários Disponíveis</h2>'; usersHtml += '<div class="users-list">'; users.forEach(user => { usersHtml += ` <div class="collection"> <li class="collection-item"> ${user.usuario_id} - ${user.nome} - ${user.email} </li> <div class="grupo"> <button class="btn waves-effect waves-light orange secondary-content update" data-id="${user.usuario_id}">Editar</button> <button class="btn waves-effect waves-light red secondary-content delete" data-id="${user.usuario_id}">Deletar</button> </div> </div> `; }); usersHtml += '</div>'; return usersHtml; } afterRender() { const editButtons = document.querySelectorAll('.update'); editButtons.forEach(button => { button.addEventListener('click', async (e) => { const id = e.target.getAttribute('data-id'); const user = await this.fetchService.fetch(`/users/${id}`); this.updateUserForm.open(user); }); }); const deleteButtons = document.querySelectorAll('.delete'); deleteButtons.forEach(button => { button.addEventListener('click', async (e) => { const id = e.target.getAttribute('data-id'); if (confirm('Tem certeza que deseja deletar este usuário?')) { await this.updateUserForm.deleteUser(id); } }); }); } } export default UsersList;