Skip to content

Commit

Permalink
Merge pull request #108 from Cavdy/ft-admin-and-staffs-can-view-users…
Browse files Browse the repository at this point in the history
…-165661767

#165661767 Admin and staffs can view all users from users page
  • Loading branch information
Cavdy authored Apr 28, 2019
2 parents 4aa5248 + a9edf45 commit 5ac1c43
Show file tree
Hide file tree
Showing 16 changed files with 823 additions and 34 deletions.
5 changes: 4 additions & 1 deletion frontend-app/accounts.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h1 class="logo">Banka</h1>
<li class="sidebar-item">
<a href="./transactions.html" class="sidebar-link">Transactions</a>
</li>
<li class="sidebar-item">
<a href="./users.html" class="sidebar-link">Users</a>
</li>
<li class="sidebar-item">
<a href="staffs.html" class="sidebar-link">Staffs</a>
</li>
Expand Down Expand Up @@ -123,7 +126,7 @@ <h1 class="logo">Banka</h1>

<!--Main Body-->
<main class="main-body">
<div class="alert alert-success"><span class="successMsg">Success </span><span id="close">X</span></div>
<div class="alert alert-success"><span class="successMsg">Success </span><span id="close">X</span></div>
<div class="alert alert-danger"><span class="errMsg">Something went wrong. Try again </span><span
id="close">X</span></div>
<div class=" transaction">
Expand Down
3 changes: 3 additions & 0 deletions frontend-app/activate.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h1 class="logo">Banka</h1>
<li class="sidebar-item">
<a href="./transactions.html" class="sidebar-link">Transactions</a>
</li>
<li class="sidebar-item">
<a href="./users.html" class="sidebar-link">Users</a>
</li>
<li class="sidebar-item">
<a href="staffs.html" class="sidebar-link">Staffs</a>
</li>
Expand Down
3 changes: 3 additions & 0 deletions frontend-app/adduser.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h1 class="logo">Banka</h1>
<li class="sidebar-item">
<a href="./transactions.html" class="sidebar-link">Transactions</a>
</li>
<li class="sidebar-item">
<a href="./users.html" class="sidebar-link">Users</a>
</li>
<li class="sidebar-item">
<a href="staffs.html" class="sidebar-link">Staffs</a>
</li>
Expand Down
33 changes: 33 additions & 0 deletions frontend-app/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,10 @@ body,
margin-bottom: .5rem;
}

.tran-btn {
margin-bottom: 1rem;
}

/*
============================
Profile page styling
Expand Down Expand Up @@ -1035,6 +1039,7 @@ body,
width: 60%;
height: 1.5rem;
margin-bottom: 1rem;
border: 1px solid var(--color-blue);
}

.credit-btn {
Expand Down Expand Up @@ -1285,4 +1290,32 @@ body,
.accountsQuery {
margin-bottom: 4rem;
}

.transaction-body {
flex: 1;
}

.transaction-details {
display: none;
}

.tran-btn {
display: flex;
flex-direction: column;
}

.dc-tran input[type=number] {
width: 100%;
height: 1.5rem;
margin-bottom: 1rem;
}

.credit-btn {
margin-bottom: .5rem;
}

.credit-btn,
.debit-btn {
width: 100%;
}
}
3 changes: 3 additions & 0 deletions frontend-app/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h1 class="logo">Banka</h1>
<li class="sidebar-item">
<a href="./transactions.html" class="sidebar-link">Transactions</a>
</li>
<li class="sidebar-item">
<a href="./users.html" class="sidebar-link">Users</a>
</li>
<li class="sidebar-item">
<a href="staffs.html" class="sidebar-link">Staffs</a>
</li>
Expand Down
2 changes: 1 addition & 1 deletion frontend-app/js/activate.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const patchApi = (url, data) => {
};

// DELETE FETCH REQUEST FOR ACCOUNTS
const deleteApi = (url, data) => {
const deleteApi = (url) => {
fetch(url, {
method: 'DELETE',
mode: 'cors',
Expand Down
121 changes: 121 additions & 0 deletions frontend-app/js/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
const token = sessionStorage.getItem('token');
const api = 'https://bankaapp-api.herokuapp.com/api';
const limitSelect = document.querySelector('#limit');
const submit = document.querySelector('#go');
const errMsg = document.querySelector('.errMsg');

// DELETE FETCH REQUEST FOR USERS
const deleteApi = (url) => {
fetch(url, {
method: 'DELETE',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
redirect: 'follow',
referrer: 'no-referrer',
})
.then((response) => {
if (response.status === 204) {
errMessage.forEach((err) => {
err.innerHTML = '';
});
onSuccess.forEach((success) => {
success.innerHTML = 'Deleted successfully';
setInterval(() => {
document.location.reload(true);
}, 3000);
});
}
});
};

// GET FETCH API REQUEST TO GET ALL ACCOUNTS OF A USER
const getUsersApi = (url) => {
fetch(url, {
method: 'GET',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
redirect: 'follow',
referrer: 'no-referrer',
})
.then((response) => {
if (response.status === 403) {
errMsg.innerHTML = 'you must be logged in to view accounts';
} else {
errMsg.innerHTML = '';
return response.json();
}
})
.then((data1) => {
if (data1.status === 401) {
errMsg.innerHTML = 'you must be an admin or staff to view accounts';
} else {
data1.data.map((i) => {
const table = document.querySelector('.table');
const tableRow = document.createElement('div');
tableRow.classList = 'table-row table-body';
const transactionId = document.createElement('div');
transactionId.className = 'none';
transactionId.innerHTML = i.id;
const createdOn = document.createElement('div');
createdOn.className = 'account-name';
createdOn.innerHTML = i.createdon;
const accountNumber = document.createElement('div');
accountNumber.className = 'account-index';
accountNumber.innerHTML = i.accountnumber;
const type = document.createElement('div');
type.className = 'account-status';
type.innerHTML = i.type;
const record = document.createElement('div');
record.className = 'record';
const aRecord = document.createElement('a');
aRecord.href = '#';
aRecord.className = 'record-btn';
aRecord.id = 'show-modal';
aRecord.innerHTML = 'View Record';
record.appendChild(aRecord);
const newBalnace = document.createElement('div');
newBalnace.className = 'account-status';
newBalnace.innerHTML = i.newbalance;
tableRow.appendChild(transactionId);
tableRow.appendChild(createdOn);
tableRow.appendChild(accountNumber);
tableRow.appendChild(type);
tableRow.appendChild(record);
tableRow.appendChild(newBalnace);
table.appendChild(tableRow);
});

// DELETE
const dels = document.querySelectorAll('.deactivate-btn');
dels.forEach((del) => {
del.addEventListener('click', (e) => {
const id = e.target.parentElement.parentElement.children[0].innerHTML;
deleteApi(`${api}/v1/users/${id}`);
e.target.parentElement.parentElement.remove();
});
});
}
return data1;
});
};
getUsersApi(`${api}/v1/users/clients`);

submit.addEventListener('click', (e) => {
e.preventDefault();
const tableBodies = document.querySelectorAll('.table-body');
tableBodies.forEach((tableBody) => {
tableBody.remove();
});

getTransactionsApi(`${api}/v1/accounts/${accountSelect.value}/transactions`);
});
3 changes: 3 additions & 0 deletions frontend-app/transactions.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ <h1 class="logo">Banka</h1>
<li class="sidebar-item sidebar-item-active">
<a href="./transactions.html" class="sidebar-link">Transactions</a>
</li>
<li class="sidebar-item">
<a href="./users.html" class="sidebar-link">Users</a>
</li>
<li class="sidebar-item">
<a href="staffs.html" class="sidebar-link">Staffs</a>
</li>
Expand Down
Loading

0 comments on commit 5ac1c43

Please sign in to comment.