forked from woocommerce/google-listings-and-ads
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
78 lines (68 loc) · 2.28 KB
/
index.js
File metadata and controls
78 lines (68 loc) · 2.28 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* External dependencies
*/
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import useActiveIssueType from '.~/hooks/useActiveIssueType';
import ReviewRequestModal from './review-request-modal';
import ReviewRequestNotice from './review-request-notice';
import { ISSUE_TYPE_ACCOUNT, REQUEST_REVIEW } from '.~/constants';
import REVIEW_STATUSES from './review-request-statuses';
import useMCIssuesTypeFilter from '.~/hooks/useMCIssuesTypeFilter';
import { recordGlaEvent } from '.~/utils/tracks';
import './index.scss';
const showNotice = ( status ) => !! REVIEW_STATUSES[ status ]?.title;
/**
* @typedef { import(".~/data/actions").AccountStatus } AccountStatus
*/
/**
* @fires gla_modal_closed with `action: 'request-review-success' | 'maybe-later' | 'dismiss', context: REQUEST_REVIEW`
* @fires gla_modal_open with `context: REQUEST_REVIEW`
*
* @param {Object} props Component props
* @param { { isResolving: boolean, hasFinishedResolution: boolean, data: AccountStatus, invalidateResolution: Function } } props.account Account data payload coming from the data store.
*/
const ReviewRequest = ( { account = {} } ) => {
const [ modalActive, setModalActive ] = useState( false );
const activeIssueType = useActiveIssueType();
const { data: mcData, hasFinishedResolution: mcDataHasFinishedResolution } =
useMCIssuesTypeFilter( ISSUE_TYPE_ACCOUNT, 1, 200 );
const { data: accountData, hasFinishedResolution } = account;
if (
! mcDataHasFinishedResolution ||
! hasFinishedResolution ||
! showNotice( accountData.status ) ||
activeIssueType !== ISSUE_TYPE_ACCOUNT
) {
return null;
}
const handleNoticeClick = () => {
setModalActive( true );
recordGlaEvent( 'gla_modal_open', { context: REQUEST_REVIEW } );
};
const handleModalClose = ( action ) => {
setModalActive( false );
recordGlaEvent( 'gla_modal_closed', {
context: REQUEST_REVIEW,
action,
} );
};
return (
<div className="gla-review-request">
<ReviewRequestModal
issues={ mcData.issues.filter( ( issue ) =>
accountData.issues.includes( issue.code )
) }
isActive={ modalActive }
onClose={ handleModalClose }
/>
<ReviewRequestNotice
account={ accountData }
onRequestReviewClick={ handleNoticeClick }
/>
</div>
);
};
export default ReviewRequest;