ordering-ui-external 14.1.40 → 14.1.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (27) hide show
  1. package/_bundles/{7.ordering-ui.2a09e7e0162e34ea955c.js → 7.ordering-ui.0bcf027ad972ccbec19e.js} +1 -1
  2. package/_bundles/{ordering-ui.2a09e7e0162e34ea955c.js → ordering-ui.0bcf027ad972ccbec19e.js} +2 -2
  3. package/_modules/themes/callcenterOriginal/src/components/AddressForm/SpreadForm/index.js +322 -0
  4. package/_modules/themes/callcenterOriginal/src/components/AddressForm/SpreadForm/styles.js +25 -0
  5. package/_modules/themes/callcenterOriginal/src/components/AddressForm/index.js +57 -58
  6. package/_modules/themes/callcenterOriginal/src/components/AddressForm/styles.js +3 -1
  7. package/_modules/themes/callcenterOriginal/src/components/AddressList/index.js +50 -20
  8. package/_modules/themes/callcenterOriginal/src/components/PhoneAutocomplete/index.js +18 -26
  9. package/_modules/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/index.js +1 -1
  10. package/package.json +1 -1
  11. package/src/themes/callcenterOriginal/src/components/AddressForm/SpreadForm/index.js +251 -0
  12. package/src/themes/callcenterOriginal/src/components/AddressForm/SpreadForm/styles.js +111 -0
  13. package/src/themes/callcenterOriginal/src/components/AddressForm/index.js +246 -230
  14. package/src/themes/callcenterOriginal/src/components/AddressForm/styles.js +2 -3
  15. package/src/themes/callcenterOriginal/src/components/AddressList/index.js +243 -214
  16. package/src/themes/callcenterOriginal/src/components/PhoneAutocomplete/index.js +1 -11
  17. package/src/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/index.js +1 -1
  18. /package/_bundles/{0.ordering-ui.2a09e7e0162e34ea955c.js → 0.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  19. /package/_bundles/{1.ordering-ui.2a09e7e0162e34ea955c.js → 1.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  20. /package/_bundles/{2.ordering-ui.2a09e7e0162e34ea955c.js → 2.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  21. /package/_bundles/{4.ordering-ui.2a09e7e0162e34ea955c.js → 4.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  22. /package/_bundles/{5.ordering-ui.2a09e7e0162e34ea955c.js → 5.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  23. /package/_bundles/{6.ordering-ui.2a09e7e0162e34ea955c.js → 6.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  24. /package/_bundles/{7.ordering-ui.2a09e7e0162e34ea955c.js.LICENSE.txt → 7.ordering-ui.0bcf027ad972ccbec19e.js.LICENSE.txt} +0 -0
  25. /package/_bundles/{8.ordering-ui.2a09e7e0162e34ea955c.js → 8.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  26. /package/_bundles/{9.ordering-ui.2a09e7e0162e34ea955c.js → 9.ordering-ui.0bcf027ad972ccbec19e.js} +0 -0
  27. /package/_bundles/{ordering-ui.2a09e7e0162e34ea955c.js.LICENSE.txt → ordering-ui.0bcf027ad972ccbec19e.js.LICENSE.txt} +0 -0
@@ -0,0 +1,251 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { FormActions, FormControl } from './styles'
3
+ import { useLanguage, useApi, useSession, useConfig, useToast, ToastType } from 'ordering-components-external'
4
+ import { useTheme } from 'styled-components'
5
+
6
+ import { Input } from '../../../styles/Inputs'
7
+ import { Button } from '../../../styles/Buttons'
8
+ import { capitalize } from '../../../../../../utils'
9
+
10
+ const inputNames = [
11
+ { id: 1, name: 'route', required: true },
12
+ { id: 2, name: 'street_number', required: true },
13
+ { id: 3, name: 'neighborhood', required: true },
14
+ { id: 4, name: 'zipcode', required: false },
15
+ { id: 5, name: 'city', required: true },
16
+ { id: 6, name: 'state', required: true },
17
+ { id: 7, name: 'country_code', enabled: false, required: false }
18
+ ]
19
+
20
+ const emptyFields = {
21
+ route: '',
22
+ street_number: '',
23
+ neighborhood: '',
24
+ city: '',
25
+ state: '',
26
+ country_code: '',
27
+ country: '',
28
+ address: '',
29
+ locality: '',
30
+ location: '',
31
+ zipcode: ''
32
+ }
33
+
34
+ const unexpectedFieldValid = ['postal_code']
35
+
36
+ export const SpreadForm = (props) => {
37
+ const {
38
+ address,
39
+ countryAutocomplete,
40
+ editSpreadAddress,
41
+ setEditSpreadAddress,
42
+ onChangeAddress
43
+ } = props
44
+
45
+ const theme = useTheme()
46
+ const [ordering] = useApi()
47
+ const [, { showToast }] = useToast()
48
+ const [{ token: sessionToken }] = useSession()
49
+ const [{ configs }] = useConfig()
50
+ const [, t] = useLanguage()
51
+ const [formState, setFormState] = useState({ changes: {}, loading: false, error: null, added: false })
52
+
53
+ const googleMapsApiKey = configs?.google_maps_api_key?.value
54
+
55
+ const handleAddAddress = () => {
56
+ onChangeAddress(formState.changes)
57
+ setFormState({ ...formState, added: true })
58
+ editSpreadAddress && setEditSpreadAddress(!editSpreadAddress)
59
+ }
60
+
61
+ const handleChangeInput = ({ name, value }) => {
62
+ const changes = formState.changes
63
+ if (changes?.location) {
64
+ delete changes.location
65
+ }
66
+
67
+ setFormState({
68
+ ...formState,
69
+ changes: {
70
+ ...changes,
71
+ [name]: value
72
+ }
73
+ })
74
+ }
75
+
76
+ const changeAttrName = (attr) => {
77
+ const list = {
78
+ sublocality_level_1: 'neighborhood',
79
+ administrative_area_level_1: 'state',
80
+ postal_code: 'zipcode'
81
+ }
82
+
83
+ return list[attr] ?? attr
84
+ }
85
+
86
+ const handlePostAddress = async (addressLines) => {
87
+ try {
88
+ setFormState({ ...formState, loading: true })
89
+ const _body = {
90
+ google_api_key: googleMapsApiKey,
91
+ body: {
92
+ address: {
93
+ regionCode: countryAutocomplete,
94
+ addressLines: addressLines ?? inputNames
95
+ .filter(i => i?.enabled !== false)
96
+ .sort((a, b) => a.id - b.id)
97
+ .map(input => formState.changes[input.name])
98
+ .filter(_i => _i)
99
+ }
100
+ }
101
+ }
102
+ formState?.previousResponseId && (_body.previousResponseId = formState?.previousResponseId)
103
+
104
+ const req = await fetch(`${ordering.root}/helpers/addresses/validate`, {
105
+ method: 'POST',
106
+ headers: {
107
+ 'Content-Type': 'application/json',
108
+ Authorization: `Bearer ${sessionToken}`
109
+ },
110
+ body: JSON.stringify(_body)
111
+ })
112
+
113
+ const { error, result } = await req.json()
114
+
115
+ const _formState = formState
116
+ if (!error && !result?.error) {
117
+ _formState.previousResponseId = result?.responseId
118
+ _formState.formattedAddress = result?.result?.address?.formattedAddress
119
+
120
+ const addressComponents = result?.result?.address?.addressComponents
121
+ .filter(_f =>
122
+ _f?.confirmationLevel !== 'UNEXPECTED' &&
123
+ (!_f?.confirmationLevel?.includes('UNCONFIRMED') || unexpectedFieldValid.includes(_f.componentType))
124
+ ).reduce((acc, field) => {
125
+ const existingField = acc.find(obj => obj.name === changeAttrName(field.componentType))
126
+ if (existingField) {
127
+ existingField.value = field.componentName?.text
128
+ } else {
129
+ acc.push({ name: changeAttrName(field.componentType), value: field.componentName?.text })
130
+ }
131
+ return acc
132
+ }, [])
133
+
134
+ addressComponents.push({
135
+ name: 'city',
136
+ value:
137
+ addressComponents.find(item => item.name === 'administrative_area_level_2')?.value ||
138
+ addressComponents.find(item => item.name === 'administrative_area_level_3')?.value ||
139
+ addressComponents.find(item => item.name === 'locality')?.value || null
140
+ })
141
+
142
+ inputNames.concat({ id: 8, name: 'country' }).map(_i => _i.name).forEach(field => {
143
+ _formState.changes[field] = addressComponents.find(c => c?.name === field)?.value ?? formState.changes?.[field]
144
+ })
145
+
146
+ _formState.changes.locality = _formState.changes.city
147
+ _formState.changes.country_code = countryAutocomplete
148
+ _formState.changes.address = result?.result?.address?.formattedAddress
149
+
150
+ result?.result?.geocode?.location && (
151
+ _formState.changes.location = {
152
+ lat: result?.result?.geocode?.location?.latitude,
153
+ lng: result?.result?.geocode?.location?.longitude
154
+ }
155
+ )
156
+ }
157
+
158
+ setFormState({
159
+ ...formState,
160
+ ..._formState,
161
+ loading: false,
162
+ error: error ? result[0] : null
163
+ })
164
+ } catch (error) {
165
+ setFormState({ ...formState, loading: false })
166
+ }
167
+ }
168
+
169
+ useEffect(() => {
170
+ if (formState.loading) return
171
+ if (address) {
172
+ if (!address?.location && !formState.changes?.location) {
173
+ handlePostAddress(address?.address?.split(','))
174
+ } else {
175
+ setFormState({
176
+ ...formState,
177
+ changes: {
178
+ ...formState.changes,
179
+ ...address
180
+ }
181
+ })
182
+ }
183
+ }
184
+ }, [JSON.stringify(address)])
185
+
186
+ useEffect(() => {
187
+ if (formState.error) {
188
+ showToast(ToastType.Error, formState.error, 3000)
189
+ setFormState({ ...formState, error: null })
190
+ }
191
+ }, [JSON.stringify(formState.error)])
192
+
193
+ useEffect(() => {
194
+ if (editSpreadAddress) {
195
+ onChangeAddress(emptyFields)
196
+ }
197
+ }, [editSpreadAddress])
198
+
199
+ return (
200
+ <FormControl
201
+ autoComplete='off'
202
+ onKeyDown={(e) => { e.key === 'Enter' && e.preventDefault() }}
203
+ >
204
+ {(!formState.added || editSpreadAddress) && (
205
+ <>
206
+ {inputNames.map(field => (
207
+ <React.Fragment key={field.name}>
208
+ <Input
209
+ className={field.name}
210
+ placeholder={t(`ADDRESS_${field.name.toUpperCase()}`, capitalize(field.name.replace('_', ' ')))}
211
+ value={formState.changes?.[field.name] ?? address?.[field.name] ?? (field.name === 'country_code' ? countryAutocomplete : '')}
212
+ disabled={field?.enabled === false}
213
+ style={{
214
+ ...(field?.enabled === false ? { background: theme.colors.disabled } : {})
215
+ }}
216
+ onChange={(e) => {
217
+ handleChangeInput({ name: field.name, value: e.target.value })
218
+ }}
219
+ autoComplete='new-field'
220
+ maxLength={70}
221
+ />
222
+ </React.Fragment>
223
+ ))}
224
+ <FormActions>
225
+ <Button
226
+ id='submit-btn'
227
+ type='button'
228
+ disabled={formState.loading || !inputNames
229
+ .filter(i => i.required)
230
+ .every(input => formState.changes?.[input.name])}
231
+ color='primary'
232
+ onClick={() => formState.changes?.location ? handleAddAddress() : handlePostAddress()}
233
+ >
234
+ {!formState.loading ? (
235
+ address?.address
236
+ ? formState.changes?.location
237
+ ? t('CONTINUE', 'Continue')
238
+ : t('VERIFY_ADDRESS', 'Verify address')
239
+ : formState.changes?.location
240
+ ? t('CONFIRM_ADDRESS', 'Confirm address')
241
+ : t('VERIFY_ADDRESS', 'Verify address')
242
+ ) : (
243
+ t('LOADING', 'Loading')
244
+ )}
245
+ </Button>
246
+ </FormActions>
247
+ </>
248
+ )}
249
+ </FormControl>
250
+ )
251
+ }
@@ -0,0 +1,111 @@
1
+ import styled, { css } from 'styled-components'
2
+ import { darken } from 'polished'
3
+
4
+ export const FormActions = styled.div`
5
+ margin-top: 35px;
6
+ padding: 10px 0px;
7
+ display: flex;
8
+ justify-content: space-between;
9
+ width: 100%;
10
+ gap: 10px;
11
+ button {
12
+ height: 44px;
13
+ width: 100%;
14
+ text-transform: lowercase;
15
+ &:first-letter {
16
+ text-transform: uppercase;
17
+ }
18
+ &:hover {
19
+ color: #CCC !important;
20
+ }
21
+ }
22
+ `
23
+
24
+ export const FormControl = styled.form`
25
+ padding: 0px;
26
+ display: flex;
27
+ flex-wrap: wrap;
28
+ justify-content: space-between;
29
+
30
+ input {
31
+ box-sizing: border-box;
32
+ margin: 10px 0px;
33
+ height: 50px;
34
+ width: 100%;
35
+ &.internal_number,
36
+ &.zipcode {
37
+ flex: auto;
38
+ }
39
+ &::placeholder{
40
+ color: #CBCBCB
41
+ }
42
+ }
43
+
44
+ textarea {
45
+ width: 100%;
46
+ margin: 10px 0;
47
+ border-radius: 7.6px;
48
+ }
49
+
50
+ .input-autocomplete {
51
+ width: 100%;
52
+ background: #FFF;
53
+ border: 1px solid #BBB;
54
+ border-radius: 30px;
55
+ font-size: 16px;
56
+ padding: 7px 15px !important;
57
+ height: 50px;
58
+ outline: none;
59
+ ::placeholder {
60
+ color: #DBDCDB;
61
+ }
62
+
63
+ &:-ms-input-placeholder {
64
+ color: #DBDCDB;
65
+ }
66
+
67
+ &::-ms-input-placeholder { /* Microsoft Edge */
68
+ color: #DBDCDB;
69
+ }
70
+ &:focus {
71
+ border-color: ${() => darken(0.07, '#CCC')};
72
+ }
73
+ }
74
+
75
+ .google-control {
76
+ .gps-button {
77
+ border-radius: 7.6px;
78
+ }
79
+
80
+ input {
81
+ border-radius: 7.6px;
82
+ border: 1px solid ${props => props.theme.colors.primary};
83
+
84
+ &:focus {
85
+ border: 1px solid ${props => props.theme.colors.primary};
86
+ }
87
+ }
88
+ }
89
+
90
+ .internal_number {
91
+ width: 45%;
92
+ ${props => props.theme?.rtl ? css`
93
+ margin-left: 15px;
94
+ ` : css`
95
+ margin-right: 15px;
96
+ `}
97
+ }
98
+
99
+ .zipcode {
100
+ width: 45%;
101
+ }
102
+
103
+ @media (min-width: 481px) {
104
+ padding: 10px;
105
+ }
106
+ `
107
+
108
+ export const FormattedAddress = styled.p`
109
+ margin: 0;
110
+ width: 100%;
111
+ `