@salla.sa/twilight-components 2.9.45 → 2.9.46
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/{index-69084b4e.js → index-4700898c.js} +2 -2
- package/dist/cjs/loader.cjs.js +2 -2
- package/dist/cjs/salla-button_35.cjs.entry.js +78 -62
- package/dist/cjs/twilight.cjs.js +2 -2
- package/dist/collection/components/salla-quick-order/salla-quick-order.js +96 -85
- package/dist/collection/components/salla-scopes/salla-scopes.js +1 -0
- package/dist/components/index.js +2 -2
- package/dist/components/salla-quick-order.js +87 -72
- package/dist/components/salla-scopes.js +1 -0
- package/dist/esm/{index-841c6a09.js → index-55e33cdf.js} +2 -2
- package/dist/esm/loader.js +2 -2
- package/dist/esm/salla-button_35.entry.js +78 -62
- package/dist/esm/twilight.js +2 -2
- package/dist/esm-es5/index-55e33cdf.js +24 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/esm-es5/salla-button_35.entry.js +1 -1
- package/dist/esm-es5/twilight.js +1 -1
- package/dist/twilight/p-0cf11465.system.js +4 -0
- package/dist/twilight/{p-8964c442.entry.js → p-47e524d6.entry.js} +1 -1
- package/dist/twilight/{p-add0b2aa.system.js → p-6b7896e1.system.js} +2 -2
- package/dist/twilight/{p-ff6cc430.system.entry.js → p-e317afc2.system.entry.js} +1 -1
- package/dist/twilight/{p-ed8fa851.js → p-f286c803.js} +1 -1
- package/dist/twilight/twilight.esm.js +1 -1
- package/dist/twilight/twilight.js +1 -1
- package/dist/types/components/salla-quick-order/salla-quick-order.d.ts +4 -2
- package/package.json +3 -3
- package/dist/esm-es5/index-841c6a09.js +0 -24
- package/dist/twilight/p-abaef410.system.js +0 -4
|
@@ -8,19 +8,19 @@ export class SallaQuickOrder {
|
|
|
8
8
|
/**
|
|
9
9
|
* quick order title
|
|
10
10
|
*/
|
|
11
|
-
this.quickOrderTitle = '
|
|
11
|
+
this.quickOrderTitle = 'ليش تنتظر؟';
|
|
12
12
|
/**
|
|
13
13
|
* quick order sub title
|
|
14
14
|
*/
|
|
15
|
-
this.subTitle = '
|
|
15
|
+
this.subTitle = 'احصل على المنتج مباشرة الآن';
|
|
16
16
|
/**
|
|
17
17
|
* quick order pay button text
|
|
18
18
|
*/
|
|
19
|
-
this.payButtonTitle = '
|
|
19
|
+
this.payButtonTitle = 'اطلب المنتج';
|
|
20
20
|
/**
|
|
21
21
|
* quick order confirm pay button text
|
|
22
22
|
*/
|
|
23
|
-
this.confirmPayButtonTitle = '
|
|
23
|
+
this.confirmPayButtonTitle = 'اشتر الآن';
|
|
24
24
|
/**
|
|
25
25
|
* agreement text from server or from props
|
|
26
26
|
*/
|
|
@@ -33,10 +33,7 @@ export class SallaQuickOrder {
|
|
|
33
33
|
* Quick Order Style
|
|
34
34
|
*/
|
|
35
35
|
this.quickOrderStyle = 'default';
|
|
36
|
-
|
|
37
|
-
* states
|
|
38
|
-
*/
|
|
39
|
-
this.isGuest = true;
|
|
36
|
+
this.isAvailable = false;
|
|
40
37
|
this.oneClick = false;
|
|
41
38
|
this.expanded = false;
|
|
42
39
|
this.isTermsRequired = false;
|
|
@@ -48,7 +45,6 @@ export class SallaQuickOrder {
|
|
|
48
45
|
this.agreementModalHead = salla.lang.get('pages.checkout.full_agreement');
|
|
49
46
|
this.userNameLabel = salla.lang.get('pages.products.your_name');
|
|
50
47
|
this.termsChecked = false;
|
|
51
|
-
this.isGuest = Salla.config.isGuest();
|
|
52
48
|
this.productId = this.productId || salla.config.get('page.id');
|
|
53
49
|
this.user = salla.config.get('user') || salla.storage.get('user') || {};
|
|
54
50
|
this.countryCode = this.user.country_code || this.countryCode;
|
|
@@ -58,81 +54,101 @@ export class SallaQuickOrder {
|
|
|
58
54
|
this.agreementShowText = salla.lang.get('pages.checkout.show_full_agreement');
|
|
59
55
|
this.agreementModalHead = salla.lang.get('pages.checkout.full_agreement');
|
|
60
56
|
this.userNameLabel = salla.lang.get('pages.products.your_name');
|
|
61
|
-
this.fetchQuickCheckout();
|
|
62
57
|
});
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
fetchQuickCheckout() {
|
|
60
|
+
return salla.api.withoutNotifier(() => salla.api.cart.getQuickCheckoutSettings()
|
|
61
|
+
.then((res) => {
|
|
62
|
+
this.isAvailable = true;
|
|
63
|
+
this.quickOrderTitle = res.data.title;
|
|
64
|
+
this.subTitle = res.data.sub_title;
|
|
65
|
+
this.payButtonTitle = res.data.order_now_button;
|
|
66
|
+
this.isEmailRequired = res.data.is_email_required;
|
|
67
|
+
this.isTermsRequired = res.data.show_agreement;
|
|
68
|
+
this.agreementText = res.data.agreement;
|
|
69
|
+
this.confirmPayButtonTitle = res.data.confirm_button;
|
|
70
|
+
this.thanksMessage = res.data.thanks_message;
|
|
71
|
+
this.quickOrderStyle = res.data.style;
|
|
72
|
+
}));
|
|
75
73
|
}
|
|
76
74
|
async submit() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
return this.getPayload()
|
|
76
|
+
.then((payload) => salla.api.cart.createQuickCheckout(payload))
|
|
77
|
+
.then(() => {
|
|
78
|
+
this.successfullModal.open();
|
|
79
|
+
this.quickOrderSubmited.emit();
|
|
80
|
+
})
|
|
81
|
+
.catch(error => error && console.error(error));
|
|
82
|
+
}
|
|
83
|
+
async getPayload() {
|
|
84
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
85
|
+
let errors = [];
|
|
80
86
|
const inputErrorClass = 's-has-error';
|
|
81
87
|
// if it's not guest get the email from user
|
|
82
88
|
if (this.user)
|
|
83
89
|
this.isEmailRequired = this.user.email ? false : this.isEmailRequired;
|
|
84
90
|
// check if one click is available
|
|
85
91
|
this.oneClick = !this.isTermsRequired && !this.isEmailRequired;
|
|
86
|
-
if (!this.
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
if (this.isTermsRequired && !this.termsChecked) {
|
|
93
|
+
this.termsInput.classList.add(inputErrorClass);
|
|
94
|
+
errors.push('Terms should be agreed.');
|
|
95
|
+
}
|
|
96
|
+
const emailValue = (_a = this.emailInput) === null || _a === void 0 ? void 0 : _a.value;
|
|
97
|
+
const nameValue = (_b = this.nameInput) === null || _b === void 0 ? void 0 : _b.value;
|
|
98
|
+
const phone = (await ((_c = this.phoneInput) === null || _c === void 0 ? void 0 : _c.getValues()));
|
|
99
|
+
const country_code = (phone === null || phone === void 0 ? void 0 : phone.countryCode) || this.countryCode;
|
|
100
|
+
const phoneValue = phone === null || phone === void 0 ? void 0 : phone.phone;
|
|
101
|
+
if (salla.config.isGuest()) {
|
|
102
|
+
(_d = this.nameInput) === null || _d === void 0 ? void 0 : _d.classList.remove(inputErrorClass);
|
|
103
|
+
(_e = this.emailInput) === null || _e === void 0 ? void 0 : _e.classList.remove(inputErrorClass);
|
|
104
|
+
(_f = this.phoneInput) === null || _f === void 0 ? void 0 : _f.classList.remove(inputErrorClass);
|
|
96
105
|
// email check
|
|
97
|
-
if (this.isEmailRequired && (emailValue
|
|
98
|
-
this.emailInput.classList.add(inputErrorClass);
|
|
99
|
-
|
|
106
|
+
if (this.isEmailRequired && (!emailValue || !/\S+@\S+\.\S+/.test(emailValue))) {
|
|
107
|
+
(_g = this.emailInput) === null || _g === void 0 ? void 0 : _g.classList.add(inputErrorClass);
|
|
108
|
+
errors.push('Correct email is required.');
|
|
100
109
|
}
|
|
101
110
|
// phone check
|
|
102
|
-
if (phoneValue
|
|
103
|
-
this.phoneInput.classList.add(inputErrorClass);
|
|
104
|
-
|
|
111
|
+
if (!phoneValue || !/^\d+$/.test(phoneValue)) {
|
|
112
|
+
(_h = this.phoneInput) === null || _h === void 0 ? void 0 : _h.classList.add(inputErrorClass);
|
|
113
|
+
errors.push('Correct phone is required.');
|
|
105
114
|
}
|
|
106
115
|
// name check
|
|
107
|
-
if (nameValue
|
|
108
|
-
this.nameInput.classList.add(inputErrorClass);
|
|
109
|
-
|
|
116
|
+
if (!nameValue || nameValue.length < 3) {
|
|
117
|
+
(_j = this.nameInput) === null || _j === void 0 ? void 0 : _j.classList.add(inputErrorClass);
|
|
118
|
+
errors.push('Name with at least 3 chars is required.');
|
|
110
119
|
}
|
|
111
|
-
if (!isValid)
|
|
112
|
-
return;
|
|
113
120
|
}
|
|
114
|
-
|
|
121
|
+
else if (errors.length == 0) { // user is logged-in && agreement is checked if is required
|
|
122
|
+
return {
|
|
123
|
+
product_ids: [this.productId],
|
|
124
|
+
agreement: this.termsChecked,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
if (errors.length) {
|
|
128
|
+
errors.forEach(error => console.error(error));
|
|
129
|
+
throw 'Validation failed.';
|
|
130
|
+
}
|
|
131
|
+
return {
|
|
115
132
|
product_ids: [this.productId],
|
|
116
133
|
email: emailValue,
|
|
117
134
|
phone: phoneValue,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
if (res.status == 'success') {
|
|
123
|
-
this.successfullModal.open();
|
|
124
|
-
// emit
|
|
125
|
-
this.quickOrderSubmited.emit();
|
|
126
|
-
}
|
|
135
|
+
country_code: country_code,
|
|
136
|
+
name: nameValue,
|
|
137
|
+
agreement: this.termsChecked,
|
|
138
|
+
};
|
|
127
139
|
}
|
|
128
140
|
formatAgreementText(agreement_text, length) {
|
|
129
141
|
if (!agreement_text)
|
|
130
142
|
return '';
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
let text = (new DOMParser()).parseFromString(agreement_text, 'text/html').documentElement.innerText;
|
|
144
|
+
return text.length > length
|
|
145
|
+
? text.substring(0, length) + '...'
|
|
133
146
|
: agreement_text;
|
|
134
147
|
}
|
|
135
148
|
render() {
|
|
149
|
+
if (!this.isAvailable) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
136
152
|
return (h(Host, { class: "s-quick-order" },
|
|
137
153
|
h("div", { class: 's-quick-order-container ' + this.quickOrderStyle },
|
|
138
154
|
h("div", { class: "s-quick-order-button-cont" },
|
|
@@ -145,23 +161,18 @@ export class SallaQuickOrder {
|
|
|
145
161
|
this.expanded = !this.expanded;
|
|
146
162
|
}, color: "primary" }, this.oneClick ? (this.confirmPayButtonTitle) : this.expanded ? (h("i", { innerHTML: HideIcon })) : (this.confirmPayButtonTitle))),
|
|
147
163
|
h("div", { class: 's-quick-order-expandable ' + (this.expanded ? 'show' : '') },
|
|
148
|
-
h("input", { type: "text", value: this.user.name, placeholder: this.user.name || this.userNameLabel, ref: el => (this.nameInput = el) }),
|
|
149
|
-
h("salla-tel-input", { phone: this.user.mobile, ref: el => (this.phoneInput = el) }),
|
|
150
|
-
h("input", { type: "email", value: this.user.email, required: this.isEmailRequired, placeholder: this.placeHolderEmail + ' ' + (this.isEmailRequired ? '' : this.emailOptional), ref: el => (this.emailInput = el) }),
|
|
164
|
+
Salla.config.isGuest() && [h("input", { type: "text", value: this.user.name, placeholder: this.user.name || this.userNameLabel, ref: el => (this.nameInput = el) }), h("salla-tel-input", { phone: this.user.mobile, ref: el => (this.phoneInput = el) }), h("input", { type: "email", value: this.user.email, required: this.isEmailRequired, placeholder: this.placeHolderEmail + ' ' + (this.isEmailRequired ? '' : this.emailOptional), ref: el => (this.emailInput = el) })],
|
|
151
165
|
this.isTermsRequired && (h("div", { class: "s-quick-order-checkbox-container" },
|
|
152
|
-
h("input", { onChange: () =>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.agreementText && (h("div", null,
|
|
156
|
-
this.formatAgreementText(this.agreementText, 150),
|
|
157
|
-
this.agreementText && this.agreementText.length > 150 && (h("salla-button", { shape: "link", onClick: () => this.agreementModal.open() }, this.agreementShowText)))))),
|
|
158
|
-
h("salla-button", { color: "primary", width: "wide", onClick: () => {
|
|
159
|
-
this.submit();
|
|
160
|
-
} }, this.payButtonTitle)),
|
|
166
|
+
h("input", { onChange: () => this.termsChecked = this.termsInput.checked, ref: el => (this.termsInput = el), type: "checkbox" }),
|
|
167
|
+
this.agreementText && (h("div", { innerHTML: this.formatAgreementText(this.agreementText, 150) }, this.agreementText && this.agreementText.length > 150 && (h("salla-button", { shape: "link", onClick: () => this.agreementModal.open() }, this.agreementShowText)))))),
|
|
168
|
+
h("salla-button", { color: "primary", width: "wide", onClick: () => this.submit() }, this.payButtonTitle)),
|
|
161
169
|
h("salla-modal", { "modal-title": this.agreementModalHead, ref: modal => (this.agreementModal = modal) },
|
|
162
|
-
h("article",
|
|
170
|
+
h("article", { innerHTML: this.agreementText })),
|
|
163
171
|
this.thanksMessage && (h("salla-modal", { "icon-style": "primary", "modal-title": this.thanksMessage, "is-closable": "true", ref: modal => (this.successfullModal = modal) })))));
|
|
164
172
|
}
|
|
173
|
+
componentDidLoad() {
|
|
174
|
+
this.fetchQuickCheckout();
|
|
175
|
+
}
|
|
165
176
|
static get is() { return "salla-quick-order"; }
|
|
166
177
|
static get originalStyleUrls() { return {
|
|
167
178
|
"$": ["salla-quick-order.scss"]
|
|
@@ -185,8 +196,8 @@ export class SallaQuickOrder {
|
|
|
185
196
|
"text": "quick order title"
|
|
186
197
|
},
|
|
187
198
|
"attribute": "quick-order-title",
|
|
188
|
-
"reflect":
|
|
189
|
-
"defaultValue": "'
|
|
199
|
+
"reflect": false,
|
|
200
|
+
"defaultValue": "'\u0644\u064A\u0634 \u062A\u0646\u062A\u0638\u0631\u061F'"
|
|
190
201
|
},
|
|
191
202
|
"subTitle": {
|
|
192
203
|
"type": "string",
|
|
@@ -203,8 +214,8 @@ export class SallaQuickOrder {
|
|
|
203
214
|
"text": "quick order sub title"
|
|
204
215
|
},
|
|
205
216
|
"attribute": "sub-title",
|
|
206
|
-
"reflect":
|
|
207
|
-
"defaultValue": "'
|
|
217
|
+
"reflect": false,
|
|
218
|
+
"defaultValue": "'\u0627\u062D\u0635\u0644 \u0639\u0644\u0649 \u0627\u0644\u0645\u0646\u062A\u062C \u0645\u0628\u0627\u0634\u0631\u0629 \u0627\u0644\u0622\u0646'"
|
|
208
219
|
},
|
|
209
220
|
"payButtonTitle": {
|
|
210
221
|
"type": "string",
|
|
@@ -221,8 +232,8 @@ export class SallaQuickOrder {
|
|
|
221
232
|
"text": "quick order pay button text"
|
|
222
233
|
},
|
|
223
234
|
"attribute": "pay-button-title",
|
|
224
|
-
"reflect":
|
|
225
|
-
"defaultValue": "'
|
|
235
|
+
"reflect": false,
|
|
236
|
+
"defaultValue": "'\u0627\u0637\u0644\u0628 \u0627\u0644\u0645\u0646\u062A\u062C'"
|
|
226
237
|
},
|
|
227
238
|
"confirmPayButtonTitle": {
|
|
228
239
|
"type": "string",
|
|
@@ -239,8 +250,8 @@ export class SallaQuickOrder {
|
|
|
239
250
|
"text": "quick order confirm pay button text"
|
|
240
251
|
},
|
|
241
252
|
"attribute": "confirm-pay-button-title",
|
|
242
|
-
"reflect":
|
|
243
|
-
"defaultValue": "'
|
|
253
|
+
"reflect": false,
|
|
254
|
+
"defaultValue": "'\u0627\u0634\u062A\u0631 \u0627\u0644\u0622\u0646'"
|
|
244
255
|
},
|
|
245
256
|
"agreementText": {
|
|
246
257
|
"type": "string",
|
|
@@ -257,8 +268,8 @@ export class SallaQuickOrder {
|
|
|
257
268
|
"text": "agreement text from server or from props"
|
|
258
269
|
},
|
|
259
270
|
"attribute": "agreement-text",
|
|
260
|
-
"reflect":
|
|
261
|
-
"defaultValue": "salla.lang.get(
|
|
271
|
+
"reflect": false,
|
|
272
|
+
"defaultValue": "salla.lang.get('pages.checkout.show_full_agreement')"
|
|
262
273
|
},
|
|
263
274
|
"isEmailRequired": {
|
|
264
275
|
"type": "boolean",
|
|
@@ -275,7 +286,7 @@ export class SallaQuickOrder {
|
|
|
275
286
|
"text": "is email required"
|
|
276
287
|
},
|
|
277
288
|
"attribute": "is-email-required",
|
|
278
|
-
"reflect":
|
|
289
|
+
"reflect": false,
|
|
279
290
|
"defaultValue": "false"
|
|
280
291
|
},
|
|
281
292
|
"productId": {
|
|
@@ -293,7 +304,7 @@ export class SallaQuickOrder {
|
|
|
293
304
|
"text": "product id local or from page"
|
|
294
305
|
},
|
|
295
306
|
"attribute": "product-id",
|
|
296
|
-
"reflect":
|
|
307
|
+
"reflect": false
|
|
297
308
|
},
|
|
298
309
|
"thanksMessage": {
|
|
299
310
|
"type": "string",
|
|
@@ -310,7 +321,7 @@ export class SallaQuickOrder {
|
|
|
310
321
|
"text": "product id local or from page"
|
|
311
322
|
},
|
|
312
323
|
"attribute": "thanks-message",
|
|
313
|
-
"reflect":
|
|
324
|
+
"reflect": false
|
|
314
325
|
},
|
|
315
326
|
"quickOrderStyle": {
|
|
316
327
|
"type": "string",
|
|
@@ -327,13 +338,13 @@ export class SallaQuickOrder {
|
|
|
327
338
|
"text": "Quick Order Style"
|
|
328
339
|
},
|
|
329
340
|
"attribute": "quick-order-style",
|
|
330
|
-
"reflect":
|
|
341
|
+
"reflect": false,
|
|
331
342
|
"defaultValue": "'default'"
|
|
332
343
|
}
|
|
333
344
|
}; }
|
|
334
345
|
static get states() { return {
|
|
335
|
-
"isGuest": {},
|
|
336
346
|
"user": {},
|
|
347
|
+
"isAvailable": {},
|
|
337
348
|
"oneClick": {},
|
|
338
349
|
"expanded": {},
|
|
339
350
|
"isTermsRequired": {},
|
|
@@ -56,6 +56,7 @@ export class SallaScopees {
|
|
|
56
56
|
* Opens the scope modal.
|
|
57
57
|
*/
|
|
58
58
|
async open(mode = ModeType.DEFAULT, product_id = null) {
|
|
59
|
+
this.hasError = false;
|
|
59
60
|
this.mode = [ModeType.AVAILABILITY, ModeType.DEFAULT].includes(mode) ? mode : ModeType.DEFAULT;
|
|
60
61
|
this.loading = !this.loadedScopes[this.mode];
|
|
61
62
|
this.setScopeValues([]);
|