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 219
Rename the checkout events #8381
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
527d4da
WIP
alexflorisca fe74794
Deprecate isPaymentPristine and undeprecate isPaymentStarted
alexflorisca abb4308
Set payment status to FAILED or SUCCESS when the storeAPI fetch returns
alexflorisca 55e642e
Remove FINISHED as a status
alexflorisca 099af5e
Remove ready status
alexflorisca 76d10b3
Revert "Remove FINISHED as a status"
alexflorisca b7b9289
Add payment status READY
alexflorisca 49a9f01
Removed payment statuses pristine, failed and success
alexflorisca 5802a5b
Remove deprecated selectors and update docs
alexflorisca 2912b25
Rename the checkout events
alexflorisca ebd0fa2
Merge conflicts
mikejolley 92cf413
Update test observer
mikejolley 1351baf
Update deprecation notice
mikejolley 6f51d55
deprecation versions
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,22 +35,31 @@ import { useEditorContext } from '../../editor-context'; | |
type CheckoutEventsContextType = { | ||
// Submits the checkout and begins processing. | ||
onSubmit: () => void; | ||
// Used to register a callback that will fire after checkout has been processed and there are no errors. | ||
// Deprecated in favour of onCheckoutSuccess. | ||
onCheckoutAfterProcessingWithSuccess: ReturnType< typeof emitterCallback >; | ||
// Used to register a callback that will fire when the checkout has been processed and has an error. | ||
// Deprecated in favour of onCheckoutFail. | ||
onCheckoutAfterProcessingWithError: ReturnType< typeof emitterCallback >; | ||
// Deprecated in favour of onCheckoutValidationBeforeProcessing. | ||
onCheckoutBeforeProcessing: ReturnType< typeof emitterCallback >; | ||
// Used to register a callback that will fire when the checkout has been submitted before being sent off to the server. | ||
// Deprecated in favour of onCheckoutValidation. | ||
onCheckoutValidationBeforeProcessing: ReturnType< typeof emitterCallback >; | ||
// Used to register a callback that will fire if the api call to /checkout is successful | ||
onCheckoutSuccess: ReturnType< typeof emitterCallback >; | ||
// Used to register a callback that will fire if the api call to /checkout fails | ||
onCheckoutFail: ReturnType< typeof emitterCallback >; | ||
// Used to register a callback that will fire when the checkout performs validation on the form | ||
onCheckoutValidation: ReturnType< typeof emitterCallback >; | ||
}; | ||
|
||
const CheckoutEventsContext = createContext< CheckoutEventsContextType >( { | ||
onSubmit: () => void null, | ||
onCheckoutAfterProcessingWithSuccess: () => () => void null, | ||
onCheckoutAfterProcessingWithError: () => () => void null, | ||
onCheckoutAfterProcessingWithSuccess: () => () => void null, // deprecated for onCheckoutSuccess | ||
onCheckoutAfterProcessingWithError: () => () => void null, // deprecated for onCheckoutFail | ||
onCheckoutBeforeProcessing: () => () => void null, // deprecated for onCheckoutValidationBeforeProcessing | ||
onCheckoutValidationBeforeProcessing: () => () => void null, | ||
onCheckoutValidationBeforeProcessing: () => () => void null, // deprecated for onCheckoutValidation | ||
onCheckoutSuccess: () => () => void null, | ||
onCheckoutFail: () => () => void null, | ||
onCheckoutValidation: () => () => void null, | ||
} ); | ||
|
||
export const useCheckoutEventsContext = () => { | ||
|
@@ -159,11 +168,8 @@ export const CheckoutEventsProvider = ( { | |
|
||
const [ observers, observerDispatch ] = useReducer( emitReducer, {} ); | ||
const currentObservers = useRef( observers ); | ||
const { | ||
onCheckoutAfterProcessingWithSuccess, | ||
onCheckoutAfterProcessingWithError, | ||
onCheckoutValidationBeforeProcessing, | ||
} = useEventEmitters( observerDispatch ); | ||
const { onCheckoutValidation, onCheckoutSuccess, onCheckoutFail } = | ||
useEventEmitters( observerDispatch ); | ||
|
||
// set observers on ref so it's always current. | ||
useEffect( () => { | ||
|
@@ -180,16 +186,53 @@ export const CheckoutEventsProvider = ( { | |
* See: https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/4039/commits/a502d1be8828848270993264c64220731b0ae181 | ||
*/ | ||
const onCheckoutBeforeProcessing = useMemo( () => { | ||
return function ( | ||
...args: Parameters< typeof onCheckoutValidationBeforeProcessing > | ||
) { | ||
return function ( ...args: Parameters< typeof onCheckoutValidation > ) { | ||
deprecated( 'onCheckoutBeforeProcessing', { | ||
alternative: 'onCheckoutValidationBeforeProcessing', | ||
plugin: 'WooCommerce Blocks', | ||
} ); | ||
return onCheckoutValidationBeforeProcessing( ...args ); | ||
return onCheckoutValidation( ...args ); | ||
}; | ||
}, [ onCheckoutValidation ] ); | ||
|
||
/** | ||
* @deprecated use onCheckoutValidation instead | ||
*/ | ||
const onCheckoutValidationBeforeProcessing = useMemo( () => { | ||
return function ( ...args: Parameters< typeof onCheckoutValidation > ) { | ||
deprecated( 'onCheckoutValidationBeforeProcessing', { | ||
alternative: 'onCheckoutValidation', | ||
plugin: 'WooCommerce Blocks', | ||
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. Should we add links and version numbers to these deprecation messages? |
||
} ); | ||
return onCheckoutValidation( ...args ); | ||
}; | ||
}, [ onCheckoutValidation ] ); | ||
|
||
/** | ||
* @deprecated use onCheckoutSuccess instead | ||
*/ | ||
const onCheckoutAfterProcessingWithSuccess = useMemo( () => { | ||
return function ( ...args: Parameters< typeof onCheckoutSuccess > ) { | ||
deprecated( 'onCheckoutAfterProcessingWithSuccess', { | ||
alternative: 'onCheckoutSuccess', | ||
plugin: 'WooCommerce Blocks', | ||
} ); | ||
return onCheckoutSuccess( ...args ); | ||
}; | ||
}, [ onCheckoutSuccess ] ); | ||
|
||
/** | ||
* @deprecated use onCheckoutFail instead | ||
*/ | ||
const onCheckoutAfterProcessingWithError = useMemo( () => { | ||
return function ( ...args: Parameters< typeof onCheckoutFail > ) { | ||
deprecated( 'onCheckoutAfterProcessingWithError', { | ||
alternative: 'onCheckoutFail', | ||
plugin: 'WooCommerce Blocks', | ||
} ); | ||
return onCheckoutFail( ...args ); | ||
}; | ||
}, [ onCheckoutValidationBeforeProcessing ] ); | ||
}, [ onCheckoutFail ] ); | ||
|
||
// Emit CHECKOUT_VALIDATE event and set the error state based on the response of | ||
// the registered callbacks | ||
|
@@ -209,7 +252,7 @@ export const CheckoutEventsProvider = ( { | |
const previousStatus = usePrevious( checkoutStatus ); | ||
const previousHasError = usePrevious( checkoutHasError ); | ||
|
||
// Emit CHECKOUT_AFTER_PROCESSING_WITH_SUCCESS and CHECKOUT_AFTER_PROCESSING_WITH_ERROR events | ||
// Emit CHECKOUT_SUCCESS and CHECKOUT_FAIL events | ||
// and set checkout errors according to the callback responses | ||
useEffect( () => { | ||
if ( | ||
|
@@ -258,6 +301,9 @@ export const CheckoutEventsProvider = ( { | |
onCheckoutValidationBeforeProcessing, | ||
onCheckoutAfterProcessingWithSuccess, | ||
onCheckoutAfterProcessingWithError, | ||
onCheckoutSuccess, | ||
onCheckoutFail, | ||
onCheckoutValidation, | ||
}; | ||
return ( | ||
<CheckoutEventsContext.Provider value={ checkoutEventHandlers }> | ||
|
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.
Should this be updated since we're now deprecating
onCheckoutValidationBeforeProcessing
too