-
Notifications
You must be signed in to change notification settings - Fork 10.7k
/
product-mvp-feedback-modal-container.tsx
58 lines (52 loc) · 1.6 KB
/
product-mvp-feedback-modal-container.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* External dependencies
*/
import { useDispatch, useSelect } from '@wordpress/data';
import {
ProductMVPFeedbackModal,
STORE_KEY,
} from '@woocommerce/customer-effort-score';
import { recordEvent } from '@woocommerce/tracks';
import { getAdminLink } from '@woocommerce/settings';
import { useFormContext } from '@woocommerce/components';
import { Product } from '@woocommerce/data';
export const ProductMVPFeedbackModalContainer: React.FC = () => {
const { values } = useFormContext< Product >();
const { hideProductMVPFeedbackModal } = useDispatch( STORE_KEY );
const { isProductMVPModalVisible } = useSelect( ( select ) => {
const { isProductMVPFeedbackModalVisible } = select( STORE_KEY );
return {
isProductMVPModalVisible: isProductMVPFeedbackModalVisible(),
};
} );
const classicEditorUrl = values.id
? getAdminLink( `post.php?post=${ values.id }&action=edit` )
: getAdminLink( 'post-new.php?post_type=product' );
const recordScore = ( checked: string[], comments: string ) => {
recordEvent( 'product_mvp_feedback', {
action: 'disable',
checked,
comments: comments || '',
} );
hideProductMVPFeedbackModal();
window.location.href = `${ classicEditorUrl }&new-product-experience-disabled=true`;
};
const onCloseModal = () => {
recordEvent( 'product_mvp_feedback', {
action: 'disable',
checked: '',
comments: '',
} );
hideProductMVPFeedbackModal();
window.location.href = classicEditorUrl;
};
if ( ! isProductMVPModalVisible ) {
return null;
}
return (
<ProductMVPFeedbackModal
recordScoreCallback={ recordScore }
onCloseModal={ onCloseModal }
/>
);
};