Skip to content

Commit 58fcc5a

Browse files
authored
Merge pull request #1617 from sacr3dc0w/swal9
SweetAlert2 v6.11.5 -> 9.5.4
2 parents 5b623e6 + 1fd8001 commit 58fcc5a

File tree

7 files changed

+258
-243
lines changed

7 files changed

+258
-243
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Draft
4+
- Update sweetalert2 library to latest version [#1617](https://github.com/bigcommerce/cornerstone/pull/1617)
45
- Allow alert text color editing from theme editor and update default alert text color for Bold variation [#1565](https://github.com/bigcommerce/cornerstone/pull/1565)
56
- Add jquery-migrate to Modal test [#1599](https://github.com/bigcommerce/cornerstone/pull/1599)
67
- Upgrade core-js to version 3 [#1598](https://github.com/bigcommerce/cornerstone/pull/1598)

assets/js/theme/account.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ export default class Account extends PageManager {
121121

122122
if (!submitForm) {
123123
event.preventDefault();
124-
swal({
124+
swal.fire({
125125
text: this.context.selectItem,
126-
type: 'error',
126+
icon: 'error',
127127
});
128128
}
129129
});
@@ -198,9 +198,9 @@ export default class Account extends PageManager {
198198
return true;
199199
}
200200

201-
swal({
201+
swal.fire({
202202
text: errorMessage,
203-
type: 'error',
203+
icon: 'error',
204204
});
205205

206206
return event.preventDefault();
@@ -299,9 +299,9 @@ export default class Account extends PageManager {
299299
storeInstrument(this.context, data, () => {
300300
window.location.href = this.context.paymentMethodsUrl;
301301
}, () => {
302-
swal({
302+
swal.fire({
303303
text: this.context.generic_error,
304-
type: 'error',
304+
icon: 'error',
305305
});
306306
});
307307
}

assets/js/theme/cart.js

+33-31
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ export default class Cart extends PageManager {
2828
const newQty = $target.data('action') === 'inc' ? oldQty + 1 : oldQty - 1;
2929
// Does not quality for min/max quantity
3030
if (newQty < minQty) {
31-
return swal({
31+
return swal.fire({
3232
text: minError,
33-
type: 'error',
33+
icon: 'error',
3434
});
3535
} else if (maxQty > 0 && newQty > maxQty) {
36-
return swal({
36+
return swal.fire({
3737
text: maxError,
38-
type: 'error',
38+
icon: 'error',
3939
});
4040
}
4141

@@ -51,9 +51,9 @@ export default class Cart extends PageManager {
5151
this.refreshContent(remove);
5252
} else {
5353
$el.val(oldQty);
54-
swal({
54+
swal.fire({
5555
text: response.data.errors.join('\n'),
56-
type: 'error',
56+
icon: 'error',
5757
});
5858
}
5959
});
@@ -74,21 +74,21 @@ export default class Cart extends PageManager {
7474
if (!newQty) {
7575
invalidEntry = $el.val();
7676
$el.val(oldQty);
77-
return swal({
77+
return swal.fire({
7878
text: `${invalidEntry} is not a valid entry`,
79-
type: 'error',
79+
icon: 'error',
8080
});
8181
} else if (newQty < minQty) {
8282
$el.val(oldQty);
83-
return swal({
83+
return swal.fire({
8484
text: minError,
85-
type: 'error',
85+
icon: 'error',
8686
});
8787
} else if (maxQty > 0 && newQty > maxQty) {
8888
$el.val(oldQty);
89-
return swal({
89+
return swal.fire({
9090
text: maxError,
91-
type: 'error',
91+
icon: 'error',
9292
});
9393
}
9494

@@ -103,9 +103,9 @@ export default class Cart extends PageManager {
103103
this.refreshContent(remove);
104104
} else {
105105
$el.val(oldQty);
106-
swal({
106+
swal.fire({
107107
text: response.data.errors.join('\n'),
108-
type: 'error',
108+
icon: 'error',
109109
});
110110
}
111111
});
@@ -117,9 +117,9 @@ export default class Cart extends PageManager {
117117
if (response.data.status === 'succeed') {
118118
this.refreshContent(true);
119119
} else {
120-
swal({
120+
swal.fire({
121121
text: response.data.errors.join('\n'),
122-
type: 'error',
122+
icon: 'error',
123123
});
124124
}
125125
});
@@ -150,9 +150,9 @@ export default class Cart extends PageManager {
150150
const data = result.data || {};
151151

152152
if (err) {
153-
swal({
153+
swal.fire({
154154
text: err,
155-
type: 'error',
155+
icon: 'error',
156156
});
157157
return false;
158158
}
@@ -240,13 +240,15 @@ export default class Cart extends PageManager {
240240
$('.cart-remove', this.$cartContent).on('click', event => {
241241
const itemId = $(event.currentTarget).data('cartItemid');
242242
const string = $(event.currentTarget).data('confirmDelete');
243-
swal({
243+
swal.fire({
244244
text: string,
245-
type: 'warning',
245+
icon: 'warning',
246246
showCancelButton: true,
247-
}).then(() => {
248-
// remove item from cart
249-
cartRemoveItem(itemId);
247+
}).then((result) => {
248+
if (result.value) {
249+
// remove item from cart
250+
cartRemoveItem(itemId);
251+
}
250252
});
251253
event.preventDefault();
252254
});
@@ -289,19 +291,19 @@ export default class Cart extends PageManager {
289291

290292
// Empty code
291293
if (!code) {
292-
return swal({
294+
return swal.fire({
293295
text: $codeInput.data('error'),
294-
type: 'error',
296+
icon: 'error',
295297
});
296298
}
297299

298300
utils.api.cart.applyCode(code, (err, response) => {
299301
if (response.data.status === 'success') {
300302
this.refreshContent();
301303
} else {
302-
swal({
304+
swal.fire({
303305
text: response.data.errors.join('\n'),
304-
type: 'error',
306+
icon: 'error',
305307
});
306308
}
307309
});
@@ -333,19 +335,19 @@ export default class Cart extends PageManager {
333335
event.preventDefault();
334336

335337
if (!giftCertCheck(code)) {
336-
return swal({
338+
return swal.fire({
337339
text: $certInput.data('error'),
338-
type: 'error',
340+
icon: 'error',
339341
});
340342
}
341343

342344
utils.api.cart.applyGiftCertificate(code, (err, resp) => {
343345
if (resp.data.status === 'success') {
344346
this.refreshContent();
345347
} else {
346-
swal({
348+
swal.fire({
347349
text: resp.data.errors.join('\n'),
348-
type: 'error',
350+
icon: 'error',
349351
});
350352
}
351353
});

assets/js/theme/cart/shipping-estimator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ export default class ShippingEstimator {
100100
// Requests the states for a country with AJAX
101101
stateCountry(this.$state, this.context, { useIdForStates: true }, (err, field) => {
102102
if (err) {
103-
swal({
103+
swal.fire({
104104
text: err,
105-
type: 'error',
105+
icon: 'error',
106106
});
107107

108108
throw new Error(err);

assets/js/theme/global/sweet-alert.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
import 'weakmap-polyfill';
12
import sweetAlert from 'sweetalert2';
23

4+
// WeakMap will defined in the global scope if native WeakMap is not supported.
5+
const weakMap = new WeakMap(); // eslint-disable-line no-unused-vars
6+
37
// Set defaults for sweetalert2 popup boxes
4-
sweetAlert.setDefaults({
8+
const Swal = sweetAlert.mixin({
59
buttonsStyling: false,
6-
confirmButtonClass: 'button',
7-
cancelButtonClass: 'button',
10+
customClass: {
11+
confirmButton: 'button',
12+
cancelButton: 'button',
13+
},
814
});
915

1016
// Re-export
11-
export default sweetAlert;
17+
export default Swal;

0 commit comments

Comments
 (0)