@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.
Files changed (28) hide show
  1. package/dist/cjs/{index-69084b4e.js → index-4700898c.js} +2 -2
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/salla-button_35.cjs.entry.js +78 -62
  4. package/dist/cjs/twilight.cjs.js +2 -2
  5. package/dist/collection/components/salla-quick-order/salla-quick-order.js +96 -85
  6. package/dist/collection/components/salla-scopes/salla-scopes.js +1 -0
  7. package/dist/components/index.js +2 -2
  8. package/dist/components/salla-quick-order.js +87 -72
  9. package/dist/components/salla-scopes.js +1 -0
  10. package/dist/esm/{index-841c6a09.js → index-55e33cdf.js} +2 -2
  11. package/dist/esm/loader.js +2 -2
  12. package/dist/esm/salla-button_35.entry.js +78 -62
  13. package/dist/esm/twilight.js +2 -2
  14. package/dist/esm-es5/index-55e33cdf.js +24 -0
  15. package/dist/esm-es5/loader.js +1 -1
  16. package/dist/esm-es5/salla-button_35.entry.js +1 -1
  17. package/dist/esm-es5/twilight.js +1 -1
  18. package/dist/twilight/p-0cf11465.system.js +4 -0
  19. package/dist/twilight/{p-8964c442.entry.js → p-47e524d6.entry.js} +1 -1
  20. package/dist/twilight/{p-add0b2aa.system.js → p-6b7896e1.system.js} +2 -2
  21. package/dist/twilight/{p-ff6cc430.system.entry.js → p-e317afc2.system.entry.js} +1 -1
  22. package/dist/twilight/{p-ed8fa851.js → p-f286c803.js} +1 -1
  23. package/dist/twilight/twilight.esm.js +1 -1
  24. package/dist/twilight/twilight.js +1 -1
  25. package/dist/types/components/salla-quick-order/salla-quick-order.d.ts +4 -2
  26. package/package.json +3 -3
  27. package/dist/esm-es5/index-841c6a09.js +0 -24
  28. 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 = 'title';
11
+ this.quickOrderTitle = 'ليش تنتظر؟';
12
12
  /**
13
13
  * quick order sub title
14
14
  */
15
- this.subTitle = 'sub title';
15
+ this.subTitle = 'احصل على المنتج مباشرة الآن';
16
16
  /**
17
17
  * quick order pay button text
18
18
  */
19
- this.payButtonTitle = 'Pay';
19
+ this.payButtonTitle = 'اطلب المنتج';
20
20
  /**
21
21
  * quick order confirm pay button text
22
22
  */
23
- this.confirmPayButtonTitle = 'Pay';
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
- async fetchQuickCheckout() {
65
- let res = await salla.api.cart.getQuickCheckoutSetting();
66
- this.quickOrderTitle = res.title;
67
- this.subTitle = res.sub_title;
68
- this.payButtonTitle = res.order_now_button;
69
- this.isEmailRequired = res.is_email_required;
70
- this.isTermsRequired = res.show_agreement;
71
- this.agreementText = res.agreement;
72
- this.confirmPayButtonTitle = res.confirm_button;
73
- this.thanksMessage = res.thanks_message;
74
- this.quickOrderStyle = res.style;
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
- const emailValue = this.emailInput.value;
78
- const nameValue = this.nameInput.value;
79
- const phoneValue = (await this.phoneInput.getValues()).phone;
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.oneClick) {
87
- let isValid = true;
88
- this.nameInput.classList.remove(inputErrorClass);
89
- this.emailInput.classList.remove(inputErrorClass);
90
- this.phoneInput.classList.remove(inputErrorClass);
91
- // terms check
92
- if (this.termsInput && this.isTermsRequired && !this.termsChecked) {
93
- this.termsInput.classList.add(inputErrorClass);
94
- isValid = false;
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 === '' || !/\S+@\S+\.\S+/.test(emailValue))) {
98
- this.emailInput.classList.add(inputErrorClass);
99
- isValid = false;
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 === '' || !/^\d+$/.test(phoneValue)) {
103
- this.phoneInput.classList.add(inputErrorClass);
104
- isValid = false;
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 === '' || nameValue.length < 10) {
108
- this.nameInput.classList.add(inputErrorClass);
109
- isValid = false;
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
- let res = await salla.api.cart.createQuickCheckout({
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
- countryCode: this.countryCode,
119
- full_name: nameValue,
120
- terms: this.termsChecked,
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
- return agreement_text.length > length
132
- ? agreement_text.substring(0, length) + '...'
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
- this.termsChecked = this.termsInput.checked;
154
- }, ref: el => (this.termsInput = el), type: "checkbox", checked: !this.isGuest }),
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", null, this.agreementText)),
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": true,
189
- "defaultValue": "'title'"
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": true,
207
- "defaultValue": "'sub title'"
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": true,
225
- "defaultValue": "'Pay'"
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": true,
243
- "defaultValue": "'Pay'"
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": true,
261
- "defaultValue": "salla.lang.get(\n 'pages.checkout.show_full_agreement'\n )"
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": true,
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": true
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": true
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": true,
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([]);