Skip to content

Commit

Permalink
fix(storefront): BCTHEME-1043 Remove sweetAlert
Browse files Browse the repository at this point in the history
  • Loading branch information
“bc-yevhenii-buliuk” committed Mar 29, 2022
1 parent 7093931 commit 761c270
Show file tree
Hide file tree
Showing 19 changed files with 234 additions and 292 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Draft
- Remove sweetAlert [#2189](https://github.com/bigcommerce/cornerstone/issues/2189)

## 6.3.0 (03-11-2022)
- Update blog component to use H1 tags on posts [#2179](https://github.com/bigcommerce/cornerstone/issues/2179)
Expand Down
20 changes: 7 additions & 13 deletions assets/js/theme/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from './common/utils/form-utils';
import { createTranslationDictionary } from './common/utils/translations-utils';
import { creditCardType, storeInstrument, Validators as CCValidators, Formatters as CCFormatters } from './common/payment-method';
import swal from './global/sweet-alert';
import { showAlertModal } from './global/modal';
import compareProducts from './global/compare-products';

export default class Account extends PageManager {
Expand Down Expand Up @@ -131,10 +131,9 @@ export default class Account extends PageManager {

if (!submitForm) {
event.preventDefault();
swal.fire({
text: this.context.selectItem,
icon: 'error',
});

const text = this.context.selectItem;
showAlertModal(text);
}
});
}
Expand Down Expand Up @@ -209,10 +208,7 @@ export default class Account extends PageManager {
return true;
}

swal.fire({
text: errorMessage,
icon: 'error',
});
showAlertModal(errorMessage);

return event.preventDefault();
});
Expand Down Expand Up @@ -313,10 +309,8 @@ export default class Account extends PageManager {
storeInstrument(this.context, data, () => {
window.location.href = this.context.paymentMethodsUrl;
}, () => {
swal.fire({
text: this.context.generic_error,
icon: 'error',
});
const text = this.context.generic_error;
showAlertModal(text);
});
}
});
Expand Down
88 changes: 28 additions & 60 deletions assets/js/theme/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import checkIsGiftCertValid from './common/gift-certificate-validator';
import { createTranslationDictionary } from './common/utils/translations-utils';
import utils from '@bigcommerce/stencil-utils';
import ShippingEstimator from './cart/shipping-estimator';
import { defaultModal, ModalEvents } from './global/modal';
import swal from './global/sweet-alert';
import { defaultModal, showAlertModal, ModalEvents } from './global/modal';
import CartItemDetails from './common/cart-item-details';

export default class Cart extends PageManager {
Expand Down Expand Up @@ -45,15 +44,9 @@ export default class Cart extends PageManager {
const newQty = $target.data('action') === 'inc' ? oldQty + 1 : oldQty - 1;
// Does not quality for min/max quantity
if (newQty < minQty) {
return swal.fire({
text: minError,
icon: 'error',
});
return showAlertModal(minError);
} else if (maxQty > 0 && newQty > maxQty) {
return swal.fire({
text: maxError,
icon: 'error',
});
return showAlertModal(maxError);
}

this.$overlay.show();
Expand All @@ -68,10 +61,9 @@ export default class Cart extends PageManager {
this.refreshContent(remove);
} else {
$el.val(oldQty);
swal.fire({
text: response.data.errors.join('\n'),
icon: 'error',
});

const text = response.data.errors.join('\n');
showAlertModal(text);
}
});
}
Expand All @@ -91,22 +83,15 @@ export default class Cart extends PageManager {
if (!newQty) {
invalidEntry = $el.val();
$el.val(oldQty);
return swal.fire({
text: this.context.invalidEntryMessage.replace('[ENTRY]', invalidEntry),
icon: 'error',
});

const text = this.context.invalidEntryMessage.replace('[ENTRY]', invalidEntry);
return showAlertModal(text);
} else if (newQty < minQty) {
$el.val(oldQty);
return swal.fire({
text: minError,
icon: 'error',
});
return showAlertModal(minError);
} else if (maxQty > 0 && newQty > maxQty) {
$el.val(oldQty);
return swal.fire({
text: maxError,
icon: 'error',
});
return showAlertModal(maxError);
}

this.$overlay.show();
Expand All @@ -120,10 +105,9 @@ export default class Cart extends PageManager {
this.refreshContent(remove);
} else {
$el.val(oldQty);
swal.fire({
text: response.data.errors.join('\n'),
icon: 'error',
});

const text = response.data.errors.join('\n');
return showAlertModal(text);
}
});
}
Expand All @@ -134,10 +118,8 @@ export default class Cart extends PageManager {
if (response.data.status === 'succeed') {
this.refreshContent(true);
} else {
swal.fire({
text: response.data.errors.join('\n'),
icon: 'error',
});
const text = response.data.errors.join('\n');
showAlertModal(text);
}
});
}
Expand Down Expand Up @@ -188,10 +170,7 @@ export default class Cart extends PageManager {
const data = result.data || {};

if (err) {
swal.fire({
text: err,
icon: 'error',
});
showAlertModal(err);
return false;
}

Expand Down Expand Up @@ -284,16 +263,13 @@ export default class Cart extends PageManager {
$('.cart-remove', this.$cartContent).on('click', event => {
const itemId = $(event.currentTarget).data('cartItemid');
const string = $(event.currentTarget).data('confirmDelete');
swal.fire({
text: string,
showAlertModal(string, {
icon: 'warning',
showCancelButton: true,
cancelButtonText: this.context.cancelButtonText,
}).then((result) => {
if (result.value) {
onConfirm: () => {
// remove item from cart
cartRemoveItem(itemId);
}
},
});
event.preventDefault();
});
Expand Down Expand Up @@ -336,20 +312,16 @@ export default class Cart extends PageManager {

// Empty code
if (!code) {
return swal.fire({
text: $codeInput.data('error'),
icon: 'error',
});
const text = $codeInput.data('error');
return showAlertModal(text);
}

utils.api.cart.applyCode(code, (err, response) => {
if (response.data.status === 'success') {
this.refreshContent();
} else {
swal.fire({
html: response.data.errors.join('\n'),
icon: 'error',
});
const text = response.data.errors.join('\n');
showAlertModal(text);
}
});
});
Expand Down Expand Up @@ -381,20 +353,16 @@ export default class Cart extends PageManager {

if (!checkIsGiftCertValid(code)) {
const validationDictionary = createTranslationDictionary(this.context);
return swal.fire({
text: validationDictionary.invalid_gift_certificate,
icon: 'error',
});
const text = validationDictionary.invalid_gift_certificate;
return showAlertModal(text);
}

utils.api.cart.applyGiftCertificate(code, (err, resp) => {
if (resp.data.status === 'success') {
this.refreshContent();
} else {
swal.fire({
html: resp.data.errors.join('\n'),
icon: 'error',
});
const text = resp.data.errors.join('\n');
showAlertModal(text);
}
});
});
Expand Down
8 changes: 2 additions & 6 deletions assets/js/theme/cart/shipping-estimator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import nod from '../common/nod';
import utils from '@bigcommerce/stencil-utils';
import { Validators, announceInputErrorMessage } from '../common/utils/form-utils';
import collapsibleFactory from '../common/collapsible';
import swal from '../global/sweet-alert';
import { showAlertModal } from '../global/modal';

export default class ShippingEstimator {
constructor($element, shippingErrorMessages) {
Expand Down Expand Up @@ -114,11 +114,7 @@ export default class ShippingEstimator {
// Requests the states for a country with AJAX
stateCountry(this.$state, this.context, { useIdForStates: true }, (err, field) => {
if (err) {
swal.fire({
text: err,
icon: 'error',
});

showAlertModal(err);
throw new Error(err);
}

Expand Down
18 changes: 7 additions & 11 deletions assets/js/theme/global/currency-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import swal from './sweet-alert';
import { showAlertModal } from './modal';
import utils from '@bigcommerce/stencil-utils';

export default function (cartId) {
Expand All @@ -11,11 +11,8 @@ export default function (cartId) {
}).done(() => {
window.location.reload();
}).fail((e) => {
swal.fire({
text: JSON.parse(e.responseText).error,
icon: 'warning',
showCancelButton: true,
});
const text = JSON.parse(e.responseText).error;
showAlertModal(text);
});
}

Expand All @@ -36,14 +33,13 @@ export default function (cartId) {
response.lineItems.giftCertificates.length > 0;

if (showWarning) {
swal.fire({
text: $(event.target).data('warning'),
const text = $(event.target).data('warning');
showAlertModal(text, {
icon: 'warning',
showCancelButton: true,
}).then(result => {
if (result.value && result.value === true) {
onConfirm: () => {
changeCurrency($(event.target).data('cart-currency-switch-url'), $(event.target).data('currency-code'));
}
},
});
} else {
changeCurrency($(event.target).data('cart-currency-switch-url'), $(event.target).data('currency-code'));
Expand Down
23 changes: 22 additions & 1 deletion assets/js/theme/global/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,29 @@ export function alertModal() {
/*
* Display the given message in the default alert modal
*/
export function showAlertModal(message) {
export function showAlertModal(message, options = {}) {
const modal = alertModal();
const cancelBtn = modal.$modal.find('.cancel');
const { icon, showCancelButton, onConfirm } = options;

modal.open();
modal.$modal.find('.alert-icon').hide();

if (icon === 'warning') {
modal.$modal.find('.warning-icon').show();
} else {
modal.$modal.find('.error-icon').show();
}

modal.updateContent(`<span>${message}</span>`);

if (onConfirm) {
modal.$modal.find('.confirm').on('click', onConfirm);
}

if (showCancelButton) {
cancelBtn.show();
} else {
cancelBtn.hide();
}
}
16 changes: 0 additions & 16 deletions assets/js/theme/global/sweet-alert.js

This file was deleted.

3 changes: 0 additions & 3 deletions assets/scss/components/_components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// Nanobar Ajax loading progress bar
@import "vendor/nanobar/component";

// SweetAlert2 replacement for JavaScript alert/confirmations
@import "vendor/sweetalert2/component";


// Foundation components
// -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 761c270

Please sign in to comment.