woocommerce/plugins/woocommerce-admin/packages/customer-effort-score
louwie17 071a68b950 Update task list component to make use of new experimental list (https://github.com/woocommerce/woocommerce-admin/pull/6849)
* Add initial task item component with the new task list

* Switch components to functional components

* Some minor updates from the last rebase

* Fix missing variables.

* Fix tests

* Add animation for the experimental list

* Fix lint error

* Add changelog

* Fix E2E tests

* Update PR suggestions and export list from experimental package

* Fix dismiss styling issue

Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com>
2021-04-27 12:23:34 -03:00
..
src Add TypeScript to CustomerFeedbackModal (https://github.com/woocommerce/woocommerce-admin/pull/6498) 2021-03-30 20:04:08 +08:00
.npmrc Basic customer effort score survey functionality (https://github.com/woocommerce/woocommerce-admin/pull/5324) 2020-10-30 16:52:52 +10:00
CHANGELOG.md bump package versions (https://github.com/woocommerce/woocommerce-admin/pull/6767) 2021-04-13 08:32:27 +12:00
README.md Add readme instructions on how to use CustomerEffortScore (https://github.com/woocommerce/woocommerce-admin/pull/6746) 2021-04-07 10:58:01 +10:00
package.json Update task list component to make use of new experimental list (https://github.com/woocommerce/woocommerce-admin/pull/6849) 2021-04-27 12:23:34 -03:00

README.md

Customer Effort Score

WooCommerce utility to measuring user satisfaction.

Installation

Install the module

npm install @woocommerce/customer-effort-score --save

This package assumes that your code will run in an ES2015+ environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using core-js or @babel/polyfill will add support for these methods. Learn more about it in Babel docs.

Usage

CustomerEffortScore component

CustomerEffortScore is a React component that can be used to implement your own effort score survey, providing your own logging infrastructure.

This creates a wrapper component around CustomerEffortScore which simply logs responses to the console:

import CustomerEffortScore from '@woocommerce/customer-effort-score';

export function CustomerEffortScoreConsole( { label } ) {
    const onNoticeShown = () => console.log( 'onNoticeShown' );
    const onModalShown = () => console.log( 'onModalShown' );
    const onNoticeDismissed = () => console.log( 'onNoticeDismissed' );
    const recordScore = ( score, comments ) => console.log( { score, comments } );

    return (
        <CustomerEffortScore
			recordScoreCallback={ recordScore }
			label={ label }
			onNoticeShownCallback={ onNoticeShown }
			onNoticeDismissedCallback={ onNoticeDismissed }
			onModalShownCallback={ onModalShown }
			icon={
				<span
					style={ { height: 21, width: 21 } }
					role="img"
					aria-label="Pencil icon"
				>
					✏️
				</span>
			}
        />
    );
};

Use this wrapper component in your code like this:

const MyComponent = function() {
    const [ ceses, setCeses ] = useState( [] );
	
    const addCES = () => {
		setCeses( 
			ceses.concat( 
				<CustomerEffortScoreConsole
					label={ `survey ${ceses.length + 1}` }
					key={ ceses.length + 1 }
				/> 
			) 
		);
	};

    return (
        <>
            { ceses }
            <button onClick={ addCES }>Show new survey</button>
        </>
    );
};