ordering-ui-external 14.1.49 → 14.1.52

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 (126) hide show
  1. package/_bundles/{7.ordering-ui.697d19ddfcc29dfbeb52.js → 7.ordering-ui.746cebc54de638e8e528.js} +1 -1
  2. package/_bundles/ordering-ui.746cebc54de638e8e528.js +2 -0
  3. package/_modules/components/GoogleGpsButton/index.js +11 -3
  4. package/_modules/components/VerticalOrdersLayout/styles.js +1 -1
  5. package/_modules/themes/callcenterOriginal/index.js +7 -0
  6. package/_modules/themes/callcenterOriginal/src/components/AddressForm/index.js +22 -5
  7. package/_modules/themes/callcenterOriginal/src/components/AddressForm/styles.js +10 -7
  8. package/_modules/themes/callcenterOriginal/src/components/AddressList/index.js +59 -19
  9. package/_modules/themes/callcenterOriginal/src/components/AddressList/styles.js +10 -4
  10. package/_modules/themes/callcenterOriginal/src/components/ConfirmAddressForm/index.js +638 -0
  11. package/_modules/themes/callcenterOriginal/src/components/ConfirmAddressForm/styles.js +50 -0
  12. package/_modules/themes/callcenterOriginal/src/components/Header/index.js +33 -4
  13. package/_modules/themes/callcenterOriginal/src/components/InputPhoneNumber/index.js +17 -10
  14. package/_modules/themes/callcenterOriginal/src/components/PhoneAutocomplete/index.js +58 -106
  15. package/_modules/themes/callcenterOriginal/src/components/PhoneAutocomplete/styles.js +6 -29
  16. package/_modules/themes/callcenterOriginal/src/components/SearchBar/index.js +2 -2
  17. package/_modules/themes/callcenterOriginal/src/components/SignUpForm/index.js +21 -1
  18. package/_modules/themes/callcenterOriginal/src/components/UserDetails/index.js +49 -8
  19. package/_modules/themes/callcenterOriginal/src/components/UserDetails/styles.js +12 -9
  20. package/_modules/themes/callcenterOriginal/src/components/UserFormDetails/index.js +30 -12
  21. package/_modules/themes/callcenterOriginal/src/components/UserFormDetails/styles.js +11 -5
  22. package/_modules/themes/five/src/components/BusinessBasicInformation/index.js +1 -1
  23. package/_modules/themes/five/src/components/BusinessController/franchises/OloBusinessController/index.js +192 -0
  24. package/_modules/themes/five/src/components/BusinessController/franchises/OloBusinessController/styles.js +114 -0
  25. package/_modules/themes/five/src/components/BusinessesListing/franchises/OloBusinessesListing/index.js +572 -0
  26. package/_modules/themes/five/src/components/BusinessesListing/franchises/OloBusinessesListing/styles.js +89 -0
  27. package/_modules/themes/five/src/components/BusinessesListing/index.js +6 -2
  28. package/_modules/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/index.js +31 -118
  29. package/_modules/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/styles.js +1 -1
  30. package/_modules/themes/five/src/components/Checkout/OrderDetail.js +1 -3
  31. package/_modules/themes/five/src/components/Checkout/index.js +22 -4
  32. package/_modules/themes/five/src/components/DriverTips/styles.js +1 -1
  33. package/_modules/themes/five/src/components/Header/index.js +8 -7
  34. package/_modules/themes/five/src/components/Header/styles.js +28 -25
  35. package/_modules/themes/five/src/components/HighestRated/franchises/OloHighestRated/index.js +116 -0
  36. package/_modules/themes/five/src/components/HighestRated/franchises/OloHighestRated/styles.js +22 -0
  37. package/_modules/themes/five/src/components/HomeHero/franchises/OloHomeHero/index.js +136 -0
  38. package/_modules/themes/five/src/components/HomeHero/franchises/OloHomeHero/styles.js +46 -0
  39. package/_modules/themes/five/src/components/HomeHero/index.js +5 -2
  40. package/_modules/themes/five/src/components/InputPhoneNumber/index.js +19 -12
  41. package/_modules/themes/five/src/components/LogoutPopup/index.js +2 -1
  42. package/_modules/themes/five/src/components/Modal/index.js +6 -3
  43. package/_modules/themes/five/src/components/MultiOrdersDetails/styles.js +2 -2
  44. package/_modules/themes/five/src/components/OrderDetails/layouts/Kiosk/index.js +2 -1
  45. package/_modules/themes/five/src/components/OrderItAgain/styles.js +1 -1
  46. package/_modules/themes/five/src/components/OrderTypesSquares/index.js +160 -0
  47. package/_modules/themes/five/src/components/OrderTypesSquares/styles.js +39 -0
  48. package/_modules/themes/five/src/components/ProductItemAccordion/index.js +4 -4
  49. package/_modules/themes/five/src/components/RenderProductsLayout/styles.js +1 -1
  50. package/_modules/themes/five/src/components/SearchBar/index.js +2 -2
  51. package/_modules/themes/five/src/components/SignUpForm/index.js +11 -8
  52. package/_modules/themes/five/src/components/SingleProductCard/layouts/original/styles.js +1 -1
  53. package/_modules/themes/five/src/components/UserDetails/index.js +5 -2
  54. package/_modules/themes/five/src/styles/Buttons/index.js +1 -1
  55. package/index-template.js +9 -1
  56. package/package.json +2 -2
  57. package/src/components/GoogleGpsButton/index.js +10 -2
  58. package/src/components/VerticalOrdersLayout/styles.js +2 -2
  59. package/src/themes/callcenterOriginal/index.js +2 -0
  60. package/src/themes/callcenterOriginal/src/components/AddressForm/index.js +44 -23
  61. package/src/themes/callcenterOriginal/src/components/AddressForm/styles.js +8 -0
  62. package/src/themes/callcenterOriginal/src/components/AddressList/index.js +67 -22
  63. package/src/themes/callcenterOriginal/src/components/AddressList/styles.js +16 -1
  64. package/src/themes/callcenterOriginal/src/components/ConfirmAddressForm/index.js +579 -0
  65. package/src/themes/callcenterOriginal/src/components/ConfirmAddressForm/styles.js +275 -0
  66. package/src/themes/callcenterOriginal/src/components/Header/index.js +22 -0
  67. package/src/themes/callcenterOriginal/src/components/InputPhoneNumber/index.js +13 -8
  68. package/src/themes/callcenterOriginal/src/components/PhoneAutocomplete/index.js +34 -100
  69. package/src/themes/callcenterOriginal/src/components/PhoneAutocomplete/styles.js +0 -52
  70. package/src/themes/callcenterOriginal/src/components/SearchBar/index.js +2 -2
  71. package/src/themes/callcenterOriginal/src/components/SignUpForm/index.js +19 -1
  72. package/src/themes/callcenterOriginal/src/components/UserDetails/index.js +45 -11
  73. package/src/themes/callcenterOriginal/src/components/UserDetails/styles.js +3 -1
  74. package/src/themes/callcenterOriginal/src/components/UserFormDetails/index.js +40 -14
  75. package/src/themes/callcenterOriginal/src/components/UserFormDetails/styles.js +19 -1
  76. package/src/themes/five/src/components/BusinessBasicInformation/index.js +1 -1
  77. package/src/themes/five/src/components/BusinessController/franchises/OloBusinessController/index.js +237 -0
  78. package/src/themes/five/src/components/BusinessController/franchises/OloBusinessController/styles.js +367 -0
  79. package/src/themes/five/src/components/BusinessesListing/franchises/OloBusinessesListing/index.js +582 -0
  80. package/src/themes/five/src/components/BusinessesListing/franchises/OloBusinessesListing/styles.js +307 -0
  81. package/src/themes/five/src/components/BusinessesListing/index.js +19 -4
  82. package/src/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/index.js +7 -104
  83. package/src/themes/five/src/components/BusinessesListing/layouts/OriginalBusinessesListing/styles.js +2 -2
  84. package/src/themes/five/src/components/Checkout/OrderDetail.js +1 -5
  85. package/src/themes/five/src/components/Checkout/index.js +20 -2
  86. package/src/themes/five/src/components/DriverTips/styles.js +1 -0
  87. package/src/themes/five/src/components/Header/index.js +17 -12
  88. package/src/themes/five/src/components/Header/styles.js +51 -4
  89. package/src/themes/five/src/components/HighestRated/franchises/OloHighestRated/index.js +114 -0
  90. package/src/themes/five/src/components/HighestRated/franchises/OloHighestRated/styles.js +57 -0
  91. package/src/themes/five/src/components/HomeHero/franchises/OloHomeHero/index.js +122 -0
  92. package/src/themes/five/src/components/HomeHero/franchises/OloHomeHero/styles.js +125 -0
  93. package/src/themes/five/src/components/HomeHero/index.js +16 -3
  94. package/src/themes/five/src/components/InputPhoneNumber/index.js +14 -9
  95. package/src/themes/five/src/components/LogoutPopup/index.js +3 -1
  96. package/src/themes/five/src/components/Modal/index.js +6 -3
  97. package/src/themes/five/src/components/MultiOrdersDetails/styles.js +3 -3
  98. package/src/themes/five/src/components/OrderDetails/layouts/Kiosk/index.js +3 -1
  99. package/src/themes/five/src/components/OrderItAgain/styles.js +2 -0
  100. package/src/themes/five/src/components/OrderTypesSquares/index.js +157 -0
  101. package/src/themes/five/src/components/OrderTypesSquares/styles.js +62 -0
  102. package/src/themes/five/src/components/ProductItemAccordion/index.js +2 -2
  103. package/src/themes/five/src/components/RenderProductsLayout/styles.js +2 -0
  104. package/src/themes/five/src/components/SearchBar/index.js +2 -2
  105. package/src/themes/five/src/components/SignUpForm/index.js +5 -3
  106. package/src/themes/five/src/components/SingleProductCard/layouts/original/styles.js +1 -1
  107. package/src/themes/five/src/components/UserDetails/index.js +3 -1
  108. package/src/themes/five/src/styles/Buttons/index.js +2 -2
  109. package/template/app.js +14 -11
  110. package/template/assets/images/catering.svg +13 -0
  111. package/template/assets/images/curbside.svg +19 -0
  112. package/template/assets/images/drivethru.svg +19 -0
  113. package/template/assets/images/eatin.svg +17 -0
  114. package/template/components/SubdomainComponent/index.js +4 -8
  115. package/template/pages/BusinessesList/index.js +1 -1
  116. package/_bundles/ordering-ui.697d19ddfcc29dfbeb52.js +0 -2
  117. /package/_bundles/{0.ordering-ui.697d19ddfcc29dfbeb52.js → 0.ordering-ui.746cebc54de638e8e528.js} +0 -0
  118. /package/_bundles/{1.ordering-ui.697d19ddfcc29dfbeb52.js → 1.ordering-ui.746cebc54de638e8e528.js} +0 -0
  119. /package/_bundles/{2.ordering-ui.697d19ddfcc29dfbeb52.js → 2.ordering-ui.746cebc54de638e8e528.js} +0 -0
  120. /package/_bundles/{4.ordering-ui.697d19ddfcc29dfbeb52.js → 4.ordering-ui.746cebc54de638e8e528.js} +0 -0
  121. /package/_bundles/{5.ordering-ui.697d19ddfcc29dfbeb52.js → 5.ordering-ui.746cebc54de638e8e528.js} +0 -0
  122. /package/_bundles/{6.ordering-ui.697d19ddfcc29dfbeb52.js → 6.ordering-ui.746cebc54de638e8e528.js} +0 -0
  123. /package/_bundles/{7.ordering-ui.697d19ddfcc29dfbeb52.js.LICENSE.txt → 7.ordering-ui.746cebc54de638e8e528.js.LICENSE.txt} +0 -0
  124. /package/_bundles/{8.ordering-ui.697d19ddfcc29dfbeb52.js → 8.ordering-ui.746cebc54de638e8e528.js} +0 -0
  125. /package/_bundles/{9.ordering-ui.697d19ddfcc29dfbeb52.js → 9.ordering-ui.746cebc54de638e8e528.js} +0 -0
  126. /package/_bundles/{ordering-ui.697d19ddfcc29dfbeb52.js.LICENSE.txt → ordering-ui.746cebc54de638e8e528.js.LICENSE.txt} +0 -0
@@ -0,0 +1,579 @@
1
+ import React, { useState, useEffect, useRef } from 'react'
2
+ import Skeleton from 'react-loading-skeleton'
3
+ import CgSearchLoading from '@meronex/icons/cg/CgSearchLoading'
4
+ import {
5
+ Heart,
6
+ Building,
7
+ PlusLg,
8
+ House,
9
+ GeoAlt
10
+ } from 'react-bootstrap-icons'
11
+ import { useTheme } from 'styled-components'
12
+ import { useForm } from 'react-hook-form'
13
+ import {
14
+ AddressForm as AddressFormController,
15
+ GoogleAutocompleteInput,
16
+ useLanguage,
17
+ GoogleMapsMap,
18
+ useSession,
19
+ useOrder,
20
+ useConfig
21
+ } from 'ordering-components-external'
22
+ import { Alert } from '../Confirm'
23
+ import { GoogleGpsButton } from '../../../../../components/GoogleGpsButton'
24
+ import {
25
+ FormControl,
26
+ FormActions,
27
+ AddressWrap,
28
+ WrapAddressInput,
29
+ AddressTagSection,
30
+ WrapperMap,
31
+ WrapperSkeleton,
32
+ AddressMarkContainer,
33
+
34
+ AddressFormContainer
35
+ } from './styles'
36
+
37
+ import { Button } from '../../styles/Buttons'
38
+ import { Input, TextArea } from '../../styles/Inputs'
39
+
40
+ const ConfirmAddressFormUI = (props) => {
41
+ const {
42
+ addressesList,
43
+ googleMapsControls,
44
+ formState,
45
+ addressState,
46
+ isRequiredField,
47
+ showField,
48
+ updateChanges,
49
+ handleChangeInput,
50
+ saveAddress,
51
+ setIsEdit,
52
+ userCustomerSetup
53
+ } = props
54
+
55
+ const [configState] = useConfig()
56
+ const [orderState] = useOrder()
57
+ const [, t] = useLanguage()
58
+ const formMethods = useForm()
59
+ const [{ auth }] = useSession()
60
+ const theme = useTheme()
61
+
62
+ const [addressTag, setAddressTag] = useState(addressState?.address?.tag)
63
+ const [alertState, setAlertState] = useState({ open: false, content: [] })
64
+ const [addressValue, setAddressValue] = useState(formState.changes?.address ?? addressState.address?.address ?? '')
65
+ const [firstLocationNoEdit, setFirstLocationNoEdit] = useState({ value: null })
66
+ const [geolocationState, setGeolocationState] = useState({ result: null, error: false })
67
+ const isEditing = !!addressState.address?.id
68
+ const googleInputRef = useRef()
69
+
70
+ const [locationChange, setLocationChange] = useState(
71
+ isEditing
72
+ ? addressState?.address?.location
73
+ : formState.changes?.location ?? null
74
+ )
75
+ const isHideMap = theme?.address?.components?.map?.hidden
76
+ const isHideIcons = theme?.address?.components?.icons?.hidden
77
+ const maxLimitLocation = configState?.configs?.meters_to_change_address?.value
78
+ const googleMapsApiKey = configState?.configs?.google_maps_api_key?.value
79
+ const isLocationRequired = configState.configs?.google_autocomplete_selection_required?.value === '1' ||
80
+ configState.configs?.google_autocomplete_selection_required?.value === 'true'
81
+
82
+ const mapErrors = {
83
+ ERROR_NOT_FOUND_ADDRESS: 'Sorry, we couldn\'t find an address',
84
+ ERROR_MAX_LIMIT_LOCATION: `Sorry, You can only set the position to ${maxLimitLocation}m`
85
+ }
86
+
87
+ const inputNames = [
88
+ { name: 'address', code: 'Address' },
89
+ { name: 'internal_number', code: 'Internal number' },
90
+ { name: 'zipcode', code: 'Zipcode' },
91
+ { name: 'address_notes', code: 'Address notes' }
92
+ ]
93
+
94
+ const closeAlert = () => {
95
+ setAlertState({
96
+ open: false,
97
+ content: []
98
+ })
99
+ }
100
+
101
+ /**
102
+ * Returns true when the user made no changes
103
+ * @param {object} address
104
+ */
105
+ const checkAddress = (address, addressToCompare) => {
106
+ const props = ['address', 'address_notes', 'zipcode', 'location', 'internal_number']
107
+ const values = []
108
+ props.forEach(prop => {
109
+ if (addressToCompare[prop]) {
110
+ if (prop === 'location') {
111
+ values.push(address[prop]?.lat === addressToCompare[prop]?.lat &&
112
+ address[prop]?.lng === addressToCompare[prop]?.lng)
113
+ } else {
114
+ values.push(address[prop] === addressToCompare[prop])
115
+ }
116
+ } else {
117
+ values.push(!address[prop])
118
+ }
119
+ })
120
+ return values.every(value => value)
121
+ }
122
+
123
+ const getAddressFormatted = (addressChange) => {
124
+ const data = { address: null, error: null }
125
+ const geocoder = window.google && new window.google.maps.Geocoder()
126
+ if (geocoder) {
127
+ geocoder.geocode({ address: addressChange }, (results, status) => {
128
+ let postalCode = null
129
+ if (status === 'OK' && results && results.length > 0) {
130
+ for (const component of results?.[0].address_components) {
131
+ const addressType = component.types?.[0]
132
+ if (addressType === 'postal_code') {
133
+ postalCode = component.short_name
134
+ break
135
+ }
136
+ }
137
+ data.address = {
138
+ address: addressChange,
139
+ location: { lat: results?.[0].geometry.location.lat(), lng: results?.[0].geometry.location.lng() },
140
+ utc_offset: results?.[0].utc_offset_minutes ?? 0,
141
+ map_data: {
142
+ library: 'google',
143
+ place_id: results?.[0].place_id
144
+ }
145
+ }
146
+ if (postalCode) {
147
+ data.address.zipcode = postalCode
148
+ }
149
+ const arrayList = isEditing
150
+ ? addressesList.filter(address => address.id !== addressState.address?.id) || []
151
+ : addressesList || []
152
+ const addressToCompare = isEditing
153
+ ? { ...addressState.address, ...data.address, ...formState?.changes }
154
+ : { ...data.address, ...formState?.changes }
155
+
156
+ const isAddressAlreadyExist = arrayList.map(address => checkAddress(address, addressToCompare)).some(value => value) ?? false
157
+ if (!isAddressAlreadyExist) {
158
+ saveAddress(data.address, userCustomerSetup)
159
+ return
160
+ }
161
+
162
+ setAlertState({
163
+ open: true,
164
+ content: [t('ADDRESS_ALREADY_EXIST', 'The address already exists')]
165
+ })
166
+ } else {
167
+ setAlertState({
168
+ open: true,
169
+ content: [t('ERROR_NOT_FOUND_ADDRESS', 'Error, address not found')]
170
+ })
171
+ }
172
+ })
173
+ } else {
174
+ setAlertState({
175
+ open: true,
176
+ content: [t('ERROR_FAILED_LOAD_GEOCODER', 'Failed to load geocoder, please try again.')]
177
+ })
178
+ }
179
+ }
180
+
181
+ const checkKeyDown = (e) => {
182
+ const keyCode = e.keyCode ? e.keyCode : e.which
183
+ if (keyCode === 13) { e.preventDefault() }
184
+ }
185
+
186
+ const showFieldWithTheme = (name) => {
187
+ return !theme?.address?.components?.[name]?.hidden
188
+ }
189
+
190
+ const onSubmit = async () => {
191
+ if (!auth && formState?.changes?.address === '' && addressState?.address?.address) {
192
+ setAlertState({
193
+ open: true,
194
+ content: [t('VALIDATION_ERROR_ADDRESS_REQUIRED', 'The field Address is required')]
195
+ })
196
+ setLocationChange(null)
197
+ return
198
+ }
199
+
200
+ if (formState?.changes?.address && !formState?.changes?.location) {
201
+ if (isLocationRequired) {
202
+ setAlertState({
203
+ open: true,
204
+ content: [t('ADDRESS_REQUIRE_LOCATION', 'The address needs a location, please select one of the suggested')]
205
+ })
206
+ return
207
+ }
208
+ getAddressFormatted(formState?.changes?.address)
209
+ return
210
+ }
211
+
212
+ const arrayList = isEditing
213
+ ? addressesList?.filter(address => address?.id !== addressState?.address?.id) || []
214
+ : addressesList || []
215
+ const addressToCompare = isEditing
216
+ ? { ...addressState.address, ...formState.changes }
217
+ : formState?.changes
218
+
219
+ const isAddressAlreadyExist = arrayList.map(address => checkAddress(address, addressToCompare)).some(value => value) ?? false
220
+
221
+ if (!isAddressAlreadyExist) {
222
+ await saveAddress({}, userCustomerSetup)
223
+ setAlertState({
224
+ open: true,
225
+ content: [t('ADDRESS_CAN_CLOSE_PAGE', 'Your address has been added, you can now close this page')]
226
+ })
227
+ return
228
+ }
229
+
230
+ setAlertState({
231
+ open: true,
232
+ content: [t('ADDRESS_ALREADY_EXIST', 'The address already exists')]
233
+ })
234
+ }
235
+
236
+ const handleAddressTag = (tag) => {
237
+ setAddressTag(tag)
238
+ handleChangeInput({
239
+ target: {
240
+ name: 'tag',
241
+ value: tag
242
+ }
243
+ })
244
+ }
245
+
246
+ const handleChangeAddress = async (address, isGps) => {
247
+ updateChanges({
248
+ ...address,
249
+ address: isGps ? address?.address : googleInputRef?.current?.value || address?.address
250
+ })
251
+ if (isGps && googleInputRef.current) {
252
+ googleInputRef.current.value = address?.address
253
+ }
254
+ setGeolocationState({ result: 'OK', error: null })
255
+ }
256
+
257
+ const setMapErrors = (errKey) => {
258
+ setAlertState({
259
+ open: true,
260
+ content: !(errKey === 'ERROR_MAX_LIMIT_LOCATION')
261
+ ? [t(errKey, mapErrors[errKey])]
262
+ : `${[t(errKey, mapErrors[errKey])]} ${maxLimitLocation} ${[t('METTERS', 'meters')]}`
263
+ })
264
+ }
265
+
266
+ const onErrorGps = (error) => {
267
+ setGeolocationState({ result: null, error })
268
+ }
269
+
270
+ useEffect(() => {
271
+ if (!auth) {
272
+ setLocationChange(formState?.changes?.location ?? orderState?.options?.address?.location ?? '')
273
+ setAddressValue(formState?.changes?.address ?? orderState?.options?.address?.address ?? '')
274
+ inputNames.forEach(field =>
275
+ formMethods.setValue(
276
+ field.name,
277
+ formState?.changes[field.name] ||
278
+ (orderState?.options?.address && orderState?.options?.address[field.name]) ||
279
+ ''
280
+ )
281
+ )
282
+ return
283
+ }
284
+
285
+ if (!formState.loading && formState.result?.error) {
286
+ setAlertState({
287
+ open: true,
288
+ content: formState.result?.result || [t('ERROR', 'Error')]
289
+ })
290
+ }
291
+
292
+ setAddressValue(formState?.changes?.address ?? addressState.address?.address ?? '')
293
+ formMethods.setValue('address', formState?.changes?.address ?? addressState.address?.address ?? '')
294
+ if (!isEditing) {
295
+ inputNames.forEach(field => formMethods.setValue(field.name, formState?.changes[field.name] || ''))
296
+ formState?.changes?.address && setLocationChange(formState?.changes?.location)
297
+ if (
298
+ formState?.changes?.address &&
299
+ formState?.changes?.address !== firstLocationNoEdit?.address &&
300
+ formState?.changes?.location &&
301
+ formState?.changes?.location?.lat !== firstLocationNoEdit.value?.lat &&
302
+ formState?.changes?.location?.lng !== firstLocationNoEdit.value?.lng
303
+ ) {
304
+ setFirstLocationNoEdit({
305
+ value: formState?.changes?.location,
306
+ address: formState?.changes?.address
307
+ })
308
+ }
309
+ }
310
+
311
+ if (isEditing) {
312
+ if (formState?.changes?.location) {
313
+ const prevLocation = { lat: Math.trunc(locationChange?.lat), lng: Math.trunc(locationChange?.lng) }
314
+ const newLocation = { lat: Math.trunc(formState?.changes?.location?.lat), lng: Math.trunc(formState?.changes?.location?.lng) }
315
+ if (prevLocation.lat !== newLocation.lat && prevLocation.lng !== newLocation.lng) {
316
+ setLocationChange(formState?.changes?.location)
317
+ }
318
+ }
319
+ }
320
+ }, [formState])
321
+
322
+ useEffect(() => {
323
+ if (isEditing) {
324
+ setIsEdit && setIsEdit(true)
325
+ setAddressValue(addressState.address?.address)
326
+ } else {
327
+ setIsEdit && setIsEdit(false)
328
+ }
329
+ }, [addressState])
330
+
331
+ useEffect(() => {
332
+ if (!auth) {
333
+ setLocationChange(formState?.changes?.location ?? orderState?.options?.address?.location ?? '')
334
+ }
335
+
336
+ return () => {
337
+ setFirstLocationNoEdit({ value: null })
338
+ }
339
+ }, [])
340
+
341
+ /** Form events control */
342
+
343
+ useEffect(() => {
344
+ if (Object.keys(formMethods.errors).length > 0) {
345
+ setAlertState({
346
+ open: true,
347
+ content: Object.values(formMethods.errors).map(error => error.message)
348
+ })
349
+ }
350
+ }, [formMethods.errors])
351
+
352
+ useEffect(() => {
353
+ inputNames.forEach(field => {
354
+ formMethods.register(field.name, {
355
+ required: isRequiredField(field.name)
356
+ ? t(`VALIDATION_ERROR_${field.name}_REQUIRED`, `The field ${field.code} is required`)
357
+ : null
358
+ })
359
+ formMethods.setValue(field.name, formState.changes?.[field.name] ?? addressState.address?.[field.name] ?? '')
360
+ })
361
+ }, [formMethods])
362
+
363
+ useEffect(() => {
364
+ if (!window.navigator?.geolocation) {
365
+ setGeolocationState({ result: null, error: t('GEOLOCATION_NOT_SUPPORTED_BROWSER', 'Geolocation not supported in your browser') })
366
+ }
367
+ }, [navigator?.geolocation])
368
+
369
+ return (
370
+ <AddressFormContainer>
371
+ <h1>
372
+ {t('ADD_YOUR_ADDRESS', 'Add your address')}
373
+ </h1>
374
+ <div className='address-form'>
375
+ {(configState.loading || addressState.loading) && (
376
+ <WrapperSkeleton>
377
+ <Skeleton height={50} count={5} style={{ marginBottom: '10px' }} />
378
+ </WrapperSkeleton>
379
+ )}
380
+
381
+ {!configState.loading && !addressState.loading && (
382
+ <div>
383
+ <FormControl
384
+ onSubmit={formMethods.handleSubmit(onSubmit)}
385
+ onKeyDown={(e) => checkKeyDown(e)}
386
+ autoComplete='off'
387
+ >
388
+ {inputNames.map(field => showField && showField(field.name) && (
389
+ field.name === 'address' ? (
390
+ <React.Fragment key={field.name}>
391
+ <AddressWrap className='google-control'>
392
+ <WrapAddressInput>
393
+ {!(addressState?.address?.location || formState?.changes?.location) && (
394
+ <>
395
+ {!geolocationState?.result && !geolocationState?.error && (
396
+ <AddressMarkContainer>
397
+ <p>
398
+ {t('GEOCALITION_PLEASE_ACCEPT_PERMISSIONS', 'We are geolocating you, please accept the permissions')}
399
+ </p>
400
+ </AddressMarkContainer>
401
+ )}
402
+ {geolocationState?.error && (
403
+ <AddressMarkContainer error>
404
+ <p>
405
+ {geolocationState?.error}
406
+ </p>
407
+ </AddressMarkContainer>
408
+ )}
409
+ </>
410
+ )}
411
+ <GoogleAutocompleteInput
412
+ className='input-autocomplete'
413
+ apiKey={googleMapsApiKey}
414
+ placeholder={t('ADDRESS', 'Address')}
415
+ onChangeAddress={(e) => {
416
+ formMethods.setValue('address', e.address)
417
+ handleChangeAddress(e)
418
+ }}
419
+ onChange={(e) => {
420
+ handleChangeInput({ target: { name: 'address', value: e.target.value } })
421
+ setAddressValue(e.target.value)
422
+ }}
423
+ childRef={(ref) => {
424
+ googleInputRef.current = ref
425
+ }}
426
+ defaultValue={
427
+ formState?.result?.result
428
+ ? formState?.result?.result?.address
429
+ : formState?.changes?.address ?? addressValue
430
+ }
431
+ autoComplete='new-password'
432
+ countryCode={configState?.configs?.country_autocomplete?.value || '*'}
433
+ />
434
+ </WrapAddressInput>
435
+ <GoogleGpsButton
436
+ enableAutoGeolocation
437
+ className='gps-button'
438
+ apiKey={googleMapsApiKey}
439
+ onAddress={(e) => {
440
+ formMethods.setValue('address', e.address)
441
+ handleChangeAddress(e, true)
442
+ }}
443
+ onError={onErrorGps}
444
+ IconButton={GeoAlt}
445
+ IconLoadingButton={CgSearchLoading}
446
+ geolocationState={geolocationState}
447
+ location={addressState?.address?.location || formState?.changes?.location}
448
+ />
449
+ </AddressWrap>
450
+
451
+ <WrapperMap height={Math.ceil(window.innerHeight * 0.31)}>
452
+ {!isHideMap && locationChange && (addressState?.address?.location || formState?.changes?.location) ? (
453
+ <GoogleMapsMap
454
+ apiKey={googleMapsApiKey}
455
+ location={locationChange}
456
+ fixedLocation={!isEditing ? firstLocationNoEdit.value : null}
457
+ mapControls={googleMapsControls}
458
+ handleChangeAddressMap={handleChangeAddress}
459
+ setErrors={setMapErrors}
460
+ maxLimitLocation={parseInt(maxLimitLocation, 10)}
461
+ />
462
+ ) : (
463
+ <Skeleton height={Math.ceil(window.innerHeight * 0.31)} />
464
+ )}
465
+ </WrapperMap>
466
+ </React.Fragment>
467
+ ) : (
468
+ <React.Fragment key={field.name}>
469
+ {(isRequiredField(field.name) || showFieldWithTheme(field.name)) && (
470
+ <>
471
+ {field.name !== 'address_notes' ? (
472
+ <Input
473
+ className={field.name}
474
+ placeholder={t(field.name.toUpperCase(), field.code)}
475
+ value={formState.changes?.[field.name] ?? addressState.address?.[field.name] ?? ''}
476
+ onChange={(e) => {
477
+ formMethods.setValue(field.name, e.target.value)
478
+ handleChangeInput({ target: { name: field.name, value: e.target.value } })
479
+ }}
480
+ autoComplete='new-field'
481
+ maxLength={30}
482
+ />
483
+ ) : (
484
+ <TextArea
485
+ rows={3}
486
+ placeholder={t('ADDRESS_NOTES', 'Address Notes')}
487
+ value={formState.changes?.address_notes ?? addressState.address.address_notes ?? ''}
488
+ onChange={(e) => {
489
+ formMethods.setValue('address_notes', e.target.value)
490
+ handleChangeInput({ target: { name: 'address_notes', value: e.target.value } })
491
+ }}
492
+ autoComplete='new-field'
493
+ maxLength={250}
494
+ />
495
+ )}
496
+ </>
497
+ )}
498
+ </React.Fragment>
499
+ )
500
+ ))}
501
+
502
+ {!formState.loading && formState.error && <p style={{ color: '#c10000' }}>{formState.error}</p>}
503
+ {!isHideIcons && (
504
+ <AddressTagSection>
505
+ <Button className={addressTag === 'home' ? 'active' : ''} bgtransparent type='button' onClick={() => handleAddressTag('home')}>
506
+ <span><House /></span>
507
+ </Button>
508
+ <Button className={addressTag === 'office' ? 'active' : ''} bgtransparent type='button' onClick={() => handleAddressTag('office')}>
509
+ <span><Building /></span>
510
+ </Button>
511
+ <Button className={addressTag === 'favorite' ? 'active' : ''} bgtransparent type='button' onClick={() => handleAddressTag('favorite')}>
512
+ <span><Heart /></span>
513
+ </Button>
514
+ <Button className={addressTag === 'other' ? 'active' : ''} bgtransparent type='button' onClick={() => handleAddressTag('other')}>
515
+ <span><PlusLg /></span>
516
+ </Button>
517
+ </AddressTagSection>
518
+ )}
519
+ <FormActions>
520
+ {Object.keys(formState?.changes).length > 0 && (
521
+ <Button
522
+ id='submit-btn'
523
+ type='submit'
524
+ disabled={formState.loading}
525
+ color='primary'
526
+ >
527
+ {!formState.loading ? (
528
+ <>
529
+ {t('ADD_ADDRESS', 'Add address')}
530
+ </>
531
+ ) : (
532
+ t('LOADING', 'Loading')
533
+ )}
534
+ </Button>
535
+ )}
536
+ </FormActions>
537
+ </FormControl>
538
+ </div>
539
+ )}
540
+
541
+ <Alert
542
+ title={t('ADDRESS', 'Address')}
543
+ content={alertState.content}
544
+ acceptText={t('ACCEPT', 'Accept')}
545
+ open={alertState.open}
546
+ onClose={() => closeAlert()}
547
+ onAccept={() => closeAlert()}
548
+ closeOnBackdrop={false}
549
+ />
550
+ </div>
551
+
552
+ </AddressFormContainer>
553
+ )
554
+ }
555
+
556
+ export const ConfirmAddressForm = (props) => {
557
+ const googleMapsControls = {
558
+ defaultZoom: 17,
559
+ zoomControl: true,
560
+ streetViewControl: false,
561
+ fullscreenControl: false,
562
+ mapTypeId: 'roadmap', // 'roadmap', 'satellite', 'hybrid', 'terrain'
563
+ mapTypeControl: true,
564
+ mapTypeControlOptions: {
565
+ mapTypeIds: ['roadmap', 'satellite']
566
+ },
567
+ isMarkerDraggable: true
568
+ }
569
+ const addressFormProps = {
570
+ ...props,
571
+ UIComponent: ConfirmAddressFormUI,
572
+ googleMapsControls,
573
+ isSelectedAfterAdd: false,
574
+ confirmAddress: true,
575
+ avoidRefreshUserInfo: true
576
+ }
577
+
578
+ return <AddressFormController {...addressFormProps} />
579
+ }