Skip to content

Commit

Permalink
conditions fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanlori committed Mar 2, 2020
1 parent 135d937 commit c1360d5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 34 deletions.
19 changes: 7 additions & 12 deletions src/components/ActionBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,17 @@ class ActionBar {
});
}

revealError = () => {
$(".x-logo-error").classList.remove("hidden");
this.scrollToError();
}

previewHandler(instance: any) {
if (instance.isImageUploaded()) {
$("body").classList.toggle("x-preview");
} else {
$(".x-logo-error").classList.remove("hidden");
this.scrollToError();
}
instance.isImageUploaded() ? $("body").classList.toggle("x-preview") : this.revealError();
}

printHandler(instance: any) {
if (instance.isImageUploaded()) {
window.print();
} else {
$(".x-logo-error").classList.remove("hidden");
this.scrollToError();
}
instance.isImageUploaded() ? window.print() : this.revealError();
}

scrollToError() {
Expand Down
24 changes: 10 additions & 14 deletions src/components/ProductsTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,21 @@ class ProductsTable {
});

document.body.addEventListener("click", (e: any) => {
if (e.target.id === `js-delete-${this.id}`) {
this.removeRowHandler();
}
e.target.id === `js-delete-${this.id}` && this.removeRowHandler();
});
}

onQuantityHandler = (e: any, unityEl: HTMLInputElement): void => {
if (unityEl.value === "") return;
let value = unityEl.value || null;

let id = e.target.attributes[0].value;

const amountPerRow = calculateAmountPerRow(
parseInt(e.target.value),
parseInt(unityEl.value)
parseInt(value)
);
if (!isNaN(amountPerRow)) {
$(`#js-amount-${e.target.attributes[0].value}`).setAttribute(
"value",
`${String(amountPerRow)}€`
);
}

!isNaN(amountPerRow) && $(`#js-amount-${id}`).setAttribute("value", `${String(amountPerRow)}€`);
};

isRowFilled = (): boolean => {
Expand Down Expand Up @@ -103,9 +99,9 @@ class ProductsTable {
<input id="js-amount-${id}" class="js-amount" placeholder="0.00" readonly value="">
</td>
${
id !== 0
? `<td class="remove-wrapper"><i id="js-delete-${id}" class="js-delete icon icon-minus"></i></td>`
: ""
id !== 0
? `<td class="remove-wrapper"><i id="js-delete-${id}" class="js-delete icon icon-minus"></i></td>`
: ""
}
</tr>`;
};
Expand Down
20 changes: 12 additions & 8 deletions src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const calculateSubtotal = (selectorsArray: any): number => {

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

return sum;
Expand All @@ -52,15 +52,19 @@ export const calculateTotalAmount = (
);
};

const addError = el => {
el.classList.add("error");
return false;
}

const removeError = el => {
el.classList.remove("error");
return true;
}

export const isFieldValid = (
value: number,
elemContainer: HTMLElement
): boolean => {
if (!value || value == 0) {
elemContainer.classList.add("error");
return false;
} else {
elemContainer.classList.remove("error");
return true;
}
return value && value != 0 ? removeError(elemContainer) : addError(elemContainer);
};

0 comments on commit c1360d5

Please sign in to comment.