-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.js
132 lines (121 loc) · 3.96 KB
/
index.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
/**
* External dependencies
*/
import { useState, useCallback } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Link } from '@woocommerce/components';
import { getNewPath, getQuery, getHistory } from '@woocommerce/navigation';
/**
* Internal dependencies
*/
import AppButton from '~/components/app-button';
import DifferentCurrencyNotice from '~/components/different-currency-notice';
import MainTabNav from '~/components/main-tab-nav';
import CustomerEffortScorePrompt from '~/components/customer-effort-score-prompt';
import AppDateRangeFilterPicker from './app-date-range-filter-picker';
import SummarySection from './summary-section';
import CampaignCreationSuccessGuide from './campaign-creation-success-guide';
import AllProgramsTableCard from './all-programs-table-card';
import { glaData, GUIDE_NAMES } from '~/constants';
import { subpaths, getCreateCampaignUrl } from '~/utils/urls';
import isWCTracksEnabled from '~/utils/isWCTracksEnabled';
import EditFreeListings from '~/pages/edit-free-listings';
import EditPaidAdsCampaign from '~/pages/edit-paid-ads-campaign';
import CreatePaidAdsCampaign from '~/pages/create-paid-ads-campaign';
import { CTA_CREATE_ANOTHER_CAMPAIGN, CTA_CONFIRM } from './constants';
import { recordGlaEvent } from '~/utils/tracks';
import RebrandingTour from '~/components/tours/rebranding-tour';
import './index.scss';
/**
* @fires gla_modal_closed when CES modal is closed.
*/
const Dashboard = () => {
const [ isCESPromptOpen, setCESPromptOpen ] = useState( false );
const handleCampaignCreationSuccessGuideClose = useCallback(
( e, specifiedAction ) => {
const action = specifiedAction || e.currentTarget.dataset.action;
const nextQuery = {
...getQuery(),
guide: undefined,
};
getHistory().replace( getNewPath( nextQuery ) );
if ( action === CTA_CREATE_ANOTHER_CAMPAIGN ) {
getHistory().push( getCreateCampaignUrl() );
} else if ( action === CTA_CONFIRM ) {
setCESPromptOpen( true );
}
recordGlaEvent( 'gla_modal_closed', {
context: GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS,
action,
} );
},
[ setCESPromptOpen ]
);
const query = getQuery();
switch ( query.subpath ) {
case subpaths.editFreeListings:
return <EditFreeListings />;
case subpaths.editCampaign:
return <EditPaidAdsCampaign />;
case subpaths.createCampaign:
return <CreatePaidAdsCampaign />;
}
const trackEventReportId = 'dashboard';
const { enableReports } = glaData;
const ReportsLink = () => {
return (
<Link href={ getNewPath( null, '/google/reports' ) }>
<AppButton isPrimary>
{ __( 'View Reports', 'google-listings-and-ads' ) }
</AppButton>
</Link>
);
};
const isCampaignCreationSuccessGuideOpen =
query?.guide === GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS;
const wcTracksEnabled = isWCTracksEnabled();
return (
<>
<div className="gla-dashboard">
<DifferentCurrencyNotice context="dashboard" />
<MainTabNav />
<RebrandingTour />
<div className="gla-dashboard__filter">
<AppDateRangeFilterPicker
trackEventReportId={ trackEventReportId }
/>
{ enableReports && <ReportsLink /> }
</div>
<div className="gla-dashboard__performance">
<SummarySection />
</div>
<div className="gla-dashboard__programs">
<AllProgramsTableCard
trackEventReportId={ trackEventReportId }
/>
</div>
</div>
{ isCampaignCreationSuccessGuideOpen && (
<CampaignCreationSuccessGuide
onGuideRequestClose={
handleCampaignCreationSuccessGuideClose
}
/>
) }
{ isCESPromptOpen && wcTracksEnabled && (
<CustomerEffortScorePrompt
label={ __(
'How easy was it to create a Google Ad campaign?',
'google-listings-and-ads'
) }
secondLabel={ __(
'How easy was it to understand the requirements for the Google Ad campaign creation?',
'google-listings-and-ads'
) }
eventContext={ GUIDE_NAMES.CAMPAIGN_CREATION_SUCCESS }
/>
) }
</>
);
};
export default Dashboard;