This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 221
Cart Action Promises with success/reject handling #8272
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
22c41fe
move thinks and create consistent promise rejection
mikejolley a4b383d
Remove notifyErrors
mikejolley 10583e4
Combine error handling
mikejolley 24db67b
Ensure thunk usage handles errors
mikejolley b6872d4
Use promise in coupon form
mikejolley 661f1bc
onsubmit type
mikejolley c41d57d
receiveCartContents during checkout
mikejolley 9589d64
Update mocks
mikejolley 36a0527
receiveCartContents mocks/types
mikejolley ecc302a
Fix receiveCartContents tests
mikejolley 5078b31
Move thunks back to actions, add todo for follow up
mikejolley ee1deb7
Sort actions alphabetically
mikejolley 976efa0
Null check is unnecessary
mikejolley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -40,14 +40,12 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => { | |
[ createErrorNotice, createNotice ] | ||
); | ||
|
||
const { applyCoupon, removeCoupon, receiveApplyingCoupon } = | ||
useDispatch( CART_STORE_KEY ); | ||
const { applyCoupon, removeCoupon } = useDispatch( CART_STORE_KEY ); | ||
|
||
const applyCouponWithNotices = ( couponCode: string ) => { | ||
applyCoupon( couponCode ) | ||
.then( ( result ) => { | ||
return applyCoupon( couponCode ) | ||
.then( () => { | ||
if ( | ||
result === true && | ||
__experimentalApplyCheckoutFilter( { | ||
filterName: 'showApplyCouponNotice', | ||
defaultValue: true, | ||
|
@@ -71,6 +69,7 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => { | |
} | ||
); | ||
} | ||
return Promise.resolve( true ); | ||
} ) | ||
.catch( ( error ) => { | ||
setValidationErrors( { | ||
|
@@ -79,16 +78,14 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => { | |
hidden: false, | ||
}, | ||
} ); | ||
// Finished handling the coupon. | ||
receiveApplyingCoupon( '' ); | ||
return Promise.resolve( false ); | ||
} ); | ||
}; | ||
|
||
const removeCouponWithNotices = ( couponCode: string ) => { | ||
removeCoupon( couponCode ) | ||
.then( ( result ) => { | ||
return removeCoupon( couponCode ) | ||
.then( () => { | ||
if ( | ||
result === true && | ||
__experimentalApplyCheckoutFilter( { | ||
filterName: 'showRemoveCouponNotice', | ||
defaultValue: true, | ||
|
@@ -112,14 +109,14 @@ export const useStoreCartCoupons = ( context = '' ): StoreCartCoupon => { | |
} | ||
); | ||
} | ||
return Promise.resolve( true ); | ||
} ) | ||
.catch( ( error ) => { | ||
createErrorNotice( error.message, { | ||
id: 'coupon-form', | ||
context, | ||
} ); | ||
// Finished handling the coupon. | ||
receiveApplyingCoupon( '' ); | ||
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 handled in the thunks already. |
||
return Promise.resolve( false ); | ||
} ); | ||
}; | ||
|
||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is possible confusing, why is onSubmit ever undefined?
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.
The typedef allows for undefined, so this just handles that case.