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: redesign modal checkout #1602

Merged
merged 56 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
73a447b
feat: redesign modal checkout
miguelpeixe Nov 22, 2023
ca7d382
fix: saved methods spacing
miguelpeixe Nov 22, 2023
07f3cdd
fix: style updates and start custom coupon form
miguelpeixe Nov 22, 2023
4cb064a
feat: start front-end 2-step
miguelpeixe Nov 22, 2023
0af5e2a
fix: style tweaks and button label
miguelpeixe Nov 22, 2023
11d7662
feat: animate modal in
miguelpeixe Nov 22, 2023
40d2a3b
fix: style tweak
miguelpeixe Nov 22, 2023
965d983
fix: hide radio if only one payment method
miguelpeixe Nov 22, 2023
3ecfc0c
fix: tweak spacing for payment form
miguelpeixe Nov 22, 2023
db56420
fix: variation modal and mobile tweaks
miguelpeixe Nov 23, 2023
5e1a990
fix: temporarily remove 2-step and ux tweaks
miguelpeixe Nov 23, 2023
9a0e08c
feat: custom shipping address option
miguelpeixe Nov 23, 2023
71a48c5
chore: lint
miguelpeixe Nov 23, 2023
c689cf0
chore: clode cleanup
miguelpeixe Nov 23, 2023
b54bdb1
chore: restore commented-out code
miguelpeixe Nov 23, 2023
d69899d
fix: tweak address field margin
miguelpeixe Nov 23, 2023
372fa1f
chore: readability
miguelpeixe Nov 23, 2023
48f3ec3
fix: remove donation text from order button
miguelpeixe Nov 23, 2023
ed95c11
fix: do shortcode instead of loading page content
miguelpeixe Nov 27, 2023
50f7f63
Merge branch 'epic/ras-acc' into feat/modal-checkout-redesign
miguelpeixe Nov 27, 2023
303b12f
fix: select2 styles
miguelpeixe Nov 27, 2023
f00be70
fix: more select2 style tweaks
miguelpeixe Nov 27, 2023
7eeddf1
Merge branch 'epic/ras-acc' into feat/modal-checkout-redesign
miguelpeixe Nov 28, 2023
7b7b1a2
feat: preliminary work on 2-step with validation
miguelpeixe Nov 30, 2023
864cb58
fix: restore original handlers
miguelpeixe Dec 1, 2023
6ec6892
fix: clear messages and scroll top
miguelpeixe Dec 4, 2023
1fe3039
fix: better handling of input errors
miguelpeixe Dec 4, 2023
63f9fd9
fix: remove red input shadow
miguelpeixe Dec 4, 2023
a963797
fix: handle back button and improve js logic
miguelpeixe Dec 5, 2023
f68120a
chore: code cleanup
miguelpeixe Dec 5, 2023
e4ecdc7
fix: remove iframe handling of inner forms
miguelpeixe Dec 5, 2023
7289ff0
feat: implement initial validation
miguelpeixe Dec 5, 2023
14775cf
feat: build checkout details
miguelpeixe Dec 5, 2023
77071bc
fix: clear details
miguelpeixe Dec 5, 2023
8be7a78
feat: ux and performance tweaks
miguelpeixe Dec 5, 2023
bbc9946
fix: resolve spinner if container is not available
miguelpeixe Dec 5, 2023
a408d0d
fix: remove block notices
miguelpeixe Dec 5, 2023
b1a6e67
chore: add todo
miguelpeixe Dec 5, 2023
535205f
chore: remove unused code
miguelpeixe Dec 6, 2023
48085a2
chore: remove unused code
miguelpeixe Dec 6, 2023
38effc2
chore: remove unused code
miguelpeixe Dec 6, 2023
8fe5b58
chore: use helper method
miguelpeixe Dec 6, 2023
a319958
fix: handle new error format
miguelpeixe Dec 6, 2023
510dca9
Merge branch 'epic/ras-acc' into feat/modal-checkout-redesign
miguelpeixe Dec 8, 2023
d29cab8
fix: better handle notices and shipping details
miguelpeixe Dec 11, 2023
635a685
chore: update line docs
miguelpeixe Dec 12, 2023
7fd2af3
chore: update inline docs
miguelpeixe Dec 12, 2023
b59b656
chore: code cleanup and inline docs
miguelpeixe Dec 12, 2023
6ca2b0f
chore: remove superfluous phpcs ignore
miguelpeixe Dec 12, 2023
9919d4f
chore: improve readability
miguelpeixe Dec 12, 2023
3cee62f
feat: focus first field on editing
miguelpeixe Dec 12, 2023
6d5e333
chore: improve readability
miguelpeixe Dec 13, 2023
c9b8bac
fix: check coupon form
miguelpeixe Dec 13, 2023
e00793f
fix: show order details if requires shipping
miguelpeixe Dec 19, 2023
fc748a2
chore: fix linter
miguelpeixe Dec 19, 2023
3cfe948
Revert "fix: show order details if requires shipping"
miguelpeixe Dec 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
379 changes: 199 additions & 180 deletions includes/class-modal-checkout.php

Large diffs are not rendered by default.

485 changes: 251 additions & 234 deletions src/modal-checkout/checkout.scss

Large diffs are not rendered by default.

415 changes: 388 additions & 27 deletions src/modal-checkout/index.js

Large diffs are not rendered by default.

75 changes: 31 additions & 44 deletions src/modal-checkout/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function closeCheckout() {
iframeResizeObserver.disconnect();
}
Array.from( document.querySelectorAll( '.newspack-blocks-modal' ) ).forEach( el => {
el.style.display = 'none';
el.classList.remove( 'open' );
if ( el.overlayId && window.newspackReaderActivation?.overlays ) {
window.newspackReaderActivation?.overlays.remove( el.overlayId );
}
Expand Down Expand Up @@ -129,7 +129,7 @@ domReady( () => {
form.addEventListener( 'submit', ev => {
const formData = new FormData( form );
// Clear any open variation modal.
variationModals.forEach( variationModal => ( variationModal.style.display = 'none' ) );
variationModals.forEach( variationModal => variationModal.classList.remove( 'open' ) );
// Trigger variation modal if variation is not selected.
if ( formData.get( 'is_variable' ) && ! formData.get( 'variation_id' ) ) {
const variationModal = [ ...variationModals ].find(
Expand All @@ -155,67 +155,54 @@ domReady( () => {
// Open the variations modal.
ev.preventDefault();
document.body.classList.add( 'newspack-modal-checkout-open' );
variationModal.style.display = 'block';
variationModal.classList.add( 'open' );
return;
}
}
// Continue with checkout modal.
spinner.style.display = 'flex';
modalCheckout.style.display = 'block';
modalCheckout.classList.add( 'open' );
document.body.classList.add( 'newspack-modal-checkout-open' );
if ( window.newspackReaderActivation?.overlays ) {
modalCheckout.overlayId = window.newspackReaderActivation?.overlays.add();
}

iframeResizeObserver = new ResizeObserver( entries => {
if ( ! entries || ! entries.length ) {
return;
}
const contentRect = entries[ 0 ].contentRect;
if ( contentRect ) {
modalContent.style.height = contentRect.top + contentRect.bottom + 'px';
spinner.style.display = 'none';
}
} );
iframe.addEventListener( 'load', () => {
const location = iframe.contentWindow.location;
// If RAS is available, set the front-end authentication.
if ( window.newspackReaderActivation && location.href.indexOf( 'order-received' ) > -1 ) {
const ras = window.newspackReaderActivation;
const params = new Proxy( new URLSearchParams( location.search ), {
get: ( searchParams, prop ) => searchParams.get( prop ),
} );
if ( params.email ) {
ras.setReaderEmail( params.email );
ras.setAuthenticated( true );
}
}
const container = iframe.contentDocument.querySelector( '#newspack_modal_checkout' );
if ( container ) {
iframeResizeObserver.observe( container );
}
const innerButtons = [
...iframe.contentDocument.querySelectorAll( '.modal-continue, .edit-billing-link' ),
];
innerButtons.forEach( innerButton => {
innerButton.addEventListener( 'click', () => ( spinner.style.display = 'flex' ) );
} );
const innerForm = iframe.contentDocument.querySelector( '.checkout' );
if ( innerForm ) {
const innerBillingFields = [
...innerForm.querySelectorAll( '.woocommerce-billing-fields input' ),
];
innerBillingFields.forEach( innerField => {
innerField.addEventListener( 'keyup', e => {
if ( 'Enter' === e.key ) {
spinner.style.display = 'flex';
innerForm.submit();
}
} );
} );
}
} );
} );
} );
} );
iframe.addEventListener( 'load', () => {
const location = iframe.contentWindow.location;
// If RAS is available, set the front-end authentication.
if ( window.newspackReaderActivation && location.href.indexOf( 'order-received' ) > -1 ) {
const ras = window.newspackReaderActivation;
const params = new Proxy( new URLSearchParams( location.search ), {
get: ( searchParams, prop ) => searchParams.get( prop ),
} );
if ( params.email ) {
ras.setReaderEmail( params.email );
ras.setAuthenticated( true );
}
}
const container = iframe.contentDocument.querySelector( '#newspack_modal_checkout' );
if ( container ) {
iframeResizeObserver.observe( container );
if ( container.checkoutReady ) {
spinner.style.display = 'none';
} else {
container.addEventListener( 'checkout-ready', () => {
spinner.style.display = 'none';
} );
}
} else {
spinner.style.display = 'none';
}
} );
} );
72 changes: 49 additions & 23 deletions src/modal-checkout/modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,67 @@
width: 100%;
height: 100%;
background: rgba( 0, 0, 0, 0.75 );
z-index: 99999;
&__content {
visibility: hidden;
pointer-events: none;
z-index: -1;
opacity: 0;
transition: opacity 0.2s ease-in-out;
&__container {
border-radius: 6px;
background: colors.$color__background-body;
position: absolute;
top: 50%;
left: 50%;
transform: translate( -50%, -50% );
width: calc( 100vw - 32px );
max-width: 580px;
min-height: 200px;
max-height: calc( 100vh - 32px );
background: colors.$color__background-body;
border-radius: 5px;
> *:not( .newspack-blocks-modal__close ) {
max-width: 600px;
min-height: 300px;
max-height: 90vh;
display: flex;
flex-direction: column;
justify-content: space-between;
transform: translate( -50%, -50% ) translateY( 50px );
transition: transform 0.2s ease-in-out;
}
&.open {
z-index: 99999;
visibility: visible;
pointer-events: auto;
opacity: 1;
.newspack-blocks-modal__container {
transform: translate( -50%, -50% );
}
}
&__header {
padding: 24px;
box-sizing: border-box;
height: 64px;
border-bottom: 1px solid #ddd;
display: flex;
align-items: center;
justify-content: space-between;
h2 {
font-size: 16px;
}
}
&__content {
position: relative;
flex-grow: 1;
> * {
width: 100%;
height: 100%;
border: 0;
border-radius: 5px;
border-radius: 6px;
}
}
&__spinner {
align-items: center;
background: #fff;
border-radius: 5px;
display: flex;
height: 100%;
justify-content: center;
left: 50%;
opacity: 0.5;
position: absolute;
top: 50%;
transform: translate( -50%, -50% );
top: 0;
bottom: 0;
width: 100%;
> span {
animation: spin 1s infinite linear;
Expand All @@ -59,12 +89,11 @@
border-radius: 50%;
height: 25px;
width: 25px;
margin-top: -12.5px;
margin-left: -12.5px;
}
}
&__close {
position: absolute;
top: 0;
right: 0;
padding: 8px;
border: 0;
background: transparent;
Expand Down Expand Up @@ -147,17 +176,14 @@

@media ( max-width: 600px ) {
.newspack-blocks-modal {
&__content {
&__container {
max-width: 100%;
width: 100%;
border-radius: 0;
top: auto;
bottom: 0;
left: 0;
transform: none;
> *:not( .newspack-blocks-modal__close ) {
border-radius: 0;
}
transform: none !important;
}
}
}
43 changes: 0 additions & 43 deletions src/modal-checkout/templates/billing-form.php

This file was deleted.

Loading