ordering-ui-react-native 0.23.96 → 0.23.98
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.
- package/package.json +1 -1
- package/themes/original/index.tsx +214 -218
- package/themes/original/src/components/Checkout/index.tsx +27 -10
- package/themes/original/src/components/Help/functions.tsx +76 -0
- package/themes/original/src/components/Help/index.tsx +74 -29
- package/themes/original/src/components/Help/styles.tsx +4 -1
- package/themes/original/src/components/HelpOptions/index.tsx +44 -0
- package/themes/original/src/components/MultiCheckout/index.tsx +22 -10
- package/themes/original/src/components/NotFoundSource/index.tsx +40 -39
- package/themes/original/src/components/NotFoundSource/styles.tsx +18 -9
- package/themes/original/src/components/PaymentOptions/index.tsx +10 -1
- package/themes/original/src/types/index.tsx +699 -699
- package/themes/original/src/components/HelpAccountAndPayment/index.tsx +0 -62
- package/themes/original/src/components/HelpAccountAndPayment/styles.tsx +0 -12
- package/themes/original/src/components/HelpGuide/index.tsx +0 -68
- package/themes/original/src/components/HelpGuide/styles.tsx +0 -12
- package/themes/original/src/components/HelpOrder/index.tsx +0 -71
- package/themes/original/src/components/HelpOrder/styles.tsx +0 -13
package/package.json
CHANGED
|
@@ -35,9 +35,7 @@ import { MessageListing } from './src/components/MessageListing';
|
|
|
35
35
|
import { Messages } from './src/components/Messages';
|
|
36
36
|
import { MyOrders } from './src/components/MyOrders';
|
|
37
37
|
import { Help } from './src/components/Help';
|
|
38
|
-
import {
|
|
39
|
-
import { HelpGuide } from './src/components/HelpGuide';
|
|
40
|
-
import { HelpOrder } from './src/components/HelpOrder';
|
|
38
|
+
import { HelpOptions } from './src/components/HelpOptions';
|
|
41
39
|
import { NetworkError } from './src/components/NetworkError';
|
|
42
40
|
import { NotFoundSource } from './src/components/NotFoundSource';
|
|
43
41
|
import { OrderTypeSelector } from './src/components/OrderTypeSelector';
|
|
@@ -113,49 +111,49 @@ import { orderTypeList, getTraduction, verifyDecimals, getOrderStatus, getOrderS
|
|
|
113
111
|
import Alert from './src/providers/AlertProvider'
|
|
114
112
|
|
|
115
113
|
import {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
114
|
+
LoginParams,
|
|
115
|
+
ProfileParams,
|
|
116
|
+
AddressListParams,
|
|
117
|
+
AddressFormParams,
|
|
118
|
+
SignupParams,
|
|
119
|
+
PhoneInputParams,
|
|
120
|
+
LanguageSelectorParams,
|
|
121
|
+
BusinessesListingParams,
|
|
122
|
+
HighestRatedBusinessesParams,
|
|
123
|
+
BusinessTypeFilterParams,
|
|
124
|
+
BusinessControllerParams,
|
|
125
|
+
BusinessProductsListingParams,
|
|
126
|
+
BusinessBasicInformationParams,
|
|
127
|
+
BusinessProductsCategoriesParams,
|
|
128
|
+
BusinessProductsListParams,
|
|
129
|
+
SingleProductCardParams,
|
|
130
|
+
BusinessInformationParams,
|
|
131
|
+
BusinessReviewsParams,
|
|
132
|
+
SearchBarParams,
|
|
133
|
+
NotFoundSourceParams,
|
|
134
|
+
OrdersOptionParams,
|
|
135
|
+
ActiveOrdersParams,
|
|
136
|
+
PreviousOrdersParams,
|
|
137
|
+
OrderDetailsParams,
|
|
138
|
+
ReviewDriverParams
|
|
141
139
|
} from './src/types';
|
|
142
140
|
|
|
143
141
|
import { Toast } from './src/components/shared/OToast';
|
|
144
142
|
import {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
143
|
+
OText,
|
|
144
|
+
OButton,
|
|
145
|
+
OInput,
|
|
146
|
+
ODropDown,
|
|
147
|
+
OIcon,
|
|
148
|
+
OIconText,
|
|
149
|
+
OIconButton,
|
|
150
|
+
OTextarea,
|
|
151
|
+
OToggle,
|
|
152
|
+
OKeyButton,
|
|
153
|
+
OAlert,
|
|
154
|
+
OModal,
|
|
155
|
+
OBottomPopup,
|
|
156
|
+
HeaderTitle
|
|
159
157
|
} from './src/components/shared';
|
|
160
158
|
|
|
161
159
|
import { Container } from './src/layouts/Container';
|
|
@@ -163,198 +161,196 @@ import { SafeAreaContainer } from './src/layouts/SafeAreaContainer';
|
|
|
163
161
|
import { FloatingBottomContainer } from './src/layouts/FloatingBottomContainer';
|
|
164
162
|
|
|
165
163
|
import {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
_retrieveStoreData,
|
|
165
|
+
_setStoreData,
|
|
166
|
+
_removeStoreData,
|
|
167
|
+
_clearStoreData
|
|
170
168
|
} from './src/providers/StoreUtil';
|
|
171
169
|
|
|
172
170
|
export {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
171
|
+
AddressForm,
|
|
172
|
+
AddressDetails,
|
|
173
|
+
AnalyticsSegment,
|
|
174
|
+
Home as HomeView,
|
|
175
|
+
SignupForm,
|
|
176
|
+
LoginForm,
|
|
177
|
+
ActiveOrders,
|
|
178
|
+
AddressList,
|
|
179
|
+
AppleLogin,
|
|
180
|
+
BusinessesListing,
|
|
181
|
+
BusinessProductsListing,
|
|
182
|
+
CartContent,
|
|
183
|
+
BusinessCart,
|
|
184
|
+
Checkout,
|
|
185
|
+
Favorite,
|
|
186
|
+
FavoriteList,
|
|
189
187
|
GPSButton,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
ProductOption,
|
|
263
|
-
ProductOptionSubOption,
|
|
188
|
+
ForgotPasswordForm,
|
|
189
|
+
MomentOption,
|
|
190
|
+
OrdersOption,
|
|
191
|
+
OrderDetails,
|
|
192
|
+
OrderProgress,
|
|
193
|
+
BusinessPreorder,
|
|
194
|
+
NotificationsList,
|
|
195
|
+
UserProfileForm,
|
|
196
|
+
ReviewOrder,
|
|
197
|
+
ReviewProducts,
|
|
198
|
+
ReviewDriver,
|
|
199
|
+
BusinessMenuList,
|
|
200
|
+
UserProfile,
|
|
201
|
+
MessageListing,
|
|
202
|
+
Messages,
|
|
203
|
+
Help,
|
|
204
|
+
HelpOptions,
|
|
205
|
+
MultiCheckout,
|
|
206
|
+
MultiOrdersDetails,
|
|
207
|
+
NetworkError,
|
|
208
|
+
NotFoundSource,
|
|
209
|
+
OrderTypeSelector,
|
|
210
|
+
Wallets,
|
|
211
|
+
PaymentOptionWallet,
|
|
212
|
+
ProductForm,
|
|
213
|
+
UpsellingProducts,
|
|
214
|
+
UserVerification,
|
|
215
|
+
BusinessListingSearch,
|
|
216
|
+
BusinessBasicInformation,
|
|
217
|
+
BusinessProductsCategories,
|
|
218
|
+
BusinessProductsList,
|
|
219
|
+
FloatingButton,
|
|
220
|
+
SearchBar,
|
|
221
|
+
LastOrders,
|
|
222
|
+
BusinessTypeFilter,
|
|
223
|
+
BusinessController,
|
|
224
|
+
BusinessFeaturedController,
|
|
225
|
+
HighestRatedBusinesses,
|
|
226
|
+
PaymentOptions,
|
|
227
|
+
DriverTips,
|
|
228
|
+
UserDetails,
|
|
229
|
+
OrderSummary,
|
|
230
|
+
OrderItAgain,
|
|
231
|
+
CartStoresListing,
|
|
232
|
+
PaymentOptionsWebView,
|
|
233
|
+
GoogleMap,
|
|
234
|
+
SingleProductCard,
|
|
235
|
+
SingleOrderCard,
|
|
236
|
+
UpsellingRedirect,
|
|
237
|
+
ProductItemAccordion,
|
|
238
|
+
ScheduleAccordion,
|
|
239
|
+
BusinessItemAccordion,
|
|
240
|
+
CouponControl,
|
|
241
|
+
TaxInformation,
|
|
242
|
+
PlaceSpot,
|
|
243
|
+
ProfessionalFilter,
|
|
244
|
+
ServiceForm,
|
|
245
|
+
ProfessionalProfile,
|
|
246
|
+
MomentSelector,
|
|
247
|
+
Cart,
|
|
248
|
+
LanguageSelector,
|
|
249
|
+
PhoneInputNumber,
|
|
250
|
+
FacebookLogin,
|
|
251
|
+
VerifyPhone,
|
|
252
|
+
GoogleLogin,
|
|
253
|
+
PreviousOrders,
|
|
254
|
+
PaymentOptionCash,
|
|
255
|
+
StripeElementsForm,
|
|
256
|
+
StripeCardsList,
|
|
257
|
+
ProductIngredient,
|
|
258
|
+
ProductOption,
|
|
259
|
+
ProductOptionSubOption,
|
|
264
260
|
SendGiftCard,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
261
|
+
Sessions,
|
|
262
|
+
SingleProductReview,
|
|
263
|
+
LogoutButton,
|
|
264
|
+
UserFormDetailsUI,
|
|
265
|
+
WalletTransactionItem,
|
|
266
|
+
Promotions,
|
|
267
|
+
PageBanner,
|
|
268
|
+
MyOrders,
|
|
269
|
+
MultiCart,
|
|
270
|
+
WebsocketStatus,
|
|
271
|
+
ORDER_TYPES,
|
|
272
|
+
USER_TYPE,
|
|
277
273
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
274
|
+
OSBill,
|
|
275
|
+
OSTable,
|
|
276
|
+
OSCoupon,
|
|
277
|
+
OSTotal,
|
|
278
|
+
OSRow,
|
|
283
279
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
280
|
+
FormInput,
|
|
281
|
+
FormSide,
|
|
282
|
+
ButtonsWrapper,
|
|
283
|
+
LoginWith,
|
|
284
|
+
OTab,
|
|
285
|
+
OTabs,
|
|
290
286
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
287
|
+
OSItem,
|
|
288
|
+
OSItemContent,
|
|
289
|
+
OSItemActions,
|
|
294
290
|
|
|
295
|
-
|
|
291
|
+
Alert,
|
|
296
292
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
293
|
+
//Types
|
|
294
|
+
LoginParams,
|
|
295
|
+
ProfileParams,
|
|
296
|
+
AddressListParams,
|
|
297
|
+
AddressFormParams,
|
|
298
|
+
SignupParams,
|
|
299
|
+
PhoneInputParams,
|
|
300
|
+
LanguageSelectorParams,
|
|
301
|
+
BusinessesListingParams,
|
|
302
|
+
HighestRatedBusinessesParams,
|
|
303
|
+
BusinessTypeFilterParams,
|
|
304
|
+
BusinessControllerParams,
|
|
305
|
+
BusinessProductsListingParams,
|
|
306
|
+
BusinessBasicInformationParams,
|
|
307
|
+
BusinessProductsCategoriesParams,
|
|
308
|
+
BusinessProductsListParams,
|
|
309
|
+
SingleProductCardParams,
|
|
310
|
+
BusinessInformationParams,
|
|
311
|
+
BusinessReviewsParams,
|
|
312
|
+
SearchBarParams,
|
|
313
|
+
NotFoundSourceParams,
|
|
314
|
+
OrdersOptionParams,
|
|
315
|
+
ActiveOrdersParams,
|
|
316
|
+
PreviousOrdersParams,
|
|
317
|
+
OrderDetailsParams,
|
|
318
|
+
ReviewDriverParams,
|
|
323
319
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
320
|
+
// OComponents
|
|
321
|
+
Toast,
|
|
322
|
+
OText,
|
|
323
|
+
OButton,
|
|
324
|
+
OInput,
|
|
325
|
+
ODropDown,
|
|
326
|
+
OIcon,
|
|
327
|
+
OIconText,
|
|
328
|
+
OIconButton,
|
|
329
|
+
OTextarea,
|
|
330
|
+
OToggle,
|
|
331
|
+
OKeyButton,
|
|
332
|
+
OAlert,
|
|
333
|
+
OModal,
|
|
334
|
+
OBottomPopup,
|
|
335
|
+
HeaderTitle,
|
|
340
336
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
337
|
+
// layout
|
|
338
|
+
Container,
|
|
339
|
+
SafeAreaContainer,
|
|
340
|
+
FloatingBottomContainer,
|
|
341
|
+
NavBar,
|
|
346
342
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
343
|
+
// utils
|
|
344
|
+
_retrieveStoreData,
|
|
345
|
+
_setStoreData,
|
|
346
|
+
_removeStoreData,
|
|
347
|
+
_clearStoreData,
|
|
348
|
+
orderTypeList,
|
|
353
349
|
getTraduction,
|
|
354
350
|
verifyDecimals,
|
|
355
351
|
getOrderStatus,
|
|
356
352
|
getOrderStatuPickUp,
|
|
357
353
|
|
|
358
|
-
|
|
359
|
-
|
|
354
|
+
// Date Picker
|
|
355
|
+
DatePickerUI
|
|
360
356
|
}
|
|
@@ -201,7 +201,7 @@ const CheckoutUI = (props: any) => {
|
|
|
201
201
|
const hideBusinessDetails = theme?.checkout?.components?.business?.hidden
|
|
202
202
|
const hideBusinessMap = theme?.checkout?.components?.business?.components?.map?.hidden
|
|
203
203
|
const hideCustomerDetails = theme?.checkout?.components?.customer?.hidden
|
|
204
|
-
|
|
204
|
+
const isGuestCheckoutEnabled = configs?.guest_checkout_enabled?.value === '1'
|
|
205
205
|
const creditPointPlan = loyaltyPlansState?.result?.find((loyal: any) => loyal.type === 'credit_point')
|
|
206
206
|
const creditPointPlanOnBusiness = creditPointPlan?.businesses?.find((b: any) => b.business_id === cart?.business_id && b.accumulates)
|
|
207
207
|
const methodsPay = ['google_pay', 'apple_pay']
|
|
@@ -230,7 +230,8 @@ const CheckoutUI = (props: any) => {
|
|
|
230
230
|
validateDriverTipField ||
|
|
231
231
|
validateCouponField ||
|
|
232
232
|
validateZipcodeCard ||
|
|
233
|
-
(!userHasCards && cardsPaymethods.includes(paymethodSelected?.gateway))
|
|
233
|
+
(!userHasCards && cardsPaymethods.includes(paymethodSelected?.gateway)) ||
|
|
234
|
+
(!isGuestCheckoutEnabled && !!user?.guest_id)
|
|
234
235
|
|
|
235
236
|
const driverTipsOptions = typeof configs?.driver_tip_options?.value === 'string'
|
|
236
237
|
? JSON.parse(configs?.driver_tip_options?.value) || []
|
|
@@ -276,6 +277,10 @@ const CheckoutUI = (props: any) => {
|
|
|
276
277
|
if (user) setOpenModal({ ...openModal, login: false })
|
|
277
278
|
}
|
|
278
279
|
|
|
280
|
+
const handleOpenGuestSignup = () => {
|
|
281
|
+
setOpenModal({ ...openModal, signup: true, isGuest: true })
|
|
282
|
+
}
|
|
283
|
+
|
|
279
284
|
const handlePlaceOrder = (confirmPayment: any, forcePlace: boolean = false) => {
|
|
280
285
|
if (stripePaymethods.includes(paymethodSelected?.gateway) && user?.guest_id) {
|
|
281
286
|
setOpenModal({ ...openModal, signup: true, isGuest: true })
|
|
@@ -671,14 +676,16 @@ const CheckoutUI = (props: any) => {
|
|
|
671
676
|
style={{ borderRadius: 7.6, marginTop: 20 }}
|
|
672
677
|
onClick={() => setOpenModal({ ...openModal, login: true })}
|
|
673
678
|
/>
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
679
|
+
{isGuestCheckoutEnabled && (
|
|
680
|
+
<OButton
|
|
681
|
+
text={t('CONTINUE_AS_GUEST', 'Continue as guest')}
|
|
682
|
+
textStyle={{ color: theme.colors.black }}
|
|
683
|
+
bgColor={theme.colors.white}
|
|
684
|
+
borderColor={theme.colors.black}
|
|
685
|
+
style={{ borderRadius: 7.6, marginTop: 20 }}
|
|
686
|
+
onClick={() => setAllowedGuest(true)}
|
|
687
|
+
/>
|
|
688
|
+
)}
|
|
682
689
|
</View>
|
|
683
690
|
) : (
|
|
684
691
|
<UserDetails
|
|
@@ -869,6 +876,8 @@ const CheckoutUI = (props: any) => {
|
|
|
869
876
|
paymethodClicked={paymethodClicked}
|
|
870
877
|
setPaymethodClicked={setPaymethodClicked}
|
|
871
878
|
setUserHasCards={setUserHasCards}
|
|
879
|
+
handleOpenGuestSignup={handleOpenGuestSignup}
|
|
880
|
+
guestDisabledError={(!isGuestCheckoutEnabled && !!user?.guest_id)}
|
|
872
881
|
/>
|
|
873
882
|
</ChPaymethods>
|
|
874
883
|
</ChSection>
|
|
@@ -1038,6 +1047,14 @@ const CheckoutUI = (props: any) => {
|
|
|
1038
1047
|
{t('WARNING_INVALID_COUPON_FIELD', 'Coupon is required.')}
|
|
1039
1048
|
</OText>
|
|
1040
1049
|
)}
|
|
1050
|
+
{(!isGuestCheckoutEnabled && !!user?.guest_id) && (
|
|
1051
|
+
<OText
|
|
1052
|
+
color={theme.colors.error}
|
|
1053
|
+
size={12}
|
|
1054
|
+
>
|
|
1055
|
+
{t('LOGIN_SIGN_UP_COMPLETE_ORDER', 'Login/Sign up to complete your order.')}
|
|
1056
|
+
</OText>
|
|
1057
|
+
)}
|
|
1041
1058
|
</ChErrors>
|
|
1042
1059
|
</View>
|
|
1043
1060
|
)}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import { useApi } from 'ordering-components/native'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Component to manage login behavior without UI component
|
|
7
|
+
*/
|
|
8
|
+
export const CmsContent = (props: any) => {
|
|
9
|
+
const { UIComponent } = props
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Array to save the body of the page
|
|
13
|
+
*/
|
|
14
|
+
const [ordering] = useApi()
|
|
15
|
+
const [cmsState, setCmsState] = useState({ items: [], pages: [], loading: true, error: null })
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Method used to get the page by slug
|
|
19
|
+
*/
|
|
20
|
+
const getPages = async () => {
|
|
21
|
+
setCmsState({ ...cmsState, loading: true })
|
|
22
|
+
try {
|
|
23
|
+
const propsToFetch = ['name', 'enabled']
|
|
24
|
+
let pages: any = []
|
|
25
|
+
const { content: { error, result } } = await ordering.pages().select(propsToFetch).get()
|
|
26
|
+
if (!error) {
|
|
27
|
+
const promises = result.map((item: any) => getPage(item.id));
|
|
28
|
+
pages = await Promise.all(promises)
|
|
29
|
+
}
|
|
30
|
+
setCmsState({
|
|
31
|
+
...cmsState,
|
|
32
|
+
loading: false,
|
|
33
|
+
error: error ? typeof result === 'string' ? result : result[0] : null,
|
|
34
|
+
items: error ? [] : result.filter((i: any) => i.enabled).map((item: any) => ({ id: item.id, name: item.name })),
|
|
35
|
+
pages
|
|
36
|
+
})
|
|
37
|
+
} catch (err: any) {
|
|
38
|
+
setCmsState({
|
|
39
|
+
...cmsState,
|
|
40
|
+
loading: false,
|
|
41
|
+
error: err?.message ?? err
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const getPage = async (id: number) => {
|
|
47
|
+
try {
|
|
48
|
+
const { content: { error, result } } = await ordering.pages(id).get()
|
|
49
|
+
return error ? null : { id, body: result?.body }
|
|
50
|
+
} catch {
|
|
51
|
+
return null
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
getPages()
|
|
57
|
+
}, [])
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<>
|
|
61
|
+
{UIComponent && (
|
|
62
|
+
<UIComponent
|
|
63
|
+
{...props}
|
|
64
|
+
cmsState={cmsState}
|
|
65
|
+
/>
|
|
66
|
+
)}
|
|
67
|
+
</>
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
CmsContent.propTypes = {
|
|
72
|
+
/**
|
|
73
|
+
* UI Component, this must be containt all graphic elements and use parent props
|
|
74
|
+
*/
|
|
75
|
+
UIComponent: PropTypes.elementType
|
|
76
|
+
}
|