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

Donation block: Make content editable #43834

Merged
merged 5 commits into from
Jul 2, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* WordPress dependencies
*/
// eslint-disable-next-line wpcalypso/import-docblock
import { createContext } from '@wordpress/element';

const Context = createContext( {
activeTab: 'one-time',
} );

export default Context;
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* WordPress dependencies
*/
// eslint-disable-next-line wpcalypso/import-docblock
import { ExternalLink, PanelBody, ToggleControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/block-editor';

const Controls = ( props ) => {
const { attributes, setAttributes, products, siteSlug } = props;
const { monthlyPlanId, annuallyPlanId, showCustomAmount } = attributes;
return (
<InspectorControls>
<PanelBody title={ __( 'Settings', 'full-site-editing' ) }>
Copy link

Choose a reason for hiding this comment

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

ℹ️ String reuse speeds up translation and improves consistency. The following string might make a good alternative and has already been translated 42 times:
translate( 'Settings', { context: 'NewDash Page Title'} ) ES Score: 8
See 2 additional suggestions in the PR translation status page

<ToggleControl
checked={ !! monthlyPlanId }
onChange={ ( value ) =>
setAttributes( { monthlyPlanId: value ? products[ '1 month' ] : null } )
}
label={ __( 'Show monthly donations', 'full-site-editing' ) }
/>
<ToggleControl
checked={ !! annuallyPlanId }
onChange={ ( value ) =>
setAttributes( { annuallyPlanId: value ? products[ '1 year' ] : null } )
}
label={ __( 'Show annual donations', 'full-site-editing' ) }
/>
<ToggleControl
checked={ showCustomAmount }
onChange={ ( value ) => setAttributes( { showCustomAmount: value } ) }
label={ __( 'Show custom amount option', 'full-site-editing' ) }
/>
<ExternalLink href={ `https://wordpress.com/earn/payments/${ siteSlug }` }>
{ __( 'View donation earnings', 'full-site-editing' ) }
</ExternalLink>
</PanelBody>
</InspectorControls>
);
};

export default Controls;
110 changes: 0 additions & 110 deletions apps/full-site-editing/full-site-editing-plugin/donations/donations.js

This file was deleted.

25 changes: 13 additions & 12 deletions apps/full-site-editing/full-site-editing-plugin/donations/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import Donations from './donations';
import Tabs from './tabs';
import LoadingError from './loading-error';
import LoadingStatus from './loading-status';
import UpgradePlan from './upgrade-plan';
import fetchDefaultProducts from './fetch-default-products';
import fetchStatus from './fetch-status';

const Edit = ( { attributes, setAttributes } ) => {
const Edit = ( props ) => {
const { attributes } = props;
const { currency } = attributes;

const [ isLoading, setIsLoading ] = useState( true );
const [ loadingError, setLoadingError ] = useState( '' );
const [ shouldUpgrade, setShouldUpgrade ] = useState( false );
Expand All @@ -28,14 +31,13 @@ const Edit = ( { attributes, setAttributes } ) => {
setIsLoading( false );
};

const filterProducts = ( productList, productCurrency ) => {
return productList.reduce( ( filteredProducts, { id, currency, type, interval } ) => {
if ( currency === productCurrency && type === 'donation' ) {
const filterProducts = ( productList ) =>
productList.reduce( ( filteredProducts, { id, currency: productCurrency, type, interval } ) => {
if ( productCurrency === currency && type === 'donation' ) {
filteredProducts[ interval ] = id;
}
return filteredProducts;
}, {} );
};

const hasRequiredProducts = ( productIdsPerInterval ) => {
const intervals = Object.keys( productIdsPerInterval );
Expand All @@ -56,13 +58,13 @@ const Edit = ( { attributes, setAttributes } ) => {
setStripeConnectUrl( result.connect_url );
setSiteSlug( result.site_slug );

const filteredProducts = filterProducts( result.products, 'USD' );
const filteredProducts = filterProducts( result.products );

if ( hasRequiredProducts( filteredProducts ) ) {
setProducts( filteredProducts );
} else {
fetchDefaultProducts( 'USD' ).then(
( defaultProducts ) => setProducts( filterProducts( defaultProducts, 'USD' ) ),
fetchDefaultProducts( currency ).then(
( defaultProducts ) => setProducts( filterProducts( defaultProducts ) ),
apiError
);
}
Expand All @@ -89,11 +91,10 @@ const Edit = ( { attributes, setAttributes } ) => {
}

return (
<Donations
attributes={ attributes }
<Tabs
{ ...props }
products={ products }
stripeConnectUrl={ stripeConnectUrl }
setAttributes={ setAttributes }
siteSlug={ siteSlug }
/>
);
Expand Down
Loading