-
Notifications
You must be signed in to change notification settings - Fork 139
/
AddressInfo.js
129 lines (118 loc) · 3.57 KB
/
AddressInfo.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
import React, { Fragment } from 'react'
import { ExtensionPoint, useChildBlock } from 'vtex.render-runtime'
import { useCssHandles } from 'vtex.css-handles'
import { pathOr } from 'ramda'
import { injectIntl, FormattedMessage } from 'react-intl'
import { IconLocationMarker } from 'vtex.store-icons'
const CSS_HANDLES = [
'addressInfoIconContainer',
'addressInfoTextContainer',
'addressInfoPrefixContainer',
'addressInfoAddressContainer',
'addressInfoDivider',
'addressInfoModalContainer',
]
const AddressInfo = ({
inverted,
inline,
orderForm,
intl,
showStreet,
showCityAndState,
showPostalCode,
showPrefix,
}) => {
const { shippingData } = orderForm
const hasModal = !!useChildBlock({ id: 'modal' })
const handles = useCssHandles(CSS_HANDLES)
if (!shippingData || !shippingData.address) return
const {
street,
number,
complement,
addressType,
city,
state,
postalCode,
} = shippingData.address
let displayStreet = number ? `${street}, ${number}` : street
if (complement) displayStreet = `${displayStreet} - ${complement}`
const displayCityAndState = `${city}, ${state}`
const displayAddress = `${showStreet ? displayStreet : ''}${
showStreet && (showCityAndState || showPostalCode) ? ', ' : ''
}${showCityAndState ? displayCityAndState : ''}${
showCityAndState && showPostalCode ? ', ' : ''
}${showPostalCode ? postalCode : ''}`
const isPickup = addressType === 'pickup'
const friendlyName = pathOr(
'',
['pickupPointCheckedIn', 'friendlyName'],
orderForm
)
return (
<div className={`flex ${inline ? 'items-end' : 'items-center flex-auto'}`}>
<div className="flex flex-auto items-center">
<div
className={`${
handles.addressInfoIconContainer
} mr3 flex items-center ${
inverted ? 'c-on-base--inverted' : 'c-muted-2'
}`}
>
<IconLocationMarker size={27} viewBox="0 0 21 27" />
</div>
<div
className={`${handles.addressInfoTextContainer} flex flex-auto flex-column`}
>
{showPrefix && (
<div
className={`${handles.addressInfoPrefixContainer} t-small ${
inverted ? 'c-on-base--inverted' : 'c-muted-2'
}`}
>
{isPickup ? (
<FormattedMessage
id="store/user-address.pickup"
values={{ name: friendlyName }}
/>
) : (
<FormattedMessage id="store/user-address.order" />
)}
</div>
)}
<div className={`${handles.addressInfoAddressContainer} truncate`}>
{displayAddress}
</div>
</div>
</div>
{hasModal && (
<Fragment>
<div
className={`${handles.addressInfoDivider} bl bw1 mh4 ${
inline ? 'nb2' : ''
} ${inverted ? 'b--on-base--inverted' : 'b--muted-5'}`}
style={{
height: '1.5rem',
}}
/>
<div
className={`${handles.addressInfoModalContainer} flex items-center`}
>
<ExtensionPoint
id="modal"
centered
buttonLabel={intl.formatMessage({
id: 'store/user-address.change',
})}
buttonClass={
inverted ? 'c-on-base--inverted' : 'c-action-primary'
}
showTopBar={false}
/>
</div>
</Fragment>
)}
</div>
)
}
export default injectIntl(AddressInfo)