Skip to content
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

feat: #82/checkout middleware #89

Merged
merged 4 commits into from
Sep 14, 2021
Merged

Conversation

Baroshem
Copy link
Contributor

Description

Closes #82

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Copy link

@Mateuszpietrusinski Mateuszpietrusinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some improvements, but LGTM

Comment on lines 13 to 34
switch (currentPath) {
case 'shipping':
if (!canEnterShipping(activeCart)) {
app.context.redirect('/');
}
break;
case 'billing':
if (!canEnterBilling(activeCart)) {
app.context.redirect('/');
}
break;
case 'payment':
if (!canEnterPayment(activeCart)) {
app.context.redirect('/');
}
break;
case 'thank-you':
if (!canEnterThankYou(app.context)) {
app.context.redirect('/');
}
break;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better option is to have just if.

Suggested change
switch (currentPath) {
case 'shipping':
if (!canEnterShipping(activeCart)) {
app.context.redirect('/');
}
break;
case 'billing':
if (!canEnterBilling(activeCart)) {
app.context.redirect('/');
}
break;
case 'payment':
if (!canEnterPayment(activeCart)) {
app.context.redirect('/');
}
break;
case 'thank-you':
if (!canEnterThankYou(app.context)) {
app.context.redirect('/');
}
break;
}
if(currentPath === 'shipping' && !canEnterShipping(activeCart)) {
app.context.redirect('/');
return;
}
if(currentPath === 'billing' && !canEnterBilling(activeCart)) {
app.context.redirect('/');
return;
}
if(currentPath === 'payment' && !canEnterPayment(activeCart)) {
app.context.redirect('/');
return;
}
if(currentPath === 'thank-you' && !canEnterThankYou(app.context)) {
app.context.redirect('/');
return;
}
}

Also IMO good idea is to replace strings via const or enum values

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const or enum values sound cool for me too

@@ -140,6 +142,18 @@ export default {
isFormSubmitted.value = true;
};

onMounted(async () => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe its better to load that onSSR, this will verify quicker if user has access to this page

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to put it in onSSRc lifecycle hook at first but it did not work. Now when you have already filled the customer step data and you are in other step (like shipping) when you come back to customer the data will be filled for you.

@Baroshem Baroshem merged commit da02273 into develop Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: implement checkout middleware and fix payment error
3 participants