-
Notifications
You must be signed in to change notification settings - Fork 610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace JavaScript alert/confirmations with sweetalert2 #1035
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import $ from 'jquery'; | |
import utils from '@bigcommerce/stencil-utils'; | ||
import _ from 'lodash'; | ||
import { insertStateHiddenField } from './form-utils'; | ||
import swal from 'sweetalert2'; | ||
|
||
/** | ||
* If there are no options from bcapp, a text field will be sent. This will create a select element to hold options after the remote request. | ||
|
@@ -129,7 +130,10 @@ export default function (stateElement, context = {}, options, callback) { | |
|
||
utils.api.country.getByName(countryName, (err, response) => { | ||
if (err) { | ||
alert(context.state_error); | ||
swal({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to only execute the callback after dismissing the alert? I think |
||
text: context.state_error, | ||
type: 'error', | ||
}); | ||
|
||
return callback(err); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import $ from 'jquery'; | ||
import _ from 'lodash'; | ||
import swal from 'sweetalert2'; | ||
|
||
function decrementCounter(counter, item) { | ||
const index = counter.indexOf(item); | ||
|
@@ -57,7 +58,10 @@ export default function (urlContext) { | |
const productsToCompare = $this.find('input[name="products\[\]"]:checked'); | ||
|
||
if (productsToCompare.length <= 1) { | ||
alert('You must select at least two products to compare'); | ||
swal({ | ||
text: 'You must select at least two products to compare', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an existing problem. So you probably don't need to fix it in this PR. Just pointing it out that the warning message needs to come from the language file, not hard-coded in here. |
||
type: 'error', | ||
}); | ||
event.preventDefault(); | ||
} | ||
}); | ||
|
@@ -66,7 +70,10 @@ export default function (urlContext) { | |
const $clickedCheckedInput = $('body').find('input[name="products\[\]"]:checked'); | ||
|
||
if ($clickedCheckedInput.length <= 1) { | ||
alert('You must select at least two products to compare'); | ||
swal({ | ||
text: 'You must select at least two products to compare', | ||
type: 'error', | ||
}); | ||
|
||
return false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import swal from 'sweetalert2'; | ||
|
||
export default function () { | ||
// Set defaults for sweetalert2 popup boxes | ||
swal.setDefaults({ | ||
buttonsStyling: false, | ||
confirmButtonClass: 'button', | ||
cancelButtonClass: 'button', | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// ============================================================================= | ||
// SWEETALERT2 | ||
// ============================================================================= | ||
|
||
// Vendor SCSS | ||
@import "../../../../../node_modules/sweetalert2/src/sweetalert2"; | ||
|
||
// Compnent | ||
@import "sweetalert2"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may choose to not import the vendor library directly. Instead, create a facade so that it's easier to change its implementation later.