-
Notifications
You must be signed in to change notification settings - Fork 21
/
shipping-rate-section.js
129 lines (123 loc) · 4.22 KB
/
shipping-rate-section.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
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { createInterpolateElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import { useAdaptiveFormContext } from '~/components/adaptive-form';
import Section from '~/components/section';
import AppRadioContentControl from '~/components/app-radio-content-control';
import RadioHelperText from '~/components/radio-helper-text';
import AppDocumentationLink from '~/components/app-documentation-link';
import VerticalGapLayout from '~/components/vertical-gap-layout';
import FlatShippingRatesInputCards from './flat-shipping-rates-input-cards';
import useSettings from '~/hooks/useSettings';
import useMCSetup from '~/hooks/useMCSetup';
/**
* @fires gla_documentation_link_click with `{ context: 'setup-mc-shipping', link_id: 'shipping-read-more', href: 'https://support.google.com/merchants/answer/7050921' }`
* @fires gla_documentation_link_click with `{ context: 'setup-mc-shipping', link_id: 'shipping-manual', href: 'https://www.google.com/retail/solutions/merchant-center/' }`
*/
const ShippingRateSection = () => {
const { getInputProps, values } = useAdaptiveFormContext();
const { settings } = useSettings();
const { hasFinishedResolution, data: mcSetup } = useMCSetup();
const inputProps = getInputProps( 'shipping_rate' );
// Hide the automatic shipping rate option if there are no shipping rates and the merchant is onboarding.
const hideAutomatticShippingRate =
! settings?.shipping_rates_count &&
hasFinishedResolution &&
mcSetup?.status === 'incomplete';
return (
<Section
title={ __( 'Shipping rates', 'google-listings-and-ads' ) }
description={
<div>
<p>
{ __(
'Your estimated shipping rates and times will be shown to potential customers on Google.',
'google-listings-and-ads'
) }
</p>
<p>
<AppDocumentationLink
context="setup-mc-shipping"
linkId="shipping-read-more"
href="https://support.google.com/merchants/answer/7050921"
>
{ __( 'Read more', 'google-listings-and-ads' ) }
</AppDocumentationLink>
</p>
</div>
}
>
<VerticalGapLayout size="large">
<Section.Card>
<Section.Card.Body>
<VerticalGapLayout size="large">
{ ! hideAutomatticShippingRate && (
<AppRadioContentControl
{ ...inputProps }
label={ __(
'Automatically sync my store’s shipping settings to Google.',
'google-listings-and-ads'
) }
value="automatic"
collapsible
>
<RadioHelperText>
{ __(
'My current settings and any future changes to my store’s shipping rates and classes will be automatically synced to Google Merchant Center.',
'google-listings-and-ads'
) }
</RadioHelperText>
</AppRadioContentControl>
) }
<AppRadioContentControl
{ ...inputProps }
label={ __(
'My shipping settings are simple. I can manually estimate flat shipping rates.',
'google-listings-and-ads'
) }
value="flat"
collapsible
/>
<AppRadioContentControl
{ ...inputProps }
label={ __(
'My shipping settings are complex. I will enter my shipping rates and times manually in Google Merchant Center.',
'google-listings-and-ads'
) }
value="manual"
collapsible
>
<RadioHelperText>
{ createInterpolateElement(
__(
'I understand that if I don’t set this up manually in <link>Google Merchant Center</link>, my products will be disapproved by Google.',
'google-listings-and-ads'
),
{
link: (
<AppDocumentationLink
context="setup-mc-shipping"
linkId="shipping-manual"
href="https://www.google.com/retail/solutions/merchant-center/"
/>
),
}
) }
</RadioHelperText>
</AppRadioContentControl>
</VerticalGapLayout>
</Section.Card.Body>
</Section.Card>
{ values.shipping_rate === 'flat' && (
<FlatShippingRatesInputCards />
) }
</VerticalGapLayout>
</Section>
);
};
export default ShippingRateSection;