Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show feedback footer on product editor page (#38599)
- Loading branch information
1 parent
f163880
commit dadc0eb
Showing
34 changed files
with
452 additions
and
260 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
packages/js/customer-effort-score/changelog/add-product-editor-feedback-footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: dev | ||
|
||
Remove unused constant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './use-customer-effort-score-modal'; | ||
export * from './use-customer-effort-score-exit-page-tracker'; |
71 changes: 71 additions & 0 deletions
71
packages/js/customer-effort-score/src/hooks/use-customer-effort-score-modal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { resolveSelect, useDispatch, useSelect } from '@wordpress/data'; | ||
import { OPTIONS_STORE_NAME } from '@woocommerce/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { SHOWN_FOR_ACTIONS_OPTION_NAME } from '../../constants'; | ||
import { STORE_KEY } from '../../store'; | ||
|
||
export const useCustomerEffortScoreModal = () => { | ||
const { showCesModal: _showCesModal, showProductMVPFeedbackModal } = | ||
useDispatch( STORE_KEY ); | ||
const { updateOptions } = useDispatch( OPTIONS_STORE_NAME ); | ||
|
||
const { wasPreviouslyShown, isLoading } = useSelect( ( select ) => { | ||
const { getOption, hasFinishedResolution } = | ||
select( OPTIONS_STORE_NAME ); | ||
|
||
const shownForActionsOption = | ||
( getOption( SHOWN_FOR_ACTIONS_OPTION_NAME ) as string[] ) || []; | ||
|
||
const resolving = ! hasFinishedResolution( 'getOption', [ | ||
SHOWN_FOR_ACTIONS_OPTION_NAME, | ||
] ); | ||
|
||
return { | ||
wasPreviouslyShown: ( action: string ) => { | ||
return shownForActionsOption.includes( action ); | ||
}, | ||
isLoading: resolving, | ||
}; | ||
} ); | ||
|
||
const markCesAsShown = async ( action: string ) => { | ||
const { getOption } = resolveSelect( OPTIONS_STORE_NAME ); | ||
|
||
const shownForActionsOption = | ||
( ( await getOption( | ||
SHOWN_FOR_ACTIONS_OPTION_NAME | ||
) ) as string[] ) || []; | ||
|
||
updateOptions( { | ||
[ SHOWN_FOR_ACTIONS_OPTION_NAME ]: [ | ||
action, | ||
...shownForActionsOption, | ||
], | ||
} ); | ||
}; | ||
|
||
const showCesModal = ( | ||
surveyProps = {}, | ||
props = {}, | ||
onSubmitNoticeProps = {}, | ||
tracksProps = {} | ||
) => { | ||
_showCesModal( surveyProps, props, onSubmitNoticeProps, tracksProps ); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore We don't have type definitions for this. | ||
markCesAsShown( surveyProps.action ); | ||
}; | ||
|
||
return { | ||
wasPreviouslyShown, | ||
isLoading, | ||
showCesModal, | ||
showProductMVPFeedbackModal, | ||
}; | ||
}; |
4 changes: 4 additions & 0 deletions
4
packages/js/product-editor/changelog/add-product-editor-feedback-footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: add | ||
|
||
Show feedback bar for the product editor. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
packages/js/product-editor/src/components/feedback-bar/feedback-bar.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button } from '@wordpress/components'; | ||
import { | ||
createElement, | ||
createInterpolateElement, | ||
Fragment, | ||
} from '@wordpress/element'; | ||
import { closeSmall } from '@wordpress/icons'; | ||
import { WooFooterItem } from '@woocommerce/admin-layout'; | ||
import { Pill } from '@woocommerce/components'; | ||
import { useCustomerEffortScoreModal } from '@woocommerce/customer-effort-score'; | ||
import { Product } from '@woocommerce/data'; | ||
import { recordEvent } from '@woocommerce/tracks'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { PRODUCT_EDITOR_FEEDBACK_CES_ACTION } from '../../constants'; | ||
import { useFeedbackBar } from '../../hooks/use-feedback-bar'; | ||
|
||
export type FeedbackBarProps = { | ||
product: Partial< Product >; | ||
}; | ||
|
||
export function FeedbackBar( { product }: FeedbackBarProps ) { | ||
const { hideFeedbackBar, shouldShowFeedbackBar } = useFeedbackBar(); | ||
const { showCesModal, showProductMVPFeedbackModal } = | ||
useCustomerEffortScoreModal(); | ||
|
||
const getProductTracksProps = () => { | ||
const tracksProps = { | ||
product_type: product.type, | ||
}; | ||
|
||
return tracksProps; | ||
}; | ||
|
||
const onShareFeedbackClick = () => { | ||
recordEvent( 'product_editor_feedback_bar_share_feedback_click', { | ||
...getProductTracksProps(), | ||
} ); | ||
|
||
showCesModal( | ||
{ | ||
action: PRODUCT_EDITOR_FEEDBACK_CES_ACTION, | ||
title: __( | ||
"How's your experience with the product editor?", | ||
'woocommerce' | ||
), | ||
firstQuestion: __( | ||
'The product editing screen is easy to use', | ||
'woocommerce' | ||
), | ||
secondQuestion: __( | ||
"The product editing screen's functionality meets my needs", | ||
'woocommerce' | ||
), | ||
onsubmitLabel: __( | ||
"Thanks for the feedback. We'll put it to good use!", | ||
'woocommerce' | ||
), | ||
shouldShowComments: () => true, | ||
}, | ||
{}, | ||
{ | ||
type: 'snackbar', | ||
icon: <span>🌟</span>, | ||
} | ||
); | ||
}; | ||
|
||
const onTurnOffEditorClick = () => { | ||
recordEvent( 'product_editor_feedback_bar_turnoff_editor_click', { | ||
...getProductTracksProps(), | ||
} ); | ||
|
||
hideFeedbackBar(); | ||
|
||
showProductMVPFeedbackModal(); | ||
}; | ||
|
||
const onHideFeedbackBarClick = () => { | ||
recordEvent( 'product_editor_feedback_bar_dismiss_click', { | ||
...getProductTracksProps(), | ||
} ); | ||
|
||
hideFeedbackBar(); | ||
}; | ||
|
||
return ( | ||
<> | ||
{ shouldShowFeedbackBar && ( | ||
<WooFooterItem> | ||
<div className="woocommerce-product-mvp-ces-footer"> | ||
<Pill>Beta</Pill> | ||
<div className="woocommerce-product-mvp-ces-footer__message"> | ||
{ createInterpolateElement( | ||
__( | ||
'How is your experience with the new product form? <span><shareButton>Share feedback</shareButton> or <turnOffButton>turn it off</turnOffButton></span>', | ||
'woocommerce' | ||
), | ||
{ | ||
span: ( | ||
<span className="woocommerce-product-mvp-ces-footer__message-buttons" /> | ||
), | ||
shareButton: ( | ||
<Button | ||
variant="link" | ||
onClick={ onShareFeedbackClick } | ||
/> | ||
), | ||
turnOffButton: ( | ||
<Button | ||
onClick={ onTurnOffEditorClick } | ||
variant="link" | ||
/> | ||
), | ||
} | ||
) } | ||
</div> | ||
<Button | ||
className="woocommerce-product-mvp-ces-footer__close-button" | ||
icon={ closeSmall } | ||
label={ __( 'Hide this message', 'woocommerce' ) } | ||
onClick={ onHideFeedbackBarClick } | ||
></Button> | ||
</div> | ||
</WooFooterItem> | ||
) } | ||
</> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/js/product-editor/src/components/feedback-bar/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './feedback-bar'; |
42 changes: 42 additions & 0 deletions
42
packages/js/product-editor/src/components/feedback-bar/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.woocommerce-product-mvp-ces-footer { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
// the left/right padding is set to this to match the padding of | ||
// .block-editor-block-list__layout.is-root-container and | ||
// .editor-styles-wrapper combined | ||
padding: $gap calc(2 * $gap + $gap-small); | ||
gap: $gap; | ||
|
||
@include breakpoint(">782px") { | ||
padding: $gap 0; | ||
max-width: 650px; | ||
margin: 0 auto; | ||
} | ||
|
||
.woocommerce-pill { | ||
background-color: $studio-yellow-5; | ||
border: 0; | ||
font-size: 1em; | ||
} | ||
|
||
&__close-button { | ||
padding: 0; | ||
} | ||
|
||
&__message { | ||
flex: 1; | ||
flex-wrap: wrap; | ||
align-items: center; | ||
white-space: pre-wrap; | ||
} | ||
|
||
&__message-buttons { | ||
white-space: nowrap; | ||
|
||
button.is-link { | ||
text-decoration: none; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/js/product-editor/src/components/footer/footer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { createElement } from '@wordpress/element'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { WooFooterItem } from '@woocommerce/admin-layout'; | ||
import { Product } from '@woocommerce/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { FeedbackBar } from '../feedback-bar'; | ||
import { ProductMVPFeedbackModalContainer } from '../product-mvp-feedback-modal-container'; | ||
|
||
export type FooterProps = { | ||
product: Partial< Product >; | ||
}; | ||
|
||
export function Footer( { product }: FooterProps ) { | ||
return ( | ||
<div | ||
className="woocommerce-product-footer" | ||
role="region" | ||
aria-label={ __( 'Product Editor bottom bar.', 'woocommerce' ) } | ||
tabIndex={ -1 } | ||
> | ||
<WooFooterItem.Slot name="product" /> | ||
|
||
<FeedbackBar product={ product } /> | ||
<ProductMVPFeedbackModalContainer productId={ product.id } /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './footer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.woocommerce-product-footer { | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/js/product-editor/src/components/product-mvp-ces-footer/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.