mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 13:38:43 +00:00
Fix bug and improve UX/UI
This commit is contained in:
@@ -354,6 +354,7 @@ export default class HomeView extends CommonView {
|
||||
|
||||
// Reload data
|
||||
await this.loadTransactionData();
|
||||
await this.updateAmountWallet();
|
||||
await this.loadData();
|
||||
|
||||
this.showSuccessToast('Delete success!', MESSAGE.DEFAULT_MESSAGE);
|
||||
@@ -382,11 +383,16 @@ export default class HomeView extends CommonView {
|
||||
);
|
||||
}
|
||||
|
||||
initDataTransactionDialog(idTransaction) {
|
||||
initValueTransactionDialog(idTransaction) {
|
||||
let categoryName;
|
||||
|
||||
if (idTransaction) {
|
||||
// Get transaction object
|
||||
const transactionArr = this.listTransactions.filter(
|
||||
(obj) => obj.id === idTransaction,
|
||||
);
|
||||
const transaction = Object.assign({}, ...transactionArr);
|
||||
// Get category object
|
||||
const categoryArr = this.listCategory.filter(
|
||||
(obj) => obj.name === transaction.categoryName,
|
||||
);
|
||||
@@ -411,6 +417,17 @@ export default class HomeView extends CommonView {
|
||||
amountEl.value = Math.abs(transaction.amount);
|
||||
noteEl.value = transaction.note;
|
||||
iconEl.src = category.url;
|
||||
|
||||
categoryName = categoryEl.value;
|
||||
}
|
||||
|
||||
// Show delete button only if it is a edit form and not a income transaction
|
||||
const deleteBtn = this.transactionDialog.querySelector('.form__delete-btn');
|
||||
const showDeleteBtn = () => {
|
||||
return idTransaction && categoryName !== 'Income';
|
||||
};
|
||||
|
||||
deleteBtn.classList.toggle('hide', !showDeleteBtn());
|
||||
}
|
||||
|
||||
async submitTransactionDialog() {
|
||||
@@ -917,14 +934,10 @@ export default class HomeView extends CommonView {
|
||||
showTransactionDialog(idTransaction = null) {
|
||||
this.clearInputTransactionForm();
|
||||
|
||||
// Show delete button only if it is a edit form
|
||||
const deleteBtn = this.transactionDialog.querySelector('.form__delete-btn');
|
||||
deleteBtn.classList.toggle('hide', !idTransaction);
|
||||
|
||||
if (idTransaction) {
|
||||
// Init data transaction to dialog
|
||||
this.initDataTransactionDialog(idTransaction);
|
||||
} else
|
||||
this.initValueTransactionDialog(idTransaction);
|
||||
|
||||
if (!idTransaction)
|
||||
this.transactionDialog.querySelector(
|
||||
"[name='selected_date']",
|
||||
).valueAsDate = new Date(); // Set default value for date input
|
||||
@@ -936,13 +949,20 @@ export default class HomeView extends CommonView {
|
||||
|
||||
addEventTransactionItem() {
|
||||
const transactionItemEl = document.querySelectorAll('.transaction__item');
|
||||
|
||||
if (transactionItemEl) {
|
||||
transactionItemEl.forEach((item) => {
|
||||
item.addEventListener('click', (e) => {
|
||||
const transactionTime = e.target.closest('.transaction__time');
|
||||
const categoryNameEl = item.querySelector(
|
||||
'.transaction__category-name',
|
||||
);
|
||||
|
||||
if (transactionTime) {
|
||||
const idTransaction = transactionTime.dataset.id;
|
||||
|
||||
// If it is income transaction, don't show dialog
|
||||
if (categoryNameEl.textContent.trim() !== 'Income')
|
||||
this.showTransactionDialog(idTransaction);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
// Layouts
|
||||
@import './layouts/header';
|
||||
@import './layouts/nav';
|
||||
|
||||
// Pages
|
||||
@import './pages/login-register';
|
||||
|
||||
@@ -1 +1,36 @@
|
||||
// TODO
|
||||
.home-page {
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: $white;
|
||||
|
||||
&__content {
|
||||
@extend %d-flex;
|
||||
@include flex-layout($justify: space-between, $align: center);
|
||||
|
||||
padding: 12px 8px;
|
||||
}
|
||||
|
||||
&__left-content {
|
||||
@extend %d-flex;
|
||||
@include flex-layout($align: center, $gap: 12px);
|
||||
}
|
||||
|
||||
&__add-btn {
|
||||
@extend %base-btn, %rounded-sm;
|
||||
|
||||
height: 32px;
|
||||
padding-inline: 12px;
|
||||
font-weight: 500;
|
||||
line-height: 16px;
|
||||
transition: 0.2s;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: $dark-primary-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
// TODO
|
||||
@@ -14,41 +14,6 @@
|
||||
padding-top: 96px;
|
||||
}
|
||||
|
||||
.header {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: $white;
|
||||
|
||||
&__content {
|
||||
@extend %d-flex;
|
||||
@include flex-layout($justify: space-between, $align: center);
|
||||
|
||||
padding: 12px 8px;
|
||||
}
|
||||
|
||||
&__left-content {
|
||||
@extend %d-flex;
|
||||
@include flex-layout($align: center, $gap: 12px);
|
||||
}
|
||||
|
||||
&__add-btn {
|
||||
@extend %base-btn, %rounded-sm;
|
||||
|
||||
height: 32px;
|
||||
padding-inline: 12px;
|
||||
font-weight: 500;
|
||||
line-height: 16px;
|
||||
transition: 0.2s;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
background: $dark-primary-color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.wallet {
|
||||
@extend %d-flex;
|
||||
@include flex-layout($align: center, $gap: 8px);
|
||||
@@ -358,12 +323,8 @@
|
||||
@extend %d-flex;
|
||||
@include flex-layout($gap: 32px);
|
||||
|
||||
& .form__input-container:first-child .form__input-field {
|
||||
width: 208px;
|
||||
}
|
||||
|
||||
& .form__input-container:last-child .form__input-field {
|
||||
width: 240px;
|
||||
& .form__input-container {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user