hemfixarna-web-components 0.3.1 → 0.9.2
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.
- package/dist/cjs/hemfixarna-address_16.cjs.entry.js +1753 -0
- package/dist/cjs/hemfixarna-address_16.cjs.entry.js.map +1 -0
- package/dist/cjs/hemfixarna-components.cjs.js +28 -0
- package/dist/cjs/hemfixarna-components.cjs.js.map +1 -0
- package/dist/cjs/index-d9e286dc.js +1652 -0
- package/dist/cjs/index-d9e286dc.js.map +1 -0
- package/dist/cjs/index.cjs.js +4 -0
- package/dist/cjs/index.cjs.js.map +1 -0
- package/dist/cjs/loader.cjs.js +24 -0
- package/dist/cjs/loader.cjs.js.map +1 -0
- package/dist/collection/assets/back.svg +3 -0
- package/dist/collection/assets/cart.svg +10 -0
- package/dist/collection/assets/checked.svg +10 -0
- package/dist/collection/assets/close.svg +5 -0
- package/dist/collection/assets/copy.png +0 -0
- package/dist/collection/assets/date.svg +6 -0
- package/dist/collection/assets/down.svg +3 -0
- package/dist/collection/assets/hemfixarna.svg +11 -0
- package/dist/collection/assets/info.svg +5 -0
- package/dist/collection/assets/minus.svg +4 -0
- package/dist/collection/assets/plus.svg +5 -0
- package/dist/collection/collection-manifest.json +27 -0
- package/dist/collection/components/hemfixarna-address/hemfixarna-address.js +67 -0
- package/dist/collection/components/hemfixarna-address/hemfixarna-address.js.map +1 -0
- package/dist/collection/components/hemfixarna-box/hemfixarna-box.js +97 -0
- package/dist/collection/components/hemfixarna-box/hemfixarna-box.js.map +1 -0
- package/dist/{hemfixarna-components/hemfixarna-breadcrumbs.entry.js → collection/components/hemfixarna-breadcrumbs/hemfixarna-breadcrumbs.js} +46 -11
- package/dist/collection/components/hemfixarna-breadcrumbs/hemfixarna-breadcrumbs.js.map +1 -0
- package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.css +0 -0
- package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.js +50 -0
- package/dist/collection/components/hemfixarna-byggmax/hemfixarna-byggmax.js.map +1 -0
- package/dist/collection/components/hemfixarna-cart/hemfixarna-cart.js +41 -0
- package/dist/collection/components/hemfixarna-cart/hemfixarna-cart.js.map +1 -0
- package/dist/collection/components/hemfixarna-category.tsx/hemfixarna-category.js +18 -0
- package/dist/collection/components/hemfixarna-category.tsx/hemfixarna-category.js.map +1 -0
- package/dist/collection/components/hemfixarna-checkout/hemfixarna-checkout.js +92 -0
- package/dist/collection/components/hemfixarna-checkout/hemfixarna-checkout.js.map +1 -0
- package/dist/collection/components/hemfixarna-component/hemfixarna-component.js +221 -0
- package/dist/collection/components/hemfixarna-component/hemfixarna-component.js.map +1 -0
- package/dist/collection/components/hemfixarna-component/hemfixarna.css +752 -0
- package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.css +118 -0
- package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.js +76 -0
- package/dist/collection/components/hemfixarna-demo/hemfixarna-demo.js.map +1 -0
- package/dist/collection/components/hemfixarna-getuser/hemfixarna-getuser.js +84 -0
- package/dist/collection/components/hemfixarna-getuser/hemfixarna-getuser.js.map +1 -0
- package/dist/{hemfixarna-components/hemfixarna-info.entry.js → collection/components/hemfixarna-info/hemfixarna-info.js} +27 -11
- package/dist/collection/components/hemfixarna-info/hemfixarna-info.js.map +1 -0
- package/dist/collection/components/hemfixarna-order/hemfixarna-order.js +50 -0
- package/dist/collection/components/hemfixarna-order/hemfixarna-order.js.map +1 -0
- package/dist/collection/components/hemfixarna-orderrows/hemfixarna-orderrows.js +80 -0
- package/dist/collection/components/hemfixarna-orderrows/hemfixarna-orderrows.js.map +1 -0
- package/dist/{hemfixarna-components/hemfixarna-product.entry.js → collection/components/hemfixarna-product/hemfixarna-product.js} +15 -16
- package/dist/collection/components/hemfixarna-product/hemfixarna-product.js.map +1 -0
- package/dist/collection/components/hemfixarna-service/hemfixarna-service.js +18 -0
- package/dist/collection/components/hemfixarna-service/hemfixarna-service.js.map +1 -0
- package/dist/collection/components/hemfixarna-start/hemfixarna-start.js +41 -0
- package/dist/collection/components/hemfixarna-start/hemfixarna-start.js.map +1 -0
- package/dist/collection/index.js +2 -0
- package/dist/collection/index.js.map +1 -0
- package/dist/collection/store/index.js +25 -0
- package/dist/collection/store/index.js.map +1 -0
- package/dist/{hemfixarna-components/index-2bf8566c.js → collection/types/index.js} +3 -6
- package/dist/collection/types/index.js.map +1 -0
- package/dist/collection/utils/api.js +41 -0
- package/dist/collection/utils/api.js.map +1 -0
- package/dist/{hemfixarna-components/calc-a9ece205.js → collection/utils/calc.js} +36 -6
- package/dist/collection/utils/calc.js.map +1 -0
- package/dist/collection/utils/creditSafe.js +18 -0
- package/dist/collection/utils/creditSafe.js.map +1 -0
- package/dist/collection/utils/felixFunctions.js +189 -0
- package/dist/collection/utils/felixFunctions.js.map +1 -0
- package/dist/collection/utils/form.js +7 -0
- package/dist/collection/utils/form.js.map +1 -0
- package/dist/esm/hemfixarna-address_16.entry.js +1734 -0
- package/dist/esm/hemfixarna-address_16.entry.js.map +1 -0
- package/dist/esm/hemfixarna-components.js +23 -0
- package/dist/esm/hemfixarna-components.js.map +1 -0
- package/dist/esm/index-ca1aada9.js +1621 -0
- package/dist/esm/index-ca1aada9.js.map +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/loader.js +20 -0
- package/dist/esm/loader.js.map +1 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/hemfixarna-components/hemfixarna-components.esm.js +1 -162
- package/dist/hemfixarna-components/hemfixarna-components.esm.js.map +1 -1
- package/dist/hemfixarna-components/index.esm.js +0 -1
- package/dist/hemfixarna-components/index.esm.js.map +1 -1
- package/dist/hemfixarna-components/p-8829e98e.js +3 -0
- package/dist/hemfixarna-components/p-8829e98e.js.map +1 -0
- package/dist/hemfixarna-components/p-c05e2af1.entry.js +2 -0
- package/dist/hemfixarna-components/p-c05e2af1.entry.js.map +1 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/types/components/hemfixarna-address/hemfixarna-address.d.ts +1 -0
- package/dist/types/components/hemfixarna-cart/hemfixarna-cart.d.ts +1 -9
- package/dist/types/components/hemfixarna-checkout/hemfixarna-checkout.d.ts +3 -1
- package/dist/types/components/hemfixarna-getuser/hemfixarna-getuser.d.ts +1 -1
- package/dist/types/components/hemfixarna-order/hemfixarna-order.d.ts +3 -0
- package/dist/types/components/hemfixarna-orderrows/hemfixarna-orderrows.d.ts +8 -0
- package/dist/types/components.d.ts +19 -0
- package/dist/types/store/index.d.ts +2 -6
- package/dist/types/types/index.d.ts +18 -7
- package/dist/types/utils/api.d.ts +20 -2
- package/dist/types/utils/calc.d.ts +5 -1
- package/dist/types/utils/creditSafe.d.ts +3 -0
- package/dist/types/utils/form.d.ts +2 -0
- package/package.json +2 -1
- package/dist/hemfixarna-components/api-3228fe30.js +0 -28
- package/dist/hemfixarna-components/api-3228fe30.js.map +0 -1
- package/dist/hemfixarna-components/app-globals-0f993ce5.js +0 -5
- package/dist/hemfixarna-components/app-globals-0f993ce5.js.map +0 -1
- package/dist/hemfixarna-components/calc-a9ece205.js.map +0 -1
- package/dist/hemfixarna-components/css-shim-62d2171c.js +0 -6
- package/dist/hemfixarna-components/css-shim-62d2171c.js.map +0 -1
- package/dist/hemfixarna-components/dom-46a68c9b.js +0 -75
- package/dist/hemfixarna-components/dom-46a68c9b.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-address.entry.js +0 -52
- package/dist/hemfixarna-components/hemfixarna-address.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-box.entry.js +0 -35
- package/dist/hemfixarna-components/hemfixarna-box.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-breadcrumbs.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js +0 -20
- package/dist/hemfixarna-components/hemfixarna-byggmax.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-cart.entry.js +0 -82
- package/dist/hemfixarna-components/hemfixarna-cart.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-category.entry.js +0 -21
- package/dist/hemfixarna-components/hemfixarna-category.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-checkout.entry.js +0 -54
- package/dist/hemfixarna-components/hemfixarna-checkout.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-component.entry.js +0 -133
- package/dist/hemfixarna-components/hemfixarna-component.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-demo.entry.js +0 -65
- package/dist/hemfixarna-components/hemfixarna-demo.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-getuser.entry.js +0 -410
- package/dist/hemfixarna-components/hemfixarna-getuser.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-info.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-order.entry.js +0 -24
- package/dist/hemfixarna-components/hemfixarna-order.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-product.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-service.entry.js +0 -21
- package/dist/hemfixarna-components/hemfixarna-service.entry.js.map +0 -1
- package/dist/hemfixarna-components/hemfixarna-start.entry.js +0 -18
- package/dist/hemfixarna-components/hemfixarna-start.entry.js.map +0 -1
- package/dist/hemfixarna-components/index-2bf8566c.js.map +0 -1
- package/dist/hemfixarna-components/index-59ed730c.js +0 -3397
- package/dist/hemfixarna-components/index-59ed730c.js.map +0 -1
- package/dist/hemfixarna-components/index-75ed3bb8.js +0 -216
- package/dist/hemfixarna-components/index-75ed3bb8.js.map +0 -1
- package/dist/hemfixarna-components/shadow-css-05e0c1f4.js +0 -389
- package/dist/hemfixarna-components/shadow-css-05e0c1f4.js.map +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Fragment, getAssetPath, h } from '@stencil/core';
|
|
2
|
+
import state from '../../store';
|
|
3
|
+
import { hideField } from '../../utils/form';
|
|
4
|
+
import { getPartPrice, getProductPrice, getStartFee, getTotalPrice } from '../../utils/calc';
|
|
5
|
+
import { postOrder } from '../../utils/api';
|
|
6
|
+
export class HemfixarnaCheckout {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.handleChangeDate = (e) => {
|
|
9
|
+
this.dateError = null;
|
|
10
|
+
this.date = e.target.value;
|
|
11
|
+
};
|
|
12
|
+
this.handleChangeTerms = () => {
|
|
13
|
+
this.generalError = null;
|
|
14
|
+
};
|
|
15
|
+
this.sendOrder = async () => {
|
|
16
|
+
// Test order post (remove later)
|
|
17
|
+
const order = {
|
|
18
|
+
name: state.user.firstName + ' ' + state.user.lastName,
|
|
19
|
+
customer: state.business,
|
|
20
|
+
phone: state.user.phone,
|
|
21
|
+
social_security_number: state.user.ssn,
|
|
22
|
+
email: state.user.email,
|
|
23
|
+
address: `${state.user.street} | ${state.user.zip} | ${state.user.town}`,
|
|
24
|
+
earliest_visit_date: this.date,
|
|
25
|
+
order_items: JSON.stringify(state.cart.map(item => `${item.amount}st ${item.name} ${getProductPrice(item, item.price, item.amount)}kr ${item.parts.length ? `| ${item.parts.map(part => `${part.amount}st ${part.name} ${getPartPrice(part, item, part.amount)}kr`).join(' | ')} ` : ''} ${item.rot && state.rot ? '(med rot)' : state.rut && item.rut ? '(med rut)' : '(utan rut/rot)'}`)),
|
|
26
|
+
start_fee: `${getStartFee().rut > 0 ? `Rut: ${getStartFee().rut}kr` : 'Rut: 0'} ` + `${getStartFee().rot > 0 ? `Rot: ${getStartFee().rot}kr` : 'Rot: 0'}`,
|
|
27
|
+
total: getTotalPrice(),
|
|
28
|
+
};
|
|
29
|
+
try {
|
|
30
|
+
const { data: orderConfirm, status } = await postOrder(order);
|
|
31
|
+
if (orderConfirm && status && status === 200) {
|
|
32
|
+
state.step = 6;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
this.generalError = 'Något gick fel, försök igen senare';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (_) {
|
|
39
|
+
this.generalError = 'Något gick fel, försök igen senare';
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
this.handleSubmit = (e) => {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
this.generalError = null;
|
|
45
|
+
const validDate = this.date.length > 0;
|
|
46
|
+
if (!validDate) {
|
|
47
|
+
this.dateError = 'Ange ett giltigt datum';
|
|
48
|
+
}
|
|
49
|
+
const checkBoxes = Array.from(this.el.querySelectorAll('input[type="checkbox"]'));
|
|
50
|
+
const notValidTerms = checkBoxes.find(i => !i.checked);
|
|
51
|
+
if (notValidTerms) {
|
|
52
|
+
this.generalError = 'Du måste godkänna villkoren';
|
|
53
|
+
}
|
|
54
|
+
if (validDate && !notValidTerms) {
|
|
55
|
+
this.sendOrder();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.render = () => {
|
|
59
|
+
const dateLogo = getAssetPath(`./assets/date.svg`);
|
|
60
|
+
const down = getAssetPath(`./assets/down.svg`);
|
|
61
|
+
if (state.checkoutEdit) {
|
|
62
|
+
return h("hemfixarna-address", null);
|
|
63
|
+
}
|
|
64
|
+
else if (state.checkoutStep === 1) {
|
|
65
|
+
return h("hemfixarna-getuser", null);
|
|
66
|
+
}
|
|
67
|
+
else if (state.checkoutStep === 2) {
|
|
68
|
+
return (h("div", { class: "mb-2" }, h("div", { class: "hemfixarna_addressinfo" }, h("div", null, h("p", null, hideField(state.user.firstName)), h("p", null, hideField(state.user.lastName)), h("p", null, state.user.email), h("p", null, state.user.phone)), h("div", null, h("p", null, hideField(state.user.street)), h("p", null, hideField(state.user.zip)), h("p", null, hideField(state.user.town))), h("button", { onClick: () => (state.checkoutEdit = true) }, "Beh\u00F6ver du \u00E4ndra adressen?")), h("form", { onSubmit: e => this.handleSubmit(e) }, h("div", null, h("img", { src: dateLogo, width: 24 }), h("input", { class: `${this.date.length ? 'input_active' : ''}`, min: new Date().toISOString().split('T')[0], onChange: e => this.handleChangeDate(e), type: "date", name: "date", value: this.date }), h("label", { htmlFor: "date" }, "Tidigaste datum f\u00F6r hembes\u00F6k"), h("img", { src: down, width: 24 })), this.dateError && h("span", null, this.dateError), h("label", { class: "hemfixarna_checkbox" }, h("input", { onChange: () => this.handleChangeTerms(), type: "checkbox" }), h("span", { innerHTML: state.options.terms })), state.cart
|
|
69
|
+
.filter(i => i.terms_checkout && i.terms_show_checkbox)
|
|
70
|
+
.map(item => (h(Fragment, null, h("label", { class: "hemfixarna_checkbox" }, h("input", { onChange: () => this.handleChangeTerms(), type: "checkbox" }), h("span", null, item.terms_checkout))))), this.generalError && h("span", null, this.generalError), h("input", { type: "submit", value: "Slutf\u00F6r Bokning" }))));
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
this.date = '';
|
|
74
|
+
this.dateError = null;
|
|
75
|
+
this.generalError = null;
|
|
76
|
+
}
|
|
77
|
+
componentWillLoad() {
|
|
78
|
+
if (Boolean(state.user && state.user.street)) {
|
|
79
|
+
state.checkoutStep = 2;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
static get is() { return "hemfixarna-checkout"; }
|
|
83
|
+
static get states() {
|
|
84
|
+
return {
|
|
85
|
+
"date": {},
|
|
86
|
+
"dateError": {},
|
|
87
|
+
"generalError": {}
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
static get elementRef() { return "el"; }
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=hemfixarna-checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hemfixarna-checkout.js","sourceRoot":"","sources":["../../../src/components/hemfixarna-checkout/hemfixarna-checkout.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,YAAY,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EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAC,UAAU,GAAG;cACnE,YAAM,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,GAAI,CAClC;YACP,KAAK,CAAC,IAAI;eACR,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,IAAI,CAAC,CAAC,mBAAmB,CAAC;eACtD,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CACX,EAAC,QAAQ;cACP,aAAO,KAAK,EAAC,qBAAqB;gBAChC,aAAO,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAC,UAAU,GAAG;gBACnE,gBAAO,IAAI,CAAC,cAAc,CAAQ,CAC5B,CACC,CACZ,CAAC;YACH,IAAI,CAAC,YAAY,IAAI,gBAAO,IAAI,CAAC,YAAY,CAAQ;YACtD,aAAO,IAAI,EAAC,QAAQ,EAAC,KAAK,EAAC,sBAAiB,GAAG,CAC1C,CACH,CACP,CAAC;OACH;IACH,CAAC,CAAC;gBAnIsB,EAAE;qBACU,IAAI;wBACD,IAAI;;EA+D3C,iBAAiB;IACf,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;MAC5C,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC;KACxB;EACH,CAAC;;;;;;;;CA+DF","sourcesContent":["import { Component, Fragment, State, getAssetPath, h, Element } from '@stencil/core';\nimport state from '../../store';\nimport { hideField } from '../../utils/form';\nimport { getPartPrice, getProductPrice, getStartFee, getTotalPrice } from '../../utils/calc';\nimport { postOrder } from '../../utils/api';\nimport { Business } from '../../types';\n\n@Component({\n tag: 'hemfixarna-checkout',\n shadow: false,\n})\nexport class HemfixarnaCheckout {\n @State() date: string = '';\n @State() dateError: string | null = null;\n @State() generalError: string | null = null;\n @Element() private el: HTMLElement;\n\n handleChangeDate = (e: Event) => {\n this.dateError = null;\n this.date = (e.target as HTMLInputElement).value;\n };\n\n handleChangeTerms = () => {\n this.generalError = null;\n };\n\n sendOrder = async () => {\n // Test order post (remove later)\n\n const order = {\n name: state.user.firstName + ' ' + state.user.lastName,\n customer: state.business as Business,\n phone: state.user.phone,\n social_security_number: state.user.ssn,\n email: state.user.email,\n address: `${state.user.street} | ${state.user.zip} | ${state.user.town}`,\n earliest_visit_date: this.date,\n order_items: JSON.stringify(\n state.cart.map(\n item =>\n `${item.amount}st ${item.name} ${getProductPrice(item, item.price, item.amount)}kr ${\n item.parts.length ? `| ${item.parts.map(part => `${part.amount}st ${part.name} ${getPartPrice(part, item, part.amount)}kr`).join(' | ')} ` : ''\n } ${item.rot && state.rot ? '(med rot)' : state.rut && item.rut ? '(med rut)' : '(utan rut/rot)'}`,\n ),\n ),\n start_fee: `${getStartFee().rut > 0 ? `Rut: ${getStartFee().rut}kr` : 'Rut: 0'} ` + `${getStartFee().rot > 0 ? `Rot: ${getStartFee().rot}kr` : 'Rot: 0'}`,\n total: getTotalPrice(),\n };\n try {\n const { data: orderConfirm, status } = await postOrder(order);\n if (orderConfirm && status && status === 200) {\n state.step = 6;\n } else {\n this.generalError = 'Något gick fel, försök igen senare';\n }\n } catch (_) {\n this.generalError = 'Något gick fel, försök igen senare';\n }\n };\n\n handleSubmit = (e: Event) => {\n e.preventDefault();\n this.generalError = null;\n const validDate = this.date.length > 0;\n if (!validDate) {\n this.dateError = 'Ange ett giltigt datum';\n }\n const checkBoxes = Array.from(this.el.querySelectorAll('input[type=\"checkbox\"]'));\n const notValidTerms = checkBoxes.find(i => !(i as HTMLInputElement).checked);\n if (notValidTerms) {\n this.generalError = 'Du måste godkänna villkoren';\n }\n if (validDate && !notValidTerms) {\n this.sendOrder();\n }\n };\n\n componentWillLoad() {\n if (Boolean(state.user && state.user.street)) {\n state.checkoutStep = 2;\n }\n }\n\n render = () => {\n const dateLogo = getAssetPath(`./assets/date.svg`);\n const down = getAssetPath(`./assets/down.svg`);\n\n if (state.checkoutEdit) {\n return <hemfixarna-address />;\n } else if (state.checkoutStep === 1) {\n return <hemfixarna-getuser />;\n } else if (state.checkoutStep === 2) {\n return (\n <div class=\"mb-2\">\n <div class=\"hemfixarna_addressinfo\">\n <div>\n <p>{hideField(state.user.firstName)}</p>\n <p>{hideField(state.user.lastName)}</p>\n <p>{state.user.email}</p>\n <p>{state.user.phone}</p>\n </div>\n <div>\n <p>{hideField(state.user.street)}</p>\n <p>{hideField(state.user.zip)}</p>\n <p>{hideField(state.user.town)}</p>\n </div>\n <button onClick={() => (state.checkoutEdit = true)}>Behöver du ändra adressen?</button>\n </div>\n <form onSubmit={e => this.handleSubmit(e)}>\n <div>\n <img src={dateLogo} width={24} />\n <input\n class={`${this.date.length ? 'input_active' : ''}`}\n min={new Date().toISOString().split('T')[0]}\n onChange={e => this.handleChangeDate(e)}\n type=\"date\"\n name=\"date\"\n value={this.date}\n />\n <label htmlFor=\"date\">Tidigaste datum för hembesök</label>\n <img src={down} width={24} />\n </div>\n {this.dateError && <span>{this.dateError}</span>}\n <label class=\"hemfixarna_checkbox\">\n <input onChange={() => this.handleChangeTerms()} type=\"checkbox\" />\n <span innerHTML={state.options.terms} />\n </label>\n {state.cart\n .filter(i => i.terms_checkout && i.terms_show_checkbox)\n .map(item => (\n <Fragment>\n <label class=\"hemfixarna_checkbox\">\n <input onChange={() => this.handleChangeTerms()} type=\"checkbox\" />\n <span>{item.terms_checkout}</span>\n </label>\n </Fragment>\n ))}\n {this.generalError && <span>{this.generalError}</span>}\n <input type=\"submit\" value=\"Slutför Bokning\" />\n </form>\n </div>\n );\n }\n };\n}\n"]}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { getAssetPath, h } from '@stencil/core';
|
|
2
|
+
import state from '../../store';
|
|
3
|
+
import { getTaxonomy, getOptions } from '../../utils/api';
|
|
4
|
+
import { getProductPriceWithRotAndRut } from '../../utils/calc';
|
|
5
|
+
export class HemfixarnaComponent {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.modal = false;
|
|
8
|
+
this.showModal = false;
|
|
9
|
+
this.tree = null;
|
|
10
|
+
this.product = null;
|
|
11
|
+
this.slug = undefined;
|
|
12
|
+
this.business = undefined;
|
|
13
|
+
this.topCategory = undefined;
|
|
14
|
+
}
|
|
15
|
+
async fetchNewTaxonomy(newValue) {
|
|
16
|
+
state.selectedCategory = null;
|
|
17
|
+
state.selectedProduct = null;
|
|
18
|
+
state.selectedService = null;
|
|
19
|
+
const res = await getTaxonomy(newValue);
|
|
20
|
+
if ((res === null || res === void 0 ? void 0 : res.code) === 'not_found' || (res === null || res === void 0 ? void 0 : res.code) === 'rest_no_route') {
|
|
21
|
+
console.log('taxonomy not found');
|
|
22
|
+
}
|
|
23
|
+
else if (res) {
|
|
24
|
+
this.setTaxonomy(res);
|
|
25
|
+
if ((res === null || res === void 0 ? void 0 : res.post_type) === 'ikea_product') {
|
|
26
|
+
this.product = res;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async componentWillLoad() {
|
|
31
|
+
state.business = this.business;
|
|
32
|
+
const cart = window.sessionStorage.getItem(`hemfixarna-${this.business}-cart`);
|
|
33
|
+
if (cart) {
|
|
34
|
+
state.cart = JSON.parse(cart);
|
|
35
|
+
}
|
|
36
|
+
const user = window.sessionStorage.getItem(`hemfixarna-${this.business}-user`);
|
|
37
|
+
if (user) {
|
|
38
|
+
state.user = JSON.parse(user);
|
|
39
|
+
}
|
|
40
|
+
const tree = await getTaxonomy(this.topCategory);
|
|
41
|
+
if ((tree === null || tree === void 0 ? void 0 : tree.code) === 'not_found') {
|
|
42
|
+
console.warn('tree not found');
|
|
43
|
+
}
|
|
44
|
+
else if (tree) {
|
|
45
|
+
this.tree = tree;
|
|
46
|
+
}
|
|
47
|
+
if (this.slug) {
|
|
48
|
+
const res = await getTaxonomy(this.slug);
|
|
49
|
+
if ((res === null || res === void 0 ? void 0 : res.code) === 'not_found') {
|
|
50
|
+
console.log('taxonomy not found');
|
|
51
|
+
}
|
|
52
|
+
else if (res) {
|
|
53
|
+
this.setTaxonomy(res);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const options = await getOptions();
|
|
57
|
+
state.options = options;
|
|
58
|
+
}
|
|
59
|
+
setTaxonomy(taxonomy) {
|
|
60
|
+
if (taxonomy) {
|
|
61
|
+
if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.taxonomy) === 'service_cat') {
|
|
62
|
+
state.selectedCategory = taxonomy;
|
|
63
|
+
state.step = 2;
|
|
64
|
+
}
|
|
65
|
+
else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'service') {
|
|
66
|
+
state.selectedService = taxonomy;
|
|
67
|
+
state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === taxonomy.ID));
|
|
68
|
+
state.step = 3;
|
|
69
|
+
}
|
|
70
|
+
else if ((taxonomy === null || taxonomy === void 0 ? void 0 : taxonomy.post_type) === 'ikea_product') {
|
|
71
|
+
state.selectedProduct = taxonomy;
|
|
72
|
+
state.selectedService = this.tree.sub_cats
|
|
73
|
+
.map(c => c.services)
|
|
74
|
+
.flat()
|
|
75
|
+
.find(s => s.products.find(p => p.ID === state.selectedProduct.ID));
|
|
76
|
+
state.selectedCategory = this.tree.sub_cats.find(c => c.services.find(s => s.ID === state.selectedService.ID));
|
|
77
|
+
state.step = 4;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// Open close modal && click outside event
|
|
82
|
+
openModal() {
|
|
83
|
+
this.modal = true;
|
|
84
|
+
setTimeout(() => {
|
|
85
|
+
this.showModal = true;
|
|
86
|
+
}, 50);
|
|
87
|
+
}
|
|
88
|
+
closeModal() {
|
|
89
|
+
this.showModal = false;
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
this.modal = false;
|
|
92
|
+
}, 200);
|
|
93
|
+
}
|
|
94
|
+
handleClick(e) {
|
|
95
|
+
const el = this.el.shadowRoot.querySelector('.hemfixarna_modal');
|
|
96
|
+
if (el) {
|
|
97
|
+
const isClickInside = el.contains(e.composedPath()[0]);
|
|
98
|
+
if (!isClickInside) {
|
|
99
|
+
this.closeModal();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const infomodal = this.el.shadowRoot.querySelector('.hemfixarna_infomodal');
|
|
103
|
+
if (infomodal) {
|
|
104
|
+
const isClickInside = infomodal.contains(e.composedPath()[0]);
|
|
105
|
+
if (!isClickInside) {
|
|
106
|
+
state.modal = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getCartLength() {
|
|
111
|
+
return state.cart.reduce((acc, curr) => acc + curr.amount, 0);
|
|
112
|
+
}
|
|
113
|
+
render() {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
const logo = getAssetPath(`./assets/hemfixarna.svg`);
|
|
116
|
+
return (h("div", { class: "hemfixarna" }, h("div", { class: "hemfixarna_box" }, h("div", null, h("div", null, h("p", null, ((_a = this.product) === null || _a === void 0 ? void 0 : _a.post_title) || (h("span", null, "Montering/Installation p\u00E5 plats - ", h("strong", null, "se priser h\u00E4r"))), this.product && ((_b = this.slug) === null || _b === void 0 ? void 0 : _b.includes('product')) ? (h("span", null, ' från', " ", h("strong", null, getProductPriceWithRotAndRut(this.product), "kr"))) : null)), h("img", { src: logo, width: 104 })), h("button", { onClick: () => this.openModal(), class: "hemfixarna_btn" }, "Till montering", this.getCartLength() > 0 && h("span", null, this.getCartLength()))), this.modal && (h("div", null, h("div", { class: `hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}` }, state.modal && (h("div", { class: "hemfixarna_infomodal" }, h("h2", null, state.modal.title), state.modal.text.map((t) => (h("p", null, t))), h("div", null, h("button", { onClick: () => (state.modal = null) }, "St\u00E4ng")))), this.tree && h("hemfixarna-breadcrumbs", { closeModal: () => this.closeModal(), tree: this.tree }), 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_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}` })))));
|
|
117
|
+
}
|
|
118
|
+
static get is() { return "hemfixarna-component"; }
|
|
119
|
+
static get encapsulation() { return "shadow"; }
|
|
120
|
+
static get originalStyleUrls() {
|
|
121
|
+
return {
|
|
122
|
+
"$": ["hemfixarna.scss"]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
static get styleUrls() {
|
|
126
|
+
return {
|
|
127
|
+
"$": ["hemfixarna.css"]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
static get assetsDirs() { return ["assets"]; }
|
|
131
|
+
static get properties() {
|
|
132
|
+
return {
|
|
133
|
+
"slug": {
|
|
134
|
+
"type": "string",
|
|
135
|
+
"mutable": false,
|
|
136
|
+
"complexType": {
|
|
137
|
+
"original": "string",
|
|
138
|
+
"resolved": "string",
|
|
139
|
+
"references": {}
|
|
140
|
+
},
|
|
141
|
+
"required": false,
|
|
142
|
+
"optional": false,
|
|
143
|
+
"docs": {
|
|
144
|
+
"tags": [],
|
|
145
|
+
"text": ""
|
|
146
|
+
},
|
|
147
|
+
"attribute": "slug",
|
|
148
|
+
"reflect": false
|
|
149
|
+
},
|
|
150
|
+
"business": {
|
|
151
|
+
"type": "string",
|
|
152
|
+
"mutable": false,
|
|
153
|
+
"complexType": {
|
|
154
|
+
"original": "Business",
|
|
155
|
+
"resolved": "Business",
|
|
156
|
+
"references": {
|
|
157
|
+
"Business": {
|
|
158
|
+
"location": "import",
|
|
159
|
+
"path": "../../types"
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"required": false,
|
|
164
|
+
"optional": false,
|
|
165
|
+
"docs": {
|
|
166
|
+
"tags": [],
|
|
167
|
+
"text": ""
|
|
168
|
+
},
|
|
169
|
+
"attribute": "business",
|
|
170
|
+
"reflect": false
|
|
171
|
+
},
|
|
172
|
+
"topCategory": {
|
|
173
|
+
"type": "string",
|
|
174
|
+
"mutable": false,
|
|
175
|
+
"complexType": {
|
|
176
|
+
"original": "TopCategory",
|
|
177
|
+
"resolved": "TopCategory",
|
|
178
|
+
"references": {
|
|
179
|
+
"TopCategory": {
|
|
180
|
+
"location": "import",
|
|
181
|
+
"path": "../../types"
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
"required": false,
|
|
186
|
+
"optional": false,
|
|
187
|
+
"docs": {
|
|
188
|
+
"tags": [],
|
|
189
|
+
"text": ""
|
|
190
|
+
},
|
|
191
|
+
"attribute": "top-category",
|
|
192
|
+
"reflect": false
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
static get states() {
|
|
197
|
+
return {
|
|
198
|
+
"modal": {},
|
|
199
|
+
"showModal": {},
|
|
200
|
+
"tree": {},
|
|
201
|
+
"product": {}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
static get elementRef() { return "el"; }
|
|
205
|
+
static get watchers() {
|
|
206
|
+
return [{
|
|
207
|
+
"propName": "slug",
|
|
208
|
+
"methodName": "fetchNewTaxonomy"
|
|
209
|
+
}];
|
|
210
|
+
}
|
|
211
|
+
static get listeners() {
|
|
212
|
+
return [{
|
|
213
|
+
"name": "click",
|
|
214
|
+
"method": "handleClick",
|
|
215
|
+
"target": undefined,
|
|
216
|
+
"capture": false,
|
|
217
|
+
"passive": false
|
|
218
|
+
}];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=hemfixarna-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hemfixarna-component.js","sour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AI,EAAE,IAAI,CAAC,IAAI,GAAI;UAC9F,WAAK,KAAK,EAAE,0CAA0C,KAAK,CAAC,IAAI,EAAE;YAE/D,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,IAAI,IAAI,wBAAkB,IAAI,EAAE,IAAI,CAAC,IAAI,GAAI;YAEtE,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,gBAAgB,IAAI,8BAAuB;YAErE,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,eAAe,IAAI,6BAAsB;YAEnE,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,CACF;QACN,WAAK,KAAK,EAAE,uBAAuB,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,EAAE,GAAQ,CAC1F,CACP,CACG,CACP,CAAC;EACJ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CACF","sourcesContent":["import { Component, Prop, getAssetPath, h, State, Listen, Element, Watch } from '@stencil/core';\nimport { Business, Category, Product, Service, TopCategory } from '../../types';\nimport state from '../../store';\nimport { getTaxonomy, getOptions } from '../../utils/api';\nimport { getProductPriceWithRotAndRut } from '../../utils/calc';\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\n @Element() private el: HTMLElement;\n\n @Prop() slug: string;\n @Prop() business: Business;\n @Prop() topCategory: TopCategory;\n\n @Watch('slug')\n async fetchNewTaxonomy(newValue: string) {\n state.selectedCategory = null;\n state.selectedProduct = null;\n state.selectedService = null;\n\n const res = await getTaxonomy(newValue);\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 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 tree = await getTaxonomy(this.topCategory);\n if (tree?.code === 'not_found') {\n console.warn('tree not found');\n } else if (tree) {\n this.tree = tree;\n }\n if (this.slug) {\n const res = await getTaxonomy(this.slug);\n if (res?.code === 'not_found') {\n console.log('taxonomy not found');\n } else if (res) {\n this.setTaxonomy(res);\n }\n }\n const options = await getOptions();\n state.options = options;\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 }\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 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\n return (\n <div class=\"hemfixarna\">\n <div class=\"hemfixarna_box\">\n <div>\n <div>\n <p>\n {this.product?.post_title || (\n <span>\n Montering/Installation på plats - <strong>se priser här</strong>\n </span>\n )}\n {this.product && this.slug?.includes('product') ? (\n <span>\n {' från'} <strong>{getProductPriceWithRotAndRut(this.product)}kr</strong>\n </span>\n ) : null}\n </p>\n </div>\n <img src={logo} width={104} />\n </div>\n <button onClick={() => this.openModal()} class=\"hemfixarna_btn\">\n Till montering\n {this.getCartLength() > 0 && <span>{this.getCartLength()}</span>}\n </button>\n </div>\n {this.modal && (\n <div>\n <div class={`hemfixarna_modal ${this.showModal ? 'hemfixarna_modal--open' : ''}`}>\n {state.modal && (\n <div class=\"hemfixarna_infomodal\">\n <h2>{state.modal.title}</h2>\n {state.modal.text.map((t: string) => (\n <p>{t}</p>\n ))}\n <div>\n <button onClick={() => (state.modal = null)}>Stäng</button>\n </div>\n </div>\n )}\n {this.tree && <hemfixarna-breadcrumbs closeModal={() => this.closeModal()} tree={this.tree} />}\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 </div>\n <div class={`hemfixarna_backdrop ${this.showModal ? 'hemfixarna_backdrop--open' : ''}`}></div>\n </div>\n )}\n </div>\n );\n }\n}\n"]}
|