Skip to content

Commit c1360d5

Browse files
committed
conditions fix
1 parent 135d937 commit c1360d5

File tree

3 files changed

+29
-34
lines changed

3 files changed

+29
-34
lines changed

src/components/ActionBar.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,17 @@ class ActionBar {
2222
});
2323
}
2424

25+
revealError = () => {
26+
$(".x-logo-error").classList.remove("hidden");
27+
this.scrollToError();
28+
}
29+
2530
previewHandler(instance: any) {
26-
if (instance.isImageUploaded()) {
27-
$("body").classList.toggle("x-preview");
28-
} else {
29-
$(".x-logo-error").classList.remove("hidden");
30-
this.scrollToError();
31-
}
31+
instance.isImageUploaded() ? $("body").classList.toggle("x-preview") : this.revealError();
3232
}
3333

3434
printHandler(instance: any) {
35-
if (instance.isImageUploaded()) {
36-
window.print();
37-
} else {
38-
$(".x-logo-error").classList.remove("hidden");
39-
this.scrollToError();
40-
}
35+
instance.isImageUploaded() ? window.print() : this.revealError();
4136
}
4237

4338
scrollToError() {

src/components/ProductsTable.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,21 @@ class ProductsTable {
3939
});
4040

4141
document.body.addEventListener("click", (e: any) => {
42-
if (e.target.id === `js-delete-${this.id}`) {
43-
this.removeRowHandler();
44-
}
42+
e.target.id === `js-delete-${this.id}` && this.removeRowHandler();
4543
});
4644
}
4745

4846
onQuantityHandler = (e: any, unityEl: HTMLInputElement): void => {
49-
if (unityEl.value === "") return;
47+
let value = unityEl.value || null;
48+
49+
let id = e.target.attributes[0].value;
5050

5151
const amountPerRow = calculateAmountPerRow(
5252
parseInt(e.target.value),
53-
parseInt(unityEl.value)
53+
parseInt(value)
5454
);
55-
if (!isNaN(amountPerRow)) {
56-
$(`#js-amount-${e.target.attributes[0].value}`).setAttribute(
57-
"value",
58-
`${String(amountPerRow)}€`
59-
);
60-
}
55+
56+
!isNaN(amountPerRow) && $(`#js-amount-${id}`).setAttribute("value", `${String(amountPerRow)}€`);
6157
};
6258

6359
isRowFilled = (): boolean => {
@@ -103,9 +99,9 @@ class ProductsTable {
10399
<input id="js-amount-${id}" class="js-amount" placeholder="0.00" readonly value="">
104100
</td>
105101
${
106-
id !== 0
107-
? `<td class="remove-wrapper"><i id="js-delete-${id}" class="js-delete icon icon-minus"></i></td>`
108-
: ""
102+
id !== 0
103+
? `<td class="remove-wrapper"><i id="js-delete-${id}" class="js-delete icon icon-minus"></i></td>`
104+
: ""
109105
}
110106
</tr>`;
111107
};

src/libs/utils.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const calculateSubtotal = (selectorsArray: any): number => {
3333

3434
// Iterate over all amount and sum
3535
selectorsArray.forEach(element => {
36-
if (element.value) sum += parseFloat(element.value);
36+
element.value ? sum += parseFloat(element.value) : null;
3737
});
3838

3939
return sum;
@@ -52,15 +52,19 @@ export const calculateTotalAmount = (
5252
);
5353
};
5454

55+
const addError = el => {
56+
el.classList.add("error");
57+
return false;
58+
}
59+
60+
const removeError = el => {
61+
el.classList.remove("error");
62+
return true;
63+
}
64+
5565
export const isFieldValid = (
5666
value: number,
5767
elemContainer: HTMLElement
5868
): boolean => {
59-
if (!value || value == 0) {
60-
elemContainer.classList.add("error");
61-
return false;
62-
} else {
63-
elemContainer.classList.remove("error");
64-
return true;
65-
}
69+
return value && value != 0 ? removeError(elemContainer) : addError(elemContainer);
6670
};

0 commit comments

Comments
 (0)