mirror of
https://github.com/Nezumi-2711/javascript-training.git
synced 2026-09-22 20:01:31 +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
|
// Reload data
|
||||||
await this.loadTransactionData();
|
await this.loadTransactionData();
|
||||||
|
await this.updateAmountWallet();
|
||||||
await this.loadData();
|
await this.loadData();
|
||||||
|
|
||||||
this.showSuccessToast('Delete success!', MESSAGE.DEFAULT_MESSAGE);
|
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(
|
const transactionArr = this.listTransactions.filter(
|
||||||
(obj) => obj.id === idTransaction,
|
(obj) => obj.id === idTransaction,
|
||||||
);
|
);
|
||||||
const transaction = Object.assign({}, ...transactionArr);
|
const transaction = Object.assign({}, ...transactionArr);
|
||||||
|
// Get category object
|
||||||
const categoryArr = this.listCategory.filter(
|
const categoryArr = this.listCategory.filter(
|
||||||
(obj) => obj.name === transaction.categoryName,
|
(obj) => obj.name === transaction.categoryName,
|
||||||
);
|
);
|
||||||
@@ -411,6 +417,17 @@ export default class HomeView extends CommonView {
|
|||||||
amountEl.value = Math.abs(transaction.amount);
|
amountEl.value = Math.abs(transaction.amount);
|
||||||
noteEl.value = transaction.note;
|
noteEl.value = transaction.note;
|
||||||
iconEl.src = category.url;
|
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() {
|
async submitTransactionDialog() {
|
||||||
@@ -917,14 +934,10 @@ export default class HomeView extends CommonView {
|
|||||||
showTransactionDialog(idTransaction = null) {
|
showTransactionDialog(idTransaction = null) {
|
||||||
this.clearInputTransactionForm();
|
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
|
// Init data transaction to dialog
|
||||||
this.initDataTransactionDialog(idTransaction);
|
this.initValueTransactionDialog(idTransaction);
|
||||||
} else
|
|
||||||
|
if (!idTransaction)
|
||||||
this.transactionDialog.querySelector(
|
this.transactionDialog.querySelector(
|
||||||
"[name='selected_date']",
|
"[name='selected_date']",
|
||||||
).valueAsDate = new Date(); // Set default value for date input
|
).valueAsDate = new Date(); // Set default value for date input
|
||||||
@@ -936,13 +949,20 @@ export default class HomeView extends CommonView {
|
|||||||
|
|
||||||
addEventTransactionItem() {
|
addEventTransactionItem() {
|
||||||
const transactionItemEl = document.querySelectorAll('.transaction__item');
|
const transactionItemEl = document.querySelectorAll('.transaction__item');
|
||||||
|
|
||||||
if (transactionItemEl) {
|
if (transactionItemEl) {
|
||||||
transactionItemEl.forEach((item) => {
|
transactionItemEl.forEach((item) => {
|
||||||
item.addEventListener('click', (e) => {
|
item.addEventListener('click', (e) => {
|
||||||
const transactionTime = e.target.closest('.transaction__time');
|
const transactionTime = e.target.closest('.transaction__time');
|
||||||
|
const categoryNameEl = item.querySelector(
|
||||||
|
'.transaction__category-name',
|
||||||
|
);
|
||||||
|
|
||||||
if (transactionTime) {
|
if (transactionTime) {
|
||||||
const idTransaction = transactionTime.dataset.id;
|
const idTransaction = transactionTime.dataset.id;
|
||||||
|
|
||||||
|
// If it is income transaction, don't show dialog
|
||||||
|
if (categoryNameEl.textContent.trim() !== 'Income')
|
||||||
this.showTransactionDialog(idTransaction);
|
this.showTransactionDialog(idTransaction);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
// Layouts
|
// Layouts
|
||||||
@import './layouts/header';
|
@import './layouts/header';
|
||||||
@import './layouts/nav';
|
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
@import './pages/login-register';
|
@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;
|
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 {
|
.wallet {
|
||||||
@extend %d-flex;
|
@extend %d-flex;
|
||||||
@include flex-layout($align: center, $gap: 8px);
|
@include flex-layout($align: center, $gap: 8px);
|
||||||
@@ -358,12 +323,8 @@
|
|||||||
@extend %d-flex;
|
@extend %d-flex;
|
||||||
@include flex-layout($gap: 32px);
|
@include flex-layout($gap: 32px);
|
||||||
|
|
||||||
& .form__input-container:first-child .form__input-field {
|
& .form__input-container {
|
||||||
width: 208px;
|
width: 100%;
|
||||||
}
|
|
||||||
|
|
||||||
& .form__input-container:last-child .form__input-field {
|
|
||||||
width: 240px;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user