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

Feature/style express piwoo 560 #961

Merged
merged 22 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
3 changes: 2 additions & 1 deletion resources/js/applepayButtonBlock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {ApplePayButtonComponent} from "./blocks/ApplePayButtonComponent";
import {ApplePayButtonEditorComponent} from "./blocks/ApplePayButtonEditorComponent";

(
function ({mollieApplePayBlockDataCart}) {
Expand All @@ -15,7 +16,7 @@ import {ApplePayButtonComponent} from "./blocks/ApplePayButtonComponent";
registerExpressPaymentMethod({
name: 'mollie_wc_gateway_applepay_express',
content: < ApplePayButtonComponent/>,
edit: < ApplePayButtonComponent/>,
edit: < ApplePayButtonEditorComponent/>,
ariaLabel: 'Apple Pay',
canMakePayment: () => true,
paymentMethodId: 'mollie_wc_gateway_applepay',
Expand Down
8 changes: 7 additions & 1 deletion resources/js/blocks/ApplePayButtonComponent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {request} from "../applePayRequest";
import {createAppleErrors} from "../applePayError";

export const ApplePayButtonComponent = ({cart, extensions}) => {
export const ApplePayButtonComponent = ({ buttonAttributes = {} }) => {
const mollieApplePayBlockDataCart = window.mollieApplePayBlockDataCart || window.mollieBlockData.mollieApplePayBlockDataCart
const nonce = document.getElementById("woocommerce-process-checkout-nonce").value
let updatedContactInfo = []
Expand All @@ -11,6 +11,11 @@ export const ApplePayButtonComponent = ({cart, extensions}) => {
shop: {countryCode, currencyCode = 'EUR', totalLabel = ''},
ajaxUrl,
} = mollieApplePayBlockDataCart
const { useMemo } = wp.element;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to import from @wordpress/element rather than from the global variable.

const style = useMemo(() => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not a React expert, but I think useMemo should be used for very expensive actions. If you decide to remove it, you can ignore my comments about importing useMemo from @wordpress/element

height: `${buttonAttributes.height || 48}px`,
borderRadius: `${buttonAttributes.borderRadius || 4}px`
}), [buttonAttributes.height, buttonAttributes.borderRadius]);

const findSelectedShippingMethod = (shippingRates) => {
let shippingRate = shippingRates.find((shippingMethod) => shippingMethod.selected === true)
Expand Down Expand Up @@ -177,6 +182,7 @@ export const ApplePayButtonComponent = ({cart, extensions}) => {
event.preventDefault();
applePaySession();
}}
style={style}
>
</button>
);
Expand Down
17 changes: 17 additions & 0 deletions resources/js/blocks/ApplePayButtonEditorComponent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export const ApplePayButtonEditorComponent = ({ buttonAttributes = {} }) => {
const { useMemo } = wp.element;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to import from @wordpress/element rather than from the global variable.

const style = useMemo(() => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same applies here. I don't think useMemo is needed.

height: `${buttonAttributes.height || 48}px`,
borderRadius: `${buttonAttributes.borderRadius || 4}px`
}), [buttonAttributes.height, buttonAttributes.borderRadius]);

return (
<button
id="mollie_applepay_button"
className="apple-pay-button apple-pay-button-black"
style={style}
>
</button>
);
};
export default ApplePayButtonEditorComponent;
11 changes: 8 additions & 3 deletions resources/js/mollieBlockIndex.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import molliePaymentMethod from './blocks/molliePaymentMethod'
import ApplePayButtonComponent from './blocks/ApplePayButtonComponent'
import ApplePayButtonEditorComponent from './blocks/ApplePayButtonEditorComponent'

(
function ({ mollieBlockData, wc, _, jQuery}) {
Expand Down Expand Up @@ -48,8 +49,8 @@ import ApplePayButtonComponent from './blocks/ApplePayButtonComponent'
}
gatewayData.forEach(item => {
let register = () => registerPaymentMethod(molliePaymentMethod(useEffect, ajaxUrl, filters, gatewayData, availableGateways, item, jQuery, requiredFields, isCompanyFieldVisible, isPhoneFieldVisible));
if (item.name === 'mollie_wc_gateway_applepay' && !isBlockEditor) {
const {isExpressEnabled} = item;
if (item.name === 'mollie_wc_gateway_applepay') {
const {isExpressEnabled} = item;
if ((isAppleSession && window.ApplePaySession.canMakePayments())) {
register();
if (isExpressEnabled !== true) {
Expand All @@ -58,13 +59,17 @@ import ApplePayButtonComponent from './blocks/ApplePayButtonComponent'
const {registerExpressPaymentMethod} = wc.wcBlocksRegistry;
registerExpressPaymentMethod({
name: 'mollie_wc_gateway_applepay_express',
title: 'Apple Pay Express button',
description: 'Apple Pay Express button',
content: <ApplePayButtonComponent />,
edit: <ApplePayButtonComponent />,
edit: <ApplePayButtonEditorComponent />,
ariaLabel: 'Apple Pay',
canMakePayment: () => true,
paymentMethodId: 'mollie_wc_gateway_applepay',
gatewayId: 'mollie_wc_gateway_applepay',
supports: {
features: ['products'],
style: ['height', 'borderRadius']
},
})
}
Expand Down
24 changes: 0 additions & 24 deletions resources/scss/mollie-applepaydirect.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@
-apple-pay-button-type: checkout; /* also: check-out, book, or subscribe */
}

@media (max-width: 480px) {
.apple-pay-button {
height: 41px;
min-height: 40px;
max-height: 47px;
}
}

@media (min-width: 481px) and (max-width: 1024px) {
.apple-pay-button {
height: 48px;
min-height: 48px;
max-height: 55px;
}
}

@media (min-width: 1025px) {
.apple-pay-button {
height: 56px;
min-height: 56px;
max-height: 64px;
}
}

.apple-pay-button-black {
-apple-pay-button-style: black;
}
Expand Down
15 changes: 14 additions & 1 deletion src/PaymentMethods/Applepay.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ protected function getConfig(): array

public function getFormFields($generalFormFields): array
{
$notice = [
'notice' => [
'title' =>

__(
'<p>Important: The Cart & Express Checkout Smart Button Stylings may be controlled in the Editor on the Block Checkout configuration.</p>',
'mollie-payments-for-woocommerce'
),
'type' => 'title',
'class' => 'notice notice-warning',
'css' => 'padding:20px;',
],
];
$paymentMethodFormFieds = [
'mollie_apple_pay_button_enabled_cart' => [
'title' => __('Enable Apple Pay Button on Cart page', 'mollie-payments-for-woocommerce'),
Expand All @@ -56,6 +69,6 @@ public function getFormFields($generalFormFields): array
'default' => 'no',
],
];
return array_merge($generalFormFields, $paymentMethodFormFieds);
return array_merge($notice, $generalFormFields, $paymentMethodFormFieds);
}
}
Loading