woocommerce/plugins/woocommerce-admin/client/payments-welcome/apms.tsx

137 lines
3.2 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { List } from '@woocommerce/components';
import { download, Icon } from '@wordpress/icons';
import {
Card,
CardBody,
CardFooter,
CardHeader,
ExternalLink,
Notice,
ToggleControl,
} from '@wordpress/components';
/**
* Internal dependencies
*/
import strings from './strings';
import { WC_ASSET_URL } from '~/utils/admin-settings';
export interface Apm {
id: string;
title: string;
icon: string;
description: string;
link: string;
extension: string;
}
export const apms: Apm[] = [
{
id: 'paypal',
title: strings.apms.paypal.title,
icon: `${ WC_ASSET_URL }images/payment_methods/72x72/paypal.png`,
description: strings.apms.paypal.description,
link: 'https://woocommerce.com/products/woocommerce-paypal-payments/',
extension: 'woocommerce-paypal-payments',
},
{
id: 'amazonpay',
title: strings.apms.amazonpay.title,
icon: `${ WC_ASSET_URL }images/payment_methods/72x72/amazonpay.png`,
description: strings.apms.amazonpay.description,
link: 'https://woocommerce.com/products/pay-with-amazon/',
extension: 'woocommerce-gateway-amazon-payments-advanced',
},
{
id: 'klarna',
title: strings.apms.klarna.title,
icon: `${ WC_ASSET_URL }images/payment_methods/72x72/klarna.png`,
description: strings.apms.klarna.description,
link: 'https://woocommerce.com/products/klarna-payments/',
extension: 'klarna-payments-for-woocommerce',
},
];
interface ApmListProps {
enabledApms: Set< Apm >;
setEnabledApms: ( value: Set< Apm > ) => void;
}
const ApmNotice = ( { enabledApms }: { enabledApms: Set< Apm > } ) => {
if ( ! enabledApms.size ) {
return null;
}
const extensions = [ ...enabledApms ]
.map( ( apm ) => apm.title )
.join( ', ' );
return (
Update WCPay welcome page incentives (#38689) * Initial refactor of components Move out from index every UI component to make it easier to maintain. * Initial implementation of new design Some minor adjustments are missing, and I've added a few TODOs to complete later. * Add changelog entry * Finish design update * Compress menu icon * Add user's first name to heading copy * Fetch and cache eligible incentive from WCPay API Sharing its properties under `window.WcSettings.admin` * Filter `allowed_promo_notes` To be able to add those form WCPay API request * Update JS side to use the new shared incentive details * Ensure we cache requests even if there are no eligible incentives * Fix a typo in WCPayBanner * Move incentive preloaded data from wcSettings to a new window variable which will be only loaded on WCPay welcome page. * Simplify `has_wcpay` check * Render sanitized HTML from incentive description * Update get incentive logic to also cache non success responses * Add incentive ID to page view track * Add changelog entry for the onboarding package * Update used options names and add them to `get_default_option_permissions * Differentiate every dismissed incentive Reuse WCPay welcome page logic for notes display conditions * Use tos_url instead of tos_link to match response * Fix incentives endpoint request payload * Back to preload incentive on admin shared settings * Move promo notes filter to where it's used to avoid any possible race conditions. * Replace every occurrence of `WooCommerce Payments` with `WooPayments` * Prevent modal large padding-bottom * Prevent another global style override on modal * Fix TS error coming from trunk merge * Fix wrong style property * Further restrict WCPay incentives to plugin not active and countries supported * Adjust the meaning of has_wcpay * Wait for dismiss option update before redirect to prevent the side menu entry to be visible after redirecting back to WC admin. * Enforce TOS asterix at the end of incentive description * Remove underscore from priavate instance var. * Fix ESLint error * Fix SCSS linting issues * Refine `has_wcpay` and `has_orders` * Enforce consistent WooPayments branding * Enforce stricter i18n calls with escape * Update page title to match new branding * docs: Enforce branding in code docs also * Remove method that is unreliable to be used outside of onboarding * Remove unused constant * Missing new line Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> --------- Co-authored-by: Vlad Olaru <vlad@pixelgrade.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-16 14:32:58 +00:00
<Notice
status={ 'info' }
isDismissible={ false }
className="woopayments-welcome-page__apms-notice"
>
<Icon icon={ download } />
<div>{ strings.apms.installText( extensions ) }</div>
</Notice>
);
};
const ApmList: React.FunctionComponent< ApmListProps > = ( {
enabledApms,
setEnabledApms,
} ) => {
const handleToggleChange = ( apm: Apm ) => {
if ( enabledApms.has( apm ) ) {
enabledApms.delete( apm );
} else {
enabledApms.add( apm );
}
setEnabledApms( new Set< Apm >( enabledApms ) );
};
const apmsList = apms.map( ( apm ) => ( {
key: apm.id,
title: apm.title,
content: (
<>
{ apm.description }{ ' ' }
<a href={ apm.link } target="_blank" rel="noreferrer">
{ strings.learnMore }
</a>
</>
),
before: <img src={ apm.icon } alt="" />,
after: (
<ToggleControl
checked={ enabledApms.has( apm ) }
onChange={ () => handleToggleChange( apm ) }
/>
),
} ) );
return (
<>
<ApmNotice enabledApms={ enabledApms } />
Update WCPay welcome page incentives (#38689) * Initial refactor of components Move out from index every UI component to make it easier to maintain. * Initial implementation of new design Some minor adjustments are missing, and I've added a few TODOs to complete later. * Add changelog entry * Finish design update * Compress menu icon * Add user's first name to heading copy * Fetch and cache eligible incentive from WCPay API Sharing its properties under `window.WcSettings.admin` * Filter `allowed_promo_notes` To be able to add those form WCPay API request * Update JS side to use the new shared incentive details * Ensure we cache requests even if there are no eligible incentives * Fix a typo in WCPayBanner * Move incentive preloaded data from wcSettings to a new window variable which will be only loaded on WCPay welcome page. * Simplify `has_wcpay` check * Render sanitized HTML from incentive description * Update get incentive logic to also cache non success responses * Add incentive ID to page view track * Add changelog entry for the onboarding package * Update used options names and add them to `get_default_option_permissions * Differentiate every dismissed incentive Reuse WCPay welcome page logic for notes display conditions * Use tos_url instead of tos_link to match response * Fix incentives endpoint request payload * Back to preload incentive on admin shared settings * Move promo notes filter to where it's used to avoid any possible race conditions. * Replace every occurrence of `WooCommerce Payments` with `WooPayments` * Prevent modal large padding-bottom * Prevent another global style override on modal * Fix TS error coming from trunk merge * Fix wrong style property * Further restrict WCPay incentives to plugin not active and countries supported * Adjust the meaning of has_wcpay * Wait for dismiss option update before redirect to prevent the side menu entry to be visible after redirecting back to WC admin. * Enforce TOS asterix at the end of incentive description * Remove underscore from priavate instance var. * Fix ESLint error * Fix SCSS linting issues * Refine `has_wcpay` and `has_orders` * Enforce consistent WooPayments branding * Enforce stricter i18n calls with escape * Update page title to match new branding * docs: Enforce branding in code docs also * Remove method that is unreliable to be used outside of onboarding * Remove unused constant * Missing new line Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> --------- Co-authored-by: Vlad Olaru <vlad@pixelgrade.com> Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com>
2023-06-16 14:32:58 +00:00
<Card size="large" className="woopayments-welcome-page__apms">
<CardHeader>
<h1>{ strings.apms.addMoreWaysToPay }</h1>
</CardHeader>
<CardBody>
<List items={ apmsList } />
</CardBody>
<CardFooter>
<ExternalLink href="https://woocommerce.com/product-category/woocommerce-extensions/payment-gateways/wallets/?categoryIds=28682&collections=product&page=1">
{ strings.apms.seeMore }
</ExternalLink>
</CardFooter>
</Card>
</>
);
};
export default ApmList;