hemfixarna-web-components 1.3.5 → 1.3.6

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 (44) hide show
  1. package/dist/cjs/{hemfixarna-address_22.cjs.entry.js → hemfixarna-address_23.cjs.entry.js} +173 -24
  2. package/dist/cjs/{hemfixarna-address_22.cjs.entry.js.map → hemfixarna-address_23.cjs.entry.js.map} +1 -1
  3. package/dist/cjs/hemfixarna-components.cjs.js +2 -2
  4. package/dist/cjs/{index-d9e286dc.js → index-83c1daf2.js} +5 -1
  5. package/dist/{esm/index-9863db6c.js.map → cjs/index-83c1daf2.js.map} +1 -1
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/collection/assets/drag-drop.svg +3 -0
  8. package/dist/collection/collection-manifest.json +1 -0
  9. package/dist/collection/components/hemfixarna-box/hemfixarna-box.js +1 -1
  10. package/dist/collection/components/hemfixarna-box/hemfixarna-box.js.map +1 -1
  11. package/dist/collection/components/hemfixarna-category.tsx/hemfixarna-category.js.map +1 -1
  12. package/dist/collection/components/hemfixarna-component/hemfixarna-component.js +4 -4
  13. package/dist/collection/components/hemfixarna-component/hemfixarna-component.js.map +1 -1
  14. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.css +76 -0
  15. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.js +164 -0
  16. package/dist/collection/components/hemfixarna-invoice/hemfixarna-invoice.js.map +1 -0
  17. package/dist/collection/components/hemfixarna-order/hemfixarna-order.js +1 -1
  18. package/dist/collection/components/hemfixarna-order/hemfixarna-order.js.map +1 -1
  19. package/dist/collection/components/hemfixarna-product/hemfixarna-product.js +3 -3
  20. package/dist/collection/components/hemfixarna-product/hemfixarna-product.js.map +1 -1
  21. package/dist/collection/components/hemfixarna-service/hemfixarna-service.js +1 -1
  22. package/dist/collection/components/hemfixarna-service/hemfixarna-service.js.map +1 -1
  23. package/dist/collection/components/hemfixarna-start/hemfixarna-start.js.map +1 -1
  24. package/dist/collection/store/index.js +1 -0
  25. package/dist/collection/store/index.js.map +1 -1
  26. package/dist/collection/types/index.js.map +1 -1
  27. package/dist/esm/{hemfixarna-address_22.entry.js → hemfixarna-address_23.entry.js} +173 -25
  28. package/dist/esm/{hemfixarna-address_22.entry.js.map → hemfixarna-address_23.entry.js.map} +1 -1
  29. package/dist/esm/hemfixarna-components.js +3 -3
  30. package/dist/esm/{index-9863db6c.js → index-1fd61928.js} +5 -1
  31. package/dist/{cjs/index-d9e286dc.js.map → esm/index-1fd61928.js.map} +1 -1
  32. package/dist/esm/loader.js +3 -3
  33. package/dist/hemfixarna-components/assets/drag-drop.svg +3 -0
  34. package/dist/hemfixarna-components/hemfixarna-components.esm.js +1 -1
  35. package/dist/hemfixarna-components/{p-62a7c1a2.js → p-33d37833.js} +3 -3
  36. package/dist/hemfixarna-components/p-7ad71b65.entry.js +2 -0
  37. package/dist/types/components/hemfixarna-invoice/hemfixarna-invoice.d.ts +17 -0
  38. package/dist/types/components.d.ts +13 -0
  39. package/dist/types/store/index.d.ts +1 -0
  40. package/dist/types/types/index.d.ts +4 -0
  41. package/package.json +1 -1
  42. package/dist/hemfixarna-components/p-d5da3c5b.entry.js +0 -2
  43. /package/dist/hemfixarna-components/{p-62a7c1a2.js.map → p-33d37833.js.map} +0 -0
  44. /package/dist/hemfixarna-components/{p-d5da3c5b.entry.js.map → p-7ad71b65.entry.js.map} +0 -0
@@ -208,14 +208,14 @@ export class HemfixarnaComponent {
208
208
  return state.cart.reduce((acc, curr) => acc + curr.amount, 0);
209
209
  }
210
210
  render() {
211
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
211
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
212
212
  const logo = getAssetPath(`./assets/hemfixarna.svg`);
213
213
  const monteringLogo = getAssetPath(`./assets/montering.svg`);
214
214
  const navBackground = ((_a = this.nav) === null || _a === void 0 ? void 0 : _a.background) ? getAssetPath(this.nav.background) : '';
215
215
  const navLogo = ((_b = this.nav) === null || _b === void 0 ? void 0 : _b.logo) ? getAssetPath(this.nav.logo) : '';
216
- return (h("div", { class: `hemfixarna ${this.loadFromQuery ? 'hemfixarna_standalone' : ''}` }, this.loadFromQuery && !this.isDemo && this.nav ? (h("nav", { class: "hemfixarna_nav" }, h("div", null, h("div", { class: "hemfixarna_nav--logos" }, h("a", { href: this.nav.url, target: "_blank" }, h("img", { src: navLogo, alt: `${this.business} logo` })), h("a", { href: "https://hemfixarna.se/", target: "_blank" }, h("p", null, "I samarbete med:"), h("img", { src: logo, alt: "hemfixarna_logo", width: 104 }))), h("div", { class: "hemfixarna_nav--links" }, h("a", { href: this.nav.url, target: "_blank" }, "Till ", this.business), h("a", { href: "https://www.hemfixarna.se/", target: "_blank" }, "Till Hemfixarna")), h("img", { src: navBackground, alt: "nav_background" })))) : null, !this.loadFromQuery || this.isDemo ? (h("div", { class: `hemfixarna_box hemfixarna_box--${this.widgetStyle}` }, [WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) ? h("img", { src: monteringLogo, alt: "montering logo", width: 32, height: 32 }) : null, h("div", null, h("div", null, h("p", { onClick: () => this.openModal(), class: `pointer ${[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) && state.selectedProduct ? 'underline' : ''}` }, ((_c = this.product) === null || _c === void 0 ? void 0 : _c.post_title) || ((_d = this.proppedProduct) === null || _d === void 0 ? void 0 : _d.post_title) || (h("span", null, "Montering", h("wbr", null), "/Installation ", (_f = (_e = state.selectedCustomerCategory) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : 'på plats', " - ", h("strong", { class: "underline" }, "se priser h\u00E4r"))), (this.product && ((_g = this.slug) === null || _g === void 0 ? void 0 : _g.includes('product'))) || this.proppedProduct ? (h("span", null, ' från', " ", h("strong", null, getProductPriceWithRotAndRut(this.proppedProduct || this.product), "kr"))) : null)), this.widgetStyle === WidgetStyle.standard ? h("img", { src: logo, width: 104 }) : null, this.widgetStyle === WidgetStyle.alternative ? (h("span", { class: "p-s" }, "Utf\u00F6rs av ", h("strong", null, "Hemfixarna"))) : null), [WidgetStyle.standard, WidgetStyle.alternative].includes(this.widgetStyle) ? (h("button", { onClick: () => this.openModal(), class: "hemfixarna_btn", style: {
217
- color: ((_h = this.buttonColor) === null || _h === void 0 ? void 0 : _h.startsWith('#')) || !((_j = this.buttonColor) === null || _j === void 0 ? void 0 : _j.length) ? this.buttonColor : `#${this.buttonColor}`,
218
- backgroundColor: ((_k = this.buttonBg) === null || _k === void 0 ? void 0 : _k.startsWith('#')) || !((_l = this.buttonBg) === null || _l === void 0 ? void 0 : _l.length) ? this.buttonBg : `#${this.buttonBg}`,
216
+ return (h("div", { class: `hemfixarna ${this.loadFromQuery ? 'hemfixarna_standalone' : ''}` }, this.loadFromQuery && !this.isDemo && this.nav ? (h("nav", { class: "hemfixarna_nav" }, h("div", null, h("div", { class: "hemfixarna_nav--logos" }, h("a", { href: this.nav.url, target: "_blank" }, h("img", { src: navLogo, alt: `${this.business} logo` })), h("a", { href: "https://hemfixarna.se/", target: "_blank" }, h("p", null, "I samarbete med:"), h("img", { src: logo, alt: "hemfixarna_logo", width: 104 }))), h("div", { class: "hemfixarna_nav--links" }, h("a", { href: this.nav.url, target: "_blank" }, "Till ", this.business), h("a", { href: "https://www.hemfixarna.se/", target: "_blank" }, "Till Hemfixarna")), h("img", { src: navBackground, alt: "nav_background" })))) : null, !this.loadFromQuery || this.isDemo ? (h("div", { class: `hemfixarna_box hemfixarna_box--${this.widgetStyle}` }, [WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) ? h("img", { src: monteringLogo, alt: "montering logo", width: 32, height: 32 }) : null, h("div", null, h("div", null, h("p", { onClick: () => this.openModal(), class: `pointer ${[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) && state.selectedProduct ? 'underline' : ''}` }, ((_c = this.product) === null || _c === void 0 ? void 0 : _c.post_title) || ((_d = this.proppedProduct) === null || _d === void 0 ? void 0 : _d.post_title) || (h("span", null, "Montering", h("wbr", null), "/Installation ", (_f = (_e = state.selectedCustomerCategory) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : 'på plats', " - ", h("strong", { class: "underline" }, "se priser h\u00E4r"))), (this.product && ((_g = this.slug) === null || _g === void 0 ? void 0 : _g.includes('product'))) || (this.proppedProduct && !((_h = this.product) === null || _h === void 0 ? void 0 : _h.invoice) && !((_j = this.proppedProduct) === null || _j === void 0 ? void 0 : _j.invoice)) ? (h("span", null, ' från', " ", h("strong", null, getProductPriceWithRotAndRut(this.proppedProduct || this.product), "kr"))) : null, ((_k = this.product) === null || _k === void 0 ? void 0 : _k.invoice) || ((_l = this.proppedProduct) === null || _l === void 0 ? void 0 : _l.invoice) ? (h("span", null, ' - ', h("strong", { class: "underling" }, "se priser h\u00E4r"))) : null)), this.widgetStyle === WidgetStyle.standard ? h("img", { src: logo, width: 104 }) : null, this.widgetStyle === WidgetStyle.alternative ? (h("span", { class: "p-s" }, "Utf\u00F6rs av ", h("strong", null, "Hemfixarna"))) : null), [WidgetStyle.standard, WidgetStyle.alternative].includes(this.widgetStyle) ? (h("button", { onClick: () => this.openModal(), class: "hemfixarna_btn", style: {
217
+ color: ((_m = this.buttonColor) === null || _m === void 0 ? void 0 : _m.startsWith('#')) || !((_o = this.buttonColor) === null || _o === void 0 ? void 0 : _o.length) ? this.buttonColor : `#${this.buttonColor}`,
218
+ backgroundColor: ((_p = this.buttonBg) === null || _p === void 0 ? void 0 : _p.startsWith('#')) || !((_q = this.buttonBg) === null || _q === void 0 ? void 0 : _q.length) ? this.buttonBg : `#${this.buttonBg}`,
219
219
  } }, "Best\u00E4ll h\u00E4r", this.getCartLength() > 0 && h("span", null, this.getCartLength()))) : null, WidgetStyle.alternative_2 === this.widgetStyle ? (h("div", { class: "hemfixarna_altbtn" }, h("strong", { class: "p-s" }, "Utf\u00F6rs av"), h("img", { src: logo, alt: "hemfixarna logo", width: 98 }))) : null)) : null, this.modal && (h("div", null, h("div", { class: `hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}` }, state.modal && (h("div", { class: "hemfixarna_infomodal" }, state.modal.title && h("h2", null, state.modal.title), state.modal.text.map((t) => (h("p", { innerHTML: t }))), h("div", null, h("button", { onClick: () => (state.modal = null) }, "St\u00E4ng")))), (this.tree || state.customer) && (h("hemfixarna-breadcrumbs", { isDemo: this.isDemo, loadFromQuery: this.loadFromQuery, closeModal: () => this.closeModal(), tree: this.tree })), !state.customer || this.slugIsOldFormat(this.slug) ? (h("div", { class: `hemfixarna_content hemfixarna_content--${state.step}` }, state.step === 1 && this.tree && h("hemfixarna-start", { tree: this.tree }), state.step === 2 && state.selectedCategory && h("hemfixarna-category", null), state.step === 3 && state.selectedService && h("hemfixarna-service", null), state.step === 4 && state.selectedProduct && h("hemfixarna-product", null), state.step === 5 && h("hemfixarna-cart", { tree: this.tree }), state.step === 6 && h("hemfixarna-order", { tree: this.tree }))) : (h("div", { class: `hemfixarna_content hemfixarna_content--${state.step}` }, state.step < 4 && h("hemfixarna-start", null), state.step === 4 && state.selectedProduct && h("hemfixarna-product", null), state.step === 5 && h("hemfixarna-cart", { tree: this.tree }), state.step === 6 && h("hemfixarna-order", { tree: this.tree })))), !this.isDemo ? h("div", { class: `hemfixarna_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}` }) : null))));
220
220
  }
221
221
  static get is() { return "hemfixarna-component"; }
@@ -1 +1 @@
1
- {"version":3,"file":"hemfixarna-component.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-component/hemfixarna-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAChG,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,EAAqD,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I,CAAC,SAAS,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,EAAE,GAAQ,CAAC,CAAC,CAAC,IAAI,CACjH,CACP,CACG,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Listen, Prop, State, Watch, getAssetPath, h } from '@stencil/core';\nimport state from '../../store';\nimport { Business, Category, Product, Service, TopCategory, WidgetStyle } from '../../types';\nimport { getCustomer, getOptions, getRot, getRut, getTaxonomy } from '../../utils/api';\nimport { getProductPriceWithRotAndRut } from '../../utils/calc';\nimport { scrollToTop } from '../../utils/scroll';\n\n@Component({\n tag: 'hemfixarna-component',\n styleUrl: 'hemfixarna.scss',\n shadow: true,\n assetsDirs: ['assets'],\n})\nexport class HemfixarnaComponent {\n @State() modal: boolean = false;\n @State() showModal: boolean = false;\n @State() tree: Category | null = null;\n @State() product: Product | null = null;\n @State() proppedProduct: Product | null = null;\n @Prop() slug?: string;\n @Prop() id?: string;\n @Prop() business: Business;\n @Prop() topCategory?: TopCategory;\n @Prop() forceOldTree?: boolean = false;\n @Prop() loadFromQuery?: boolean = false;\n @Prop() isDemo?: boolean = false;\n @Prop() widgetStyle: WidgetStyle;\n @Prop() nav?: {\n url: string;\n logo: string;\n background?: string;\n } = undefined;\n @Prop() buttonColor?: string;\n @Prop() buttonBg?: string;\n\n @Element() private el: HTMLElement;\n\n loadCategoryOrProduct(id: string) {\n this.proppedProduct = null;\n if (id.startsWith('c-')) {\n const categories = [...state.customer.categories, ...state.customer.categories.map(c => c.sub_categories ?? [])].flat();\n const category = categories.find(c => c && c.id === id.replace('c-', ''));\n if (category) {\n state.selectedCustomerCategory = category;\n state.step = 2;\n }\n } else {\n const products = state.customer.categories\n .map(c => (c.show_products ? c.products : c.sub_categories ? c.sub_categories.map(c => c.products) : []))\n .flat()\n .flat();\n const product = products.find(p => p && p.fields.ID === parseInt(id));\n if (product) {\n state.selectedProduct = product.fields;\n state.step = 4;\n this.proppedProduct = product.fields;\n }\n }\n }\n\n @Watch('slug')\n async watchSlugChange(newValue: string) {\n if (this.slugIsOldFormat(newValue)) {\n this.fetchNewTaxonomy(newValue);\n } else if (state.customer && newValue) {\n this.loadCategoryOrProduct(newValue);\n }\n }\n\n @Watch('id')\n async watchIdChange(id: string) {\n if (id && state.customer) {\n this.loadCategoryOrProduct(id);\n }\n }\n\n async fetchNewTaxonomy(slug: string) {\n state.selectedCategory = null;\n state.selectedProduct = null;\n state.selectedService = null;\n\n const res = await getTaxonomy(slug);\n if (res?.code === 'not_found' || res?.code === 'rest_no_route') {\n console.log('taxonomy not found');\n } else if (res) {\n this.setTaxonomy(res);\n if ((res as Product)?.post_type === 'ikea_product') {\n this.product = res as Product;\n }\n }\n }\n\n slugIsOldFormat = (slug?: string) => {\n if (!slug) return false;\n return ['product', 'service', 'category'].some(str => slug.includes(str));\n };\n\n async componentWillLoad() {\n state.business = this.business;\n const cart = window.sessionStorage.getItem(`hemfixarna-${this.business}-cart`);\n if (cart) {\n state.cart = JSON.parse(cart);\n }\n const user = window.sessionStorage.getItem(`hemfixarna-${this.business}-user`);\n if (user) {\n state.user = JSON.parse(user);\n }\n const creditSafeUser = window.sessionStorage.getItem(`hemfixarna-${this.business}-creditSafeUser`);\n if (creditSafeUser) {\n state.creditSafeUser = JSON.parse(creditSafeUser);\n }\n\n const [tree, res, options, rut, rot] = await Promise.all([\n this.topCategory ? getTaxonomy(this.topCategory) : null,\n this.slug ? getTaxonomy(this.slug) : Promise.resolve(null),\n getOptions(),\n getRut(),\n getRot(),\n ]);\n\n if ((!this.slug || !this.slugIsOldFormat(this.slug)) && !this.forceOldTree) {\n try {\n const customer = await getCustomer(this.business);\n if (customer?.code === 'not_found') {\n console.warn('customer not found');\n } else if (customer) {\n state.customer = customer;\n if (this.id) {\n this.loadCategoryOrProduct(this.id);\n } else if (this.slug && !this.slugIsOldFormat(this.slug)) {\n this.loadCategoryOrProduct(this.slug);\n }\n }\n } catch (error) {\n console.warn('customer not found');\n }\n }\n\n if (tree?.code === 'not_found') {\n // console.warn('tree not found');\n } else if (tree) {\n this.tree = tree;\n }\n\n if (res?.code === 'not_found') {\n console.log('taxonomy not found');\n } else if (res) {\n this.setTaxonomy(res);\n if ((res as Product)?.post_type === 'ikea_product') {\n this.product = res as Product;\n }\n }\n\n if (this.loadFromQuery) {\n const params = new URL(document.location.toString()).searchParams;\n this.id = params.get('id');\n if (!this.isDemo) {\n this.openModal();\n }\n }\n\n state.rotOptions = rot;\n state.rutOptions = rut;\n state.options = options;\n }\n\n triggerScrollTotop = () => {\n const el = this.el.shadowRoot.querySelector('.hemfixarna_content');\n scrollToTop(el);\n };\n\n setTaxonomy(taxonomy: Category | Service | Product) {\n if (taxonomy) {\n if ((taxonomy as Category)?.taxonomy === 'service_cat') {\n state.selectedCategory = taxonomy as Category;\n state.step = 2;\n } else if ((taxonomy as Service)?.post_type === 'service') {\n state.selectedService = taxonomy as Service;\n state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === (taxonomy as Service).ID));\n state.step = 3;\n } else if ((taxonomy as Product)?.post_type === 'ikea_product') {\n state.selectedProduct = taxonomy as Product;\n state.selectedService = this.tree.sub_cats\n .map(c => c.services)\n .flat()\n .find(s => s.products.find(p => p.ID === state.selectedProduct.ID));\n state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === state.selectedService.ID));\n state.step = 4;\n }\n this.triggerScrollTotop();\n }\n }\n\n // Open close modal && click outside event\n openModal() {\n this.modal = true;\n setTimeout(() => {\n this.showModal = true;\n }, 50);\n }\n closeModal() {\n this.showModal = false;\n setTimeout(() => {\n this.modal = false;\n }, 200);\n }\n @Listen('click')\n handleClick(e: Event) {\n if (this.loadFromQuery && !this.isDemo) return;\n const el = this.el.shadowRoot.querySelector('.hemfixarna_modal');\n if (el) {\n const isClickInside = el.contains(e.composedPath()[0] as HTMLInputElement);\n if (!isClickInside) {\n this.closeModal();\n }\n }\n const infomodal = this.el.shadowRoot.querySelector('.hemfixarna_infomodal');\n if (infomodal) {\n const isClickInside = infomodal.contains(e.composedPath()[0] as HTMLInputElement);\n if (!isClickInside) {\n state.modal = null;\n }\n }\n }\n\n getCartLength() {\n return state.cart.reduce((acc, curr) => acc + curr.amount, 0);\n }\n\n render() {\n const logo = getAssetPath(`./assets/hemfixarna.svg`);\n const monteringLogo = getAssetPath(`./assets/montering.svg`);\n const navBackground = this.nav?.background ? getAssetPath(this.nav.background) : '';\n const navLogo = this.nav?.logo ? getAssetPath(this.nav.logo) : '';\n\n return (\n <div class={`hemfixarna ${this.loadFromQuery ? 'hemfixarna_standalone' : ''}`}>\n {this.loadFromQuery && !this.isDemo && this.nav ? (\n <nav class=\"hemfixarna_nav\">\n <div>\n <div class=\"hemfixarna_nav--logos\">\n <a href={this.nav.url} target=\"_blank\">\n <img src={navLogo} alt={`${this.business} logo`} />\n </a>\n <a href=\"https://hemfixarna.se/\" target=\"_blank\">\n <p>I samarbete med:</p>\n <img src={logo} alt=\"hemfixarna_logo\" width={104} />\n </a>\n </div>\n\n <div class=\"hemfixarna_nav--links\">\n <a href={this.nav.url} target=\"_blank\">\n Till {this.business}\n </a>\n <a href=\"https://www.hemfixarna.se/\" target=\"_blank\">\n Till Hemfixarna\n </a>\n </div>\n <img src={navBackground} alt=\"nav_background\" />\n </div>\n </nav>\n ) : null}\n {!this.loadFromQuery || this.isDemo ? (\n <div class={`hemfixarna_box hemfixarna_box--${this.widgetStyle}`}>\n {[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) ? <img src={monteringLogo} alt=\"montering logo\" width={32} height={32} /> : null}\n <div>\n <div>\n <p\n onClick={() => this.openModal()}\n class={`pointer ${[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) && state.selectedProduct ? 'underline' : ''}`}\n >\n {this.product?.post_title || this.proppedProduct?.post_title || (\n <span>\n Montering\n <wbr />\n /Installation {state.selectedCustomerCategory?.name ?? 'på plats'} - <strong class=\"underline\">se priser här</strong>\n </span>\n )}\n {(this.product && this.slug?.includes('product')) || this.proppedProduct ? (\n <span>\n {' från'} <strong>{getProductPriceWithRotAndRut(this.proppedProduct || this.product)}kr</strong>\n </span>\n ) : null}\n </p>\n </div>\n {this.widgetStyle === WidgetStyle.standard ? <img src={logo} width={104} /> : null}\n {this.widgetStyle === WidgetStyle.alternative ? (\n <span class=\"p-s\">\n Utförs av <strong>Hemfixarna</strong>\n </span>\n ) : null}\n </div>\n {[WidgetStyle.standard, WidgetStyle.alternative].includes(this.widgetStyle) ? (\n <button\n onClick={() => this.openModal()}\n class=\"hemfixarna_btn\"\n style={{\n color: this.buttonColor?.startsWith('#') || !this.buttonColor?.length ? this.buttonColor : `#${this.buttonColor}`,\n backgroundColor: this.buttonBg?.startsWith('#') || !this.buttonBg?.length ? this.buttonBg : `#${this.buttonBg}`,\n }}\n >\n Beställ här\n {this.getCartLength() > 0 && <span>{this.getCartLength()}</span>}\n </button>\n ) : null}\n {WidgetStyle.alternative_2 === this.widgetStyle ? (\n <div class=\"hemfixarna_altbtn\">\n <strong class=\"p-s\">Utförs av</strong>\n <img src={logo} alt=\"hemfixarna logo\" width={98} />\n </div>\n ) : null}\n </div>\n ) : null}\n {this.modal && (\n <div>\n <div class={`hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}`}>\n {state.modal && (\n <div class=\"hemfixarna_infomodal\">\n {state.modal.title && <h2>{state.modal.title}</h2>}\n {state.modal.text.map((t: string) => (\n <p innerHTML={t}></p>\n ))}\n <div>\n <button onClick={() => (state.modal = null)}>Stäng</button>\n </div>\n </div>\n )}\n {(this.tree || state.customer) && (\n <hemfixarna-breadcrumbs isDemo={this.isDemo} loadFromQuery={this.loadFromQuery} closeModal={() => this.closeModal()} tree={this.tree} />\n )}\n {!state.customer || this.slugIsOldFormat(this.slug) ? (\n <div class={`hemfixarna_content hemfixarna_content--${state.step}`}>\n {/* // IF AT TOP LEVEL (step 1) */}\n {state.step === 1 && this.tree && <hemfixarna-start tree={this.tree} />}\n {/* // IF SELECTED CATEGORY (step 2) */}\n {state.step === 2 && state.selectedCategory && <hemfixarna-category />}\n {/* // IF SELECTED SERVICE (step 3) */}\n {state.step === 3 && state.selectedService && <hemfixarna-service />}\n {/* // IF SELECTED PRODUCT (step 4) */}\n {state.step === 4 && state.selectedProduct && <hemfixarna-product />}\n {/* // IF CHECKOUT (step 5) */}\n {state.step === 5 && <hemfixarna-cart tree={this.tree} />}\n {/* // IF ORDER CONFIRM (step 6) */}\n {state.step === 6 && <hemfixarna-order tree={this.tree} />}\n </div>\n ) : (\n <div class={`hemfixarna_content hemfixarna_content--${state.step}`}>\n {state.step < 4 && <hemfixarna-start />}\n {/* // IF SELECTED PRODUCT (step 4) */}\n {state.step === 4 && state.selectedProduct && <hemfixarna-product />}\n {/* // IF CHECKOUT (step 5) */}\n {state.step === 5 && <hemfixarna-cart tree={this.tree} />}\n {/* // IF ORDER CONFIRM (step 6) */}\n {state.step === 6 && <hemfixarna-order tree={this.tree} />}\n </div>\n )}\n </div>\n {!this.isDemo ? <div class={`hemfixarna_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}`}></div> : null}\n </div>\n )}\n </div>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"hemfixarna-component.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-component/hemfixarna-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,e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AC,IAAI,EAAE;YAC/D,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,2BAAoB;YAEtC,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,eAAe,IAAI,6BAAsB;YAEnE,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,uBAAiB,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI;YAExD,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,wBAAkB,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI,CACtD,CACP,CACG;QACL,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,WAAK,KAAK,EAAE,uBAAuB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,EAAE,GAAQ,CAAC,CAAC,CAAC,IAAI,CACjH,CACP,CACG,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, Listen, Prop, State, Watch, getAssetPath, h } from '@stencil/core';\nimport state from '../../store';\nimport { Business, Category, Product, Service, TopCategory, WidgetStyle } from '../../types';\nimport { getCustomer, getOptions, getRot, getRut, getTaxonomy } from '../../utils/api';\nimport { getProductPriceWithRotAndRut } from '../../utils/calc';\nimport { scrollToTop } from '../../utils/scroll';\n\n@Component({\n tag: 'hemfixarna-component',\n styleUrl: 'hemfixarna.scss',\n shadow: true,\n assetsDirs: ['assets'],\n})\nexport class HemfixarnaComponent {\n @State() modal: boolean = false;\n @State() showModal: boolean = false;\n @State() tree: Category | null = null;\n @State() product: Product | null = null;\n @State() proppedProduct: Product | null = null;\n @Prop() slug?: string;\n @Prop() id?: string;\n @Prop() business: Business;\n @Prop() topCategory?: TopCategory;\n @Prop() forceOldTree?: boolean = false;\n @Prop() loadFromQuery?: boolean = false;\n @Prop() isDemo?: boolean = false;\n @Prop() widgetStyle: WidgetStyle;\n @Prop() nav?: {\n url: string;\n logo: string;\n background?: string;\n } = undefined;\n @Prop() buttonColor?: string;\n @Prop() buttonBg?: string;\n\n @Element() private el: HTMLElement;\n\n loadCategoryOrProduct(id: string) {\n this.proppedProduct = null;\n if (id.startsWith('c-')) {\n const categories = [...state.customer.categories, ...state.customer.categories.map(c => c.sub_categories ?? [])].flat();\n const category = categories.find(c => c && c.id === id.replace('c-', ''));\n if (category) {\n state.selectedCustomerCategory = category;\n state.step = 2;\n }\n } else {\n const products = state.customer.categories\n .map(c => (c.show_products ? c.products : c.sub_categories ? c.sub_categories.map(c => c.products) : []))\n .flat()\n .flat();\n const product = products.find(p => p && p.fields.ID === parseInt(id));\n if (product) {\n state.selectedProduct = product.fields;\n state.step = 4;\n this.proppedProduct = product.fields;\n }\n }\n }\n\n @Watch('slug')\n async watchSlugChange(newValue: string) {\n if (this.slugIsOldFormat(newValue)) {\n this.fetchNewTaxonomy(newValue);\n } else if (state.customer && newValue) {\n this.loadCategoryOrProduct(newValue);\n }\n }\n\n @Watch('id')\n async watchIdChange(id: string) {\n if (id && state.customer) {\n this.loadCategoryOrProduct(id);\n }\n }\n\n async fetchNewTaxonomy(slug: string) {\n state.selectedCategory = null;\n state.selectedProduct = null;\n state.selectedService = null;\n\n const res = await getTaxonomy(slug);\n if (res?.code === 'not_found' || res?.code === 'rest_no_route') {\n console.log('taxonomy not found');\n } else if (res) {\n this.setTaxonomy(res);\n if ((res as Product)?.post_type === 'ikea_product') {\n this.product = res as Product;\n }\n }\n }\n\n slugIsOldFormat = (slug?: string) => {\n if (!slug) return false;\n return ['product', 'service', 'category'].some(str => slug.includes(str));\n };\n\n async componentWillLoad() {\n state.business = this.business;\n const cart = window.sessionStorage.getItem(`hemfixarna-${this.business}-cart`);\n if (cart) {\n state.cart = JSON.parse(cart);\n }\n const user = window.sessionStorage.getItem(`hemfixarna-${this.business}-user`);\n if (user) {\n state.user = JSON.parse(user);\n }\n const creditSafeUser = window.sessionStorage.getItem(`hemfixarna-${this.business}-creditSafeUser`);\n if (creditSafeUser) {\n state.creditSafeUser = JSON.parse(creditSafeUser);\n }\n\n const [tree, res, options, rut, rot] = await Promise.all([\n this.topCategory ? getTaxonomy(this.topCategory) : null,\n this.slug ? getTaxonomy(this.slug) : Promise.resolve(null),\n getOptions(),\n getRut(),\n getRot(),\n ]);\n\n if ((!this.slug || !this.slugIsOldFormat(this.slug)) && !this.forceOldTree) {\n try {\n const customer = await getCustomer(this.business);\n if (customer?.code === 'not_found') {\n console.warn('customer not found');\n } else if (customer) {\n state.customer = customer;\n if (this.id) {\n this.loadCategoryOrProduct(this.id);\n } else if (this.slug && !this.slugIsOldFormat(this.slug)) {\n this.loadCategoryOrProduct(this.slug);\n }\n }\n } catch (error) {\n console.warn('customer not found');\n }\n }\n\n if (tree?.code === 'not_found') {\n // console.warn('tree not found');\n } else if (tree) {\n this.tree = tree;\n }\n\n if (res?.code === 'not_found') {\n console.log('taxonomy not found');\n } else if (res) {\n this.setTaxonomy(res);\n if ((res as Product)?.post_type === 'ikea_product') {\n this.product = res as Product;\n }\n }\n\n if (this.loadFromQuery) {\n const params = new URL(document.location.toString()).searchParams;\n this.id = params.get('id');\n if (!this.isDemo) {\n this.openModal();\n }\n }\n\n state.rotOptions = rot;\n state.rutOptions = rut;\n state.options = options;\n }\n\n triggerScrollTotop = () => {\n const el = this.el.shadowRoot.querySelector('.hemfixarna_content');\n scrollToTop(el);\n };\n\n setTaxonomy(taxonomy: Category | Service | Product) {\n if (taxonomy) {\n if ((taxonomy as Category)?.taxonomy === 'service_cat') {\n state.selectedCategory = taxonomy as Category;\n state.step = 2;\n } else if ((taxonomy as Service)?.post_type === 'service') {\n state.selectedService = taxonomy as Service;\n state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === (taxonomy as Service).ID));\n state.step = 3;\n } else if ((taxonomy as Product)?.post_type === 'ikea_product') {\n state.selectedProduct = taxonomy as Product;\n state.selectedService = this.tree.sub_cats\n .map(c => c.services)\n .flat()\n .find(s => s.products.find(p => p.ID === state.selectedProduct.ID));\n state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === state.selectedService.ID));\n state.step = 4;\n }\n this.triggerScrollTotop();\n }\n }\n\n // Open close modal && click outside event\n openModal() {\n this.modal = true;\n setTimeout(() => {\n this.showModal = true;\n }, 50);\n }\n closeModal() {\n this.showModal = false;\n setTimeout(() => {\n this.modal = false;\n }, 200);\n }\n @Listen('click')\n handleClick(e: Event) {\n if (this.loadFromQuery && !this.isDemo) return;\n const el = this.el.shadowRoot.querySelector('.hemfixarna_modal');\n if (el) {\n const isClickInside = el.contains(e.composedPath()[0] as HTMLInputElement);\n if (!isClickInside) {\n this.closeModal();\n }\n }\n const infomodal = this.el.shadowRoot.querySelector('.hemfixarna_infomodal');\n if (infomodal) {\n const isClickInside = infomodal.contains(e.composedPath()[0] as HTMLInputElement);\n if (!isClickInside) {\n state.modal = null;\n }\n }\n }\n\n getCartLength() {\n return state.cart.reduce((acc, curr) => acc + curr.amount, 0);\n }\n\n render() {\n const logo = getAssetPath(`./assets/hemfixarna.svg`);\n const monteringLogo = getAssetPath(`./assets/montering.svg`);\n const navBackground = this.nav?.background ? getAssetPath(this.nav.background) : '';\n const navLogo = this.nav?.logo ? getAssetPath(this.nav.logo) : '';\n\n return (\n <div class={`hemfixarna ${this.loadFromQuery ? 'hemfixarna_standalone' : ''}`}>\n {this.loadFromQuery && !this.isDemo && this.nav ? (\n <nav class=\"hemfixarna_nav\">\n <div>\n <div class=\"hemfixarna_nav--logos\">\n <a href={this.nav.url} target=\"_blank\">\n <img src={navLogo} alt={`${this.business} logo`} />\n </a>\n <a href=\"https://hemfixarna.se/\" target=\"_blank\">\n <p>I samarbete med:</p>\n <img src={logo} alt=\"hemfixarna_logo\" width={104} />\n </a>\n </div>\n\n <div class=\"hemfixarna_nav--links\">\n <a href={this.nav.url} target=\"_blank\">\n Till {this.business}\n </a>\n <a href=\"https://www.hemfixarna.se/\" target=\"_blank\">\n Till Hemfixarna\n </a>\n </div>\n <img src={navBackground} alt=\"nav_background\" />\n </div>\n </nav>\n ) : null}\n {!this.loadFromQuery || this.isDemo ? (\n <div class={`hemfixarna_box hemfixarna_box--${this.widgetStyle}`}>\n {[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) ? <img src={monteringLogo} alt=\"montering logo\" width={32} height={32} /> : null}\n <div>\n <div>\n <p\n onClick={() => this.openModal()}\n class={`pointer ${[WidgetStyle.alternative_2, WidgetStyle.alternative_3].includes(this.widgetStyle) && state.selectedProduct ? 'underline' : ''}`}\n >\n {this.product?.post_title || this.proppedProduct?.post_title || (\n <span>\n Montering\n <wbr />\n /Installation {state.selectedCustomerCategory?.name ?? 'på plats'} - <strong class=\"underline\">se priser här</strong>\n </span>\n )}\n {(this.product && this.slug?.includes('product')) || (this.proppedProduct && !this.product?.invoice && !this.proppedProduct?.invoice) ? (\n <span>\n {' från'} <strong>{getProductPriceWithRotAndRut(this.proppedProduct || this.product)}kr</strong>\n </span>\n ) : null}\n {this.product?.invoice || this.proppedProduct?.invoice ? (\n <span>\n {' - '}\n <strong class=\"underling\">se priser här</strong>\n </span>\n ) : null}\n </p>\n </div>\n {this.widgetStyle === WidgetStyle.standard ? <img src={logo} width={104} /> : null}\n {this.widgetStyle === WidgetStyle.alternative ? (\n <span class=\"p-s\">\n Utförs av <strong>Hemfixarna</strong>\n </span>\n ) : null}\n </div>\n {[WidgetStyle.standard, WidgetStyle.alternative].includes(this.widgetStyle) ? (\n <button\n onClick={() => this.openModal()}\n class=\"hemfixarna_btn\"\n style={{\n color: this.buttonColor?.startsWith('#') || !this.buttonColor?.length ? this.buttonColor : `#${this.buttonColor}`,\n backgroundColor: this.buttonBg?.startsWith('#') || !this.buttonBg?.length ? this.buttonBg : `#${this.buttonBg}`,\n }}\n >\n Beställ här\n {this.getCartLength() > 0 && <span>{this.getCartLength()}</span>}\n </button>\n ) : null}\n {WidgetStyle.alternative_2 === this.widgetStyle ? (\n <div class=\"hemfixarna_altbtn\">\n <strong class=\"p-s\">Utförs av</strong>\n <img src={logo} alt=\"hemfixarna logo\" width={98} />\n </div>\n ) : null}\n </div>\n ) : null}\n {this.modal && (\n <div>\n <div class={`hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}`}>\n {state.modal && (\n <div class=\"hemfixarna_infomodal\">\n {state.modal.title && <h2>{state.modal.title}</h2>}\n {state.modal.text.map((t: string) => (\n <p innerHTML={t}></p>\n ))}\n <div>\n <button onClick={() => (state.modal = null)}>Stäng</button>\n </div>\n </div>\n )}\n {(this.tree || state.customer) && (\n <hemfixarna-breadcrumbs isDemo={this.isDemo} loadFromQuery={this.loadFromQuery} closeModal={() => this.closeModal()} tree={this.tree} />\n )}\n {!state.customer || this.slugIsOldFormat(this.slug) ? (\n <div class={`hemfixarna_content hemfixarna_content--${state.step}`}>\n {/* // IF AT TOP LEVEL (step 1) */}\n {state.step === 1 && this.tree && <hemfixarna-start tree={this.tree} />}\n {/* // IF SELECTED CATEGORY (step 2) */}\n {state.step === 2 && state.selectedCategory && <hemfixarna-category />}\n {/* // IF SELECTED SERVICE (step 3) */}\n {state.step === 3 && state.selectedService && <hemfixarna-service />}\n {/* // IF SELECTED PRODUCT (step 4) */}\n {state.step === 4 && state.selectedProduct && <hemfixarna-product />}\n {/* // IF CHECKOUT (step 5) */}\n {state.step === 5 && <hemfixarna-cart tree={this.tree} />}\n {/* // IF ORDER CONFIRM (step 6) */}\n {state.step === 6 && <hemfixarna-order tree={this.tree} />}\n </div>\n ) : (\n <div class={`hemfixarna_content hemfixarna_content--${state.step}`}>\n {state.step < 4 && <hemfixarna-start />}\n {/* // IF SELECTED PRODUCT (step 4) */}\n {state.step === 4 && state.selectedProduct && <hemfixarna-product />}\n {/* // IF CHECKOUT (step 5) */}\n {state.step === 5 && <hemfixarna-cart tree={this.tree} />}\n {/* // IF ORDER CONFIRM (step 6) */}\n {state.step === 6 && <hemfixarna-order tree={this.tree} />}\n </div>\n )}\n </div>\n {!this.isDemo ? <div class={`hemfixarna_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}`}></div> : null}\n </div>\n )}\n </div>\n );\n }\n}\n"]}
@@ -0,0 +1,76 @@
1
+ :host .invoice {
2
+ gap: 16px;
3
+ display: grid;
4
+ }
5
+ :host .invoice form > span {
6
+ text-align: center;
7
+ padding: 16px 0;
8
+ }
9
+ :host .invoice img {
10
+ right: unset;
11
+ left: unset;
12
+ position: initial;
13
+ transform: none;
14
+ }
15
+ :host .invoice label {
16
+ cursor: pointer;
17
+ font-size: 14px;
18
+ display: flex;
19
+ align-items: flex-start;
20
+ padding: 16px 0;
21
+ }
22
+ :host .invoice label input {
23
+ margin: 0 5px 0 0;
24
+ accent-color: #ea662c;
25
+ }
26
+ :host .invoice-preview {
27
+ display: flex;
28
+ gap: 4px;
29
+ }
30
+ :host .invoice-preview div {
31
+ position: relative;
32
+ }
33
+ :host .invoice-preview div button {
34
+ position: absolute;
35
+ top: 0;
36
+ right: 0;
37
+ padding: 0;
38
+ }
39
+ :host .invoice-preview div button img {
40
+ width: 24px;
41
+ height: 24px;
42
+ }
43
+ :host .invoice-preview div > img {
44
+ width: 100px;
45
+ height: 80px;
46
+ object-fit: cover;
47
+ }
48
+ :host .invoice input[type=email],
49
+ :host .invoice input[type=tel],
50
+ :host .invoice textarea {
51
+ padding: 16px;
52
+ border: 1px solid #fcd9c9;
53
+ font-size: 16px;
54
+ }
55
+ :host .invoice textarea {
56
+ resize: none;
57
+ height: 200px;
58
+ font-family: "Inter", sans-serif;
59
+ }
60
+ :host .invoice div:has(> input[type=file]) {
61
+ display: flex;
62
+ align-items: center;
63
+ justify-content: center;
64
+ cursor: pointer;
65
+ background: #fff;
66
+ border: 1px solid #fcd9c9;
67
+ padding: 32px 16px;
68
+ gap: 16px;
69
+ }
70
+ :host .invoice div:has(> input[type=file]) span {
71
+ color: #000;
72
+ font-size: 12px;
73
+ }
74
+ :host .invoice input[type=file] {
75
+ display: none;
76
+ }
@@ -0,0 +1,164 @@
1
+ import { getAssetPath, h } from '@stencil/core';
2
+ import state from '../../store';
3
+ const base = process.env.API_URL ? `${process.env.API_URL}/wp-json/headless` : 'https://hemfixarna.se/wp-json/headless';
4
+ export class HemfixarnaInvoice {
5
+ constructor() {
6
+ this.formError = null;
7
+ this.displayImages = [];
8
+ this.formImages = [];
9
+ this.formState = 'initial';
10
+ }
11
+ isValidEmail(email) {
12
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
13
+ return emailRegex.test(email);
14
+ }
15
+ componentDidRender() {
16
+ const form = this.el.querySelector('form');
17
+ if (form) {
18
+ form.addEventListener('input', () => {
19
+ this.formError = null;
20
+ });
21
+ }
22
+ }
23
+ disconnectedCallback() {
24
+ const form = this.el.querySelector('form');
25
+ if (form) {
26
+ form.removeEventListener('input', () => {
27
+ this.formError = null;
28
+ });
29
+ }
30
+ }
31
+ async submit(e) {
32
+ var _a;
33
+ e.preventDefault();
34
+ this.formState = 'loading';
35
+ this.formError = null;
36
+ const form = e.currentTarget.elements;
37
+ const values = {
38
+ description: form.descriptionInput.value.length ? form.descriptionInput.value : null,
39
+ email: form.emailInput.value.length ? form.emailInput.value : null,
40
+ tel: form.telInput.value.length ? form.telInput.value : null,
41
+ terms: (_a = form.termsInput) === null || _a === void 0 ? void 0 : _a.checked,
42
+ };
43
+ if (!values.description) {
44
+ this.formError = 'Vänligen fyll i formulärtexten';
45
+ this.formState = 'initial';
46
+ return;
47
+ }
48
+ if (!values.email || !this.isValidEmail(values.email)) {
49
+ this.formError = 'Vänligen ange en giltig e-postadress';
50
+ this.formState = 'initial';
51
+ return;
52
+ }
53
+ if (!values.tel) {
54
+ this.formError = 'Vänligen ange ditt telefonnummer';
55
+ this.formState = 'initial';
56
+ return;
57
+ }
58
+ if (state.selectedProduct.terms_show_checkbox && !values.terms) {
59
+ this.formError = 'Vänligen acceptera villkoren';
60
+ this.formState = 'initial';
61
+ return;
62
+ }
63
+ const formData = new FormData();
64
+ formData.append('text', values.description);
65
+ formData.append('email', values.email);
66
+ formData.append('tel', values.tel);
67
+ formData.append('customer', state.business);
68
+ this.formImages.forEach(file => {
69
+ formData.append('images[]', file);
70
+ });
71
+ formData.append('product', JSON.stringify({
72
+ title: state.selectedProduct.post_title,
73
+ amount: 1,
74
+ has_rut: state.selectedProduct.rut,
75
+ has_rot: state.selectedProduct.rot,
76
+ ID: state.selectedProduct.ID,
77
+ parts: [],
78
+ }));
79
+ try {
80
+ const res = await fetch(`${base}/saveinvoiceproduct`, {
81
+ method: 'POST',
82
+ body: formData,
83
+ });
84
+ const { response } = await res.json();
85
+ if (response.code === 200) {
86
+ state.checkoutInvoice = true;
87
+ state.step = 6;
88
+ }
89
+ else {
90
+ this.formError = 'Vi kan inte ta emot din beställning just nu';
91
+ this.formState = 'initial';
92
+ }
93
+ }
94
+ catch (error) {
95
+ this.formError = 'Vi kan inte ta emot din beställning just nu';
96
+ this.formState = 'initial';
97
+ }
98
+ }
99
+ handleImageDrop(e) {
100
+ e.preventDefault();
101
+ const files = e.dataTransfer.files;
102
+ for (let i = 0; i < files.length; i++) {
103
+ const file = files[i];
104
+ if (file.type.startsWith('image/')) {
105
+ const reader = new FileReader();
106
+ reader.onload = () => {
107
+ this.displayImages = [...this.displayImages, reader.result];
108
+ this.formImages = [...this.formImages, file];
109
+ };
110
+ reader.readAsDataURL(file);
111
+ }
112
+ }
113
+ }
114
+ handleFileInputChange(e) {
115
+ e.preventDefault();
116
+ const files = e.target.files;
117
+ for (let i = 0; i < files.length; i++) {
118
+ const file = files[i];
119
+ if (file.type.startsWith('image/')) {
120
+ const reader = new FileReader();
121
+ reader.onload = () => {
122
+ this.displayImages = [...this.displayImages, reader.result];
123
+ this.formImages = [...this.formImages, file];
124
+ };
125
+ reader.readAsDataURL(file);
126
+ }
127
+ }
128
+ }
129
+ handleImageClick() {
130
+ this.el.querySelector('.hemfixarna-file-upload').click();
131
+ }
132
+ preventDragOver(e) {
133
+ e.preventDefault();
134
+ }
135
+ removeImage(index) {
136
+ this.displayImages = this.displayImages.filter((_, i) => i !== index);
137
+ this.formImages = this.formImages.filter((_, i) => i !== index);
138
+ }
139
+ render() {
140
+ const upload = getAssetPath(`./assets/drag-drop.svg`);
141
+ return (h("div", { class: "invoice" }, h("p", null, state.selectedProduct.invoice_description), h("form", { onSubmit: e => this.submit(e) }, h("textarea", { name: "descriptionInput", placeholder: "Beskriv ditt \u00E4rende" }), h("div", { role: "button", "aria-label": "upload image", onDragOver: e => this.preventDragOver(e), onDrop: e => this.handleImageDrop(e), onClick: () => this.handleImageClick() }, h("img", { src: upload, alt: "hemfixarna_logo", width: 24 }), h("div", null, h("p", null, "Bifoga ev bilder"), h("span", null, "(dra bilder hit)")), h("input", { onChange: e => this.handleFileInputChange(e), class: "hemfixarna-file-upload", accept: "image/*", type: "file", multiple: true, name: "fileInput" })), h("div", { class: "invoice-preview" }, this.displayImages.map((img, i) => (h("div", { key: i }, h("img", { src: img, alt: "uploaded image" }), h("button", { onClick: () => this.removeImage(i) }, h("img", { src: getAssetPath(`./assets/close.svg`), alt: "close" })))))), h("input", { placeholder: "E-post", type: "email", name: "emailInput" }), h("input", { placeholder: "Telefonnummer", type: "tel", name: "telInput" }), state.selectedProduct.terms_show_checkbox ? (h("label", null, h("input", { type: "checkbox", name: "termsInput" }), state.selectedProduct.terms)) : null, this.formError ? h("span", null, this.formError) : null, h("input", { type: "submit", value: this.formState === 'loading' ? 'Skickar' : 'Kontakta mig' }))));
142
+ }
143
+ static get is() { return "hemfixarna-invoice"; }
144
+ static get originalStyleUrls() {
145
+ return {
146
+ "$": ["hemfixarna-invoice.scss"]
147
+ };
148
+ }
149
+ static get styleUrls() {
150
+ return {
151
+ "$": ["hemfixarna-invoice.css"]
152
+ };
153
+ }
154
+ static get states() {
155
+ return {
156
+ "formError": {},
157
+ "displayImages": {},
158
+ "formImages": {},
159
+ "formState": {}
160
+ };
161
+ }
162
+ static get elementRef() { return "el"; }
163
+ }
164
+ //# sourceMappingURL=hemfixarna-invoice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hemfixarna-invoice.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-invoice/hemfixarna-invoice.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,CAAC,wCAAwC,CAAC;AAsBxH,MAAM,OAAO,iBAAiB;;qBACQ,IAAI;yBAEc,EAAE;sBACrB,EAAE;qBACO,SAAS;;EAErD,YAAY,CAAC,KAAa;IACxB,MAAM,UAAU,GAAG,4BAA4B,CAAC;IAChD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;EAChC,CAAC;EAED,kBAAkB;IAChB,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAoB,CAAC;IAC9D,IAAI,IAAI,EAAE;MACR,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;QAClC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;MACxB,CAAC,CAAC,CAAC;KACJ;EACH,CAAC;EAED,oBAAoB;IAClB,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAoB,CAAC;IAC9D,IAAI,IAAI,EAAE;MACR,IAAI,CAAC,mBAAmB,CAA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AAI,EAAC,OAAO,EAAC,IAAI,EAAC,YAAY,GAAG;QAC7D,aAAO,WAAW,EAAC,eAAe,EAAC,IAAI,EAAC,KAAK,EAAC,IAAI,EAAC,UAAU,GAAG;QAC/D,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAC3C;UACE,aAAO,IAAI,EAAC,UAAU,EAAC,IAAI,EAAC,YAAY,GAAG;UAC1C,KAAK,CAAC,eAAe,CAAC,KAAK,CACtB,CACT,CAAC,CAAC,CAAC,IAAI;QACP,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,gBAAO,IAAI,CAAC,SAAS,CAAQ,CAAC,CAAC,CAAC,IAAI;QACtD,aAAO,IAAI,EAAC,QAAQ,EAAC,KAAK,EAAE,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,GAAI,CACpF,CACH,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Element, State, getAssetPath, h } from '@stencil/core';\nimport state from '../../store';\n\nconst base = process.env.API_URL ? `${process.env.API_URL}/wp-json/headless` : 'https://hemfixarna.se/wp-json/headless';\n\ninterface FormElements extends HTMLCollection {\n descriptionInput: {\n value: string;\n };\n emailInput: {\n value: string;\n };\n telInput: {\n value: string;\n };\n termsInput: {\n checked: boolean;\n };\n}\n\n@Component({\n tag: 'hemfixarna-invoice',\n styleUrl: 'hemfixarna-invoice.scss',\n shadow: false,\n})\nexport class HemfixarnaInvoice {\n @State() formError: string | null = null;\n @Element() private el: HTMLElement;\n @State() displayImages: Array<string | ArrayBuffer> = [];\n @State() formImages: Array<File> = [];\n @State() formState: 'initial' | 'loading' = 'initial';\n\n isValidEmail(email: string) {\n const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\n return emailRegex.test(email);\n }\n\n componentDidRender() {\n const form = this.el.querySelector('form') as HTMLFormElement;\n if (form) {\n form.addEventListener('input', () => {\n this.formError = null;\n });\n }\n }\n\n disconnectedCallback() {\n const form = this.el.querySelector('form') as HTMLFormElement;\n if (form) {\n form.removeEventListener('input', () => {\n this.formError = null;\n });\n }\n }\n\n async submit(e: Event) {\n e.preventDefault();\n this.formState = 'loading';\n this.formError = null;\n const form = (e.currentTarget as HTMLFormElement).elements as FormElements;\n const values = {\n description: form.descriptionInput.value.length ? form.descriptionInput.value : null,\n email: form.emailInput.value.length ? form.emailInput.value : null,\n tel: form.telInput.value.length ? form.telInput.value : null,\n terms: form.termsInput?.checked,\n };\n\n if (!values.description) {\n this.formError = 'Vänligen fyll i formulärtexten';\n this.formState = 'initial';\n return;\n }\n if (!values.email || !this.isValidEmail(values.email)) {\n this.formError = 'Vänligen ange en giltig e-postadress';\n this.formState = 'initial';\n return;\n }\n if (!values.tel) {\n this.formError = 'Vänligen ange ditt telefonnummer';\n this.formState = 'initial';\n return;\n }\n if (state.selectedProduct.terms_show_checkbox && !values.terms) {\n this.formError = 'Vänligen acceptera villkoren';\n this.formState = 'initial';\n return;\n }\n\n const formData = new FormData();\n formData.append('text', values.description);\n formData.append('email', values.email);\n formData.append('tel', values.tel);\n formData.append('customer', state.business);\n\n this.formImages.forEach(file => {\n formData.append('images[]', file);\n });\n\n formData.append(\n 'product',\n JSON.stringify({\n title: state.selectedProduct.post_title,\n amount: 1,\n has_rut: state.selectedProduct.rut,\n has_rot: state.selectedProduct.rot,\n ID: state.selectedProduct.ID,\n parts: [],\n }),\n );\n\n try {\n const res = await fetch(`${base}/saveinvoiceproduct`, {\n method: 'POST',\n body: formData,\n });\n const { response } = await res.json();\n if (response.code === 200) {\n state.checkoutInvoice = true;\n state.step = 6;\n } else {\n this.formError = 'Vi kan inte ta emot din beställning just nu';\n this.formState = 'initial';\n }\n } catch (error) {\n this.formError = 'Vi kan inte ta emot din beställning just nu';\n this.formState = 'initial';\n }\n }\n\n handleImageDrop(e: DragEvent) {\n e.preventDefault();\n const files = e.dataTransfer.files;\n for (let i = 0; i < files.length; i++) {\n const file = files[i];\n\n if (file.type.startsWith('image/')) {\n const reader = new FileReader();\n\n reader.onload = () => {\n this.displayImages = [...this.displayImages, reader.result];\n this.formImages = [...this.formImages, file];\n };\n\n reader.readAsDataURL(file);\n }\n }\n }\n\n handleFileInputChange(e: Event) {\n e.preventDefault();\n const files = (e.target as HTMLInputElement).files;\n\n for (let i = 0; i < files.length; i++) {\n const file = files[i];\n if (file.type.startsWith('image/')) {\n const reader = new FileReader();\n reader.onload = () => {\n this.displayImages = [...this.displayImages, reader.result];\n this.formImages = [...this.formImages, file];\n };\n\n reader.readAsDataURL(file);\n }\n }\n }\n\n handleImageClick() {\n (this.el.querySelector('.hemfixarna-file-upload') as HTMLInputElement).click();\n }\n\n preventDragOver(e: DragEvent) {\n e.preventDefault();\n }\n\n removeImage(index: number) {\n this.displayImages = this.displayImages.filter((_, i) => i !== index);\n this.formImages = this.formImages.filter((_, i) => i !== index);\n }\n\n render() {\n const upload = getAssetPath(`./assets/drag-drop.svg`);\n return (\n <div class=\"invoice\">\n <p>{state.selectedProduct.invoice_description}</p>\n <form onSubmit={e => this.submit(e)}>\n <textarea name=\"descriptionInput\" placeholder=\"Beskriv ditt ärende\" />\n <div role=\"button\" aria-label=\"upload image\" onDragOver={e => this.preventDragOver(e)} onDrop={e => this.handleImageDrop(e)} onClick={() => this.handleImageClick()}>\n <img src={upload} alt=\"hemfixarna_logo\" width={24} />\n <div>\n <p>Bifoga ev bilder</p>\n <span>(dra bilder hit)</span>\n </div>\n <input onChange={e => this.handleFileInputChange(e)} class=\"hemfixarna-file-upload\" accept=\"image/*\" type=\"file\" multiple name=\"fileInput\" />\n </div>\n <div class=\"invoice-preview\">\n {this.displayImages.map((img, i) => (\n <div key={i}>\n <img src={img as string} alt=\"uploaded image\" />\n <button onClick={() => this.removeImage(i)}>\n <img src={getAssetPath(`./assets/close.svg`)} alt=\"close\" />\n </button>\n </div>\n ))}\n </div>\n <input placeholder=\"E-post\" type=\"email\" name=\"emailInput\" />\n <input placeholder=\"Telefonnummer\" type=\"tel\" name=\"telInput\" />\n {state.selectedProduct.terms_show_checkbox ? (\n <label>\n <input type=\"checkbox\" name=\"termsInput\" />\n {state.selectedProduct.terms}\n </label>\n ) : null}\n {this.formError ? <span>{this.formError}</span> : null}\n <input type=\"submit\" value={this.formState === 'loading' ? 'Skickar' : 'Kontakta mig'} />\n </form>\n </div>\n );\n }\n}\n"]}
@@ -3,7 +3,7 @@ import state from '../../store';
3
3
  export class HemfixarnaOrder {
4
4
  constructor() {
5
5
  this.render = () => {
6
- return (h("div", { style: { background: `url(${state.options.thank_you_image})` }, class: "hemfixarna_order" }, h("div", null), h("div", null, h("h2", null, "Tack f\u00F6r din bokning"), h("hemfixarna-orderrows", { tree: this.tree, cart: false }), h("span", { onClick: () => this.resetShop() }, h("button", null, "G\u00F6r en ny bokning")), h("hemfixarna-info", { list: [
6
+ return (h("div", { style: { background: `url(${state.options.thank_you_image})` }, class: "hemfixarna_order" }, h("div", null), h("div", null, h("h2", null, state.checkoutInvoice ? 'Tack för din förfrågan' : 'Tack för din bokning'), state.checkoutInvoice ? h("p", null, "Vi \u00E5terkommer inom kort till dig p\u00E5 angivet telefonnummer eller epost") : null, state.checkoutInvoice ? h("div", null) : h("hemfixarna-orderrows", { tree: this.tree, cart: false }), h("span", { onClick: () => this.resetShop() }, h("button", null, "G\u00F6r en ny bokning")), h("hemfixarna-info", { list: [
7
7
  { trust_badge: 'Du kommer bli kontaktad av en Hemfixare för bokning av tid.' },
8
8
  { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },
9
9
  ] }))));
@@ -1 +1 @@
1
- {"version":3,"file":"hemfixarna-order.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-order/hemfixarna-order.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,MAAM,aAAa,CAAC;AAOhC,MAAM,OAAO,eAAe;;IAgB1B,WAAM,GAAG,GAAG,EAAE;MACZ,OAAO,CACL,WAAK,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,EAAE,EAAE,KAAK,EAAC,kBAAkB;QAC3F,cAAW;QACX;UACE,0CAA6B;UAC7B,4BAAsB,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,GAAyB;UAC3E,YAAM,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;YACnC,2CAAkC,CAC7B;UACP,uBACE,IAAI,EAAE;cACJ,EAAE,WAAW,EAAE,6DAA6D,EAAE;cAC9E,EAAE,WAAW,EAAE,iEAAiE,EAAE;aACnF,GACD,CACE,CACF,CACP,CAAC;IACJ,CAAC,CAAC;;;EAhCF,SAAS;IACP,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;EACzB,CAAC;EAED,oBAAoB;IAClB,IAAI,CAAC,SAAS,EAAE,CAAC;EACnB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CAsBF","sourcesContent":["import { Component, Prop, h } from '@stencil/core';\nimport state from '../../store';\nimport { Category } from '../../types';\n\n@Component({\n tag: 'hemfixarna-order',\n shadow: false,\n})\nexport class HemfixarnaOrder {\n @Prop() tree: Category;\n\n resetShop() {\n state.step = 1;\n state.cart = [];\n state.selectedCategory = null;\n state.selectedService = null;\n state.selectedProduct = null;\n state.checkoutStep = 1;\n }\n\n disconnectedCallback() {\n this.resetShop();\n }\n\n render = () => {\n return (\n <div style={{ background: `url(${state.options.thank_you_image})` }} class=\"hemfixarna_order\">\n <div></div>\n <div>\n <h2>Tack för din bokning</h2>\n <hemfixarna-orderrows tree={this.tree} cart={false}></hemfixarna-orderrows>\n <span onClick={() => this.resetShop()}>\n <button>Gör en ny bokning</button>\n </span>\n <hemfixarna-info\n list={[\n { trust_badge: 'Du kommer bli kontaktad av en Hemfixare för bokning av tid.' },\n { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },\n ]}\n />\n </div>\n </div>\n );\n };\n}\n"]}
1
+ {"version":3,"file":"hemfixarna-order.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-order/hemfixarna-order.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,KAAK,MAAM,aAAa,CAAC;AAOhC,MAAM,OAAO,eAAe;;IAgB1B,WAAM,GAAG,GAAG,EAAE;MACZ,OAAO,CACL,WAAK,KAAK,EAAE,EAAE,UAAU,EAAE,OAAO,KAAK,CAAC,OAAO,CAAC,eAAe,GAAG,EAAE,EAAE,KAAK,EAAC,kBAAkB;QAC3F,cAAW;QACX;UACE,cAAK,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,sBAAsB,CAAM;UACnF,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,+FAA4E,CAAC,CAAC,CAAC,IAAI;UAC3G,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC,cAAW,CAAC,CAAC,CAAC,4BAAsB,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,GAAyB;UAClH,YAAM,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE;YACnC,2CAAkC,CAC7B;UACP,uBACE,IAAI,EAAE;cACJ,EAAE,WAAW,EAAE,6DAA6D,EAAE;cAC9E,EAAE,WAAW,EAAE,iEAAiE,EAAE;aACnF,GACD,CACE,CACF,CACP,CAAC;IACJ,CAAC,CAAC;;;EAjCF,SAAS;IACP,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,GAAG,EAAE,CAAC;IAChB,KAAK,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAC9B,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC;IAC7B,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;EACzB,CAAC;EAED,oBAAoB;IAClB,IAAI,CAAC,SAAS,EAAE,CAAC;EACnB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;CAuBF","sourcesContent":["import { Component, Prop, h } from '@stencil/core';\nimport state from '../../store';\nimport { Category } from '../../types';\n\n@Component({\n tag: 'hemfixarna-order',\n shadow: false,\n})\nexport class HemfixarnaOrder {\n @Prop() tree: Category;\n\n resetShop() {\n state.step = 1;\n state.cart = [];\n state.selectedCategory = null;\n state.selectedService = null;\n state.selectedProduct = null;\n state.checkoutStep = 1;\n }\n\n disconnectedCallback() {\n this.resetShop();\n }\n\n render = () => {\n return (\n <div style={{ background: `url(${state.options.thank_you_image})` }} class=\"hemfixarna_order\">\n <div></div>\n <div>\n <h2>{state.checkoutInvoice ? 'Tack för din förfrågan' : 'Tack för din bokning'}</h2>\n {state.checkoutInvoice ? <p>Vi återkommer inom kort till dig på angivet telefonnummer eller epost</p> : null}\n {state.checkoutInvoice ? <div></div> : <hemfixarna-orderrows tree={this.tree} cart={false}></hemfixarna-orderrows>}\n <span onClick={() => this.resetShop()}>\n <button>Gör en ny bokning</button>\n </span>\n <hemfixarna-info\n list={[\n { trust_badge: 'Du kommer bli kontaktad av en Hemfixare för bokning av tid.' },\n { trust_badge: 'När jobbet är klart kommer du få en faktura med RUT/ROT-avdrag.' },\n ]}\n />\n </div>\n </div>\n );\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { getAssetPath, h } from '@stencil/core';
1
+ import { Fragment, getAssetPath, h } from '@stencil/core';
2
2
  import state from '../../store';
3
3
  import { getPartPrice, getProductPrice } from '../../utils/calc';
4
4
  import { scrollToTop } from '../../utils/scroll';
@@ -111,11 +111,11 @@ export class HemfixarnaProduct {
111
111
  const checked = getAssetPath(`./assets/checked.svg`);
112
112
  const plus = getAssetPath(`./assets/plus.svg`);
113
113
  const minus = getAssetPath(`./assets/minus.svg`);
114
- return (h("div", { class: "hemfixarna_product" }, h("div", { class: "hemfixarna_product--top" }, state.selectedProduct.icon && (h("img", { width: 80, src: (_a = state.selectedProduct.icon.url) !== null && _a !== void 0 ? _a : state.selectedProduct.icon, alt: state.selectedProduct.post_title })), h("div", null, h("h1", null, state.selectedProduct.post_title), h("h2", null, "Fr\u00E5n: ", getProductPrice(state.selectedProduct), " kr"))), h("div", { class: "hemfixarna_product--grid" }, h("div", { class: "hemfixarna_product--left" }, ((_b = state.selectedProduct.list) === null || _b === void 0 ? void 0 : _b.length) && (h("ul", { class: "hemfixarna_features" }, state.selectedProduct.list.map(l => (h("li", { key: l.bullet }, h("img", { src: checked, alt: "checked" }), h("p", null, l.bullet)))))), state.selectedProduct.description && (h("p", { onClick: () => (this.hideDescription = false), class: `hemfixarna_description ${this.hideDescription ? 'hemfixarna_description--hidden' : ''}`, innerHTML: state.selectedProduct.description }))), h("div", { class: "hemfixarna_product--right" }, h("ul", null, h("li", { class: "hemfixarna_product--item" }, h("div", null, h("p", null, "Antal ", state.selectedProduct.post_title), h("p", { class: "hemfixarna_product--price" }, getProductPrice(state.selectedProduct), "kr/st")), h("div", { class: "hemfixarna_counter" }, h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removeProduct() }), h("span", null, this.getAmount()), h("img", { src: plus, onClick: () => this.addProduct() }))), ((_c = state.selectedProduct.parts) === null || _c === void 0 ? void 0 : _c.length) &&
114
+ return (h("div", { class: "hemfixarna_product" }, h("div", { class: "hemfixarna_product--top" }, state.selectedProduct.icon && (h("img", { width: 80, src: (_a = state.selectedProduct.icon.url) !== null && _a !== void 0 ? _a : state.selectedProduct.icon, alt: state.selectedProduct.post_title })), h("div", null, h("h1", null, state.selectedProduct.post_title), !state.selectedProduct.invoice ? h("h2", null, getProductPrice(state.selectedProduct), " kr/st") : h("h2", null, state.selectedProduct.invoice_price))), h("div", { class: "hemfixarna_product--grid" }, h("div", { class: "hemfixarna_product--left" }, ((_b = state.selectedProduct.list) === null || _b === void 0 ? void 0 : _b.length) && (h("ul", { class: "hemfixarna_features" }, state.selectedProduct.list.map(l => (h("li", { key: l.bullet }, h("img", { src: checked, alt: "checked" }), h("p", null, l.bullet)))))), state.selectedProduct.description && (h("p", { onClick: () => (this.hideDescription = false), class: `hemfixarna_description ${this.hideDescription ? 'hemfixarna_description--hidden' : ''}`, innerHTML: state.selectedProduct.description }))), h("div", { class: "hemfixarna_product--right" }, state.selectedProduct.invoice ? (h("hemfixarna-invoice", null)) : (h(Fragment, null, h("ul", null, h("li", { class: "hemfixarna_product--item" }, h("div", null, h("p", null, "Antal ", state.selectedProduct.post_title), h("p", { class: "hemfixarna_product--price" }, getProductPrice(state.selectedProduct), "kr/st")), h("div", { class: "hemfixarna_counter" }, h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removeProduct() }), h("span", null, this.getAmount()), h("img", { src: plus, onClick: () => this.addProduct() }))), ((_c = state.selectedProduct.parts) === null || _c === void 0 ? void 0 : _c.length) &&
115
115
  state.selectedProduct.parts.map(p => {
116
116
  var _a;
117
117
  return (h("li", { class: "hemfixarna_part" }, h("div", null, h("p", null, (_a = p.title) !== null && _a !== void 0 ? _a : p.post_title), h("p", { class: "hemfixarna_product--price" }, getPartPrice(p, state.selectedProduct), "kr/st")), h("div", { class: "hemfixarna_counter" }, h("img", { class: `${this.getPartAmount(p.ID) === 0 ? 'disabled' : ''}`, src: minus, onClick: () => this.removePart(p) }), h("span", null, this.getPartAmount(p.ID)), h("img", { class: `${this.getAmount() === 0 ? 'disabled' : ''}`, src: plus, onClick: () => this.addPart(p) }))));
118
- })), h("h4", { class: "hemfixarna_product--total" }, "Totalt ", this.getTotalPrice(), " kr"), h("button", { onClick: () => this.goToCart(), class: `hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}` }, "Forts\u00E4tt"), !state.selectedProduct.hide_start_fee && (state.selectedProduct.rot || state.selectedProduct.rut) && state.rutOptions && state.rotOptions && (h("p", { class: "hemfixarna_terms" }, h("strong", null, state.selectedProduct.rot ? state.rotOptions.rot_start_fee_heading : state.rutOptions.rut_start_fee_heading), h("br", null), h("span", { innerHTML: state.selectedProduct.rot ? state.rotOptions.rot_start_fee_text : state.rutOptions.rut_start_fee_text }))), state.options && h("hemfixarna-info", { list: state.options.trust })))));
118
+ })), h("h4", { class: "hemfixarna_product--total" }, "Totalt ", this.getTotalPrice(), " kr"), h("button", { onClick: () => this.goToCart(), class: `hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}` }, "Forts\u00E4tt"))), !state.selectedProduct.hide_start_fee && (state.selectedProduct.rot || state.selectedProduct.rut) && state.rutOptions && state.rotOptions && (h("p", { class: "hemfixarna_terms" }, h("strong", null, state.selectedProduct.rot ? state.rotOptions.rot_start_fee_heading : state.rutOptions.rut_start_fee_heading), h("br", null), h("span", { innerHTML: state.selectedProduct.rot ? state.rotOptions.rot_start_fee_text : state.rutOptions.rut_start_fee_text }))), state.options && h("hemfixarna-info", { list: state.options.trust })))));
119
119
  }
120
120
  static get is() { return "hemfixarna-product"; }
121
121
  static get states() {
@@ -1 +1 @@
1
- {"version":3,"file":"hemfixarna-product.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-product/hemfixarna-product.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAC3E,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACjE,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,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,GAAS,CAC7H,CACL;UACA,KAAK,CAAC,OAAO,IAAI,uBAAiB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAI,CAC5D,CACF,CACF,CACP,CAAC;EACJ,CAAC;;;;;;;CACF","sourcesContent":["import { Component, Element, State, getAssetPath, h } from '@stencil/core';\nimport state from '../../store';\nimport { Icon, Part } from '../../types';\nimport { getPartPrice, getProductPrice } from '../../utils/calc';\nimport { scrollToTop } from '../../utils/scroll';\n\n@Component({\n tag: 'hemfixarna-product',\n shadow: false,\n})\nexport class HemfixarnaProduct {\n @State() amount: number = 0;\n @State() hideDescription: boolean = true;\n @Element() private el: HTMLElement;\n\n addProduct() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n productInCart.amount++;\n state.cart = [...state.cart];\n } else {\n state.cart = [\n ...state.cart,\n {\n id: state.selectedProduct.ID,\n rut: state.selectedProduct.rut,\n rot: state.selectedProduct.rot,\n amount: 1,\n parts: [],\n price: state.selectedProduct.price,\n name: state.selectedProduct.post_title,\n start_fee: !state.selectedProduct.hide_start_fee,\n terms_checkout: state.selectedProduct.terms_checkout,\n icon: state.selectedProduct.icon,\n },\n ];\n }\n }\n\n removeProduct() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart && productInCart.amount > 1) {\n productInCart.amount--;\n state.cart = [...state.cart];\n } else {\n state.cart = state.cart.filter(p => p.id !== state.selectedProduct.ID);\n }\n }\n\n //Handle cart and parts\n addPart(part: Part) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partInCart = productInCart.parts.find(sp => sp.id === part.ID);\n if (partInCart) {\n partInCart.amount++;\n productInCart.parts = [...productInCart.parts];\n } else {\n productInCart.parts = [...productInCart.parts, { id: part.ID, amount: 1, price: part.price, name: part.title ?? part.post_title }];\n }\n state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];\n }\n }\n\n removePart(part: Part) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partInCart = productInCart.parts.find(sp => sp.id === part.ID);\n if (partInCart && partInCart.amount > 1) {\n partInCart.amount--;\n productInCart.parts = [...productInCart.parts];\n } else {\n productInCart.parts = productInCart.parts.filter(sp => sp.id !== part.ID);\n }\n state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];\n }\n }\n\n goToCart() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n state.step = 5;\n const el = this.el.closest('.hemfixarna_content');\n scrollToTop(el);\n }\n }\n\n getAmount() {\n return state.cart.find(p => p.id === state.selectedProduct.ID)?.amount || 0;\n }\n\n getPartAmount(partId: number) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n return productInCart?.parts.find(sp => sp.id === partId)?.amount || 0;\n }\n\n getTotalPrice() {\n let price = 0;\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partsPrice = productInCart.parts.reduce((acc, curr) => {\n const part = state.selectedProduct.parts.find(p => p.ID === curr.id);\n if (part) {\n return acc + part.price * curr.amount;\n }\n return acc;\n }, 0);\n price = state.selectedProduct.price * productInCart.amount + partsPrice;\n } else {\n price = state.selectedProduct.price;\n }\n return getProductPrice(state.selectedProduct, price);\n }\n\n render() {\n const checked = getAssetPath(`./assets/checked.svg`);\n const plus = getAssetPath(`./assets/plus.svg`);\n const minus = getAssetPath(`./assets/minus.svg`);\n\n return (\n <div class=\"hemfixarna_product\">\n <div class=\"hemfixarna_product--top\">\n {state.selectedProduct.icon && (\n <img width={80} src={(state.selectedProduct.icon as Icon).url ?? (state.selectedProduct.icon as string)} alt={state.selectedProduct.post_title} />\n )}\n <div>\n <h1>{state.selectedProduct.post_title}</h1>\n <h2>Från: {getProductPrice(state.selectedProduct)} kr</h2>\n </div>\n </div>\n\n <div class=\"hemfixarna_product--grid\">\n <div class=\"hemfixarna_product--left\">\n {state.selectedProduct.list?.length && (\n <ul class=\"hemfixarna_features\">\n {state.selectedProduct.list.map(l => (\n <li key={l.bullet}>\n <img src={checked} alt=\"checked\" />\n <p>{l.bullet}</p>\n </li>\n ))}\n </ul>\n )}\n {state.selectedProduct.description && (\n <p\n onClick={() => (this.hideDescription = false)}\n class={`hemfixarna_description ${this.hideDescription ? 'hemfixarna_description--hidden' : ''}`}\n innerHTML={state.selectedProduct.description}\n ></p>\n )}\n </div>\n <div class=\"hemfixarna_product--right\">\n <ul>\n <li class=\"hemfixarna_product--item\">\n <div>\n <p>Antal {state.selectedProduct.post_title}</p>\n <p class=\"hemfixarna_product--price\">{getProductPrice(state.selectedProduct)}kr/st</p>\n </div>\n <div class=\"hemfixarna_counter\">\n <img class={`${this.getAmount() === 0 ? 'disabled' : ''}`} src={minus} onClick={() => this.removeProduct()} />\n <span>{this.getAmount()}</span>\n <img src={plus} onClick={() => this.addProduct()} />\n </div>\n </li>\n {state.selectedProduct.parts?.length &&\n state.selectedProduct.parts.map(p => (\n <li class=\"hemfixarna_part\">\n <div>\n <p>{p.title ?? p.post_title}</p>\n <p class=\"hemfixarna_product--price\">{getPartPrice(p, state.selectedProduct)}kr/st</p>\n </div>\n <div class=\"hemfixarna_counter\">\n <img class={`${this.getPartAmount(p.ID) === 0 ? 'disabled' : ''}`} src={minus} onClick={() => this.removePart(p)} />\n <span>{this.getPartAmount(p.ID)}</span>\n <img class={`${this.getAmount() === 0 ? 'disabled' : ''}`} src={plus} onClick={() => this.addPart(p)} />\n </div>\n </li>\n ))}\n </ul>\n <h4 class=\"hemfixarna_product--total\">Totalt {this.getTotalPrice()} kr</h4>\n <button onClick={() => this.goToCart()} class={`hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}`}>\n Fortsätt\n </button>\n {!state.selectedProduct.hide_start_fee && (state.selectedProduct.rot || state.selectedProduct.rut) && state.rutOptions && state.rotOptions && (\n <p class=\"hemfixarna_terms\">\n <strong>{state.selectedProduct.rot ? state.rotOptions.rot_start_fee_heading : state.rutOptions.rut_start_fee_heading}</strong>\n <br />\n <span innerHTML={state.selectedProduct.rot ? state.rotOptions.rot_start_fee_text : state.rutOptions.rut_start_fee_text}></span>\n </p>\n )}\n {state.options && <hemfixarna-info list={state.options.trust} />}\n </div>\n </div>\n </div>\n );\n }\n}\n"]}
1
+ {"version":3,"file":"hemfixarna-product.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-product/hemfixarna-product.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAMjD,MAAM,OAAO,iBAAiB;;kBACF,CAAC;2BACS,IAAI;;EAGxC,UAAU;IACR,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAC9E,IAAI,aAAa,EAAE;MACjB,aAAa,CAAC,MAAM,EAAE,CAAC;MACvB,KAAK,CAAC,IAAI,GAAG,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;KAC9B;SAAM;MACL,KAAK,CAAC,IAAI,GAAG;QACX,GAAG,KAAK,CAAC,IAAI;QACb;UACE,EAAE,EAAE,KAAK,CAAC,eAAe,CAAC,EAAE;UAC5B,GAAG,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG;UAC9B,GAAG,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG;U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AC,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAI,CACpG,CACH,CACN,CAAA;iBAAA,CAAC,CACD;YACL,UAAI,KAAK,EAAC,2BAA2B;;cAAS,IAAI,CAAC,aAAa,EAAE;oBAAS;YAC3E,cAAQ,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,kBAAkB,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,oBAElG,CACA,CACZ;UACA,CAAC,KAAK,CAAC,eAAe,CAAC,cAAc,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,IAAI,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,IAAI,CAC5I,SAAG,KAAK,EAAC,kBAAkB;YACzB,kBAAS,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,qBAAqB,CAAU;YAC9H,aAAM;YACN,YAAM,SAAS,EAAE,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,CAAC,CAAC,CAAC,KAAK,CAAC,UAAU,CAAC,kBAAkB,GAAS,CAC7H,CACL;UACA,KAAK,CAAC,OAAO,IAAI,uBAAiB,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAI,CAC5D,CACF,CACF,CACP,CAAC;EACJ,CAAC;;;;;;;CACF","sourcesContent":["import { Component, Element, Fragment, State, getAssetPath, h } from '@stencil/core';\nimport state from '../../store';\nimport { Icon, Part } from '../../types';\nimport { getPartPrice, getProductPrice } from '../../utils/calc';\nimport { scrollToTop } from '../../utils/scroll';\n\n@Component({\n tag: 'hemfixarna-product',\n shadow: false,\n})\nexport class HemfixarnaProduct {\n @State() amount: number = 0;\n @State() hideDescription: boolean = true;\n @Element() private el: HTMLElement;\n\n addProduct() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n productInCart.amount++;\n state.cart = [...state.cart];\n } else {\n state.cart = [\n ...state.cart,\n {\n id: state.selectedProduct.ID,\n rut: state.selectedProduct.rut,\n rot: state.selectedProduct.rot,\n amount: 1,\n parts: [],\n price: state.selectedProduct.price,\n name: state.selectedProduct.post_title,\n start_fee: !state.selectedProduct.hide_start_fee,\n terms_checkout: state.selectedProduct.terms_checkout,\n icon: state.selectedProduct.icon,\n },\n ];\n }\n }\n\n removeProduct() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart && productInCart.amount > 1) {\n productInCart.amount--;\n state.cart = [...state.cart];\n } else {\n state.cart = state.cart.filter(p => p.id !== state.selectedProduct.ID);\n }\n }\n\n //Handle cart and parts\n addPart(part: Part) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partInCart = productInCart.parts.find(sp => sp.id === part.ID);\n if (partInCart) {\n partInCart.amount++;\n productInCart.parts = [...productInCart.parts];\n } else {\n productInCart.parts = [...productInCart.parts, { id: part.ID, amount: 1, price: part.price, name: part.title ?? part.post_title }];\n }\n state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];\n }\n }\n\n removePart(part: Part) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partInCart = productInCart.parts.find(sp => sp.id === part.ID);\n if (partInCart && partInCart.amount > 1) {\n partInCart.amount--;\n productInCart.parts = [...productInCart.parts];\n } else {\n productInCart.parts = productInCart.parts.filter(sp => sp.id !== part.ID);\n }\n state.cart = [...state.cart.filter(p => p.id !== productInCart.id), productInCart];\n }\n }\n\n goToCart() {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n state.step = 5;\n const el = this.el.closest('.hemfixarna_content');\n scrollToTop(el);\n }\n }\n\n getAmount() {\n return state.cart.find(p => p.id === state.selectedProduct.ID)?.amount || 0;\n }\n\n getPartAmount(partId: number) {\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n return productInCart?.parts.find(sp => sp.id === partId)?.amount || 0;\n }\n\n getTotalPrice() {\n let price = 0;\n const productInCart = state.cart.find(p => p.id === state.selectedProduct.ID);\n if (productInCart) {\n const partsPrice = productInCart.parts.reduce((acc, curr) => {\n const part = state.selectedProduct.parts.find(p => p.ID === curr.id);\n if (part) {\n return acc + part.price * curr.amount;\n }\n return acc;\n }, 0);\n price = state.selectedProduct.price * productInCart.amount + partsPrice;\n } else {\n price = state.selectedProduct.price;\n }\n return getProductPrice(state.selectedProduct, price);\n }\n\n render() {\n const checked = getAssetPath(`./assets/checked.svg`);\n const plus = getAssetPath(`./assets/plus.svg`);\n const minus = getAssetPath(`./assets/minus.svg`);\n\n return (\n <div class=\"hemfixarna_product\">\n <div class=\"hemfixarna_product--top\">\n {state.selectedProduct.icon && (\n <img width={80} src={(state.selectedProduct.icon as Icon).url ?? (state.selectedProduct.icon as string)} alt={state.selectedProduct.post_title} />\n )}\n <div>\n <h1>{state.selectedProduct.post_title}</h1>\n {!state.selectedProduct.invoice ? <h2>{getProductPrice(state.selectedProduct)} kr/st</h2> : <h2>{state.selectedProduct.invoice_price}</h2>}\n </div>\n </div>\n\n <div class=\"hemfixarna_product--grid\">\n <div class=\"hemfixarna_product--left\">\n {state.selectedProduct.list?.length && (\n <ul class=\"hemfixarna_features\">\n {state.selectedProduct.list.map(l => (\n <li key={l.bullet}>\n <img src={checked} alt=\"checked\" />\n <p>{l.bullet}</p>\n </li>\n ))}\n </ul>\n )}\n {state.selectedProduct.description && (\n <p\n onClick={() => (this.hideDescription = false)}\n class={`hemfixarna_description ${this.hideDescription ? 'hemfixarna_description--hidden' : ''}`}\n innerHTML={state.selectedProduct.description}\n ></p>\n )}\n </div>\n <div class=\"hemfixarna_product--right\">\n {state.selectedProduct.invoice ? (\n <hemfixarna-invoice />\n ) : (\n <Fragment>\n <ul>\n <li class=\"hemfixarna_product--item\">\n <div>\n <p>Antal {state.selectedProduct.post_title}</p>\n <p class=\"hemfixarna_product--price\">{getProductPrice(state.selectedProduct)}kr/st</p>\n </div>\n <div class=\"hemfixarna_counter\">\n <img class={`${this.getAmount() === 0 ? 'disabled' : ''}`} src={minus} onClick={() => this.removeProduct()} />\n <span>{this.getAmount()}</span>\n <img src={plus} onClick={() => this.addProduct()} />\n </div>\n </li>\n {state.selectedProduct.parts?.length &&\n state.selectedProduct.parts.map(p => (\n <li class=\"hemfixarna_part\">\n <div>\n <p>{p.title ?? p.post_title}</p>\n <p class=\"hemfixarna_product--price\">{getPartPrice(p, state.selectedProduct)}kr/st</p>\n </div>\n <div class=\"hemfixarna_counter\">\n <img class={`${this.getPartAmount(p.ID) === 0 ? 'disabled' : ''}`} src={minus} onClick={() => this.removePart(p)} />\n <span>{this.getPartAmount(p.ID)}</span>\n <img class={`${this.getAmount() === 0 ? 'disabled' : ''}`} src={plus} onClick={() => this.addPart(p)} />\n </div>\n </li>\n ))}\n </ul>\n <h4 class=\"hemfixarna_product--total\">Totalt {this.getTotalPrice()} kr</h4>\n <button onClick={() => this.goToCart()} class={`hemfixarna_buy ${this.getAmount() === 0 ? 'disabled' : ''}`}>\n Fortsätt\n </button>\n </Fragment>\n )}\n {!state.selectedProduct.hide_start_fee && (state.selectedProduct.rot || state.selectedProduct.rut) && state.rutOptions && state.rotOptions && (\n <p class=\"hemfixarna_terms\">\n <strong>{state.selectedProduct.rot ? state.rotOptions.rot_start_fee_heading : state.rutOptions.rut_start_fee_heading}</strong>\n <br />\n <span innerHTML={state.selectedProduct.rot ? state.rotOptions.rot_start_fee_text : state.rutOptions.rut_start_fee_text}></span>\n </p>\n )}\n {state.options && <hemfixarna-info list={state.options.trust} />}\n </div>\n </div>\n </div>\n );\n }\n}\n"]}
@@ -6,7 +6,7 @@ export class HemfixarnaService {
6
6
  .sort((a, b) => (a.post_title < b.post_title ? -1 : 1))
7
7
  .map(p => {
8
8
  var _a;
9
- return (h("hemfixarna-box", { post: p, icon: (_a = p.icon.url) !== null && _a !== void 0 ? _a : p.icon, postTitle: p.post_title }));
9
+ return (h("hemfixarna-box", { post: p, icon: (_a = p.icon.url) !== null && _a !== void 0 ? _a : p.icon, postTitle: p.title }));
10
10
  }))), h("hemfixarna-info", { list: state.options.trust }))));
11
11
  }
12
12
  static get is() { return "hemfixarna-service"; }