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

Fix WooPay opt-in blocks field #9131

Merged
merged 9 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions changelog/fix-woopay-opt-in-blocks-field
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix WooPay opt-in blocks field on WooCommerce 9.1+.
2 changes: 2 additions & 0 deletions client/checkout/woopay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const renderSaveUserSection = () => {
paymentOptions.nextSibling
);

paymentOptions.classList.add( 'is-woopay' );

ReactDOM.render(
<CheckoutPageSaveUser isBlocksCheckout={ true } />,
checkoutPageSaveUserContainer
Expand Down
16 changes: 15 additions & 1 deletion client/components/woopay/save-user/checkout-page-save-user.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useWooPayUser from '../hooks/use-woopay-user';
import useSelectedPaymentMethod from '../hooks/use-selected-payment-method';
import { recordUserEvent } from 'tracks';
import './style.scss';
import { compare } from 'compare-versions';

const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
const [ isSaveDetailsChecked, setIsSaveDetailsChecked ] = useState(
Expand All @@ -34,6 +35,12 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
);
const viewportWidth = window.document.documentElement.clientWidth;
const viewportHeight = window.document.documentElement.clientHeight;
const wooCommerceVersionString = window.wcSettings?.wcVersion;
const wcVersionGreaterThan91 = compare(
wooCommerceVersionString,
'9.1',
'>='
);

const getPhoneFieldValue = () => {
let phoneFieldValue = '';
Expand Down Expand Up @@ -174,7 +181,10 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
}

return (
<Container isBlocksCheckout={ isBlocksCheckout }>
<Container
isBlocksCheckout={ isBlocksCheckout }
wcVersionGreaterThan91={ wcVersionGreaterThan91 }
>
<div className="save-details">
<div className="save-details-header">
<div
Expand All @@ -193,6 +203,10 @@ const CheckoutPageSaveUser = ( { isBlocksCheckout } ) => {
id="save_user_in_woopay"
value="true"
className={ `save-details-checkbox ${
wcVersionGreaterThan91
? 'without-margin-right'
: ''
} ${
isBlocksCheckout
? 'wc-block-components-checkbox__input'
: ''
Expand Down
12 changes: 10 additions & 2 deletions client/components/woopay/save-user/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,19 @@
*/
import { __ } from '@wordpress/i18n';

const Container = ( { children, isBlocksCheckout } ) => {
const Container = ( {
children,
isBlocksCheckout,
wcVersionGreaterThan91,
} ) => {
if ( ! isBlocksCheckout ) return children;
return (
<>
<div className="woopay-save-new-user-container">
<div
className={ `woopay-save-new-user-container ${
wcVersionGreaterThan91 ? 'wc-version-greater-than-91' : ''
}` }
>
<h2>{ __( 'Save my info' ) }</h2>
{ children }
</div>
Expand Down
48 changes: 47 additions & 1 deletion client/components/woopay/save-user/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,53 @@
}
}

.is-mobile,
.is-small {
.woopay-save-new-user-container.wc-version-greater-than-91::after {
background: currentColor;
box-shadow: -50vw 0 0 0 currentColor, 50vw 0 0 0 currentColor;
content: '';
height: 1px;
opacity: 0.11;
width: 100%;
margin-top: 22px;
}
}

.is-medium,
.is-large {
.woopay-save-new-user-container.wc-version-greater-than-91 {
border-bottom: 1px solid hsla( 0, 0%, 7%, 0.11 );
margin-bottom: 48px;
}
}

@media ( max-width: 600px ) {
.is-mobile,
.is-small {
.wc-block-components-form
.wc-block-components-checkout-step.is-woopay::after {
height: 0;
}
}
}

.woopay-save-new-user-container {
.save-details {
.wc-block-components-text-input input:-webkit-autofill {
padding: 1.5em 0.5em 1.5em 0.5em;
}
}

&.wc-version-greater-than-91 {
@media ( min-width: 601px ),
( min-width: 566px ) and ( max-width: 568px ) {
.save-details {
margin-bottom: 48px;
}
}
}

.save-details-header {
display: flex;
align-items: flex-start;
Expand Down Expand Up @@ -41,7 +87,7 @@
text-indent: 0;
}

input {
input:not( .without-margin-right ) {
margin-right: $gap-small;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ describe( 'CheckoutPageSaveUser', () => {
( setting ) => setting === 'forceNetworkSavedCards'
);

window.wcSettings = {
wcVersion: '9.1.2',
storePages: {
checkout: {
permalink: 'http://localhost/',
},
},
};

window.wcpaySettings = {
accountStatus: {
country: 'US',
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@woocommerce/explat": "2.3.0",
"@woocommerce/number": "2.4.0",
"canvas-confetti": "1.9.2",
"compare-versions": "6.1.1",
"debug": "4.1.1",
"intl-tel-input": "17.0.15",
"lodash": "4.17.21"
Expand Down
Loading