hemfixarna-web-components 1.8.23 → 1.8.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/cjs/hemfixarna-address_15.cjs.entry.js +24 -6
  2. package/dist/cjs/hemfixarna-address_15.cjs.entry.js.map +1 -1
  3. package/dist/cjs/hemfixarna-components.cjs.js +1 -1
  4. package/dist/cjs/index-53d1843b.js.map +1 -1
  5. package/dist/cjs/loader.cjs.js +1 -1
  6. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.css +6 -2
  7. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.js +5 -2
  8. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.js.map +1 -1
  9. package/dist/collection/types/index.js.map +1 -1
  10. package/dist/collection/utils/api.js +1 -1
  11. package/dist/collection/utils/api.js.map +1 -1
  12. package/dist/collection/utils/calc.js +19 -3
  13. package/dist/collection/utils/calc.js.map +1 -1
  14. package/dist/esm/hemfixarna-address_15.entry.js +24 -6
  15. package/dist/esm/hemfixarna-address_15.entry.js.map +1 -1
  16. package/dist/esm/hemfixarna-components.js +1 -1
  17. package/dist/esm/index-8fbc0f86.js.map +1 -1
  18. package/dist/esm/loader.js +1 -1
  19. package/dist/hemfixarna-components/hemfixarna-components.esm.js +1 -1
  20. package/dist/hemfixarna-components/hemfixarna-components.esm.js.map +1 -1
  21. package/dist/hemfixarna-components/p-194c73fc.entry.js +2 -0
  22. package/dist/hemfixarna-components/p-194c73fc.entry.js.map +1 -0
  23. package/dist/hemfixarna-components/p-2fb4a299.js.map +1 -1
  24. package/dist/types/components/hemfixarna-invoice/hemfixarna-invoice.d.ts +1 -0
  25. package/dist/types/types/index.d.ts +3 -0
  26. package/dist/types/utils/api.d.ts +2 -2
  27. package/package.json +1 -1
  28. package/dist/hemfixarna-components/p-107a4712.entry.js +0 -2
  29. package/dist/hemfixarna-components/p-107a4712.entry.js.map +0 -1
@@ -87,14 +87,30 @@ const HemfixarnaAddress = class {
87
87
  get el() { return index.getElement(this); }
88
88
  };
89
89
 
90
+ const DEFAULT_RUT_DISCOUNT_PERCENT = 50;
91
+ const DEFAULT_ROT_DISCOUNT_PERCENT = 30;
92
+ const DEFAULT_GREEN_DISCOUNT_PERCENT = 48.5;
93
+ const getDiscountPercentage = (type) => {
94
+ var _a, _b, _c, _d, _e, _f;
95
+ if (type === 'rut') {
96
+ return (_b = (_a = index$1.state.rutOptions) === null || _a === void 0 ? void 0 : _a.percentage) !== null && _b !== void 0 ? _b : DEFAULT_RUT_DISCOUNT_PERCENT;
97
+ }
98
+ if (type === 'rot') {
99
+ return (_d = (_c = index$1.state.rotOptions) === null || _c === void 0 ? void 0 : _c.percentage) !== null && _d !== void 0 ? _d : DEFAULT_ROT_DISCOUNT_PERCENT;
100
+ }
101
+ return (_f = (_e = index$1.state.greenOptions) === null || _e === void 0 ? void 0 : _e.percentage) !== null && _f !== void 0 ? _f : DEFAULT_GREEN_DISCOUNT_PERCENT;
102
+ };
103
+ const getDiscountedPrice = (price, percentage) => {
104
+ return Math.ceil(price * (100 - percentage) / 100);
105
+ };
90
106
  const getRutPrice = (price) => {
91
- return Math.ceil(price / 2);
107
+ return getDiscountedPrice(price, getDiscountPercentage('rut'));
92
108
  };
93
109
  const getRotPrice = (price) => {
94
- return Math.ceil(price * 0.7);
110
+ return getDiscountedPrice(price, getDiscountPercentage('rot'));
95
111
  };
96
112
  const getGreenPrice = (price) => {
97
- return Math.ceil(price * 0.5);
113
+ return getDiscountedPrice(price, getDiscountPercentage('green'));
98
114
  };
99
115
  const getProductPrice = (product, price, amount = 1) => {
100
116
  if (product.rot && index$1.state.rot) {
@@ -461,7 +477,7 @@ const getRot = async () => {
461
477
  const getGreenDiscount = async () => {
462
478
  try {
463
479
  const res = await fetch(`${base$2}/green-discount`);
464
- return await res.json();
480
+ return (await res.json());
465
481
  }
466
482
  catch (error) {
467
483
  console.log(error);
@@ -1747,9 +1763,10 @@ const HemfixarnaInfo = class {
1747
1763
  }
1748
1764
  };
1749
1765
 
1750
- const hemfixarnaInvoiceCss = ":host .invoice{gap:16px;display:grid}:host .invoice form>span{text-align:center;padding:16px 0}:host .invoice img{right:unset;left:unset;position:initial;transform:none}:host .invoice label{cursor:pointer;font-size:14px;display:flex;align-items:flex-start;padding:16px 0}:host .invoice label input{margin:0 5px 0 0;accent-color:#ea662c}:host .invoice-preview{display:flex;gap:4px}:host .invoice-preview div{position:relative}:host .invoice-preview div button{position:absolute;top:0;right:0;padding:0}:host .invoice-preview div button img{width:24px;height:24px}:host .invoice-preview div>img{width:100px;height:80px;object-fit:cover}:host .invoice input[type=email],:host .invoice input[type=tel],:host .invoice textarea{padding:16px;border:1px solid #fcd9c9;font-size:16px}:host .invoice textarea{resize:none;height:200px;font-family:\"Inter\", sans-serif}:host .invoice div:has(>input[type=file]){display:flex;align-items:center;justify-content:center;cursor:pointer;background:#fff;border:1px solid #fcd9c9;padding:32px 16px;gap:16px}:host .invoice div:has(>input[type=file]) span{color:#000;font-size:12px}:host .invoice input[type=file]{display:none}";
1766
+ const hemfixarnaInvoiceCss = ":host .invoice{gap:16px;display:grid}:host .invoice form>span{text-align:right}:host .invoice img{right:unset;left:unset;position:initial;transform:none}:host .invoice label{cursor:pointer;font-size:14px;display:flex;align-items:flex-start;padding:16px 0}:host .invoice label input{margin:0 5px 0 0;accent-color:#ea662c}:host .invoice-preview{display:flex;gap:4px}:host .invoice-preview div{position:relative}:host .invoice-preview div button{position:absolute;top:0;right:0;padding:0}:host .invoice-preview div button img{width:24px;height:24px}:host .invoice-preview div>img{width:100px;height:80px;object-fit:cover}:host .invoice input[type=email],:host .invoice input[type=tel],:host .invoice textarea{padding:16px;border:1px solid #fcd9c9;font-size:16px}:host .invoice textarea{resize:none;height:200px;font-family:\"Inter\", sans-serif}:host .invoice-description-counter{text-align:right;font-size:12px;color:#888}:host .invoice div:has(>input[type=file]){display:flex;align-items:center;justify-content:center;cursor:pointer;background:#fff;border:1px solid #fcd9c9;padding:32px 16px;gap:16px}:host .invoice div:has(>input[type=file]) span{color:#000;font-size:12px}:host .invoice input[type=file]{display:none}";
1751
1767
 
1752
1768
  const base = `${getApiUrl()}/wp-json/headless`;
1769
+ const DESCRIPTION_MAX_LENGTH = 600;
1753
1770
  const HemfixarnaInvoice = class {
1754
1771
  constructor(hostRef) {
1755
1772
  index.registerInstance(this, hostRef);
@@ -1757,6 +1774,7 @@ const HemfixarnaInvoice = class {
1757
1774
  this.displayImages = [];
1758
1775
  this.formImages = [];
1759
1776
  this.formState = 'initial';
1777
+ this.descriptionLength = 0;
1760
1778
  }
1761
1779
  isValidEmail(email) {
1762
1780
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
@@ -1890,7 +1908,7 @@ const HemfixarnaInvoice = class {
1890
1908
  render() {
1891
1909
  var _a;
1892
1910
  const upload = index.getAssetPath(`./assets/drag-drop.svg`);
1893
- return (index.h("div", { class: "invoice" }, ((_a = index$1.state.selectedProduct) === null || _a === void 0 ? void 0 : _a.invoice_description) ? index.h("p", null, index$1.state.selectedProduct.invoice_description) : null, index.h("form", { onSubmit: e => this.submit(e) }, index.h("textarea", { name: "descriptionInput", placeholder: "Beskriv ditt \u00E4rende" }), index.h("div", { role: "button", "aria-label": "upload image", onDragOver: e => this.preventDragOver(e), onDrop: e => this.handleImageDrop(e), onClick: () => this.handleImageClick() }, index.h("img", { src: upload, alt: "hemfixarna_logo", width: 24 }), index.h("div", null, index.h("p", null, "Bifoga ev bilder"), index.h("span", null, "(dra bilder hit)")), index.h("input", { onChange: e => this.handleFileInputChange(e), class: "hemfixarna-file-upload", accept: "image/*", type: "file", multiple: true, name: "fileInput" })), index.h("div", { class: "invoice-preview" }, this.displayImages.map((img, i) => (index.h("div", { key: i }, index.h("img", { src: img, alt: "uploaded image" }), index.h("button", { onClick: () => this.removeImage(i) }, index.h("img", { src: index.getAssetPath(`./assets/close.svg`), alt: "close" })))))), index.h("input", { placeholder: "E-post", type: "email", name: "emailInput" }), index.h("input", { placeholder: "Telefonnummer", type: "tel", name: "telInput" }), index$1.state.selectedProduct.terms_show_checkbox ? (index.h("label", null, index.h("input", { type: "checkbox", name: "termsInput" }), index$1.state.selectedProduct.terms)) : null, this.formError ? index.h("span", null, this.formError) : null, index.h("input", { type: "submit", value: this.formState === 'loading' ? 'Skickar' : 'Kontakta mig', disabled: this.formState === 'loading' }))));
1911
+ return (index.h("div", { class: "invoice" }, ((_a = index$1.state.selectedProduct) === null || _a === void 0 ? void 0 : _a.invoice_description) ? index.h("p", null, index$1.state.selectedProduct.invoice_description) : null, index.h("form", { onSubmit: e => this.submit(e) }, index.h("textarea", { name: "descriptionInput", placeholder: "Beskriv ditt \u00E4rende", maxLength: DESCRIPTION_MAX_LENGTH, onInput: e => (this.descriptionLength = e.target.value.length) }), index.h("span", { class: "invoice-description-counter" }, this.descriptionLength, "/", DESCRIPTION_MAX_LENGTH), index.h("div", { role: "button", "aria-label": "upload image", onDragOver: e => this.preventDragOver(e), onDrop: e => this.handleImageDrop(e), onClick: () => this.handleImageClick() }, index.h("img", { src: upload, alt: "hemfixarna_logo", width: 24 }), index.h("div", null, index.h("p", null, "Bifoga ev bilder"), index.h("span", null, "(dra bilder hit)")), index.h("input", { onChange: e => this.handleFileInputChange(e), class: "hemfixarna-file-upload", accept: "image/*", type: "file", multiple: true, name: "fileInput" })), index.h("div", { class: "invoice-preview" }, this.displayImages.map((img, i) => (index.h("div", { key: i }, index.h("img", { src: img, alt: "uploaded image" }), index.h("button", { onClick: () => this.removeImage(i) }, index.h("img", { src: index.getAssetPath(`./assets/close.svg`), alt: "close" })))))), index.h("input", { placeholder: "E-post", type: "email", name: "emailInput" }), index.h("input", { placeholder: "Telefonnummer", type: "tel", name: "telInput" }), index$1.state.selectedProduct.terms_show_checkbox ? (index.h("label", null, index.h("input", { type: "checkbox", name: "termsInput" }), index$1.state.selectedProduct.terms)) : null, this.formError ? index.h("span", null, this.formError) : null, index.h("input", { type: "submit", value: this.formState === 'loading' ? 'Skickar' : 'Kontakta mig', disabled: this.formState === 'loading' }))));
1894
1912
  }
1895
1913
  get el() { return index.getElement(this); }
1896
1914
  };