-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathApp.js
142 lines (124 loc) · 3.75 KB
/
App.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* External dependencies
*/
import '@wordpress/notices';
import { useSelect } from '@wordpress/data';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { recordEvent } from '@woocommerce/tracks';
/**
* Internal dependencies
*/
import SyncState from './sections/SyncState';
import AdCreditsNotice from './sections/AdCreditsNotice';
import SyncIssues from './sections/SyncIssues';
import HealthCheck from '../setup-guide/app/components/HealthCheck';
import { useCreateNotice, useDismissAdsModalDispatch } from './helpers/effects';
import NavigationClassic from '../components/navigation-classic';
import OnboardingModals from './components/OnboardingModals';
import { USER_INTERACTION_STORE_NAME } from './data';
import { useSettingsSelect } from '../setup-guide/app/helpers/effects';
/**
* Opening a modal.
*
* @event wcadmin_pfw_modal_open
* @property {string} name Ads Onboarding Modal.
* @property {string} context catalog-sync
*/
/**
* Closing a modal.
*
* @event wcadmin_pfw_modal_closed
* @property {string} name Ads Onboarding Modal.
* @property {string} context catalog-sync
*/
/**
* Catalog Sync Tab.
*
* @fires wcadmin_pfw_modal_open with `{ name: 'ads-credits-onboarding' }`
* @fires wcadmin_pfw_modal_close with `{ name: 'ads-credits-onboarding' }`
*
* @return {JSX.Element} rendered component
*/
const CatalogSyncApp = () => {
const adsCampaignIsActive = useSettingsSelect()?.ads_campaign_is_active;
const couponRedeemErrorID =
useSettingsSelect()?.account_data?.coupon_redeem_info?.error_id;
useCreateNotice( wcSettings.pinterest_for_woocommerce.error );
const [ isOnboardingModalOpen, setIsOnboardingModalOpen ] =
useState( false );
const [ isAdCreditsNoticeOpen, setIsAdCreditsNoticeOpen ] =
useState( false );
const userInteractions = useSelect( ( select ) =>
select( USER_INTERACTION_STORE_NAME ).getUserInteractions()
);
const userInteractionsLoaded = useSelect( ( select ) =>
select( USER_INTERACTION_STORE_NAME ).areInteractionsLoaded()
);
const openOnboardingModal = useCallback( () => {
if (
userInteractionsLoaded === false ||
userInteractions?.ads_modal_dismissed
) {
return;
}
setIsOnboardingModalOpen( true );
recordEvent( 'pfw_modal_open', {
context: 'catalog-sync',
name: 'ads-credits-onboarding',
} );
}, [ userInteractions?.ads_modal_dismissed, userInteractionsLoaded ] );
const openAdsCreditsNotice = useCallback( () => {
if (
userInteractionsLoaded === false ||
userInteractions?.ads_notice_dismissed
) {
return;
}
if (
couponRedeemErrorID !== undefined &&
couponRedeemErrorID !== 2322
) {
return;
}
setIsAdCreditsNoticeOpen( true );
}, [
userInteractions?.ads_notice_dismissed,
userInteractionsLoaded,
couponRedeemErrorID,
] );
const closeOnboardingModal = () => {
setIsOnboardingModalOpen( false );
handleSetDismissAdsModal();
recordEvent( 'pfw_modal_closed', {
context: 'catalog-sync',
name: 'ads-credits-onboarding',
} );
};
const setDismissAdsModal = useDismissAdsModalDispatch();
const handleSetDismissAdsModal = useCallback( async () => {
try {
await setDismissAdsModal();
} catch ( error ) {}
}, [ setDismissAdsModal ] );
useEffect( () => {
openOnboardingModal();
openAdsCreditsNotice();
}, [ openOnboardingModal, openAdsCreditsNotice ] );
return (
<div className="pinterest-for-woocommerce-catalog-sync">
<HealthCheck />
<NavigationClassic />
<div className="pinterest-for-woocommerce-catalog-sync__container">
<SyncState />
{ isAdCreditsNoticeOpen && adsCampaignIsActive && (
<AdCreditsNotice />
) }
<SyncIssues />
</div>
{ isOnboardingModalOpen && (
<OnboardingModals onCloseModal={ closeOnboardingModal } />
) }
</div>
);
};
export default CatalogSyncApp;