-
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from Oksydan/core-js-refacto
Cart page error handling, general error handling/alert notification handling
- Loading branch information
Showing
26 changed files
with
278 additions
and
67 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
_dev/js/theme/components/http/error/GenericHttpRequestError.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Generic Http Request error | ||
* @class GenericHttpRequestError | ||
* @property {string} message - Error message | ||
*/ | ||
class GenericHttpRequestError extends Error { | ||
NAME = 'GenericHttpRequestError'; | ||
|
||
constructor(message) { | ||
super(message); | ||
this.name = this.NAME; | ||
} | ||
} | ||
|
||
export default GenericHttpRequestError; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import prestashop from 'prestashop'; | ||
import cartStateStore from '../../store/cartStateStore'; | ||
|
||
const { | ||
setIsUpdateOperation, | ||
setHasError, | ||
setErrorMsg, | ||
getErrorMsg, | ||
getHasError, | ||
getIsUpdateOperation, | ||
} = cartStateStore(); | ||
|
||
/** | ||
* Handles cart page errors | ||
* Side effects: updates cart state and cart notification DOM | ||
* @returns {void} | ||
*/ | ||
const cartErrorsHandler = () => { | ||
const checkoutBtn = document.querySelector(prestashop.selectors.checkout.btn); | ||
const errorMsg = getErrorMsg(); | ||
const hasError = getHasError(); | ||
const isUpdateOperation = getIsUpdateOperation(); | ||
const notification = document.querySelector(prestashop.selectors.notifications.container); | ||
|
||
if (document.querySelector(prestashop.selectors.notifications.dangerAlert) || (errorMsg !== '' && !hasError)) { | ||
checkoutBtn.classList.add('disabled'); | ||
} | ||
|
||
if (errorMsg !== '') { | ||
const alertBlock = ` | ||
<article class="alert alert-danger" role="alert" data-alert="danger"> | ||
<ul class="mb-0"> | ||
<li>${errorMsg}</li> | ||
</ul> | ||
</article> | ||
`; | ||
|
||
if (notification) { | ||
notification.innerHTML = alertBlock; | ||
} | ||
|
||
setErrorMsg(''); | ||
setIsUpdateOperation(false); | ||
|
||
if (hasError) { | ||
// if hasError is true, quantity was not updated : allow checkout | ||
checkoutBtn.classList.remove('disabled'); | ||
} | ||
} else if (!hasError && isUpdateOperation) { | ||
setHasError(false); | ||
setIsUpdateOperation(false); | ||
|
||
if (notification) { | ||
notification.innerHTML = ''; | ||
} | ||
|
||
checkoutBtn.classList.remove('disabled'); | ||
} | ||
}; | ||
|
||
export default cartErrorsHandler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.