woocommerce/plugins/woocommerce-blocks/assets/js/editor-components/feedback-prompt/index.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import PropTypes from 'prop-types';
import { Icon, commentContent, external } from '@wordpress/icons';
Add dismissible compatibility notice to sidebar when editing Cart and Checkout (https://github.com/woocommerce/woocommerce-blocks/pull/6869) * Add default page notice * show notice all inner blocks * support flow when page isnt saved * switch from where we get the current post id * update lock * fix types * Remove old compatibility notices from Cart and Checkout * Move useCompatibilityNotice to sidebar-compatibility-notice directory * Remove old CartCheckoutCompatibilityNotice * Create sidebar compatibility notice hoc * Add isCartOrCheckoutOrInnerBlock function * Refactor defaultNotice to use new isCartOrCheckoutOrInnerBlock func * Remove BlockSettings from checkout edit and export from checkout-shared * Change so component still renders, it is just hidden with display: none This is required because when it returns null the component gets skipped from being added to the Slot, then when it does return a component, then it gets rendered at the bottom of the Slot. By ensuring it always renders we can have it at the top all the time. * Set the priorities of the hoc filters so compat notice renders first * Make isCartOrCheckoutInnerBlock a hook * Remove old compatibility notice related tests * Remove BlockSettings from Cart * Remove withDefaultNotice hoc * Include DefaultNotice in compatibility notice * Remove DefaultNotice from Checkout * Rename withSidebarCompatibilityNotice to withSidebarNotices This is because it includes the sidebar compatibility notice and the default notices * Remove useIsCartOrCheckoutOrInnerBlock hook * Remove compatibility notice code from tests * Revert DefaultNotice back to the old one * Remove unused components * Remove withBlockSettings HOC and fix TS types This is an abstraction that is no longer required, we can just include BlockSettings in the Cart and Checkout blocks * Remove CartCheckoutFeedbackPrompt from BlockSettings It will be included in sidebar-notices instead * Fix TS Types in DefaultNotice * Add BlockSettings to cart and checkout edit * Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881) * Show "Feedback prompt" for all inner blocks * Fix the "feedback" notice position for these blocks The "checkout fields", "checkout billing address" and "checkout shipping address" have the addressFields option which gets rerendered and placed at the bottom of the inspector controls. * Tidy up the address-fields hoc * Use correct block name to check for billing or shipping address * Revert "Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)" This reverts commit 5f3d6cf15ce08d9c303e62ec3e0d0315ead1281f. * Add hack to get feedback prompt to render last * Fix TS errors for context and attributes * Include CartCheckoutFeedbackPrompt in accountcontrols & addresscontrols * Do not include feedback prompt if on an address block or contact info * Remove unused hoc for address fields Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-12 14:23:08 +00:00
import { useEffect, useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import './style.scss';
/**
* Component to render a Feedback prompt in the sidebar.
*
* @param {Object} props Incoming props for the component.
* @param {string} props.text
* @param {string} props.title
* @param {string} props.url
*/
const FeedbackPrompt = ( {
text,
title = __( 'Feedback?', 'woo-gutenberg-products-block' ),
url = 'https://ideas.woocommerce.com/forums/133476-woocommerce?category_id=384565',
} ) => {
Add dismissible compatibility notice to sidebar when editing Cart and Checkout (https://github.com/woocommerce/woocommerce-blocks/pull/6869) * Add default page notice * show notice all inner blocks * support flow when page isnt saved * switch from where we get the current post id * update lock * fix types * Remove old compatibility notices from Cart and Checkout * Move useCompatibilityNotice to sidebar-compatibility-notice directory * Remove old CartCheckoutCompatibilityNotice * Create sidebar compatibility notice hoc * Add isCartOrCheckoutOrInnerBlock function * Refactor defaultNotice to use new isCartOrCheckoutOrInnerBlock func * Remove BlockSettings from checkout edit and export from checkout-shared * Change so component still renders, it is just hidden with display: none This is required because when it returns null the component gets skipped from being added to the Slot, then when it does return a component, then it gets rendered at the bottom of the Slot. By ensuring it always renders we can have it at the top all the time. * Set the priorities of the hoc filters so compat notice renders first * Make isCartOrCheckoutInnerBlock a hook * Remove old compatibility notice related tests * Remove BlockSettings from Cart * Remove withDefaultNotice hoc * Include DefaultNotice in compatibility notice * Remove DefaultNotice from Checkout * Rename withSidebarCompatibilityNotice to withSidebarNotices This is because it includes the sidebar compatibility notice and the default notices * Remove useIsCartOrCheckoutOrInnerBlock hook * Remove compatibility notice code from tests * Revert DefaultNotice back to the old one * Remove unused components * Remove withBlockSettings HOC and fix TS types This is an abstraction that is no longer required, we can just include BlockSettings in the Cart and Checkout blocks * Remove CartCheckoutFeedbackPrompt from BlockSettings It will be included in sidebar-notices instead * Fix TS Types in DefaultNotice * Add BlockSettings to cart and checkout edit * Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881) * Show "Feedback prompt" for all inner blocks * Fix the "feedback" notice position for these blocks The "checkout fields", "checkout billing address" and "checkout shipping address" have the addressFields option which gets rerendered and placed at the bottom of the inspector controls. * Tidy up the address-fields hoc * Use correct block name to check for billing or shipping address * Revert "Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)" This reverts commit 5f3d6cf15ce08d9c303e62ec3e0d0315ead1281f. * Add hack to get feedback prompt to render last * Fix TS errors for context and attributes * Include CartCheckoutFeedbackPrompt in accountcontrols & addresscontrols * Do not include feedback prompt if on an address block or contact info * Remove unused hoc for address fields Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-12 14:23:08 +00:00
// By returning false we ensure that this component is not entered into the InspectorControls
// (which is a slot fill), children array on first render, on the second render when the state
// gets updated this component does get put into the InspectorControls children array but as the
// last item, ensuring it shows last in the sidebar.
const [ isVisible, setIsVisible ] = useState( false );
useEffect( () => {
setIsVisible( true );
}, [] );
return (
Add dismissible compatibility notice to sidebar when editing Cart and Checkout (https://github.com/woocommerce/woocommerce-blocks/pull/6869) * Add default page notice * show notice all inner blocks * support flow when page isnt saved * switch from where we get the current post id * update lock * fix types * Remove old compatibility notices from Cart and Checkout * Move useCompatibilityNotice to sidebar-compatibility-notice directory * Remove old CartCheckoutCompatibilityNotice * Create sidebar compatibility notice hoc * Add isCartOrCheckoutOrInnerBlock function * Refactor defaultNotice to use new isCartOrCheckoutOrInnerBlock func * Remove BlockSettings from checkout edit and export from checkout-shared * Change so component still renders, it is just hidden with display: none This is required because when it returns null the component gets skipped from being added to the Slot, then when it does return a component, then it gets rendered at the bottom of the Slot. By ensuring it always renders we can have it at the top all the time. * Set the priorities of the hoc filters so compat notice renders first * Make isCartOrCheckoutInnerBlock a hook * Remove old compatibility notice related tests * Remove BlockSettings from Cart * Remove withDefaultNotice hoc * Include DefaultNotice in compatibility notice * Remove DefaultNotice from Checkout * Rename withSidebarCompatibilityNotice to withSidebarNotices This is because it includes the sidebar compatibility notice and the default notices * Remove useIsCartOrCheckoutOrInnerBlock hook * Remove compatibility notice code from tests * Revert DefaultNotice back to the old one * Remove unused components * Remove withBlockSettings HOC and fix TS types This is an abstraction that is no longer required, we can just include BlockSettings in the Cart and Checkout blocks * Remove CartCheckoutFeedbackPrompt from BlockSettings It will be included in sidebar-notices instead * Fix TS Types in DefaultNotice * Add BlockSettings to cart and checkout edit * Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881) * Show "Feedback prompt" for all inner blocks * Fix the "feedback" notice position for these blocks The "checkout fields", "checkout billing address" and "checkout shipping address" have the addressFields option which gets rerendered and placed at the bottom of the inspector controls. * Tidy up the address-fields hoc * Use correct block name to check for billing or shipping address * Revert "Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)" This reverts commit 5f3d6cf15ce08d9c303e62ec3e0d0315ead1281f. * Add hack to get feedback prompt to render last * Fix TS errors for context and attributes * Include CartCheckoutFeedbackPrompt in accountcontrols & addresscontrols * Do not include feedback prompt if on an address block or contact info * Remove unused hoc for address fields Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-12 14:23:08 +00:00
isVisible && (
<div className="wc-block-feedback-prompt">
<Icon icon={ commentContent } />
<h2 className="wc-block-feedback-prompt__title">{ title }</h2>
Add dismissible compatibility notice to sidebar when editing Cart and Checkout (https://github.com/woocommerce/woocommerce-blocks/pull/6869) * Add default page notice * show notice all inner blocks * support flow when page isnt saved * switch from where we get the current post id * update lock * fix types * Remove old compatibility notices from Cart and Checkout * Move useCompatibilityNotice to sidebar-compatibility-notice directory * Remove old CartCheckoutCompatibilityNotice * Create sidebar compatibility notice hoc * Add isCartOrCheckoutOrInnerBlock function * Refactor defaultNotice to use new isCartOrCheckoutOrInnerBlock func * Remove BlockSettings from checkout edit and export from checkout-shared * Change so component still renders, it is just hidden with display: none This is required because when it returns null the component gets skipped from being added to the Slot, then when it does return a component, then it gets rendered at the bottom of the Slot. By ensuring it always renders we can have it at the top all the time. * Set the priorities of the hoc filters so compat notice renders first * Make isCartOrCheckoutInnerBlock a hook * Remove old compatibility notice related tests * Remove BlockSettings from Cart * Remove withDefaultNotice hoc * Include DefaultNotice in compatibility notice * Remove DefaultNotice from Checkout * Rename withSidebarCompatibilityNotice to withSidebarNotices This is because it includes the sidebar compatibility notice and the default notices * Remove useIsCartOrCheckoutOrInnerBlock hook * Remove compatibility notice code from tests * Revert DefaultNotice back to the old one * Remove unused components * Remove withBlockSettings HOC and fix TS types This is an abstraction that is no longer required, we can just include BlockSettings in the Cart and Checkout blocks * Remove CartCheckoutFeedbackPrompt from BlockSettings It will be included in sidebar-notices instead * Fix TS Types in DefaultNotice * Add BlockSettings to cart and checkout edit * Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881) * Show "Feedback prompt" for all inner blocks * Fix the "feedback" notice position for these blocks The "checkout fields", "checkout billing address" and "checkout shipping address" have the addressFields option which gets rerendered and placed at the bottom of the inspector controls. * Tidy up the address-fields hoc * Use correct block name to check for billing or shipping address * Revert "Editor: Add feedback box to the Cart & Checkout Inner Blocks (https://github.com/woocommerce/woocommerce-blocks/pull/6881)" This reverts commit 5f3d6cf15ce08d9c303e62ec3e0d0315ead1281f. * Add hack to get feedback prompt to render last * Fix TS errors for context and attributes * Include CartCheckoutFeedbackPrompt in accountcontrols & addresscontrols * Do not include feedback prompt if on an address block or contact info * Remove unused hoc for address fields Co-authored-by: Nadir Seghir <nadir.seghir@gmail.com> Co-authored-by: Saad Tarhi <saad.trh@gmail.com>
2022-08-12 14:23:08 +00:00
<p className="wc-block-feedback-prompt__text">{ text }</p>
<a
href={ url }
className="wc-block-feedback-prompt__link"
rel="noreferrer noopener"
target="_blank"
>
{ __(
'Give us your feedback.',
'woo-gutenberg-products-block'
) }
<Icon icon={ external } size={ 16 } />
</a>
</div>
)
);
};
FeedbackPrompt.propTypes = {
text: PropTypes.string,
url: PropTypes.string,
};
export default FeedbackPrompt;
export const CartCheckoutFeedbackPrompt = () => (
<FeedbackPrompt
text={ __(
'We are currently working on improving our cart and checkout blocks to provide merchants with the tools and customization options they need.',
'woo-gutenberg-products-block'
) }
url="https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/new?template=--cart-checkout-feedback.md"
/>
);
export const LegacyFeedbackPrompt = () => (
<FeedbackPrompt
text={ __(
'We are working on a better editing experience that will replace classic blocks. Keep an eye out for updates!',
'woo-gutenberg-products-block'
) }
url="https://github.com/woocommerce/woocommerce-gutenberg-products-block/issues/new?template=--classic-block-feedback.md"
/>
);
export const ProductQueryFeedbackPrompt = () => (
<FeedbackPrompt
text={ __(
'Thanks for trying out the Products block! Help us make it better by sharing your feedback.',
'woo-gutenberg-products-block'
) }
title={ __( 'Share your feedback!', 'woo-gutenberg-products-block' ) }
url={ 'https://airtable.com/shrFX5FAqmCY6hVYI' }
/>
);