Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Checkout Context and Validation: Improve onCheckoutProcessing event emitter to allow for aborted subscribers. #1939

Closed
nerrad opened this issue Mar 11, 2020 · 1 comment · Fixed by #2033
Assignees
Labels
type: enhancement The issue is a request for an enhancement.
Milestone

Comments

@nerrad
Copy link
Contributor

nerrad commented Mar 11, 2020

The onCheckoutProcessing event handler in the checkout context will get used by validation routines or processes that can abort the checkout being processed.

For reference, see the flow as outlined here:

Image 2020-03-11 at 9 32 28 AM

This means:

  • eventEmitter must handle aborting running any subsequent subscribed observers as soon as an observer returns an error object (anything but true).
  • onCheckoutProcessing will handle error objects that are returned from aborted events and update relevant checkout statuses and error states.

Suggested apis (roughly):

This has the overall idea, but there are still some specifics that likely will need worked out as a part of the implementation.

A subscriber triggering a processing abort would be expected to return an error object in the following shape:

const error = {
    message: 'Main error message',
    validation: {
        propertyFailingValidation: 'error message for field',
        anotherPropertyFailingValidation: 'error message for field',
    }
};

The message property will be output in an error notice by the checkout context.
The validation property is for errors triggered by validation fails. The value is an object where properties correspond to field properties/ids for existing form fields and values correspond to the validation error message to accompany the field error.

Implementation wise, the errors can be exposed on the checkout context and field components can grab that (via context hook) to determine whether there is an error and whether there are any matching validation properties for the field the component outputs.

Additional considerations

  • I don't anticipate there would be a lot of subscribers hooked into the onCheckoutProcessing hook, but I do wonder if instead of aborting after a single subscriber fail, if we should accumulate all the error objects and aggregate them? That might be a better customer experience for fixing all the potential issues rather than fixing for one subscriber and then getting hit by the next subscriber after?
@nerrad
Copy link
Contributor Author

nerrad commented Mar 17, 2020

Followups from #1972:

  • increase specificity of the selector in text-input/style.css to remove the need for !important
  • As noted by Nadir, there's an alignment issue with the invalid coupon message in the context of the checkout.
  • CSS and alignment of validation messages could be improved (in context of checkout). Layout will break if the error message is longer and breaks into two lines.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants