diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/donations-tabs.js b/apps/full-site-editing/full-site-editing-plugin/donations/donations-tabs.js new file mode 100644 index 0000000000000..452628e924ad4 --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/donations/donations-tabs.js @@ -0,0 +1,55 @@ +/** + * External dependencies + */ +import classNames from 'classnames'; + +/** + * WordPress dependencies + */ +import { useState } from '@wordpress/element'; +import { __ } from '@wordpress/i18n'; +import { Button } from '@wordpress/components'; + +/** + * Internal dependencies + */ + +const DonationsTabs = () => { + const [ activeTab, setActiveTab ] = useState( 'one-time' ); + + const isActive = ( button ) => ( activeTab === button ? 'active' : null ); + + return ( +
+ + + +
+ { __( 'One time', 'full-site-editing' ) } +
+
+ { __( 'Monthly', 'full-site-editing' ) } +
+
+ { __( 'Annually', 'full-site-editing' ) } +
+
+ ); +}; + +export default DonationsTabs; diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/edit.js b/apps/full-site-editing/full-site-editing-plugin/donations/edit.js index 6c0c32df84d42..c0a6e2f651092 100644 --- a/apps/full-site-editing/full-site-editing-plugin/donations/edit.js +++ b/apps/full-site-editing/full-site-editing-plugin/donations/edit.js @@ -1,55 +1,57 @@ /** * External dependencies */ -import classNames from 'classnames'; /** * WordPress dependencies */ -import { useState } from '@wordpress/element'; -import { __ } from '@wordpress/i18n'; -import { Button } from '@wordpress/components'; +import { useState, useEffect } from '@wordpress/element'; /** * Internal dependencies */ +import DonationsTabs from './donations-tabs'; +import LoadingError from './loading-error'; +import LoadingStatus from './loading-status'; +import UpgradePlan from './upgrade-plan'; +import fetchStatus from './fetch-status'; const Edit = () => { - const [ activeTab, setActiveTab ] = useState( 'one-time' ); - - const isActive = ( button ) => ( activeTab === button ? 'active' : null ); - - return ( -
- - - -
- { __( 'One time', 'full-site-editing' ) } -
-
- { __( 'Monthly', 'full-site-editing' ) } -
-
- { __( 'Annually', 'full-site-editing' ) } -
-
- ); + const [ isLoading, setIsLoading ] = useState( true ); + const [ loadingError, setLoadingError ] = useState( '' ); + const [ shouldUpgrade, setShouldUpgrade ] = useState( false ); + const [ upgradeUrl, setUpgradeUrl ] = useState( '' ); + + const mapStatusToState = ( result ) => { + setShouldUpgrade( result.should_upgrade_to_access_memberships ); + setUpgradeUrl( result.upgrade_url ); + setIsLoading( false ); + }; + + const apiError = ( message ) => { + setLoadingError( message ); + setIsLoading( false ); + }; + + const updateData = () => { + fetchStatus().then( mapStatusToState, apiError ); + }; + + useEffect( () => updateData() ); + + if ( isLoading ) { + return ; + } + + if ( loadingError ) { + return ; + } + + if ( shouldUpgrade ) { + return ; + } + + return ; }; export default Edit; diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/fetch-status.js b/apps/full-site-editing/full-site-editing-plugin/donations/fetch-status.js new file mode 100644 index 0000000000000..4bc5dbadd173d --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/donations/fetch-status.js @@ -0,0 +1,26 @@ +/** + * External dependencies + */ + +/** + * WordPress dependencies + */ +import apiFetch from '@wordpress/api-fetch'; + +/** + * Internal dependencies + */ + +const fetchStatus = async () => { + try { + const result = await apiFetch( { + path: '/wpcom/v2/memberships/status', + method: 'GET', + } ); + return result; + } catch ( error ) { + return Promise.reject( error.message ); + } +}; + +export default fetchStatus; diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/loading-error.js b/apps/full-site-editing/full-site-editing-plugin/donations/loading-error.js new file mode 100644 index 0000000000000..4ad8cb3f067e4 --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/donations/loading-error.js @@ -0,0 +1,27 @@ +/** + * External dependencies + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Placeholder } from '@wordpress/components'; + +/** + * Internal dependencies + */ + +const LoadingError = ( { error } ) => { + return ( +
+ +
+ ); +}; + +export default LoadingError; diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/loading-status.js b/apps/full-site-editing/full-site-editing-plugin/donations/loading-status.js new file mode 100644 index 0000000000000..fab2b9561c607 --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/donations/loading-status.js @@ -0,0 +1,29 @@ +/** + * External dependencies + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Placeholder, Spinner } from '@wordpress/components'; + +/** + * Internal dependencies + */ + +const LoadingStatus = () => { + return ( +
+ + + +
+ ); +}; + +export default LoadingStatus; diff --git a/apps/full-site-editing/full-site-editing-plugin/donations/upgrade-plan.js b/apps/full-site-editing/full-site-editing-plugin/donations/upgrade-plan.js new file mode 100644 index 0000000000000..9366d003aa016 --- /dev/null +++ b/apps/full-site-editing/full-site-editing-plugin/donations/upgrade-plan.js @@ -0,0 +1,49 @@ +/** + * External dependencies + */ + +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { Button, ExternalLink, Placeholder } from '@wordpress/components'; + +/** + * Internal dependencies + */ + +const UpgradePlan = ( { upgradeUrl } ) => { + return ( +
+ + +
+ + { __( 'Read more about Donations and related fees.', 'full-site-editing' ) } + +
+
+
+ ); +}; + +export default UpgradePlan;