ordering-components-external 13.2.32 → 13.2.34
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/.babelrc +22 -22
- package/.vscode/settings.json +3 -3
- package/_bundles/{7.ordering-component.5e6b244837705c07824f.js → 7.ordering-component.6cdb5ba8147ea6e69b23.js} +1 -1
- package/_bundles/{ordering-component.5e6b244837705c07824f.js → ordering-component.6cdb5ba8147ea6e69b23.js} +2 -2
- package/_modules/components/AddressDetails/index.js +26 -26
- package/_modules/components/AddressForm/index.js +50 -50
- package/_modules/components/AddressList/index.js +40 -40
- package/_modules/components/Analitycs/index.js +6 -6
- package/_modules/components/AnalyticsSegment/index.js +3 -3
- package/_modules/components/AppleLogin/index.js +26 -26
- package/_modules/components/BaseComponent/index.js +14 -14
- package/_modules/components/BusinessAndProductList/index.js +16 -16
- package/_modules/components/BusinessBasicInformation/index.js +20 -20
- package/_modules/components/BusinessController/index.js +50 -50
- package/_modules/components/BusinessInformation/BusinessOption/index.js +20 -20
- package/_modules/components/BusinessInformation/index.js +18 -18
- package/_modules/components/BusinessList/index.js +42 -42
- package/_modules/components/BusinessMenuListing/index.js +20 -20
- package/_modules/components/BusinessProductsCategories/index.js +16 -16
- package/_modules/components/BusinessProductsSearch/index.js +14 -14
- package/_modules/components/BusinessReviews/index.js +27 -27
- package/_modules/components/BusinessSearchList/index.js +18 -18
- package/_modules/components/BusinessSortControl/index.js +28 -28
- package/_modules/components/BusinessTypeFilter/index.js +26 -26
- package/_modules/components/BusinessesMap/index.js +27 -27
- package/_modules/components/Cart/index.js +38 -38
- package/_modules/components/CartStoresListing/index.js +4 -4
- package/_modules/components/Checkout/index.js +60 -60
- package/_modules/components/CmsContent/index.js +20 -20
- package/_modules/components/Contacts/index.js +28 -28
- package/_modules/components/CouponControl/index.js +22 -22
- package/_modules/components/DriverList/index.js +22 -22
- package/_modules/components/DriverTips/index.js +35 -35
- package/_modules/components/FacebookLoginButton/index.js +40 -40
- package/_modules/components/FacebookPixel/index.js +3 -3
- package/_modules/components/FavoriteList/index.js +28 -28
- package/_modules/components/FirebaseGoogleLoginButton/index.js +10 -10
- package/_modules/components/FloatingButton/index.js +20 -20
- package/_modules/components/ForgotPasswordForm/index.js +43 -43
- package/_modules/components/GiftCard/GiftCardOrdersList/index.js +4 -4
- package/_modules/components/GiftCard/PurchaseGiftCard/index.js +6 -6
- package/_modules/components/GiftCard/RedeemGiftCard/index.js +4 -4
- package/_modules/components/GiftCard/SendGiftCard/index.js +4 -4
- package/_modules/components/GoogleAutocompleteInput/index.js +18 -18
- package/_modules/components/GoogleIdentity/index.js +28 -28
- package/_modules/components/GoogleLoginButton/index.js +49 -49
- package/_modules/components/GoogleMaps/index.js +37 -37
- package/_modules/components/GpsButton/index.js +20 -20
- package/_modules/components/LanguageSelector/index.js +28 -28
- package/_modules/components/LoginForm/index.js +58 -58
- package/_modules/components/LogoutAction/index.js +17 -17
- package/_modules/components/MainSearch/index.js +31 -31
- package/_modules/components/MenuControl/index.js +51 -51
- package/_modules/components/Messages/index.js +22 -22
- package/_modules/components/MomentOption/index.js +51 -51
- package/_modules/components/MultiCartCreate/index.js +2 -2
- package/_modules/components/MultiCartsPaymethodsAndWallets/index.js +8 -8
- package/_modules/components/MultiCheckout/index.js +12 -12
- package/_modules/components/MultiOrdersDetails/index.js +6 -6
- package/_modules/components/MyOrders/index.js +24 -24
- package/_modules/components/MyOrdersList/index.js +26 -26
- package/_modules/components/NewOrderNotification/index.js +2 -2
- package/_modules/components/OrderChange/index.js +20 -20
- package/_modules/components/OrderDetails/index.js +43 -43
- package/_modules/components/OrderList/index.js +44 -44
- package/_modules/components/OrderReview/index.js +22 -22
- package/_modules/components/OrderTypeControl/index.js +18 -18
- package/_modules/components/OrdersControlFilters/index.js +6 -6
- package/_modules/components/OrdersDashboardComponents/Appointments/index.js +4 -4
- package/_modules/components/OrdersDashboardComponents/BusinessProductsListing/index.js +26 -26
- package/_modules/components/OrdersDashboardComponents/CheckPassword/index.js +24 -24
- package/_modules/components/OrdersDashboardComponents/CityList/index.js +20 -20
- package/_modules/components/OrdersDashboardComponents/CountryList/index.js +20 -20
- package/_modules/components/OrdersDashboardComponents/CustomOrderDetails/index.js +12 -12
- package/_modules/components/OrdersDashboardComponents/DashboardBusinessList/index.js +54 -54
- package/_modules/components/OrdersDashboardComponents/DashboardOrdersList/index.js +60 -60
- package/_modules/components/OrdersDashboardComponents/DriversList/index.js +58 -58
- package/_modules/components/OrdersDashboardComponents/ExportCSV/index.js +16 -16
- package/_modules/components/OrdersDashboardComponents/GiftCardsList/index.js +6 -6
- package/_modules/components/OrdersDashboardComponents/GoogleMapsApiKeySetting/index.js +4 -4
- package/_modules/components/OrdersDashboardComponents/LogisticInformation/index.js +20 -20
- package/_modules/components/OrdersDashboardComponents/Logistics/index.js +20 -20
- package/_modules/components/OrdersDashboardComponents/Messages/index.js +27 -27
- package/_modules/components/OrdersDashboardComponents/MetaFields/index.js +26 -26
- package/_modules/components/OrdersDashboardComponents/OrderDetails/index.js +36 -36
- package/_modules/components/OrdersDashboardComponents/OrderNotification/index.js +14 -14
- package/_modules/components/OrdersDashboardComponents/OrdersFilter/index.js +62 -62
- package/_modules/components/OrdersDashboardComponents/OrdersManage/index.js +56 -56
- package/_modules/components/OrdersDashboardComponents/PointsWalletLevels/index.js +25 -25
- package/_modules/components/OrdersDashboardComponents/ReviewCustomer/index.js +16 -16
- package/_modules/components/OrdersDashboardComponents/Schedule/index.js +46 -46
- package/_modules/components/OrdersDashboardComponents/SettingsList/index.js +39 -39
- package/_modules/components/OrdersDashboardComponents/UserFormDetails/index.js +66 -66
- package/_modules/components/OrdersDashboardComponents/UsersList/index.js +54 -54
- package/_modules/components/OrdersDashboardComponents/WebsocketStatus/index.js +4 -4
- package/_modules/components/PageBanner/index.js +4 -4
- package/_modules/components/PaymentOptionCash/index.js +24 -24
- package/_modules/components/PaymentOptionPaypal/index.js +24 -24
- package/_modules/components/PaymentOptionSquare/index.js +2 -2
- package/_modules/components/PaymentOptionStripe/index.js +32 -32
- package/_modules/components/PaymentOptionStripeDirect/index.js +24 -24
- package/_modules/components/PaymentOptionStripeLink/index.js +4 -4
- package/_modules/components/PaymentOptionStripeRedirect/StripeRedirectForm/index.js +19 -19
- package/_modules/components/PaymentOptionStripeRedirect/index.js +30 -30
- package/_modules/components/PaymentOptions/index.js +27 -27
- package/_modules/components/PaymethodList/index.js +20 -20
- package/_modules/components/PhoneAutocomplete/index.js +18 -18
- package/_modules/components/PlaceSpot/index.js +2 -2
- package/_modules/components/Popup/index.js +33 -33
- package/_modules/components/ProductComponent/index.js +27 -27
- package/_modules/components/ProductForm/index.js +159 -135
- package/_modules/components/ProductImages/index.js +18 -18
- package/_modules/components/ProductIngredient/index.js +17 -17
- package/_modules/components/ProductItemAccordion/index.js +8 -8
- package/_modules/components/ProductOption/index.js +8 -8
- package/_modules/components/ProductOptionSuboption/index.js +33 -33
- package/_modules/components/ProductShare/index.js +20 -20
- package/_modules/components/ProductsList/index.js +20 -20
- package/_modules/components/ProductsListing/index.js +39 -39
- package/_modules/components/ProfessionalInfo/index.js +24 -24
- package/_modules/components/QueryLoginSpoonity/index.js +20 -20
- package/_modules/components/ReCaptcha/index.js +4 -4
- package/_modules/components/ResetPassword/index.js +20 -20
- package/_modules/components/ReviewCustomer/index.js +16 -16
- package/_modules/components/ReviewDriver/index.js +20 -20
- package/_modules/components/ReviewProduct/index.js +22 -22
- package/_modules/components/SearchOptions/index.js +17 -17
- package/_modules/components/Sessions/index.js +21 -21
- package/_modules/components/SignupForm/index.js +58 -58
- package/_modules/components/SingleBusinessCard/index.js +28 -28
- package/_modules/components/SingleOrderCard/index.js +20 -20
- package/_modules/components/SingleProductCard/index.js +18 -18
- package/_modules/components/SingleProfessionalCard/index.js +18 -18
- package/_modules/components/SmartAppBanner/index.js +8 -8
- package/_modules/components/StoreProductList/index.js +22 -22
- package/_modules/components/StripeElementsForm/CardForm/index.js +25 -25
- package/_modules/components/StripeElementsForm/index.js +16 -16
- package/_modules/components/UpsellingPage/index.js +19 -19
- package/_modules/components/UserFormDetails/index.js +68 -68
- package/_modules/components/UserVerification/index.js +24 -17
- package/_modules/components/WebsocketStatus/index.js +4 -4
- package/_modules/components/WrapperGoogleMaps/index.js +3 -3
- package/_modules/contexts/ApiContext/index.js +8 -8
- package/_modules/contexts/BillingContext/index.js +7 -7
- package/_modules/contexts/BusinessContext/index.js +9 -9
- package/_modules/contexts/ConfigContext/index.js +9 -9
- package/_modules/contexts/EventContext/index.js +9 -9
- package/_modules/contexts/LanguageContext/index.js +13 -13
- package/_modules/contexts/OptimizationLoadContext/index.js +8 -8
- package/_modules/contexts/OrderContext/index.js +62 -62
- package/_modules/contexts/OrderingContext/index.js +7 -7
- package/_modules/contexts/OrderingThemeContext/index.js +11 -11
- package/_modules/contexts/ProductContext/index.js +13 -13
- package/_modules/contexts/SessionContext/index.js +9 -9
- package/_modules/contexts/SiteContext/index.js +9 -9
- package/_modules/contexts/UtilsContext/index.js +9 -9
- package/_modules/contexts/WebsocketContext/index.js +9 -9
- package/_modules/native/src/contexts/OrderingContext/index.js +7 -7
- package/cypress/fixtures/example.json +4 -4
- package/cypress/integration/naked/BusinessProductsCategories.spec.js +9 -9
- package/cypress/integration/naked/PhoneAutocomplete.spec.js +22 -22
- package/cypress/integration/naked/activeOrders.spec.js +15 -15
- package/cypress/integration/naked/addressDetails.spec.js +10 -10
- package/cypress/integration/naked/appleLogin.spec.js +14 -14
- package/cypress/integration/naked/businessBasicInformation.spec.js +14 -14
- package/cypress/integration/naked/businessController.spec.js +9 -9
- package/cypress/integration/naked/businessInformation.spec.js +19 -19
- package/cypress/integration/naked/businessProductsSearch.spec.js +9 -9
- package/cypress/integration/naked/businessReviews.spec.js +16 -16
- package/cypress/integration/naked/businessSortControl.spec.js +9 -9
- package/cypress/integration/naked/businessTypeFilter.spec.js +10 -10
- package/cypress/integration/naked/businessesMap.spec.js +13 -13
- package/cypress/integration/naked/cms.spec.js +9 -9
- package/cypress/integration/naked/config.spec.js +34 -34
- package/cypress/integration/naked/driverTips.spec.js +10 -10
- package/cypress/integration/naked/events.spec.js +13 -13
- package/cypress/integration/naked/facebookLogin.spec.js +13 -13
- package/cypress/integration/naked/floatingButton.spec.js +13 -13
- package/cypress/integration/naked/forgotPassword.spec.js +20 -20
- package/cypress/integration/naked/googleLogin.spec.js +11 -11
- package/cypress/integration/naked/languageExamples.spec.js +25 -25
- package/cypress/integration/naked/languageSelector.spec.js +10 -10
- package/cypress/integration/naked/login.spec.js +38 -38
- package/cypress/integration/naked/logout.spec.js +15 -15
- package/cypress/integration/naked/mainSearch.spec.js +9 -9
- package/cypress/integration/naked/menuControl.spec.js +9 -9
- package/cypress/integration/naked/messages.spec.js +25 -25
- package/cypress/integration/naked/momentOption.spec.js +10 -10
- package/cypress/integration/naked/myOrders.spec.js +11 -11
- package/cypress/integration/naked/myOrdersList.spec.js +9 -9
- package/cypress/integration/naked/orderContextAdvanced.spec.js +23 -23
- package/cypress/integration/naked/orderDetails.spec.js +11 -11
- package/cypress/integration/naked/paymentOptionCash.spec.js +21 -21
- package/cypress/integration/naked/paymentOptionStripe.spec.js +11 -11
- package/cypress/integration/naked/paymentOptionStripeDirect.spec.js +11 -11
- package/cypress/integration/naked/paymentOptions.spec.js +9 -9
- package/cypress/integration/naked/popupExample.spec.js +17 -17
- package/cypress/integration/naked/productImages.spec.js +11 -11
- package/cypress/integration/naked/productOptionExample.spec.js +21 -21
- package/cypress/integration/naked/productShare.spec.js +9 -9
- package/cypress/integration/naked/productsList.spec.js +9 -9
- package/cypress/integration/naked/resetPassword.spec.js +11 -11
- package/cypress/integration/naked/reviewOrders.spec.js +13 -13
- package/cypress/integration/naked/searchOptions.spec.js +18 -18
- package/cypress/integration/naked/signup.spec.js +31 -31
- package/cypress/integration/naked/upselling.spec.js +13 -13
- package/cypress/integration/naked/userDetails.spec.js +12 -12
- package/cypress/plugins/index.js +21 -21
- package/cypress/support/commands.js +35 -35
- package/cypress/support/index.js +20 -20
- package/cypress.json +12 -12
- package/example/App.js +263 -263
- package/example/components/ActiveOrdersUI/index.js +72 -72
- package/example/components/AddressDetailsUI/index.js +101 -101
- package/example/components/AddressFormUI/index.js +161 -161
- package/example/components/AddressListUI/index.js +33 -33
- package/example/components/AlertPopup/index.js +10 -10
- package/example/components/AlertUI/index.js +49 -49
- package/example/components/AlertUI/style.css +5 -5
- package/example/components/AppleLoginUI/index.js +40 -40
- package/example/components/BaseComponentUI/index.js +34 -34
- package/example/components/BusinessBasicInformationUI/index.js +118 -118
- package/example/components/BusinessControllerUI/index.js +89 -89
- package/example/components/BusinessInformationUI/BusinessOptionUI/index.js +83 -83
- package/example/components/BusinessInformationUI/index.js +83 -83
- package/example/components/BusinessProductsCategoriesUI/index.js +42 -42
- package/example/components/BusinessProductsSearchUI/index.js +38 -38
- package/example/components/BusinessReviewsUI/index.js +77 -77
- package/example/components/BusinessSortControlUI/index.js +47 -47
- package/example/components/BusinessTypeFilterUI/index.js +53 -53
- package/example/components/BusinessesMapUI/index.js +57 -57
- package/example/components/CartUI/index.js +154 -154
- package/example/components/ChangeView/index.js +19 -19
- package/example/components/CheckoutUI/index.js +206 -206
- package/example/components/CmsContentUI/index.js +52 -52
- package/example/components/ConfigsExample/index.js +118 -118
- package/example/components/CouponControlUI/index.js +63 -63
- package/example/components/DriverTipsUI/index.js +58 -58
- package/example/components/FacebookLoginButtonUI/index.js +48 -48
- package/example/components/FloatingButtonUI/index.js +145 -145
- package/example/components/ForgotPasswordFormUI/index.js +93 -93
- package/example/components/GoogleLoginUI/index.js +30 -30
- package/example/components/GpsButtonUI/index.js +22 -22
- package/example/components/Header/index.js +18 -18
- package/example/components/LanguageSelectorUI/index.js +57 -57
- package/example/components/LanguagesExample/index.js +51 -51
- package/example/components/LoginFormUI/index.js +159 -159
- package/example/components/LogoutButtonUI/index.js +21 -21
- package/example/components/MainSearchUI/index.js +131 -131
- package/example/components/MenuControlUI/index.js +103 -103
- package/example/components/MessagesUI/index.js +162 -162
- package/example/components/ModalUI/index.js +36 -36
- package/example/components/ModalUI/style.css +5 -5
- package/example/components/MomentOptionUI/index.js +68 -68
- package/example/components/MyOrdersListUI/index.js +51 -51
- package/example/components/MyOrdersUI/index.js +52 -52
- package/example/components/OrderChangeUI/index.js +54 -54
- package/example/components/OrderDetailsUI/index.js +174 -174
- package/example/components/OrderReviewUI/index.js +125 -125
- package/example/components/OrderTypeControlUI/index.js +32 -32
- package/example/components/PaymentOptionCashUI/index.js +60 -60
- package/example/components/PaymentOptionPaypalUI/index.js +50 -50
- package/example/components/PaymentOptionStripeDirectUI/index.js +89 -89
- package/example/components/PaymentOptionStripeRedirectUI/index.js +97 -97
- package/example/components/PaymentOptionStripeUI/index.js +129 -129
- package/example/components/PaymentOptionsUI/index.js +169 -169
- package/example/components/PhoneAutocompleteUI/index.js +67 -67
- package/example/components/PhoneAutocompleteUI/styles.css +49 -49
- package/example/components/ProductComponentUI/index.js +113 -113
- package/example/components/ProductFormUI/index.js +131 -131
- package/example/components/ProductImagesUI/index.js +82 -82
- package/example/components/ProductIngredientUI/index.js +21 -21
- package/example/components/ProductOptionSuboptionUI/index.js +65 -65
- package/example/components/ProductOptionUI/index.js +31 -31
- package/example/components/ProductShareUI/index.js +48 -48
- package/example/components/ProductsListUI/index.js +108 -108
- package/example/components/ProductsListingUI/index.js +42 -42
- package/example/components/ResetPasswordUI/index.js +121 -121
- package/example/components/SearchOptionsUI/index.js +82 -82
- package/example/components/SignupFormUI/index.js +117 -117
- package/example/components/SingleBusinessCardUI/index.js +82 -82
- package/example/components/SingleOrderCardUI/index.js +52 -52
- package/example/components/SingleProductCardUI/index.js +47 -47
- package/example/components/StripeElementsFormUI/CardFormUI/index.js +51 -51
- package/example/components/StripeElementsFormUI/CardFormUI/style.css +118 -118
- package/example/components/StripeElementsFormUI/index.js +38 -38
- package/example/components/StripeRedirectFormUI/index.js +99 -99
- package/example/components/TestComponent/index.js +5 -5
- package/example/components/UpsellingPageUI/index.js +26 -26
- package/example/components/UserDetailsUI/index.js +94 -94
- package/example/components/UserProfileUI/index.js +156 -156
- package/example/views/ActiveOrders/index.js +86 -86
- package/example/views/AddressDetailsExample/index.js +57 -57
- package/example/views/AppleLoginExample/index.js +51 -51
- package/example/views/BaseComponentExample/index.js +35 -35
- package/example/views/BusinessBasicInformationExample/index.js +43 -43
- package/example/views/BusinessControllerExample/index.js +55 -55
- package/example/views/BusinessInformationExample/index.js +68 -68
- package/example/views/BusinessProductsCategoriesExample/index.js +50 -50
- package/example/views/BusinessProductsSearchExample/index.js +39 -39
- package/example/views/BusinessReviewsExample/index.js +43 -43
- package/example/views/BusinessSortControlExample/index.js +53 -53
- package/example/views/BusinessTypeFilterExample/index.js +53 -53
- package/example/views/BusinessesMapExample/index.js +57 -57
- package/example/views/CheckoutExample/index.js +143 -143
- package/example/views/CmsContentExample/index.js +44 -44
- package/example/views/DriverTipsExample/index.js +47 -47
- package/example/views/EventsExample/index.js +26 -26
- package/example/views/FacebookLogin/index.js +63 -63
- package/example/views/FloatingButtonExample/index.js +47 -47
- package/example/views/ForgotPassword/index.js +77 -77
- package/example/views/GoogleLoginExample/index.js +85 -85
- package/example/views/Home/index.js +200 -200
- package/example/views/LanguageSelectorExample/index.js +55 -55
- package/example/views/Login/index.js +84 -84
- package/example/views/MainSearchExample/index.js +43 -43
- package/example/views/MenuControlExample/index.js +68 -68
- package/example/views/MessagesExample/index.js +58 -58
- package/example/views/MomentOptionExample/index.js +52 -52
- package/example/views/MyOrdersExample/index.js +35 -35
- package/example/views/MyOrdersListExample/index.js +50 -50
- package/example/views/OrderChangeExample/index.js +46 -46
- package/example/views/OrderContextExample/index.js +139 -139
- package/example/views/OrderDetailsExample/index.js +50 -50
- package/example/views/OrderReviewExample/index.js +64 -64
- package/example/views/PaymentOptionCashExample/index.js +51 -51
- package/example/views/PaymentOptionPaypalExample/index.js +71 -71
- package/example/views/PaymentOptionStripeDirectExample/index.js +43 -43
- package/example/views/PaymentOptionStripeExample/index.js +47 -47
- package/example/views/PaymentOptionStripeRedirectExample/index.js +56 -56
- package/example/views/PaymentOptionsExample/index.js +47 -47
- package/example/views/PhoneAutocompleteExample/index.js +34 -34
- package/example/views/PlacesExample/index.js +94 -94
- package/example/views/PopupExample/index.js +78 -78
- package/example/views/PopupExample/style.css +18 -18
- package/example/views/ProductDetail/index.js +323 -323
- package/example/views/ProductImagesExample/index.js +43 -43
- package/example/views/ProductOptionExample/index.js +88 -88
- package/example/views/ProductShareExample/index.js +51 -51
- package/example/views/ProductsListExample/index.js +77 -77
- package/example/views/ProductsListingExample/index.js +47 -47
- package/example/views/ResetPasswordExample/index.js +60 -60
- package/example/views/SearchOptionsExample/index.js +42 -42
- package/example/views/SessionManager/index.js +122 -122
- package/example/views/Signup/index.js +64 -64
- package/example/views/UpsellingPageExample/index.js +35 -35
- package/example/views/UserDetailsExample/index.js +69 -69
- package/example/views/UserProfile/index.js +73 -73
- package/index-example.js +23 -23
- package/index.html +13 -13
- package/native/index.js +257 -257
- package/native/src/NativeStrategy/index.js +20 -20
- package/native/src/contexts/OrderingContext/index.js +85 -85
- package/package.json +92 -92
- package/src/components/AddressDetails/index.js +149 -149
- package/src/components/AddressForm/index.js +380 -380
- package/src/components/AddressList/index.js +254 -254
- package/src/components/Analitycs/index.js +119 -119
- package/src/components/AnalyticsSegment/index.js +145 -145
- package/src/components/AppleLogin/index.js +164 -164
- package/src/components/BaseComponent/index.js +52 -52
- package/src/components/BusinessAndProductList/index.js +1005 -1005
- package/src/components/BusinessBasicInformation/index.js +119 -119
- package/src/components/BusinessController/index.js +351 -351
- package/src/components/BusinessInformation/BusinessOption/index.js +86 -86
- package/src/components/BusinessInformation/index.js +93 -93
- package/src/components/BusinessList/index.js +670 -670
- package/src/components/BusinessMenuListing/index.js +99 -99
- package/src/components/BusinessProductsCategories/index.js +60 -60
- package/src/components/BusinessProductsSearch/index.js +54 -54
- package/src/components/BusinessReviews/index.js +187 -187
- package/src/components/BusinessSearchList/index.js +364 -364
- package/src/components/BusinessSortControl/index.js +100 -100
- package/src/components/BusinessTypeFilter/index.js +142 -142
- package/src/components/BusinessesMap/index.js +110 -110
- package/src/components/Cart/index.js +211 -211
- package/src/components/CartStoresListing/index.js +157 -157
- package/src/components/Checkout/index.js +652 -652
- package/src/components/CmsContent/index.js +97 -97
- package/src/components/Contacts/index.js +512 -512
- package/src/components/CouponControl/index.js +171 -171
- package/src/components/DragAndDrop/index.js +41 -41
- package/src/components/DriverList/index.js +112 -112
- package/src/components/DriverTips/index.js +141 -141
- package/src/components/Emitter/index.js +36 -36
- package/src/components/ExamineClick/index.js +40 -40
- package/src/components/FacebookLoginButton/index.js +214 -214
- package/src/components/FacebookPixel/index.js +148 -148
- package/src/components/FavoriteList/index.js +278 -278
- package/src/components/FirebaseGoogleLoginButton/index.js +93 -93
- package/src/components/FloatingButton/index.js +70 -70
- package/src/components/ForgotPasswordForm/index.js +180 -180
- package/src/components/GiftCard/GiftCardOrdersList/index.js +155 -155
- package/src/components/GiftCard/PurchaseGiftCard/index.js +127 -127
- package/src/components/GiftCard/RedeemGiftCard/index.js +77 -77
- package/src/components/GiftCard/SendGiftCard/index.js +83 -83
- package/src/components/GoogleAutocompleteInput/index.js +154 -154
- package/src/components/GoogleIdentity/index.js +144 -144
- package/src/components/GoogleLoginButton/index.js +276 -276
- package/src/components/GoogleMaps/index.js +523 -523
- package/src/components/GpsButton/index.js +154 -154
- package/src/components/LanguageSelector/index.js +163 -163
- package/src/components/LoginForm/index.js +531 -531
- package/src/components/LogoutAction/index.js +211 -211
- package/src/components/MainSearch/index.js +149 -149
- package/src/components/MapView/index.js +116 -116
- package/src/components/MenuControl/index.js +238 -238
- package/src/components/Messages/index.js +166 -166
- package/src/components/MomentOption/index.js +322 -322
- package/src/components/MultiCartCreate/index.js +70 -70
- package/src/components/MultiCartsPaymethodsAndWallets/index.js +201 -201
- package/src/components/MultiCheckout/index.js +378 -378
- package/src/components/MultiOrdersDetails/index.js +109 -109
- package/src/components/MyOrders/index.js +150 -150
- package/src/components/MyOrdersList/index.js +104 -104
- package/src/components/NewOrderNotification/index.js +30 -30
- package/src/components/OrderChange/index.js +128 -128
- package/src/components/OrderDetails/index.js +684 -684
- package/src/components/OrderList/index.js +814 -814
- package/src/components/OrderListGroups/index.js +1256 -1256
- package/src/components/OrderReview/index.js +180 -180
- package/src/components/OrderTypeControl/index.js +75 -75
- package/src/components/OrderVerticalList/index.js +422 -422
- package/src/components/OrdersControlFilters/index.js +75 -75
- package/src/components/OrdersDashboardComponents/Appointments/index.js +72 -72
- package/src/components/OrdersDashboardComponents/BusinessProductsListing/index.js +629 -629
- package/src/components/OrdersDashboardComponents/CheckPassword/index.js +177 -177
- package/src/components/OrdersDashboardComponents/CityList/index.js +98 -98
- package/src/components/OrdersDashboardComponents/CountryList/index.js +162 -162
- package/src/components/OrdersDashboardComponents/CustomOrderDetails/index.js +238 -238
- package/src/components/OrdersDashboardComponents/DashboardBusinessList/index.js +617 -617
- package/src/components/OrdersDashboardComponents/DashboardOrdersList/index.js +943 -943
- package/src/components/OrdersDashboardComponents/DriversList/index.js +448 -448
- package/src/components/OrdersDashboardComponents/ExportCSV/index.js +192 -192
- package/src/components/OrdersDashboardComponents/GiftCardsList/index.js +189 -189
- package/src/components/OrdersDashboardComponents/GoogleMapsApiKeySetting/index.js +77 -77
- package/src/components/OrdersDashboardComponents/LogisticInformation/index.js +97 -97
- package/src/components/OrdersDashboardComponents/Logistics/index.js +174 -174
- package/src/components/OrdersDashboardComponents/Messages/index.js +384 -384
- package/src/components/OrdersDashboardComponents/MetaFields/index.js +186 -186
- package/src/components/OrdersDashboardComponents/OrderDetails/index.js +404 -404
- package/src/components/OrdersDashboardComponents/OrderNotification/index.js +70 -70
- package/src/components/OrdersDashboardComponents/OrdersFilter/index.js +362 -362
- package/src/components/OrdersDashboardComponents/OrdersManage/index.js +873 -873
- package/src/components/OrdersDashboardComponents/PointsWalletLevels/index.js +123 -123
- package/src/components/OrdersDashboardComponents/ReviewCustomer/index.js +113 -113
- package/src/components/OrdersDashboardComponents/Schedule/index.js +315 -315
- package/src/components/OrdersDashboardComponents/SettingsList/index.js +298 -298
- package/src/components/OrdersDashboardComponents/UserFormDetails/index.js +463 -463
- package/src/components/OrdersDashboardComponents/UsersList/index.js +944 -944
- package/src/components/OrdersDashboardComponents/WebsocketStatus/index.js +77 -77
- package/src/components/OrdersDashboardComponents/index.js +57 -57
- package/src/components/PageBanner/index.js +107 -107
- package/src/components/PaymentOptionCash/index.js +74 -74
- package/src/components/PaymentOptionPaypal/index.js +146 -146
- package/src/components/PaymentOptionSquare/index.js +336 -336
- package/src/components/PaymentOptionStripe/index.js +289 -289
- package/src/components/PaymentOptionStripeDirect/index.js +116 -116
- package/src/components/PaymentOptionStripeLink/index.js +101 -101
- package/src/components/PaymentOptionStripeRedirect/StripeRedirectForm/index.js +71 -71
- package/src/components/PaymentOptionStripeRedirect/index.js +122 -122
- package/src/components/PaymentOptionWallet/index.js +185 -185
- package/src/components/PaymentOptions/index.js +263 -263
- package/src/components/PaymethodList/index.js +119 -119
- package/src/components/PhoneAutocomplete/index.js +318 -318
- package/src/components/PlaceSpot/index.js +183 -183
- package/src/components/Popup/index.js +169 -169
- package/src/components/ProductComponent/index.js +269 -269
- package/src/components/ProductForm/index.js +1149 -1119
- package/src/components/ProductImages/index.js +64 -64
- package/src/components/ProductIngredient/index.js +72 -72
- package/src/components/ProductItemAccordion/index.js +72 -72
- package/src/components/ProductOption/index.js +42 -42
- package/src/components/ProductOptionSuboption/index.js +225 -225
- package/src/components/ProductShare/index.js +97 -97
- package/src/components/ProductsList/index.js +74 -74
- package/src/components/ProductsListing/index.js +166 -166
- package/src/components/ProfessionalInfo/index.js +156 -156
- package/src/components/PromotionsController/index.js +123 -123
- package/src/components/QueryLoginSpoonity/index.js +159 -159
- package/src/components/ReCaptcha/index.js +53 -53
- package/src/components/ResetPassword/index.js +111 -111
- package/src/components/ReviewCustomer/index.js +117 -117
- package/src/components/ReviewDriver/index.js +157 -157
- package/src/components/ReviewProduct/index.js +162 -162
- package/src/components/SearchOptions/index.js +69 -69
- package/src/components/Sessions/index.js +217 -217
- package/src/components/SignupForm/index.js +557 -557
- package/src/components/SingleBusinessCard/index.js +80 -80
- package/src/components/SingleOrderCard/index.js +160 -160
- package/src/components/SingleProductCard/index.js +130 -130
- package/src/components/SingleProfessionalCard/index.js +121 -121
- package/src/components/SmartAppBanner/index.js +71 -71
- package/src/components/StoreProductList/index.js +303 -303
- package/src/components/StripeElementsForm/CardForm/index.js +248 -248
- package/src/components/StripeElementsForm/index.js +78 -78
- package/src/components/UpsellingPage/index.js +156 -156
- package/src/components/UserFormDetails/index.js +742 -742
- package/src/components/UserVerification/index.js +246 -246
- package/src/components/WalletList/index.js +160 -160
- package/src/components/WebsocketStatus/index.js +80 -80
- package/src/components/WrapperGoogleMaps/index.js +67 -67
- package/src/constants/code-numbers.js +219 -219
- package/src/constants/timezones.js +427 -427
- package/src/contexts/ApiContext/index.js +59 -59
- package/src/contexts/BillingContext/index.js +28 -28
- package/src/contexts/BusinessContext/index.js +71 -71
- package/src/contexts/ConfigContext/index.js +217 -217
- package/src/contexts/CustomerContext/index.js +69 -69
- package/src/contexts/EventContext/index.js +31 -31
- package/src/contexts/LanguageContext/index.js +144 -144
- package/src/contexts/OptimizationLoadContext/index.js +95 -95
- package/src/contexts/OrderContext/index.js +1450 -1450
- package/src/contexts/OrderingContext/index.js +86 -86
- package/src/contexts/OrderingThemeContext/index.js +107 -107
- package/src/contexts/ProductContext/index.js +62 -62
- package/src/contexts/SessionContext/index.js +172 -172
- package/src/contexts/SiteContext/index.js +79 -79
- package/src/contexts/ToastContext/index.js +42 -42
- package/src/contexts/UtilsContext/index.js +343 -343
- package/src/contexts/ValidationsFieldsContext/index.js +65 -65
- package/src/contexts/WebsocketContext/index.js +95 -95
- package/src/contexts/WebsocketContext/socket.js +92 -92
- package/src/index.js +373 -373
- package/src/utils/index.js +32 -32
- package/src/webStrategy/index.js +18 -18
- package/webpack.dev.js +41 -41
- package/webpack.prod.js +64 -64
- /package/_bundles/{0.ordering-component.5e6b244837705c07824f.js → 0.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{1.ordering-component.5e6b244837705c07824f.js → 1.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{2.ordering-component.5e6b244837705c07824f.js → 2.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{4.ordering-component.5e6b244837705c07824f.js → 4.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{5.ordering-component.5e6b244837705c07824f.js → 5.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{6.ordering-component.5e6b244837705c07824f.js → 6.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{7.ordering-component.5e6b244837705c07824f.js.LICENSE.txt → 7.ordering-component.6cdb5ba8147ea6e69b23.js.LICENSE.txt} +0 -0
- /package/_bundles/{8.ordering-component.5e6b244837705c07824f.js → 8.ordering-component.6cdb5ba8147ea6e69b23.js} +0 -0
- /package/_bundles/{ordering-component.5e6b244837705c07824f.js.LICENSE.txt → ordering-component.6cdb5ba8147ea6e69b23.js.LICENSE.txt} +0 -0
|
@@ -1,1256 +1,1256 @@
|
|
|
1
|
-
import React, { useEffect, useState, useCallback } from 'react'
|
|
2
|
-
import { useSession } from '../../contexts/SessionContext'
|
|
3
|
-
import { useApi } from '../../contexts/ApiContext'
|
|
4
|
-
import { useWebsocket } from '../../contexts/WebsocketContext'
|
|
5
|
-
import { ToastType, useToast } from '../../contexts/ToastContext'
|
|
6
|
-
import { useLanguage } from '../../contexts/LanguageContext'
|
|
7
|
-
import { useEvent } from '../../contexts/EventContext'
|
|
8
|
-
import { useConfig } from '../../contexts/ConfigContext'
|
|
9
|
-
|
|
10
|
-
export const OrderListGroups = (props) => {
|
|
11
|
-
const {
|
|
12
|
-
UIComponent,
|
|
13
|
-
orderBy,
|
|
14
|
-
isIos,
|
|
15
|
-
paginationSettings,
|
|
16
|
-
asDashboard,
|
|
17
|
-
orderGroupStatusCustom,
|
|
18
|
-
onOrdersDeleted,
|
|
19
|
-
customOrderTypes,
|
|
20
|
-
customPaymethods,
|
|
21
|
-
isDriverApp
|
|
22
|
-
} = props
|
|
23
|
-
|
|
24
|
-
const [ordering] = useApi()
|
|
25
|
-
const socket = useWebsocket()
|
|
26
|
-
const [session] = useSession()
|
|
27
|
-
const [events] = useEvent()
|
|
28
|
-
const [, t] = useLanguage()
|
|
29
|
-
const [, { showToast }] = useToast()
|
|
30
|
-
const [{ configs }] = useConfig()
|
|
31
|
-
|
|
32
|
-
const _combineTabs = props.combineTabs ?? configs?.combine_pending_and_progress_orders?.value === '1'
|
|
33
|
-
const [combineTabs, setCombineTabsState] = useState(_combineTabs)
|
|
34
|
-
|
|
35
|
-
const isLogisticActivated = configs?.logistic_module?.value
|
|
36
|
-
const ordersStatusArray = combineTabs ? ['active', 'completed', 'cancelled'] : ['pending', 'inProgress', 'completed', 'cancelled']
|
|
37
|
-
const notificationStatusses = props.isDriverApp
|
|
38
|
-
? configs?.notification_driver_states?.value.split('|').map(value => Number(value)) || []
|
|
39
|
-
: configs?.notification_business_states?.value.split('|').map(value => Number(value)) || []
|
|
40
|
-
const ordersGroupStatus = {
|
|
41
|
-
active: orderGroupStatusCustom?.active ?? [0, 3, 4, 7, 8, 9, 13, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26],
|
|
42
|
-
pending: orderGroupStatusCustom?.pending ?? [0, 13],
|
|
43
|
-
inProgress: orderGroupStatusCustom?.inProgress ?? [3, 4, 7, 8, 9, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26],
|
|
44
|
-
completed: orderGroupStatusCustom?.completed ?? [1, 11, 15],
|
|
45
|
-
cancelled: orderGroupStatusCustom?.cancelled ?? [2, 5, 6, 10, 12, 16, 17]
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const orderStructure = {
|
|
49
|
-
loading: false,
|
|
50
|
-
error: null,
|
|
51
|
-
orders: [],
|
|
52
|
-
pagination: {
|
|
53
|
-
currentPage: (paginationSettings.controlType === 'pages' && paginationSettings.initialPage && paginationSettings.initialPage >= 1)
|
|
54
|
-
? paginationSettings.initialPage - 1
|
|
55
|
-
: 1,
|
|
56
|
-
pageSize: paginationSettings.pageSize ?? 10,
|
|
57
|
-
total: null
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let [ordersGroup, setOrdersGroup] = useState({
|
|
62
|
-
active: {
|
|
63
|
-
...orderStructure,
|
|
64
|
-
defaultFilter: ordersGroupStatus.active,
|
|
65
|
-
currentFilter: ordersGroupStatus.active,
|
|
66
|
-
fetched: false
|
|
67
|
-
},
|
|
68
|
-
pending: {
|
|
69
|
-
...orderStructure,
|
|
70
|
-
defaultFilter: ordersGroupStatus.pending,
|
|
71
|
-
currentFilter: ordersGroupStatus.pending,
|
|
72
|
-
fetched: false
|
|
73
|
-
},
|
|
74
|
-
inProgress: {
|
|
75
|
-
...orderStructure,
|
|
76
|
-
defaultFilter: ordersGroupStatus.inProgress,
|
|
77
|
-
currentFilter: ordersGroupStatus.inProgress,
|
|
78
|
-
fetched: false
|
|
79
|
-
},
|
|
80
|
-
completed: {
|
|
81
|
-
...orderStructure,
|
|
82
|
-
defaultFilter: ordersGroupStatus.completed,
|
|
83
|
-
currentFilter: ordersGroupStatus.completed,
|
|
84
|
-
fetched: false
|
|
85
|
-
},
|
|
86
|
-
cancelled: {
|
|
87
|
-
...orderStructure,
|
|
88
|
-
defaultFilter: ordersGroupStatus.cancelled,
|
|
89
|
-
currentFilter: ordersGroupStatus.cancelled,
|
|
90
|
-
fetched: false
|
|
91
|
-
}
|
|
92
|
-
})
|
|
93
|
-
const [currentTabSelected, setCurrentTabSelected] = useState(combineTabs ? 'active' : 'pending')
|
|
94
|
-
const [logisticOrders, setlogisticOrders] = useState({ loading: false, error: null, orders: [] })
|
|
95
|
-
const [messages, setMessages] = useState({ loading: false, error: null, messages: [] })
|
|
96
|
-
const [currentFilters, setCurrentFilters] = useState(null)
|
|
97
|
-
const [filtered, setFiltered] = useState(null)
|
|
98
|
-
const [ordersDeleted, setOrdersDeleted] = useState({ loading: false, error: null, result: [] })
|
|
99
|
-
const [controlsState, setControlsState] = useState({ loading: true, error: null, paymethods: [] })
|
|
100
|
-
const [businessIDs, setBusinessIDs] = useState([])
|
|
101
|
-
const [orderLogisticAdded, setOrderLogisticAdded] = useState(null)
|
|
102
|
-
const [orderLogisticUpdated, setOrderLogisticUpdated] = useState(null)
|
|
103
|
-
const [recentlyReceivedMessage, setRecentlyReceivedMessage] = useState(null)
|
|
104
|
-
|
|
105
|
-
const [ordersFiltered, setOrdersFiltered] = useState({
|
|
106
|
-
orders: [],
|
|
107
|
-
loading: false,
|
|
108
|
-
error: null,
|
|
109
|
-
pagination: {
|
|
110
|
-
currentPage: (paginationSettings.controlType === 'pages' && paginationSettings.initialPage && paginationSettings.initialPage >= 1)
|
|
111
|
-
? paginationSettings.initialPage - 1
|
|
112
|
-
: 0,
|
|
113
|
-
pageSize: paginationSettings.pageSize ?? 10,
|
|
114
|
-
total: null
|
|
115
|
-
}
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
const requestsState = {}
|
|
119
|
-
|
|
120
|
-
const handleSelectCurrentTab = (value) => {
|
|
121
|
-
if (!isDriverApp) {
|
|
122
|
-
setOrdersGroup({
|
|
123
|
-
...ordersGroup,
|
|
124
|
-
[value]: {
|
|
125
|
-
...ordersGroup[value],
|
|
126
|
-
loading: true
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
if (value === 'logisticOrders') {
|
|
131
|
-
setlogisticOrders({
|
|
132
|
-
...logisticOrders,
|
|
133
|
-
loading: true
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
setCurrentTabSelected(value)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const getOrders = async ({
|
|
140
|
-
page,
|
|
141
|
-
pageSize = paginationSettings.pageSize,
|
|
142
|
-
orderStatus,
|
|
143
|
-
newFetch
|
|
144
|
-
}) => {
|
|
145
|
-
const options = {
|
|
146
|
-
query: {
|
|
147
|
-
orderBy,
|
|
148
|
-
page: page,
|
|
149
|
-
page_size: pageSize
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
options.query.where = []
|
|
153
|
-
if (orderStatus) {
|
|
154
|
-
if (!filtered?.state) {
|
|
155
|
-
options.query.where.push({ attribute: 'status', value: orderStatus })
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (ordersGroup[currentTabSelected]?.orders?.length > 0 && !newFetch) {
|
|
159
|
-
options.query = {
|
|
160
|
-
...options.query,
|
|
161
|
-
page: 1
|
|
162
|
-
}
|
|
163
|
-
if (!filtered?.id) {
|
|
164
|
-
options.query.where.push({
|
|
165
|
-
attribute: 'id',
|
|
166
|
-
value: {
|
|
167
|
-
condition: '!=',
|
|
168
|
-
value: ordersGroup[currentTabSelected]?.orders?.map((o) => o.id)
|
|
169
|
-
}
|
|
170
|
-
})
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (filtered?.id) {
|
|
176
|
-
options.query.where.push({
|
|
177
|
-
attribute: 'id',
|
|
178
|
-
value: {
|
|
179
|
-
condition: 'ilike',
|
|
180
|
-
value: isIos ? `%${filtered?.id}%` : encodeURI(`%${filtered?.id}%`)
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
if (filtered?.external_id) {
|
|
186
|
-
options.query.where.push({
|
|
187
|
-
attribute: 'external_id',
|
|
188
|
-
value: {
|
|
189
|
-
condition: 'ilike',
|
|
190
|
-
value: isIos ? `%${filtered?.external_id}%` : encodeURI(`%${filtered?.external_id}%`)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (filtered?.state) {
|
|
196
|
-
options.query.where.push({ attribute: 'status', value: filtered.state })
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
if (filtered?.city) {
|
|
200
|
-
options.query.where.push({
|
|
201
|
-
attribute: 'business',
|
|
202
|
-
conditions: [{
|
|
203
|
-
attribute: 'city_id',
|
|
204
|
-
value: filtered?.city
|
|
205
|
-
}]
|
|
206
|
-
})
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (filtered?.paymethod || customPaymethods) {
|
|
210
|
-
let paymethodResult = controlsState
|
|
211
|
-
if (!controlsState.paymethods.length) {
|
|
212
|
-
paymethodResult = await getControls()
|
|
213
|
-
}
|
|
214
|
-
options.query.where.push({
|
|
215
|
-
attribute: 'paymethod_id',
|
|
216
|
-
value: (!!filtered?.paymethod && filtered?.paymethod) || paymethodResult?.paymethods
|
|
217
|
-
})
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (filtered?.driver) {
|
|
221
|
-
options.query.where.push({ attribute: 'driver_id', value: filtered?.driver })
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (filtered?.driver_groups) {
|
|
225
|
-
options.query.where.push({ attribute: 'driver_id', value: filtered?.driver_groups?.drivers })
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (filtered?.customer?.email || filtered?.customer?.phone) {
|
|
229
|
-
const customerOptions = []
|
|
230
|
-
if (filtered?.customer?.email) {
|
|
231
|
-
customerOptions.push({
|
|
232
|
-
attribute: 'email',
|
|
233
|
-
value: {
|
|
234
|
-
condition: 'ilike',
|
|
235
|
-
value: isIos ? `%${filtered?.customer?.email}%` : encodeURI(`%${filtered?.customer?.email}%`)
|
|
236
|
-
}
|
|
237
|
-
})
|
|
238
|
-
}
|
|
239
|
-
if (filtered?.customer?.phone) {
|
|
240
|
-
customerOptions.push({
|
|
241
|
-
attribute: 'cellphone',
|
|
242
|
-
value: {
|
|
243
|
-
condition: 'ilike',
|
|
244
|
-
value: isIos ? `%${filtered?.customer?.phone}%` : encodeURI(`%${filtered?.customer?.phone}%`)
|
|
245
|
-
}
|
|
246
|
-
})
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
options.query.where.push({
|
|
250
|
-
attribute: 'customer',
|
|
251
|
-
conditions: customerOptions
|
|
252
|
-
})
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (filtered?.delivery_type || customOrderTypes) {
|
|
256
|
-
options.query.where.push({
|
|
257
|
-
attribute: 'delivery_type',
|
|
258
|
-
value: (!!filtered?.delivery_type && filtered?.delivery_type) || customOrderTypes
|
|
259
|
-
})
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (filtered?.date?.from) {
|
|
263
|
-
options.query.where.push({
|
|
264
|
-
attribute: 'delivery_datetime',
|
|
265
|
-
value: {
|
|
266
|
-
condition: '>=',
|
|
267
|
-
value: filtered?.date?.from
|
|
268
|
-
}
|
|
269
|
-
})
|
|
270
|
-
}
|
|
271
|
-
if (filtered?.date?.to) {
|
|
272
|
-
options.query.where.push({
|
|
273
|
-
attribute: 'delivery_datetime',
|
|
274
|
-
value: {
|
|
275
|
-
condition: '<=',
|
|
276
|
-
value: filtered?.date?.to
|
|
277
|
-
}
|
|
278
|
-
})
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
if (filtered?.timeStatus) {
|
|
282
|
-
options.query.where.push({
|
|
283
|
-
attribute: 'time_status',
|
|
284
|
-
value: filtered?.timeStatus
|
|
285
|
-
})
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (!isDriverApp) {
|
|
289
|
-
options.query.where.push({
|
|
290
|
-
attribute: 'products',
|
|
291
|
-
conditions: [{
|
|
292
|
-
attribute: 'type',
|
|
293
|
-
value: {
|
|
294
|
-
condition: '=',
|
|
295
|
-
value: 'item'
|
|
296
|
-
}
|
|
297
|
-
}]
|
|
298
|
-
})
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
const source = {}
|
|
302
|
-
requestsState.orders = source
|
|
303
|
-
options.cancelToken = source
|
|
304
|
-
|
|
305
|
-
const functionFetch = asDashboard
|
|
306
|
-
? ordering.setAccessToken(session.token).orders().asDashboard()
|
|
307
|
-
: ordering.setAccessToken(session.token).orders()
|
|
308
|
-
return await functionFetch.get(options)
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const getControls = async () => {
|
|
312
|
-
try {
|
|
313
|
-
setControlsState({ ...controlsState, loading: true })
|
|
314
|
-
const { content: { error, result } } = await ordering
|
|
315
|
-
.setAccessToken(session.token)
|
|
316
|
-
.controls()
|
|
317
|
-
.get()
|
|
318
|
-
const obj = {
|
|
319
|
-
...controlsState,
|
|
320
|
-
loading: false,
|
|
321
|
-
paymethods: result?.paymethods
|
|
322
|
-
?.filter((p) => customPaymethods?.includes(p.name))
|
|
323
|
-
?.map((pay) => pay.id),
|
|
324
|
-
error: error ? result : null
|
|
325
|
-
}
|
|
326
|
-
setControlsState(obj)
|
|
327
|
-
return obj
|
|
328
|
-
} catch (e) {
|
|
329
|
-
setControlsState({
|
|
330
|
-
...controlsState,
|
|
331
|
-
loading: false,
|
|
332
|
-
error: e?.message ? controlsState.error?.push(e?.message) : ['ERROR']
|
|
333
|
-
})
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const loadOrders = async ({ newFetch, newFetchCurrent } = {}, options = {}) => {
|
|
338
|
-
if (
|
|
339
|
-
!(newFetch || newFetchCurrent) &&
|
|
340
|
-
ordersGroup[currentTabSelected].pagination.currentPage === ordersGroup[currentTabSelected].pagination.totalPages &&
|
|
341
|
-
ordersGroup[currentTabSelected].pagination.total !== null
|
|
342
|
-
) {
|
|
343
|
-
return
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (newFetch) {
|
|
347
|
-
ordersStatusArray?.map(tab => {
|
|
348
|
-
ordersGroup = {
|
|
349
|
-
...ordersGroup,
|
|
350
|
-
[tab]: {
|
|
351
|
-
...orderStructure,
|
|
352
|
-
defaultFilter: ordersGroupStatus[tab],
|
|
353
|
-
currentFilter: ordersGroup[tab].currentFilter,
|
|
354
|
-
orders: ordersGroup[tab].orders
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
})
|
|
358
|
-
} else if (newFetchCurrent) {
|
|
359
|
-
ordersGroup = {
|
|
360
|
-
...ordersGroup,
|
|
361
|
-
[currentTabSelected]: {
|
|
362
|
-
...orderStructure,
|
|
363
|
-
defaultFilter: ordersGroupStatus[currentTabSelected],
|
|
364
|
-
currentFilter: ordersGroup[currentTabSelected]?.currentFilter
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const pageSize = paginationSettings.pageSize
|
|
370
|
-
|
|
371
|
-
try {
|
|
372
|
-
if (options?.allStatusses) {
|
|
373
|
-
setOrdersFiltered({
|
|
374
|
-
...ordersFiltered,
|
|
375
|
-
loading: true
|
|
376
|
-
})
|
|
377
|
-
} else {
|
|
378
|
-
setOrdersGroup({
|
|
379
|
-
...ordersGroup,
|
|
380
|
-
[currentTabSelected]: {
|
|
381
|
-
...ordersGroup[currentTabSelected],
|
|
382
|
-
loading: true
|
|
383
|
-
}
|
|
384
|
-
})
|
|
385
|
-
}
|
|
386
|
-
const { content: { error, result, pagination } } = await getOrders({
|
|
387
|
-
page: 1,
|
|
388
|
-
pageSize,
|
|
389
|
-
orderStatus: options?.allStatusses ? null : ordersGroup[currentTabSelected]?.currentFilter,
|
|
390
|
-
newFetch: (newFetch || newFetchCurrent)
|
|
391
|
-
})
|
|
392
|
-
const _ordersCleaned = error
|
|
393
|
-
? (newFetch || newFetchCurrent)
|
|
394
|
-
? []
|
|
395
|
-
: sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
396
|
-
: (newFetch || newFetchCurrent)
|
|
397
|
-
? sortOrders(result)
|
|
398
|
-
: sortOrders(ordersGroup[currentTabSelected]?.orders.concat(result))
|
|
399
|
-
|
|
400
|
-
if (options?.allStatusses) {
|
|
401
|
-
setOrdersFiltered({
|
|
402
|
-
error,
|
|
403
|
-
orders: formatOrdersGrouped(_ordersCleaned, { allStatusses: true }),
|
|
404
|
-
pagination: {
|
|
405
|
-
...ordersFiltered.pagination,
|
|
406
|
-
currentPage: pagination.current_page,
|
|
407
|
-
pageSize: pagination.page_size,
|
|
408
|
-
totalPages: pagination.total_pages,
|
|
409
|
-
total: pagination.total,
|
|
410
|
-
from: pagination.from,
|
|
411
|
-
to: pagination.to
|
|
412
|
-
},
|
|
413
|
-
loading: false
|
|
414
|
-
})
|
|
415
|
-
return
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
setOrdersGroup({
|
|
419
|
-
...ordersGroup,
|
|
420
|
-
[currentTabSelected]: {
|
|
421
|
-
...ordersGroup[currentTabSelected],
|
|
422
|
-
loading: false,
|
|
423
|
-
orders: _ordersCleaned,
|
|
424
|
-
error: error ? result : null,
|
|
425
|
-
fetched: true,
|
|
426
|
-
pagination: {
|
|
427
|
-
...ordersGroup[currentTabSelected].pagination,
|
|
428
|
-
currentPage: pagination.current_page,
|
|
429
|
-
pageSize: pagination.page_size,
|
|
430
|
-
totalPages: pagination.total_pages,
|
|
431
|
-
total: pagination.total,
|
|
432
|
-
from: pagination.from,
|
|
433
|
-
to: pagination.to
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
})
|
|
437
|
-
} catch (err) {
|
|
438
|
-
if (err.constructor.name !== 'Cancel') {
|
|
439
|
-
if (options?.allStatusses) {
|
|
440
|
-
setOrdersFiltered({
|
|
441
|
-
...ordersFiltered,
|
|
442
|
-
loading: false,
|
|
443
|
-
error: [err?.message ?? 'ERROR']
|
|
444
|
-
})
|
|
445
|
-
} else {
|
|
446
|
-
setOrdersGroup({
|
|
447
|
-
...ordersGroup,
|
|
448
|
-
[currentTabSelected]: {
|
|
449
|
-
...ordersGroup[currentTabSelected],
|
|
450
|
-
loading: false,
|
|
451
|
-
error: [err?.message ?? 'ERROR']
|
|
452
|
-
}
|
|
453
|
-
})
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const loadMoreOrders = async (options = {}) => {
|
|
460
|
-
if (!options?.allStatusses) {
|
|
461
|
-
setOrdersGroup({
|
|
462
|
-
...ordersGroup,
|
|
463
|
-
[currentTabSelected]: {
|
|
464
|
-
...ordersGroup[currentTabSelected],
|
|
465
|
-
loading: true
|
|
466
|
-
}
|
|
467
|
-
})
|
|
468
|
-
} else {
|
|
469
|
-
setOrdersFiltered({
|
|
470
|
-
...ordersFiltered,
|
|
471
|
-
loading: true
|
|
472
|
-
})
|
|
473
|
-
}
|
|
474
|
-
try {
|
|
475
|
-
const { content: { error, result, pagination } } = await getOrders({
|
|
476
|
-
page: options?.allStatusses ? ordersFiltered.pagination.currentPage + 1 : ordersGroup[currentTabSelected].pagination.currentPage + 1,
|
|
477
|
-
orderStatus: options?.allStatusses ? null : ordersGroup[currentTabSelected]?.currentFilter,
|
|
478
|
-
newFetch: true
|
|
479
|
-
})
|
|
480
|
-
|
|
481
|
-
if (options?.allStatusses) {
|
|
482
|
-
setOrdersFiltered({
|
|
483
|
-
error,
|
|
484
|
-
orders: formatOrdersGrouped([
|
|
485
|
-
...ordersFiltered?.orders,
|
|
486
|
-
...sortOrders(result)
|
|
487
|
-
], { allStatusses: true }),
|
|
488
|
-
pagination: {
|
|
489
|
-
...ordersFiltered.pagination,
|
|
490
|
-
currentPage: pagination.current_page,
|
|
491
|
-
pageSize: pagination.page_size,
|
|
492
|
-
totalPages: pagination.total_pages,
|
|
493
|
-
total: pagination.total,
|
|
494
|
-
from: pagination.from,
|
|
495
|
-
to: pagination.to
|
|
496
|
-
},
|
|
497
|
-
loading: false
|
|
498
|
-
})
|
|
499
|
-
return
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
const _ordersCleaned = error
|
|
503
|
-
? sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
504
|
-
: sortOrders(ordersGroup[currentTabSelected]?.orders?.concat(result))
|
|
505
|
-
setOrdersGroup({
|
|
506
|
-
...ordersGroup,
|
|
507
|
-
[currentTabSelected]: {
|
|
508
|
-
...ordersGroup[currentTabSelected],
|
|
509
|
-
loading: false,
|
|
510
|
-
orders: _ordersCleaned,
|
|
511
|
-
error: error ? result : null,
|
|
512
|
-
pagination: !error
|
|
513
|
-
? {
|
|
514
|
-
...ordersGroup[currentTabSelected].pagination,
|
|
515
|
-
currentPage: pagination.current_page,
|
|
516
|
-
pageSize: pagination.page_size,
|
|
517
|
-
totalPages: pagination.total_pages,
|
|
518
|
-
total: pagination.total,
|
|
519
|
-
from: pagination.from,
|
|
520
|
-
to: pagination.to
|
|
521
|
-
}
|
|
522
|
-
: ordersGroup[currentTabSelected].pagination
|
|
523
|
-
}
|
|
524
|
-
})
|
|
525
|
-
} catch (err) {
|
|
526
|
-
if (err.constructor.name !== 'Cancel') {
|
|
527
|
-
setOrdersGroup({
|
|
528
|
-
...ordersGroup,
|
|
529
|
-
[currentTabSelected]: {
|
|
530
|
-
...ordersGroup[currentTabSelected],
|
|
531
|
-
loading: false,
|
|
532
|
-
error: [err?.message ?? 'ERROR']
|
|
533
|
-
}
|
|
534
|
-
})
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
const loadMessages = async (orderId) => {
|
|
540
|
-
try {
|
|
541
|
-
setMessages({ ...messages, loading: true })
|
|
542
|
-
const url = `${ordering.root}/orders/${orderId}/messages?mode=dashboard`
|
|
543
|
-
|
|
544
|
-
const response = await fetch(url, {
|
|
545
|
-
method: 'GET',
|
|
546
|
-
headers: {
|
|
547
|
-
'Content-Type': 'application/json',
|
|
548
|
-
Authorization: `Bearer ${session.token}`,
|
|
549
|
-
'X-App-X': ordering.appId,
|
|
550
|
-
'X-Socket-Id-X': socket?.getId()
|
|
551
|
-
}
|
|
552
|
-
})
|
|
553
|
-
const { error, result } = await response.json()
|
|
554
|
-
if (!error) {
|
|
555
|
-
setMessages({
|
|
556
|
-
messages: result,
|
|
557
|
-
loading: false,
|
|
558
|
-
error: null
|
|
559
|
-
})
|
|
560
|
-
} else {
|
|
561
|
-
setMessages({
|
|
562
|
-
...messages,
|
|
563
|
-
loading: false,
|
|
564
|
-
error: result
|
|
565
|
-
})
|
|
566
|
-
}
|
|
567
|
-
} catch (error) {
|
|
568
|
-
setMessages({ ...messages, loading: false, error: [error.Messages] })
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
const deleteOrders = async (orderIds) => {
|
|
573
|
-
try {
|
|
574
|
-
setOrdersDeleted({ ...ordersDeleted, loading: true })
|
|
575
|
-
const errorState = []
|
|
576
|
-
|
|
577
|
-
if (orderIds.length === 1) {
|
|
578
|
-
const { content: { error } } = await ordering.setAccessToken(session.token).orders(orderIds[0]).delete()
|
|
579
|
-
errorState.push({ error, id: orderIds[0] })
|
|
580
|
-
} else if (orderIds.length > 1) {
|
|
581
|
-
for (const id of orderIds) {
|
|
582
|
-
const { content: { error: multiError } } = await ordering.setAccessToken(session.token).orders(id).delete()
|
|
583
|
-
errorState.push({ error: multiError, id })
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
const isError = errorState.some((e) => e.error)
|
|
588
|
-
const idsDeleted = errorState?.map((obj) => !obj.error && obj.id)
|
|
589
|
-
|
|
590
|
-
onOrdersDeleted && onOrdersDeleted({ isError, list: idsDeleted })
|
|
591
|
-
setOrdersDeleted({ ...ordersDeleted, loading: false })
|
|
592
|
-
setOrdersGroup({
|
|
593
|
-
...ordersGroup,
|
|
594
|
-
[currentTabSelected]: {
|
|
595
|
-
...ordersGroup[currentTabSelected],
|
|
596
|
-
orders: idsDeleted.length
|
|
597
|
-
? sortOrders(ordersGroup[currentTabSelected]?.orders?.filter((order) => !idsDeleted.includes(order.id)))
|
|
598
|
-
: sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
599
|
-
}
|
|
600
|
-
})
|
|
601
|
-
} catch (err) {
|
|
602
|
-
if (err.constructor.name !== 'Cancel') {
|
|
603
|
-
setOrdersGroup({
|
|
604
|
-
...ordersGroup,
|
|
605
|
-
[currentTabSelected]: {
|
|
606
|
-
...ordersGroup[currentTabSelected],
|
|
607
|
-
loading: false,
|
|
608
|
-
error: [err?.message ?? 'ERROR']
|
|
609
|
-
}
|
|
610
|
-
})
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
const loadLogisticOrders = async (isAlreadyFetched) => {
|
|
616
|
-
try {
|
|
617
|
-
setlogisticOrders({ ...logisticOrders, loading: true })
|
|
618
|
-
const url = `${ordering.root}/drivers/${session.user?.id}/assign_requests`
|
|
619
|
-
const response = await fetch(url, {
|
|
620
|
-
method: 'GET',
|
|
621
|
-
headers: {
|
|
622
|
-
'Content-Type': 'application/json',
|
|
623
|
-
Authorization: `Bearer ${session.token}`,
|
|
624
|
-
'X-App-X': ordering.appId,
|
|
625
|
-
'X-Socket-Id-X': socket?.getId()
|
|
626
|
-
}
|
|
627
|
-
})
|
|
628
|
-
const { result, error } = await response.json()
|
|
629
|
-
if (!error) {
|
|
630
|
-
setlogisticOrders({ ...logisticOrders, loading: false, orders: result.filter(order => !(order?.order_group && order?.order_group?.orders?.length === 0)) })
|
|
631
|
-
return
|
|
632
|
-
}
|
|
633
|
-
setlogisticOrders({ loading: false, orders: [], error: result })
|
|
634
|
-
} catch (err) {
|
|
635
|
-
setlogisticOrders({ loading: false, orders: [], error: err.message })
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
const sortOrders = (orders, sortBy = 'desc') => {
|
|
640
|
-
const ordersSorted = orders?.sort((a, b) => {
|
|
641
|
-
if (sortBy === 'desc') {
|
|
642
|
-
return b.id - a.id
|
|
643
|
-
}
|
|
644
|
-
return a.id - b.id
|
|
645
|
-
})
|
|
646
|
-
|
|
647
|
-
return ordersSorted
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
const filterByIdUnique = (array, currentTabSelected) => {
|
|
651
|
-
if (!array) return []
|
|
652
|
-
|
|
653
|
-
const tempObj = {}
|
|
654
|
-
const status = ordersGroupStatus[currentTabSelected] ?? []
|
|
655
|
-
|
|
656
|
-
return array.map((element) => {
|
|
657
|
-
if (Array.isArray(element)) {
|
|
658
|
-
const _array = element[0][1].map((item) => {
|
|
659
|
-
if (!tempObj[item.id] && status.includes(item.status)) {
|
|
660
|
-
tempObj[item.id] = true
|
|
661
|
-
return item
|
|
662
|
-
}
|
|
663
|
-
return null
|
|
664
|
-
}).filter((item) => item !== null)
|
|
665
|
-
return _array.length ? [[_array[0]?.cart_group_id.toString(), _array]] : null
|
|
666
|
-
} else {
|
|
667
|
-
if (!tempObj[element.id] && status.includes(element.status)) {
|
|
668
|
-
tempObj[element.id] = true
|
|
669
|
-
return element
|
|
670
|
-
}
|
|
671
|
-
return null
|
|
672
|
-
}
|
|
673
|
-
}).filter((item) => Array.isArray(item) ? item.length : item)
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
const formatOrdersGrouped = (orders, options = {}) => {
|
|
677
|
-
let totalOrders = orders
|
|
678
|
-
const ordersGroupids = []
|
|
679
|
-
|
|
680
|
-
totalOrders = totalOrders
|
|
681
|
-
?.map(item => {
|
|
682
|
-
if (!item?.cart_group_id) return item
|
|
683
|
-
|
|
684
|
-
const groupIds = totalOrders.filter(o => o.cart_group_id === item?.cart_group_id)
|
|
685
|
-
const _item = !ordersGroupids.includes(item?.cart_group_id)
|
|
686
|
-
? Object.entries({ [item?.cart_group_id]: groupIds }) : ''
|
|
687
|
-
|
|
688
|
-
if (_item) ordersGroupids.push(item?.cart_group_id)
|
|
689
|
-
return _item
|
|
690
|
-
}).filter(item => item)
|
|
691
|
-
return options?.allStatusses ? totalOrders : filterByIdUnique(totalOrders, currentTabSelected)
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
const getStatusById = (id) => {
|
|
695
|
-
if (!id && id !== 0) return
|
|
696
|
-
const active = orderGroupStatusCustom?.active ?? [0, 3, 4, 7, 8, 9, 13, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
|
697
|
-
const pending = orderGroupStatusCustom?.pending ?? [0, 13]
|
|
698
|
-
const inProgress = orderGroupStatusCustom?.inProgress ?? [3, 4, 7, 8, 9, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
|
699
|
-
const completed = orderGroupStatusCustom?.completed ?? [1, 11, 15]
|
|
700
|
-
// const cancelled = orderGroupStatusCustom?.cancelled ?? [2, 5, 6, 10, 12, 16, 17]
|
|
701
|
-
|
|
702
|
-
const status = pending.includes(id)
|
|
703
|
-
? 'pending'
|
|
704
|
-
: inProgress.includes(id)
|
|
705
|
-
? 'inProgress'
|
|
706
|
-
: completed.includes(id)
|
|
707
|
-
? 'completed'
|
|
708
|
-
: 'cancelled'
|
|
709
|
-
|
|
710
|
-
const combinedStatus = active.includes(id)
|
|
711
|
-
? 'active'
|
|
712
|
-
: completed.includes(id)
|
|
713
|
-
? 'completed'
|
|
714
|
-
: 'cancelled'
|
|
715
|
-
|
|
716
|
-
return combineTabs ? combinedStatus : status
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
const actionOrderToTab = (orderAux, status, type) => {
|
|
720
|
-
setOrdersGroup(prevState => {
|
|
721
|
-
if (!prevState[status]?.orders) return
|
|
722
|
-
const orderList = prevState[status]?.orders
|
|
723
|
-
const order = { ...orderAux, showNotification: false }
|
|
724
|
-
let updatedOrders
|
|
725
|
-
|
|
726
|
-
switch (type) {
|
|
727
|
-
case 'update':
|
|
728
|
-
updatedOrders = orderList.map(o => o.id === order.id ? { ...order, action: `${type}${order?.status}` } : o)
|
|
729
|
-
break
|
|
730
|
-
case 'add':
|
|
731
|
-
updatedOrders = [{ ...order, action: `${type}${order?.status}` }, ...orderList]
|
|
732
|
-
break
|
|
733
|
-
case 'remove':
|
|
734
|
-
updatedOrders = orderList.filter(o => o.id !== order.id)
|
|
735
|
-
break
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
const updatedPagination = {
|
|
739
|
-
...prevState[status].pagination,
|
|
740
|
-
total: prevState[status].pagination.total + (type === 'add' ? 1 : type === 'remove' ? -1 : 0)
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
return {
|
|
744
|
-
...prevState,
|
|
745
|
-
[status]: {
|
|
746
|
-
...prevState[status],
|
|
747
|
-
orders: filterByIdUnique(sortOrders(updatedOrders), status),
|
|
748
|
-
pagination: updatedPagination
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
})
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
const handleClickOrder = (orderAux) => {
|
|
755
|
-
const order = {
|
|
756
|
-
...orderAux,
|
|
757
|
-
showNotification: false
|
|
758
|
-
}
|
|
759
|
-
const ordersGroups = order?.order_group?.orders
|
|
760
|
-
if (!ordersGroups) {
|
|
761
|
-
const status = getStatusById(order?.status)
|
|
762
|
-
const orderList = ordersGroup[status]?.orders
|
|
763
|
-
const indexToUpdate = orderList?.findIndex((o) => o?.id === order?.id)
|
|
764
|
-
orderList[indexToUpdate] = order
|
|
765
|
-
setOrdersGroup({
|
|
766
|
-
...ordersGroup,
|
|
767
|
-
[status]: {
|
|
768
|
-
...ordersGroup[status],
|
|
769
|
-
orders: sortOrders(orderList)
|
|
770
|
-
}
|
|
771
|
-
})
|
|
772
|
-
} else {
|
|
773
|
-
const status = getStatusById(order?.order_group?.orders?.[0]?.status)
|
|
774
|
-
let orderList
|
|
775
|
-
ordersGroups?.map(order => {
|
|
776
|
-
orderList = ordersGroup[status]?.orders
|
|
777
|
-
const indexToUpdate = orderList?.findIndex((o) => o?.id === order?.id)
|
|
778
|
-
orderList[indexToUpdate] = order
|
|
779
|
-
})
|
|
780
|
-
setOrdersGroup({
|
|
781
|
-
...ordersGroup,
|
|
782
|
-
[status]: {
|
|
783
|
-
...ordersGroup[status],
|
|
784
|
-
orders: sortOrders(orderList)
|
|
785
|
-
}
|
|
786
|
-
})
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
const handleClickLogisticOrder = async (status, orderId) => {
|
|
791
|
-
try {
|
|
792
|
-
const response = await fetch(`${ordering.root}/drivers/${session.user?.id}/assign_requests/${orderId}`, {
|
|
793
|
-
method: 'PUT',
|
|
794
|
-
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session.token}` },
|
|
795
|
-
body: JSON.stringify({
|
|
796
|
-
status,
|
|
797
|
-
user_id: session.user?.id
|
|
798
|
-
})
|
|
799
|
-
})
|
|
800
|
-
const { result, error } = await response.json()
|
|
801
|
-
if (!error) {
|
|
802
|
-
const order = logisticOrders?.orders?.find(order => order?.id === orderId)
|
|
803
|
-
const newOrders = sortOrders(logisticOrders?.orders?.filter(_order => _order?.id !== orderId))
|
|
804
|
-
setlogisticOrders({ ...logisticOrders, orders: newOrders })
|
|
805
|
-
if (status === 1) {
|
|
806
|
-
handleClickOrder(order?.order ?? order)
|
|
807
|
-
showToast(
|
|
808
|
-
ToastType.Success,
|
|
809
|
-
t('SPECIFIC_ORDER_ACCEPTED', 'Your accepted the order number _NUMBER_').replace('_NUMBER_', order?.order?.id ?? order?.id)
|
|
810
|
-
)
|
|
811
|
-
} else {
|
|
812
|
-
showToast(
|
|
813
|
-
ToastType.Info,
|
|
814
|
-
t('SPECIFIC_ORDER_REJECTED', 'Your rejected the order number _NUMBER_').replace('_NUMBER_', order?.order?.id ?? order?.id)
|
|
815
|
-
)
|
|
816
|
-
}
|
|
817
|
-
return
|
|
818
|
-
}
|
|
819
|
-
showToast(ToastType.Error, result)
|
|
820
|
-
} catch (err) {
|
|
821
|
-
setlogisticOrders({ ...logisticOrders, error: err.message })
|
|
822
|
-
showToast(ToastType.Error, err.message)
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
const handleChangeOrderStatus = async (status, orderIds, body = {}) => {
|
|
827
|
-
try {
|
|
828
|
-
delete body.id
|
|
829
|
-
const bodyToSend = Object.keys(body || {}).length > 0 ? body : { status }
|
|
830
|
-
const setOrderStatus = async (id) => {
|
|
831
|
-
try {
|
|
832
|
-
const { content: { result, error } } = await ordering.setAccessToken(session?.token).orders(id).save({ ...bodyToSend, id })
|
|
833
|
-
return error ? null : result
|
|
834
|
-
} catch {
|
|
835
|
-
return null
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
const result = await Promise.all(orderIds?.map(id => setOrderStatus(id)))
|
|
840
|
-
return result
|
|
841
|
-
} catch (err) {
|
|
842
|
-
return err?.message ?? err
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
const handleSendCustomerReview = async ({ customerId, orderIds, body, onClose }) => {
|
|
847
|
-
try {
|
|
848
|
-
const setCustomerReview = async (body) => {
|
|
849
|
-
try {
|
|
850
|
-
const response = await fetch(`${ordering.root}/users/${customerId}/user_reviews`, {
|
|
851
|
-
method: 'POST',
|
|
852
|
-
headers: {
|
|
853
|
-
Authorization: `Bearer ${session.token}`,
|
|
854
|
-
'Content-Type': 'application/json',
|
|
855
|
-
'X-App-X': ordering.appId,
|
|
856
|
-
'X-Socket-Id-X': socket?.getId()
|
|
857
|
-
},
|
|
858
|
-
body: JSON.stringify(body)
|
|
859
|
-
})
|
|
860
|
-
const { result, error } = await response.json()
|
|
861
|
-
return error ? null : result
|
|
862
|
-
} catch (err) {
|
|
863
|
-
return null
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
const result = await Promise.all(orderIds?.map(id => setCustomerReview({ ...body, order_id: id, user_id: customerId })))
|
|
868
|
-
if (result?.length) {
|
|
869
|
-
const orders = ordersGroup[currentTabSelected].orders
|
|
870
|
-
result?.map(order => {
|
|
871
|
-
let orderFound = orders.find(o => o.id === order.order_id)
|
|
872
|
-
const idxOrderFound = orders.findIndex(o => o.id === order.order_id)
|
|
873
|
-
|
|
874
|
-
if (orderFound) {
|
|
875
|
-
orderFound = { ...orderFound, user_review: order }
|
|
876
|
-
orders[idxOrderFound] = orderFound
|
|
877
|
-
setOrdersGroup({ ...ordersGroup, orders })
|
|
878
|
-
}
|
|
879
|
-
})
|
|
880
|
-
showToast(
|
|
881
|
-
ToastType.Success,
|
|
882
|
-
t('ORDERS_SUCCESSFULLY_REVIEWED', 'Orders successfully reviewed')
|
|
883
|
-
)
|
|
884
|
-
}
|
|
885
|
-
onClose && onClose()
|
|
886
|
-
return result
|
|
887
|
-
} catch (err) {
|
|
888
|
-
return err?.message ?? err
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
const getBusinessesIDs = async () => {
|
|
893
|
-
const propsToFetch = ['id', 'name']
|
|
894
|
-
try {
|
|
895
|
-
const { content: { error, result } } = await ordering.businesses().asDashboard().select(propsToFetch).get()
|
|
896
|
-
if (!error) {
|
|
897
|
-
const _businessIDs = result.length > 0 && result.map(({ id }) => id)
|
|
898
|
-
setBusinessIDs(_businessIDs)
|
|
899
|
-
}
|
|
900
|
-
} catch (err) {
|
|
901
|
-
if (err.constructor.name !== 'Cancel') {
|
|
902
|
-
setOrdersGroup({
|
|
903
|
-
...ordersGroup,
|
|
904
|
-
[currentTabSelected]: {
|
|
905
|
-
...ordersGroup[currentTabSelected],
|
|
906
|
-
loading: false,
|
|
907
|
-
error: [err?.message ?? 'ERROR']
|
|
908
|
-
}
|
|
909
|
-
})
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
useEffect(() => {
|
|
915
|
-
if (session?.user?.level !== 2) return
|
|
916
|
-
getBusinessesIDs()
|
|
917
|
-
}, [])
|
|
918
|
-
|
|
919
|
-
useEffect(() => {
|
|
920
|
-
setCurrentFilters(ordersGroup[currentTabSelected]?.currentFilter)
|
|
921
|
-
if (currentTabSelected === 'logisticOrders') {
|
|
922
|
-
loadLogisticOrders(!!logisticOrders?.orders)
|
|
923
|
-
} else if (!ordersGroup[currentTabSelected]?.fetched && props.isNetConnected) {
|
|
924
|
-
loadOrders({ newFetchCurrent: true })
|
|
925
|
-
}
|
|
926
|
-
}, [currentTabSelected, props.isNetConnected])
|
|
927
|
-
|
|
928
|
-
useEffect(() => {
|
|
929
|
-
if (currentFilters && !isDriverApp) {
|
|
930
|
-
loadOrders({ newFetchCurrent: true })
|
|
931
|
-
}
|
|
932
|
-
}, [currentFilters])
|
|
933
|
-
|
|
934
|
-
useEffect(() => {
|
|
935
|
-
if (!filtered) return
|
|
936
|
-
loadOrders({ newFetch: true }, { allStatusses: true })
|
|
937
|
-
}, [filtered])
|
|
938
|
-
|
|
939
|
-
const handleActionEvent = (event, value) => {
|
|
940
|
-
const evts = {
|
|
941
|
-
order_added: 'order_added_notification',
|
|
942
|
-
update_order: 'order_updated_notification',
|
|
943
|
-
messages: 'message_added_notification',
|
|
944
|
-
request_register: 'request_register_notification',
|
|
945
|
-
request_update: 'request_update_notification'
|
|
946
|
-
}
|
|
947
|
-
events.emit(evts[event], value)
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
useEffect(() => {
|
|
951
|
-
if (!socket?.socket) return
|
|
952
|
-
const handleUpdateOrder = (order) => {
|
|
953
|
-
const isGiftCard = order?.products?.some(product => product?.type === 'gift_card')
|
|
954
|
-
if (isGiftCard && !isDriverApp) return
|
|
955
|
-
if (session?.user?.level === 2 && businessIDs.length > 0 && !businessIDs.includes(order.business_id)) return
|
|
956
|
-
events.emit('order_updated', order)
|
|
957
|
-
let orderFound = null
|
|
958
|
-
for (let i = 0; i < ordersStatusArray.length; i++) {
|
|
959
|
-
const status = ordersStatusArray[i]
|
|
960
|
-
if (order?.products) {
|
|
961
|
-
orderFound = ordersGroup[status]?.orders?.find((_order) => _order.id === order.id)
|
|
962
|
-
}
|
|
963
|
-
if (orderFound) break
|
|
964
|
-
}
|
|
965
|
-
if (notificationStatusses.includes(order?.status)) {
|
|
966
|
-
showToast(
|
|
967
|
-
ToastType.Info,
|
|
968
|
-
t('SPECIFIC_ORDER_UPDATED', 'Your order number _NUMBER_ has updated').replace('_NUMBER_', order.id),
|
|
969
|
-
1000
|
|
970
|
-
)
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
if (!orderFound) {
|
|
974
|
-
if (
|
|
975
|
-
!order?.products ||
|
|
976
|
-
!order?.summary ||
|
|
977
|
-
typeof order?.status !== 'number' ||
|
|
978
|
-
!order?.customer ||
|
|
979
|
-
!order?.business ||
|
|
980
|
-
((!order?.paymethod && !order?.payment_events?.some(e => e.event === 'payment')) && order?.total !== 0)
|
|
981
|
-
) {
|
|
982
|
-
return
|
|
983
|
-
}
|
|
984
|
-
delete order.total
|
|
985
|
-
delete order.subtotal
|
|
986
|
-
const currentFilter = ordersGroup[getStatusById(order?.status) ?? '']?.currentFilter
|
|
987
|
-
!currentFilter.includes(order.status)
|
|
988
|
-
? actionOrderToTab(order, getStatusById(order?.status), 'remove')
|
|
989
|
-
: actionOrderToTab(order, getStatusById(order?.status), 'add')
|
|
990
|
-
|
|
991
|
-
return
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
if (
|
|
995
|
-
orderFound.id === order.id &&
|
|
996
|
-
orderFound?.driver?.id !== order?.driver?.id &&
|
|
997
|
-
session?.user?.level === 4
|
|
998
|
-
) {
|
|
999
|
-
actionOrderToTab(orderFound, getStatusById(orderFound.status), 'remove')
|
|
1000
|
-
}
|
|
1001
|
-
|
|
1002
|
-
if (orderFound.id === order.id) {
|
|
1003
|
-
delete order.total
|
|
1004
|
-
delete order.subtotal
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
if (!order?.status && order?.status !== 0) {
|
|
1008
|
-
Object.assign(orderFound, order)
|
|
1009
|
-
} else {
|
|
1010
|
-
const newOrderStatus = getStatusById(order?.status) ?? ''
|
|
1011
|
-
const currentOrderStatus = getStatusById(orderFound?.status) ?? ''
|
|
1012
|
-
|
|
1013
|
-
const currentFilter = ordersGroup[newOrderStatus]?.currentFilter
|
|
1014
|
-
Object.assign(orderFound, order)
|
|
1015
|
-
|
|
1016
|
-
if (newOrderStatus !== currentOrderStatus) {
|
|
1017
|
-
actionOrderToTab(orderFound, currentOrderStatus, 'remove')
|
|
1018
|
-
|
|
1019
|
-
const total = ordersGroup[newOrderStatus].pagination.total ?? null
|
|
1020
|
-
|
|
1021
|
-
if (
|
|
1022
|
-
currentFilter.includes(orderFound.status) &&
|
|
1023
|
-
total !== null
|
|
1024
|
-
) {
|
|
1025
|
-
actionOrderToTab(orderFound, newOrderStatus, 'add')
|
|
1026
|
-
}
|
|
1027
|
-
} else {
|
|
1028
|
-
!currentFilter.includes(orderFound.status) || (orderFound?.driver === null && isDriverApp)
|
|
1029
|
-
? actionOrderToTab(orderFound, newOrderStatus, 'remove')
|
|
1030
|
-
: actionOrderToTab(orderFound, newOrderStatus, 'update')
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
|
|
1035
|
-
const handleAddNewOrder = (order) => {
|
|
1036
|
-
const isGiftCard = order?.products?.some(product => product?.type === 'gift_card')
|
|
1037
|
-
if (isGiftCard && !isDriverApp) return
|
|
1038
|
-
events.emit('order_added', order)
|
|
1039
|
-
handleActionEvent('order_added', order)
|
|
1040
|
-
if (notificationStatusses.includes(order?.status)) {
|
|
1041
|
-
showToast(
|
|
1042
|
-
ToastType.Info,
|
|
1043
|
-
t('SPECIFIC_ORDER_ORDERED', 'Order _NUMBER_ has been ordered').replace('_NUMBER_', order.id),
|
|
1044
|
-
1000
|
|
1045
|
-
)
|
|
1046
|
-
}
|
|
1047
|
-
const status = getStatusById(order?.status) ?? ''
|
|
1048
|
-
actionOrderToTab(order, status, 'add')
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
const handleReceiveMessage = (message) => {
|
|
1052
|
-
if (message?.id !== recentlyReceivedMessage?.id) {
|
|
1053
|
-
handleActionEvent('messages', message)
|
|
1054
|
-
setRecentlyReceivedMessage(message)
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
socket.on('orders_register', handleAddNewOrder)
|
|
1058
|
-
socket.on('order_assigned', handleAddNewOrder)
|
|
1059
|
-
socket.on('update_order', handleUpdateOrder)
|
|
1060
|
-
socket.on('message', handleReceiveMessage)
|
|
1061
|
-
|
|
1062
|
-
return () => {
|
|
1063
|
-
socket.off('orders_register', handleAddNewOrder)
|
|
1064
|
-
socket.off('order_assigned', handleAddNewOrder)
|
|
1065
|
-
socket.off('update_order', handleUpdateOrder)
|
|
1066
|
-
socket.off('message', handleReceiveMessage)
|
|
1067
|
-
}
|
|
1068
|
-
}, [JSON.stringify(ordersGroup), socket?.socket, session])
|
|
1069
|
-
|
|
1070
|
-
const handleAddAssignRequest = useCallback(
|
|
1071
|
-
(order) => {
|
|
1072
|
-
setOrderLogisticAdded(order)
|
|
1073
|
-
const isSameEvent = orderLogisticAdded?.id === order?.id && orderLogisticAdded.status === order?.status
|
|
1074
|
-
if (!order?.locked && !isSameEvent) {
|
|
1075
|
-
handleActionEvent('request_register', order)
|
|
1076
|
-
}
|
|
1077
|
-
setlogisticOrders((prevState) => ({
|
|
1078
|
-
...prevState,
|
|
1079
|
-
orders: sortOrders([...prevState?.orders, order].filter((order, index, hash) => { // remove possibles duplicates
|
|
1080
|
-
const val = JSON.stringify(order)
|
|
1081
|
-
return index === hash.findIndex(_order => {
|
|
1082
|
-
return JSON.stringify(_order) === val
|
|
1083
|
-
})
|
|
1084
|
-
}))
|
|
1085
|
-
}))
|
|
1086
|
-
showToast(
|
|
1087
|
-
ToastType.Info,
|
|
1088
|
-
t('SPECIFIC_LOGISTIC_ORDER_ORDERED', 'Logisitc order _NUMBER_ has been ordered').replace('_NUMBER_', order?.order?.id ?? order.id),
|
|
1089
|
-
1000
|
|
1090
|
-
)
|
|
1091
|
-
},
|
|
1092
|
-
[logisticOrders]
|
|
1093
|
-
)
|
|
1094
|
-
|
|
1095
|
-
const handleDeleteAssignRequest = useCallback(
|
|
1096
|
-
(order) => {
|
|
1097
|
-
setlogisticOrders(prevState => ({
|
|
1098
|
-
...prevState,
|
|
1099
|
-
orders: prevState?.orders?.some(_order => _order?.id === order?.id)
|
|
1100
|
-
? sortOrders([...prevState?.orders?.filter(_order => _order?.id !== order?.id), { ...prevState?.orders?.find(_order => _order?.id === order?.id), expired: true }])
|
|
1101
|
-
: sortOrders(prevState?.orders)
|
|
1102
|
-
}))
|
|
1103
|
-
},
|
|
1104
|
-
[logisticOrders]
|
|
1105
|
-
)
|
|
1106
|
-
|
|
1107
|
-
const handleUpdateAssignRequest = useCallback(
|
|
1108
|
-
(order) => {
|
|
1109
|
-
setOrderLogisticUpdated(order)
|
|
1110
|
-
const isSameEvent = orderLogisticUpdated?.id === order?.id && orderLogisticUpdated.status === order?.status
|
|
1111
|
-
if (!order?.locked && !isSameEvent) {
|
|
1112
|
-
handleActionEvent('request_update', order)
|
|
1113
|
-
}
|
|
1114
|
-
setlogisticOrders(prevState => ({
|
|
1115
|
-
...prevState,
|
|
1116
|
-
orders: prevState?.orders?.some(_order => _order?.id === order?.id)
|
|
1117
|
-
? sortOrders([...prevState?.orders?.filter(_order => _order?.id !== order?.id), { ...prevState?.orders?.find(_order => _order?.id === order?.id), ...order }])
|
|
1118
|
-
: sortOrders(prevState?.orders)
|
|
1119
|
-
}))
|
|
1120
|
-
showToast(
|
|
1121
|
-
ToastType.Info,
|
|
1122
|
-
t('SPECIFIC_LOGISTIC_ORDER_UPDATED', 'Your logisitc order number _NUMBER_ has updated').replace('_NUMBER_', order?.order?.id ?? order.id),
|
|
1123
|
-
1000
|
|
1124
|
-
)
|
|
1125
|
-
},
|
|
1126
|
-
[logisticOrders]
|
|
1127
|
-
)
|
|
1128
|
-
|
|
1129
|
-
useEffect(() => {
|
|
1130
|
-
if (isLogisticActivated) {
|
|
1131
|
-
socket.on('request_register', handleAddAssignRequest)
|
|
1132
|
-
socket.on('request_update', handleUpdateAssignRequest)
|
|
1133
|
-
socket.on('request_cancel', handleDeleteAssignRequest)
|
|
1134
|
-
}
|
|
1135
|
-
return () => {
|
|
1136
|
-
socket.off('request_register')
|
|
1137
|
-
socket.off('request_update')
|
|
1138
|
-
socket.off('request_cancel')
|
|
1139
|
-
}
|
|
1140
|
-
}, [socket, session, isLogisticActivated])
|
|
1141
|
-
|
|
1142
|
-
useEffect(() => {
|
|
1143
|
-
if (!session.user) return
|
|
1144
|
-
|
|
1145
|
-
const userId = session.user.id
|
|
1146
|
-
const userLevel = session.user.level
|
|
1147
|
-
|
|
1148
|
-
const ordersRoom = userLevel === 0
|
|
1149
|
-
? 'orders'
|
|
1150
|
-
: `orders_${userId}`
|
|
1151
|
-
|
|
1152
|
-
const requestsRoom = `requests_${userId}`
|
|
1153
|
-
const groupsRoom = `ordergroups_${userId}`
|
|
1154
|
-
const messagesOrdersRoom = userLevel === 0 ? 'messages_orders' : `messages_orders_${userId}`
|
|
1155
|
-
const joinRooms = () => {
|
|
1156
|
-
socket.join(ordersRoom)
|
|
1157
|
-
socket.join(requestsRoom)
|
|
1158
|
-
socket.join(groupsRoom)
|
|
1159
|
-
socket.join(messagesOrdersRoom)
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
const leaveRooms = () => {
|
|
1163
|
-
socket.leave(ordersRoom)
|
|
1164
|
-
socket.leave(requestsRoom)
|
|
1165
|
-
socket.leave(groupsRoom)
|
|
1166
|
-
socket.leave(messagesOrdersRoom)
|
|
1167
|
-
}
|
|
1168
|
-
|
|
1169
|
-
socket.on('disconnect', joinRooms)
|
|
1170
|
-
|
|
1171
|
-
joinRooms()
|
|
1172
|
-
|
|
1173
|
-
return () => {
|
|
1174
|
-
leaveRooms()
|
|
1175
|
-
socket.off('disconnect', joinRooms)
|
|
1176
|
-
}
|
|
1177
|
-
}, [socket, session])
|
|
1178
|
-
|
|
1179
|
-
useEffect(() => {
|
|
1180
|
-
const request = requestsState?.orders
|
|
1181
|
-
return () => {
|
|
1182
|
-
request && request.cancel && request.cancel()
|
|
1183
|
-
}
|
|
1184
|
-
}, [requestsState?.orders])
|
|
1185
|
-
|
|
1186
|
-
useEffect(() => {
|
|
1187
|
-
const handleCustomerReviewed = (review) => {
|
|
1188
|
-
let orderFound = null
|
|
1189
|
-
for (let i = 0; i < ordersStatusArray.length; i++) {
|
|
1190
|
-
const status = ordersStatusArray[i]
|
|
1191
|
-
orderFound = ordersGroup[status]?.orders?.find((_order) => _order.id === review.order_id)
|
|
1192
|
-
if (orderFound) break
|
|
1193
|
-
}
|
|
1194
|
-
if (orderFound) {
|
|
1195
|
-
const newOrderStatus = getStatusById(orderFound?.status) ?? ''
|
|
1196
|
-
orderFound.user_review = review
|
|
1197
|
-
actionOrderToTab(orderFound, newOrderStatus, 'update')
|
|
1198
|
-
}
|
|
1199
|
-
}
|
|
1200
|
-
events.on('customer_reviewed', handleCustomerReviewed)
|
|
1201
|
-
return () => {
|
|
1202
|
-
events.off('customer_reviewed', handleCustomerReviewed)
|
|
1203
|
-
}
|
|
1204
|
-
}, [ordersGroup])
|
|
1205
|
-
|
|
1206
|
-
useEffect(() => {
|
|
1207
|
-
setCurrentTabSelected(combineTabs ? 'active' : 'pending')
|
|
1208
|
-
}, [combineTabs])
|
|
1209
|
-
|
|
1210
|
-
return (
|
|
1211
|
-
<>
|
|
1212
|
-
{UIComponent && (
|
|
1213
|
-
<UIComponent
|
|
1214
|
-
{...props}
|
|
1215
|
-
currentFilters={currentFilters}
|
|
1216
|
-
setCurrentFilters={setCurrentFilters}
|
|
1217
|
-
currentTabSelected={currentTabSelected}
|
|
1218
|
-
setCurrentTabSelected={handleSelectCurrentTab}
|
|
1219
|
-
ordersGroup={ordersGroup}
|
|
1220
|
-
setOrdersGroup={setOrdersGroup}
|
|
1221
|
-
logisticOrders={logisticOrders}
|
|
1222
|
-
messages={messages}
|
|
1223
|
-
setCombineTabsState={setCombineTabsState}
|
|
1224
|
-
ordersDeleted={ordersDeleted}
|
|
1225
|
-
setOrdersDeleted={setOrdersDeleted}
|
|
1226
|
-
setMessages={setMessages}
|
|
1227
|
-
loadOrders={loadOrders}
|
|
1228
|
-
loadLogisticOrders={loadLogisticOrders}
|
|
1229
|
-
deleteOrders={deleteOrders}
|
|
1230
|
-
loadMessages={loadMessages}
|
|
1231
|
-
loadMoreOrders={loadMoreOrders}
|
|
1232
|
-
handleClickOrder={handleClickOrder}
|
|
1233
|
-
handleClickLogisticOrder={handleClickLogisticOrder}
|
|
1234
|
-
filtered={filtered}
|
|
1235
|
-
onFiltered={setFiltered}
|
|
1236
|
-
handleChangeOrderStatus={handleChangeOrderStatus}
|
|
1237
|
-
handleSendCustomerReview={handleSendCustomerReview}
|
|
1238
|
-
ordersFormatted={formatOrdersGrouped(ordersGroup[currentTabSelected]?.orders)}
|
|
1239
|
-
isLogisticActivated={isLogisticActivated}
|
|
1240
|
-
ordersFiltered={ordersFiltered}
|
|
1241
|
-
/>
|
|
1242
|
-
)}
|
|
1243
|
-
</>
|
|
1244
|
-
)
|
|
1245
|
-
}
|
|
1246
|
-
|
|
1247
|
-
OrderListGroups.defaultProps = {
|
|
1248
|
-
orderBy: '-id',
|
|
1249
|
-
orderDirection: 'desc',
|
|
1250
|
-
isNetConnected: true,
|
|
1251
|
-
paginationSettings: { initialPage: 1, pageSize: 10, controlType: 'infinity' },
|
|
1252
|
-
beforeComponents: [],
|
|
1253
|
-
afterComponents: [],
|
|
1254
|
-
beforeElements: [],
|
|
1255
|
-
afterElements: []
|
|
1256
|
-
}
|
|
1
|
+
import React, { useEffect, useState, useCallback } from 'react'
|
|
2
|
+
import { useSession } from '../../contexts/SessionContext'
|
|
3
|
+
import { useApi } from '../../contexts/ApiContext'
|
|
4
|
+
import { useWebsocket } from '../../contexts/WebsocketContext'
|
|
5
|
+
import { ToastType, useToast } from '../../contexts/ToastContext'
|
|
6
|
+
import { useLanguage } from '../../contexts/LanguageContext'
|
|
7
|
+
import { useEvent } from '../../contexts/EventContext'
|
|
8
|
+
import { useConfig } from '../../contexts/ConfigContext'
|
|
9
|
+
|
|
10
|
+
export const OrderListGroups = (props) => {
|
|
11
|
+
const {
|
|
12
|
+
UIComponent,
|
|
13
|
+
orderBy,
|
|
14
|
+
isIos,
|
|
15
|
+
paginationSettings,
|
|
16
|
+
asDashboard,
|
|
17
|
+
orderGroupStatusCustom,
|
|
18
|
+
onOrdersDeleted,
|
|
19
|
+
customOrderTypes,
|
|
20
|
+
customPaymethods,
|
|
21
|
+
isDriverApp
|
|
22
|
+
} = props
|
|
23
|
+
|
|
24
|
+
const [ordering] = useApi()
|
|
25
|
+
const socket = useWebsocket()
|
|
26
|
+
const [session] = useSession()
|
|
27
|
+
const [events] = useEvent()
|
|
28
|
+
const [, t] = useLanguage()
|
|
29
|
+
const [, { showToast }] = useToast()
|
|
30
|
+
const [{ configs }] = useConfig()
|
|
31
|
+
|
|
32
|
+
const _combineTabs = props.combineTabs ?? configs?.combine_pending_and_progress_orders?.value === '1'
|
|
33
|
+
const [combineTabs, setCombineTabsState] = useState(_combineTabs)
|
|
34
|
+
|
|
35
|
+
const isLogisticActivated = configs?.logistic_module?.value
|
|
36
|
+
const ordersStatusArray = combineTabs ? ['active', 'completed', 'cancelled'] : ['pending', 'inProgress', 'completed', 'cancelled']
|
|
37
|
+
const notificationStatusses = props.isDriverApp
|
|
38
|
+
? configs?.notification_driver_states?.value.split('|').map(value => Number(value)) || []
|
|
39
|
+
: configs?.notification_business_states?.value.split('|').map(value => Number(value)) || []
|
|
40
|
+
const ordersGroupStatus = {
|
|
41
|
+
active: orderGroupStatusCustom?.active ?? [0, 3, 4, 7, 8, 9, 13, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26],
|
|
42
|
+
pending: orderGroupStatusCustom?.pending ?? [0, 13],
|
|
43
|
+
inProgress: orderGroupStatusCustom?.inProgress ?? [3, 4, 7, 8, 9, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26],
|
|
44
|
+
completed: orderGroupStatusCustom?.completed ?? [1, 11, 15],
|
|
45
|
+
cancelled: orderGroupStatusCustom?.cancelled ?? [2, 5, 6, 10, 12, 16, 17]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const orderStructure = {
|
|
49
|
+
loading: false,
|
|
50
|
+
error: null,
|
|
51
|
+
orders: [],
|
|
52
|
+
pagination: {
|
|
53
|
+
currentPage: (paginationSettings.controlType === 'pages' && paginationSettings.initialPage && paginationSettings.initialPage >= 1)
|
|
54
|
+
? paginationSettings.initialPage - 1
|
|
55
|
+
: 1,
|
|
56
|
+
pageSize: paginationSettings.pageSize ?? 10,
|
|
57
|
+
total: null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
let [ordersGroup, setOrdersGroup] = useState({
|
|
62
|
+
active: {
|
|
63
|
+
...orderStructure,
|
|
64
|
+
defaultFilter: ordersGroupStatus.active,
|
|
65
|
+
currentFilter: ordersGroupStatus.active,
|
|
66
|
+
fetched: false
|
|
67
|
+
},
|
|
68
|
+
pending: {
|
|
69
|
+
...orderStructure,
|
|
70
|
+
defaultFilter: ordersGroupStatus.pending,
|
|
71
|
+
currentFilter: ordersGroupStatus.pending,
|
|
72
|
+
fetched: false
|
|
73
|
+
},
|
|
74
|
+
inProgress: {
|
|
75
|
+
...orderStructure,
|
|
76
|
+
defaultFilter: ordersGroupStatus.inProgress,
|
|
77
|
+
currentFilter: ordersGroupStatus.inProgress,
|
|
78
|
+
fetched: false
|
|
79
|
+
},
|
|
80
|
+
completed: {
|
|
81
|
+
...orderStructure,
|
|
82
|
+
defaultFilter: ordersGroupStatus.completed,
|
|
83
|
+
currentFilter: ordersGroupStatus.completed,
|
|
84
|
+
fetched: false
|
|
85
|
+
},
|
|
86
|
+
cancelled: {
|
|
87
|
+
...orderStructure,
|
|
88
|
+
defaultFilter: ordersGroupStatus.cancelled,
|
|
89
|
+
currentFilter: ordersGroupStatus.cancelled,
|
|
90
|
+
fetched: false
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
const [currentTabSelected, setCurrentTabSelected] = useState(combineTabs ? 'active' : 'pending')
|
|
94
|
+
const [logisticOrders, setlogisticOrders] = useState({ loading: false, error: null, orders: [] })
|
|
95
|
+
const [messages, setMessages] = useState({ loading: false, error: null, messages: [] })
|
|
96
|
+
const [currentFilters, setCurrentFilters] = useState(null)
|
|
97
|
+
const [filtered, setFiltered] = useState(null)
|
|
98
|
+
const [ordersDeleted, setOrdersDeleted] = useState({ loading: false, error: null, result: [] })
|
|
99
|
+
const [controlsState, setControlsState] = useState({ loading: true, error: null, paymethods: [] })
|
|
100
|
+
const [businessIDs, setBusinessIDs] = useState([])
|
|
101
|
+
const [orderLogisticAdded, setOrderLogisticAdded] = useState(null)
|
|
102
|
+
const [orderLogisticUpdated, setOrderLogisticUpdated] = useState(null)
|
|
103
|
+
const [recentlyReceivedMessage, setRecentlyReceivedMessage] = useState(null)
|
|
104
|
+
|
|
105
|
+
const [ordersFiltered, setOrdersFiltered] = useState({
|
|
106
|
+
orders: [],
|
|
107
|
+
loading: false,
|
|
108
|
+
error: null,
|
|
109
|
+
pagination: {
|
|
110
|
+
currentPage: (paginationSettings.controlType === 'pages' && paginationSettings.initialPage && paginationSettings.initialPage >= 1)
|
|
111
|
+
? paginationSettings.initialPage - 1
|
|
112
|
+
: 0,
|
|
113
|
+
pageSize: paginationSettings.pageSize ?? 10,
|
|
114
|
+
total: null
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const requestsState = {}
|
|
119
|
+
|
|
120
|
+
const handleSelectCurrentTab = (value) => {
|
|
121
|
+
if (!isDriverApp) {
|
|
122
|
+
setOrdersGroup({
|
|
123
|
+
...ordersGroup,
|
|
124
|
+
[value]: {
|
|
125
|
+
...ordersGroup[value],
|
|
126
|
+
loading: true
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
if (value === 'logisticOrders') {
|
|
131
|
+
setlogisticOrders({
|
|
132
|
+
...logisticOrders,
|
|
133
|
+
loading: true
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
setCurrentTabSelected(value)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const getOrders = async ({
|
|
140
|
+
page,
|
|
141
|
+
pageSize = paginationSettings.pageSize,
|
|
142
|
+
orderStatus,
|
|
143
|
+
newFetch
|
|
144
|
+
}) => {
|
|
145
|
+
const options = {
|
|
146
|
+
query: {
|
|
147
|
+
orderBy,
|
|
148
|
+
page: page,
|
|
149
|
+
page_size: pageSize
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
options.query.where = []
|
|
153
|
+
if (orderStatus) {
|
|
154
|
+
if (!filtered?.state) {
|
|
155
|
+
options.query.where.push({ attribute: 'status', value: orderStatus })
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (ordersGroup[currentTabSelected]?.orders?.length > 0 && !newFetch) {
|
|
159
|
+
options.query = {
|
|
160
|
+
...options.query,
|
|
161
|
+
page: 1
|
|
162
|
+
}
|
|
163
|
+
if (!filtered?.id) {
|
|
164
|
+
options.query.where.push({
|
|
165
|
+
attribute: 'id',
|
|
166
|
+
value: {
|
|
167
|
+
condition: '!=',
|
|
168
|
+
value: ordersGroup[currentTabSelected]?.orders?.map((o) => o.id)
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (filtered?.id) {
|
|
176
|
+
options.query.where.push({
|
|
177
|
+
attribute: 'id',
|
|
178
|
+
value: {
|
|
179
|
+
condition: 'ilike',
|
|
180
|
+
value: isIos ? `%${filtered?.id}%` : encodeURI(`%${filtered?.id}%`)
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (filtered?.external_id) {
|
|
186
|
+
options.query.where.push({
|
|
187
|
+
attribute: 'external_id',
|
|
188
|
+
value: {
|
|
189
|
+
condition: 'ilike',
|
|
190
|
+
value: isIos ? `%${filtered?.external_id}%` : encodeURI(`%${filtered?.external_id}%`)
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (filtered?.state) {
|
|
196
|
+
options.query.where.push({ attribute: 'status', value: filtered.state })
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (filtered?.city) {
|
|
200
|
+
options.query.where.push({
|
|
201
|
+
attribute: 'business',
|
|
202
|
+
conditions: [{
|
|
203
|
+
attribute: 'city_id',
|
|
204
|
+
value: filtered?.city
|
|
205
|
+
}]
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (filtered?.paymethod || customPaymethods) {
|
|
210
|
+
let paymethodResult = controlsState
|
|
211
|
+
if (!controlsState.paymethods.length) {
|
|
212
|
+
paymethodResult = await getControls()
|
|
213
|
+
}
|
|
214
|
+
options.query.where.push({
|
|
215
|
+
attribute: 'paymethod_id',
|
|
216
|
+
value: (!!filtered?.paymethod && filtered?.paymethod) || paymethodResult?.paymethods
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (filtered?.driver) {
|
|
221
|
+
options.query.where.push({ attribute: 'driver_id', value: filtered?.driver })
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (filtered?.driver_groups) {
|
|
225
|
+
options.query.where.push({ attribute: 'driver_id', value: filtered?.driver_groups?.drivers })
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (filtered?.customer?.email || filtered?.customer?.phone) {
|
|
229
|
+
const customerOptions = []
|
|
230
|
+
if (filtered?.customer?.email) {
|
|
231
|
+
customerOptions.push({
|
|
232
|
+
attribute: 'email',
|
|
233
|
+
value: {
|
|
234
|
+
condition: 'ilike',
|
|
235
|
+
value: isIos ? `%${filtered?.customer?.email}%` : encodeURI(`%${filtered?.customer?.email}%`)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
}
|
|
239
|
+
if (filtered?.customer?.phone) {
|
|
240
|
+
customerOptions.push({
|
|
241
|
+
attribute: 'cellphone',
|
|
242
|
+
value: {
|
|
243
|
+
condition: 'ilike',
|
|
244
|
+
value: isIos ? `%${filtered?.customer?.phone}%` : encodeURI(`%${filtered?.customer?.phone}%`)
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
options.query.where.push({
|
|
250
|
+
attribute: 'customer',
|
|
251
|
+
conditions: customerOptions
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (filtered?.delivery_type || customOrderTypes) {
|
|
256
|
+
options.query.where.push({
|
|
257
|
+
attribute: 'delivery_type',
|
|
258
|
+
value: (!!filtered?.delivery_type && filtered?.delivery_type) || customOrderTypes
|
|
259
|
+
})
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
if (filtered?.date?.from) {
|
|
263
|
+
options.query.where.push({
|
|
264
|
+
attribute: 'delivery_datetime',
|
|
265
|
+
value: {
|
|
266
|
+
condition: '>=',
|
|
267
|
+
value: filtered?.date?.from
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
if (filtered?.date?.to) {
|
|
272
|
+
options.query.where.push({
|
|
273
|
+
attribute: 'delivery_datetime',
|
|
274
|
+
value: {
|
|
275
|
+
condition: '<=',
|
|
276
|
+
value: filtered?.date?.to
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (filtered?.timeStatus) {
|
|
282
|
+
options.query.where.push({
|
|
283
|
+
attribute: 'time_status',
|
|
284
|
+
value: filtered?.timeStatus
|
|
285
|
+
})
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
if (!isDriverApp) {
|
|
289
|
+
options.query.where.push({
|
|
290
|
+
attribute: 'products',
|
|
291
|
+
conditions: [{
|
|
292
|
+
attribute: 'type',
|
|
293
|
+
value: {
|
|
294
|
+
condition: '=',
|
|
295
|
+
value: 'item'
|
|
296
|
+
}
|
|
297
|
+
}]
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
const source = {}
|
|
302
|
+
requestsState.orders = source
|
|
303
|
+
options.cancelToken = source
|
|
304
|
+
|
|
305
|
+
const functionFetch = asDashboard
|
|
306
|
+
? ordering.setAccessToken(session.token).orders().asDashboard()
|
|
307
|
+
: ordering.setAccessToken(session.token).orders()
|
|
308
|
+
return await functionFetch.get(options)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const getControls = async () => {
|
|
312
|
+
try {
|
|
313
|
+
setControlsState({ ...controlsState, loading: true })
|
|
314
|
+
const { content: { error, result } } = await ordering
|
|
315
|
+
.setAccessToken(session.token)
|
|
316
|
+
.controls()
|
|
317
|
+
.get()
|
|
318
|
+
const obj = {
|
|
319
|
+
...controlsState,
|
|
320
|
+
loading: false,
|
|
321
|
+
paymethods: result?.paymethods
|
|
322
|
+
?.filter((p) => customPaymethods?.includes(p.name))
|
|
323
|
+
?.map((pay) => pay.id),
|
|
324
|
+
error: error ? result : null
|
|
325
|
+
}
|
|
326
|
+
setControlsState(obj)
|
|
327
|
+
return obj
|
|
328
|
+
} catch (e) {
|
|
329
|
+
setControlsState({
|
|
330
|
+
...controlsState,
|
|
331
|
+
loading: false,
|
|
332
|
+
error: e?.message ? controlsState.error?.push(e?.message) : ['ERROR']
|
|
333
|
+
})
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const loadOrders = async ({ newFetch, newFetchCurrent } = {}, options = {}) => {
|
|
338
|
+
if (
|
|
339
|
+
!(newFetch || newFetchCurrent) &&
|
|
340
|
+
ordersGroup[currentTabSelected].pagination.currentPage === ordersGroup[currentTabSelected].pagination.totalPages &&
|
|
341
|
+
ordersGroup[currentTabSelected].pagination.total !== null
|
|
342
|
+
) {
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
if (newFetch) {
|
|
347
|
+
ordersStatusArray?.map(tab => {
|
|
348
|
+
ordersGroup = {
|
|
349
|
+
...ordersGroup,
|
|
350
|
+
[tab]: {
|
|
351
|
+
...orderStructure,
|
|
352
|
+
defaultFilter: ordersGroupStatus[tab],
|
|
353
|
+
currentFilter: ordersGroup[tab].currentFilter,
|
|
354
|
+
orders: ordersGroup[tab].orders
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
})
|
|
358
|
+
} else if (newFetchCurrent) {
|
|
359
|
+
ordersGroup = {
|
|
360
|
+
...ordersGroup,
|
|
361
|
+
[currentTabSelected]: {
|
|
362
|
+
...orderStructure,
|
|
363
|
+
defaultFilter: ordersGroupStatus[currentTabSelected],
|
|
364
|
+
currentFilter: ordersGroup[currentTabSelected]?.currentFilter
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
const pageSize = paginationSettings.pageSize
|
|
370
|
+
|
|
371
|
+
try {
|
|
372
|
+
if (options?.allStatusses) {
|
|
373
|
+
setOrdersFiltered({
|
|
374
|
+
...ordersFiltered,
|
|
375
|
+
loading: true
|
|
376
|
+
})
|
|
377
|
+
} else {
|
|
378
|
+
setOrdersGroup({
|
|
379
|
+
...ordersGroup,
|
|
380
|
+
[currentTabSelected]: {
|
|
381
|
+
...ordersGroup[currentTabSelected],
|
|
382
|
+
loading: true
|
|
383
|
+
}
|
|
384
|
+
})
|
|
385
|
+
}
|
|
386
|
+
const { content: { error, result, pagination } } = await getOrders({
|
|
387
|
+
page: 1,
|
|
388
|
+
pageSize,
|
|
389
|
+
orderStatus: options?.allStatusses ? null : ordersGroup[currentTabSelected]?.currentFilter,
|
|
390
|
+
newFetch: (newFetch || newFetchCurrent)
|
|
391
|
+
})
|
|
392
|
+
const _ordersCleaned = error
|
|
393
|
+
? (newFetch || newFetchCurrent)
|
|
394
|
+
? []
|
|
395
|
+
: sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
396
|
+
: (newFetch || newFetchCurrent)
|
|
397
|
+
? sortOrders(result)
|
|
398
|
+
: sortOrders(ordersGroup[currentTabSelected]?.orders.concat(result))
|
|
399
|
+
|
|
400
|
+
if (options?.allStatusses) {
|
|
401
|
+
setOrdersFiltered({
|
|
402
|
+
error,
|
|
403
|
+
orders: formatOrdersGrouped(_ordersCleaned, { allStatusses: true }),
|
|
404
|
+
pagination: {
|
|
405
|
+
...ordersFiltered.pagination,
|
|
406
|
+
currentPage: pagination.current_page,
|
|
407
|
+
pageSize: pagination.page_size,
|
|
408
|
+
totalPages: pagination.total_pages,
|
|
409
|
+
total: pagination.total,
|
|
410
|
+
from: pagination.from,
|
|
411
|
+
to: pagination.to
|
|
412
|
+
},
|
|
413
|
+
loading: false
|
|
414
|
+
})
|
|
415
|
+
return
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
setOrdersGroup({
|
|
419
|
+
...ordersGroup,
|
|
420
|
+
[currentTabSelected]: {
|
|
421
|
+
...ordersGroup[currentTabSelected],
|
|
422
|
+
loading: false,
|
|
423
|
+
orders: _ordersCleaned,
|
|
424
|
+
error: error ? result : null,
|
|
425
|
+
fetched: true,
|
|
426
|
+
pagination: {
|
|
427
|
+
...ordersGroup[currentTabSelected].pagination,
|
|
428
|
+
currentPage: pagination.current_page,
|
|
429
|
+
pageSize: pagination.page_size,
|
|
430
|
+
totalPages: pagination.total_pages,
|
|
431
|
+
total: pagination.total,
|
|
432
|
+
from: pagination.from,
|
|
433
|
+
to: pagination.to
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
})
|
|
437
|
+
} catch (err) {
|
|
438
|
+
if (err.constructor.name !== 'Cancel') {
|
|
439
|
+
if (options?.allStatusses) {
|
|
440
|
+
setOrdersFiltered({
|
|
441
|
+
...ordersFiltered,
|
|
442
|
+
loading: false,
|
|
443
|
+
error: [err?.message ?? 'ERROR']
|
|
444
|
+
})
|
|
445
|
+
} else {
|
|
446
|
+
setOrdersGroup({
|
|
447
|
+
...ordersGroup,
|
|
448
|
+
[currentTabSelected]: {
|
|
449
|
+
...ordersGroup[currentTabSelected],
|
|
450
|
+
loading: false,
|
|
451
|
+
error: [err?.message ?? 'ERROR']
|
|
452
|
+
}
|
|
453
|
+
})
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
const loadMoreOrders = async (options = {}) => {
|
|
460
|
+
if (!options?.allStatusses) {
|
|
461
|
+
setOrdersGroup({
|
|
462
|
+
...ordersGroup,
|
|
463
|
+
[currentTabSelected]: {
|
|
464
|
+
...ordersGroup[currentTabSelected],
|
|
465
|
+
loading: true
|
|
466
|
+
}
|
|
467
|
+
})
|
|
468
|
+
} else {
|
|
469
|
+
setOrdersFiltered({
|
|
470
|
+
...ordersFiltered,
|
|
471
|
+
loading: true
|
|
472
|
+
})
|
|
473
|
+
}
|
|
474
|
+
try {
|
|
475
|
+
const { content: { error, result, pagination } } = await getOrders({
|
|
476
|
+
page: options?.allStatusses ? ordersFiltered.pagination.currentPage + 1 : ordersGroup[currentTabSelected].pagination.currentPage + 1,
|
|
477
|
+
orderStatus: options?.allStatusses ? null : ordersGroup[currentTabSelected]?.currentFilter,
|
|
478
|
+
newFetch: true
|
|
479
|
+
})
|
|
480
|
+
|
|
481
|
+
if (options?.allStatusses) {
|
|
482
|
+
setOrdersFiltered({
|
|
483
|
+
error,
|
|
484
|
+
orders: formatOrdersGrouped([
|
|
485
|
+
...ordersFiltered?.orders,
|
|
486
|
+
...sortOrders(result)
|
|
487
|
+
], { allStatusses: true }),
|
|
488
|
+
pagination: {
|
|
489
|
+
...ordersFiltered.pagination,
|
|
490
|
+
currentPage: pagination.current_page,
|
|
491
|
+
pageSize: pagination.page_size,
|
|
492
|
+
totalPages: pagination.total_pages,
|
|
493
|
+
total: pagination.total,
|
|
494
|
+
from: pagination.from,
|
|
495
|
+
to: pagination.to
|
|
496
|
+
},
|
|
497
|
+
loading: false
|
|
498
|
+
})
|
|
499
|
+
return
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const _ordersCleaned = error
|
|
503
|
+
? sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
504
|
+
: sortOrders(ordersGroup[currentTabSelected]?.orders?.concat(result))
|
|
505
|
+
setOrdersGroup({
|
|
506
|
+
...ordersGroup,
|
|
507
|
+
[currentTabSelected]: {
|
|
508
|
+
...ordersGroup[currentTabSelected],
|
|
509
|
+
loading: false,
|
|
510
|
+
orders: _ordersCleaned,
|
|
511
|
+
error: error ? result : null,
|
|
512
|
+
pagination: !error
|
|
513
|
+
? {
|
|
514
|
+
...ordersGroup[currentTabSelected].pagination,
|
|
515
|
+
currentPage: pagination.current_page,
|
|
516
|
+
pageSize: pagination.page_size,
|
|
517
|
+
totalPages: pagination.total_pages,
|
|
518
|
+
total: pagination.total,
|
|
519
|
+
from: pagination.from,
|
|
520
|
+
to: pagination.to
|
|
521
|
+
}
|
|
522
|
+
: ordersGroup[currentTabSelected].pagination
|
|
523
|
+
}
|
|
524
|
+
})
|
|
525
|
+
} catch (err) {
|
|
526
|
+
if (err.constructor.name !== 'Cancel') {
|
|
527
|
+
setOrdersGroup({
|
|
528
|
+
...ordersGroup,
|
|
529
|
+
[currentTabSelected]: {
|
|
530
|
+
...ordersGroup[currentTabSelected],
|
|
531
|
+
loading: false,
|
|
532
|
+
error: [err?.message ?? 'ERROR']
|
|
533
|
+
}
|
|
534
|
+
})
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
const loadMessages = async (orderId) => {
|
|
540
|
+
try {
|
|
541
|
+
setMessages({ ...messages, loading: true })
|
|
542
|
+
const url = `${ordering.root}/orders/${orderId}/messages?mode=dashboard`
|
|
543
|
+
|
|
544
|
+
const response = await fetch(url, {
|
|
545
|
+
method: 'GET',
|
|
546
|
+
headers: {
|
|
547
|
+
'Content-Type': 'application/json',
|
|
548
|
+
Authorization: `Bearer ${session.token}`,
|
|
549
|
+
'X-App-X': ordering.appId,
|
|
550
|
+
'X-Socket-Id-X': socket?.getId()
|
|
551
|
+
}
|
|
552
|
+
})
|
|
553
|
+
const { error, result } = await response.json()
|
|
554
|
+
if (!error) {
|
|
555
|
+
setMessages({
|
|
556
|
+
messages: result,
|
|
557
|
+
loading: false,
|
|
558
|
+
error: null
|
|
559
|
+
})
|
|
560
|
+
} else {
|
|
561
|
+
setMessages({
|
|
562
|
+
...messages,
|
|
563
|
+
loading: false,
|
|
564
|
+
error: result
|
|
565
|
+
})
|
|
566
|
+
}
|
|
567
|
+
} catch (error) {
|
|
568
|
+
setMessages({ ...messages, loading: false, error: [error.Messages] })
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const deleteOrders = async (orderIds) => {
|
|
573
|
+
try {
|
|
574
|
+
setOrdersDeleted({ ...ordersDeleted, loading: true })
|
|
575
|
+
const errorState = []
|
|
576
|
+
|
|
577
|
+
if (orderIds.length === 1) {
|
|
578
|
+
const { content: { error } } = await ordering.setAccessToken(session.token).orders(orderIds[0]).delete()
|
|
579
|
+
errorState.push({ error, id: orderIds[0] })
|
|
580
|
+
} else if (orderIds.length > 1) {
|
|
581
|
+
for (const id of orderIds) {
|
|
582
|
+
const { content: { error: multiError } } = await ordering.setAccessToken(session.token).orders(id).delete()
|
|
583
|
+
errorState.push({ error: multiError, id })
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
const isError = errorState.some((e) => e.error)
|
|
588
|
+
const idsDeleted = errorState?.map((obj) => !obj.error && obj.id)
|
|
589
|
+
|
|
590
|
+
onOrdersDeleted && onOrdersDeleted({ isError, list: idsDeleted })
|
|
591
|
+
setOrdersDeleted({ ...ordersDeleted, loading: false })
|
|
592
|
+
setOrdersGroup({
|
|
593
|
+
...ordersGroup,
|
|
594
|
+
[currentTabSelected]: {
|
|
595
|
+
...ordersGroup[currentTabSelected],
|
|
596
|
+
orders: idsDeleted.length
|
|
597
|
+
? sortOrders(ordersGroup[currentTabSelected]?.orders?.filter((order) => !idsDeleted.includes(order.id)))
|
|
598
|
+
: sortOrders(ordersGroup[currentTabSelected]?.orders)
|
|
599
|
+
}
|
|
600
|
+
})
|
|
601
|
+
} catch (err) {
|
|
602
|
+
if (err.constructor.name !== 'Cancel') {
|
|
603
|
+
setOrdersGroup({
|
|
604
|
+
...ordersGroup,
|
|
605
|
+
[currentTabSelected]: {
|
|
606
|
+
...ordersGroup[currentTabSelected],
|
|
607
|
+
loading: false,
|
|
608
|
+
error: [err?.message ?? 'ERROR']
|
|
609
|
+
}
|
|
610
|
+
})
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const loadLogisticOrders = async (isAlreadyFetched) => {
|
|
616
|
+
try {
|
|
617
|
+
setlogisticOrders({ ...logisticOrders, loading: true })
|
|
618
|
+
const url = `${ordering.root}/drivers/${session.user?.id}/assign_requests`
|
|
619
|
+
const response = await fetch(url, {
|
|
620
|
+
method: 'GET',
|
|
621
|
+
headers: {
|
|
622
|
+
'Content-Type': 'application/json',
|
|
623
|
+
Authorization: `Bearer ${session.token}`,
|
|
624
|
+
'X-App-X': ordering.appId,
|
|
625
|
+
'X-Socket-Id-X': socket?.getId()
|
|
626
|
+
}
|
|
627
|
+
})
|
|
628
|
+
const { result, error } = await response.json()
|
|
629
|
+
if (!error) {
|
|
630
|
+
setlogisticOrders({ ...logisticOrders, loading: false, orders: result.filter(order => !(order?.order_group && order?.order_group?.orders?.length === 0)) })
|
|
631
|
+
return
|
|
632
|
+
}
|
|
633
|
+
setlogisticOrders({ loading: false, orders: [], error: result })
|
|
634
|
+
} catch (err) {
|
|
635
|
+
setlogisticOrders({ loading: false, orders: [], error: err.message })
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const sortOrders = (orders, sortBy = 'desc') => {
|
|
640
|
+
const ordersSorted = orders?.sort((a, b) => {
|
|
641
|
+
if (sortBy === 'desc') {
|
|
642
|
+
return b.id - a.id
|
|
643
|
+
}
|
|
644
|
+
return a.id - b.id
|
|
645
|
+
})
|
|
646
|
+
|
|
647
|
+
return ordersSorted
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
const filterByIdUnique = (array, currentTabSelected) => {
|
|
651
|
+
if (!array) return []
|
|
652
|
+
|
|
653
|
+
const tempObj = {}
|
|
654
|
+
const status = ordersGroupStatus[currentTabSelected] ?? []
|
|
655
|
+
|
|
656
|
+
return array.map((element) => {
|
|
657
|
+
if (Array.isArray(element)) {
|
|
658
|
+
const _array = element[0][1].map((item) => {
|
|
659
|
+
if (!tempObj[item.id] && status.includes(item.status)) {
|
|
660
|
+
tempObj[item.id] = true
|
|
661
|
+
return item
|
|
662
|
+
}
|
|
663
|
+
return null
|
|
664
|
+
}).filter((item) => item !== null)
|
|
665
|
+
return _array.length ? [[_array[0]?.cart_group_id.toString(), _array]] : null
|
|
666
|
+
} else {
|
|
667
|
+
if (!tempObj[element.id] && status.includes(element.status)) {
|
|
668
|
+
tempObj[element.id] = true
|
|
669
|
+
return element
|
|
670
|
+
}
|
|
671
|
+
return null
|
|
672
|
+
}
|
|
673
|
+
}).filter((item) => Array.isArray(item) ? item.length : item)
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const formatOrdersGrouped = (orders, options = {}) => {
|
|
677
|
+
let totalOrders = orders
|
|
678
|
+
const ordersGroupids = []
|
|
679
|
+
|
|
680
|
+
totalOrders = totalOrders
|
|
681
|
+
?.map(item => {
|
|
682
|
+
if (!item?.cart_group_id) return item
|
|
683
|
+
|
|
684
|
+
const groupIds = totalOrders.filter(o => o.cart_group_id === item?.cart_group_id)
|
|
685
|
+
const _item = !ordersGroupids.includes(item?.cart_group_id)
|
|
686
|
+
? Object.entries({ [item?.cart_group_id]: groupIds }) : ''
|
|
687
|
+
|
|
688
|
+
if (_item) ordersGroupids.push(item?.cart_group_id)
|
|
689
|
+
return _item
|
|
690
|
+
}).filter(item => item)
|
|
691
|
+
return options?.allStatusses ? totalOrders : filterByIdUnique(totalOrders, currentTabSelected)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const getStatusById = (id) => {
|
|
695
|
+
if (!id && id !== 0) return
|
|
696
|
+
const active = orderGroupStatusCustom?.active ?? [0, 3, 4, 7, 8, 9, 13, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
|
697
|
+
const pending = orderGroupStatusCustom?.pending ?? [0, 13]
|
|
698
|
+
const inProgress = orderGroupStatusCustom?.inProgress ?? [3, 4, 7, 8, 9, 14, 18, 19, 20, 21, 22, 23, 24, 25, 26]
|
|
699
|
+
const completed = orderGroupStatusCustom?.completed ?? [1, 11, 15]
|
|
700
|
+
// const cancelled = orderGroupStatusCustom?.cancelled ?? [2, 5, 6, 10, 12, 16, 17]
|
|
701
|
+
|
|
702
|
+
const status = pending.includes(id)
|
|
703
|
+
? 'pending'
|
|
704
|
+
: inProgress.includes(id)
|
|
705
|
+
? 'inProgress'
|
|
706
|
+
: completed.includes(id)
|
|
707
|
+
? 'completed'
|
|
708
|
+
: 'cancelled'
|
|
709
|
+
|
|
710
|
+
const combinedStatus = active.includes(id)
|
|
711
|
+
? 'active'
|
|
712
|
+
: completed.includes(id)
|
|
713
|
+
? 'completed'
|
|
714
|
+
: 'cancelled'
|
|
715
|
+
|
|
716
|
+
return combineTabs ? combinedStatus : status
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
const actionOrderToTab = (orderAux, status, type) => {
|
|
720
|
+
setOrdersGroup(prevState => {
|
|
721
|
+
if (!prevState[status]?.orders) return
|
|
722
|
+
const orderList = prevState[status]?.orders
|
|
723
|
+
const order = { ...orderAux, showNotification: false }
|
|
724
|
+
let updatedOrders
|
|
725
|
+
|
|
726
|
+
switch (type) {
|
|
727
|
+
case 'update':
|
|
728
|
+
updatedOrders = orderList.map(o => o.id === order.id ? { ...order, action: `${type}${order?.status}` } : o)
|
|
729
|
+
break
|
|
730
|
+
case 'add':
|
|
731
|
+
updatedOrders = [{ ...order, action: `${type}${order?.status}` }, ...orderList]
|
|
732
|
+
break
|
|
733
|
+
case 'remove':
|
|
734
|
+
updatedOrders = orderList.filter(o => o.id !== order.id)
|
|
735
|
+
break
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
const updatedPagination = {
|
|
739
|
+
...prevState[status].pagination,
|
|
740
|
+
total: prevState[status].pagination.total + (type === 'add' ? 1 : type === 'remove' ? -1 : 0)
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
return {
|
|
744
|
+
...prevState,
|
|
745
|
+
[status]: {
|
|
746
|
+
...prevState[status],
|
|
747
|
+
orders: filterByIdUnique(sortOrders(updatedOrders), status),
|
|
748
|
+
pagination: updatedPagination
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
})
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const handleClickOrder = (orderAux) => {
|
|
755
|
+
const order = {
|
|
756
|
+
...orderAux,
|
|
757
|
+
showNotification: false
|
|
758
|
+
}
|
|
759
|
+
const ordersGroups = order?.order_group?.orders
|
|
760
|
+
if (!ordersGroups) {
|
|
761
|
+
const status = getStatusById(order?.status)
|
|
762
|
+
const orderList = ordersGroup[status]?.orders
|
|
763
|
+
const indexToUpdate = orderList?.findIndex((o) => o?.id === order?.id)
|
|
764
|
+
orderList[indexToUpdate] = order
|
|
765
|
+
setOrdersGroup({
|
|
766
|
+
...ordersGroup,
|
|
767
|
+
[status]: {
|
|
768
|
+
...ordersGroup[status],
|
|
769
|
+
orders: sortOrders(orderList)
|
|
770
|
+
}
|
|
771
|
+
})
|
|
772
|
+
} else {
|
|
773
|
+
const status = getStatusById(order?.order_group?.orders?.[0]?.status)
|
|
774
|
+
let orderList
|
|
775
|
+
ordersGroups?.map(order => {
|
|
776
|
+
orderList = ordersGroup[status]?.orders
|
|
777
|
+
const indexToUpdate = orderList?.findIndex((o) => o?.id === order?.id)
|
|
778
|
+
orderList[indexToUpdate] = order
|
|
779
|
+
})
|
|
780
|
+
setOrdersGroup({
|
|
781
|
+
...ordersGroup,
|
|
782
|
+
[status]: {
|
|
783
|
+
...ordersGroup[status],
|
|
784
|
+
orders: sortOrders(orderList)
|
|
785
|
+
}
|
|
786
|
+
})
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
const handleClickLogisticOrder = async (status, orderId) => {
|
|
791
|
+
try {
|
|
792
|
+
const response = await fetch(`${ordering.root}/drivers/${session.user?.id}/assign_requests/${orderId}`, {
|
|
793
|
+
method: 'PUT',
|
|
794
|
+
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session.token}` },
|
|
795
|
+
body: JSON.stringify({
|
|
796
|
+
status,
|
|
797
|
+
user_id: session.user?.id
|
|
798
|
+
})
|
|
799
|
+
})
|
|
800
|
+
const { result, error } = await response.json()
|
|
801
|
+
if (!error) {
|
|
802
|
+
const order = logisticOrders?.orders?.find(order => order?.id === orderId)
|
|
803
|
+
const newOrders = sortOrders(logisticOrders?.orders?.filter(_order => _order?.id !== orderId))
|
|
804
|
+
setlogisticOrders({ ...logisticOrders, orders: newOrders })
|
|
805
|
+
if (status === 1) {
|
|
806
|
+
handleClickOrder(order?.order ?? order)
|
|
807
|
+
showToast(
|
|
808
|
+
ToastType.Success,
|
|
809
|
+
t('SPECIFIC_ORDER_ACCEPTED', 'Your accepted the order number _NUMBER_').replace('_NUMBER_', order?.order?.id ?? order?.id)
|
|
810
|
+
)
|
|
811
|
+
} else {
|
|
812
|
+
showToast(
|
|
813
|
+
ToastType.Info,
|
|
814
|
+
t('SPECIFIC_ORDER_REJECTED', 'Your rejected the order number _NUMBER_').replace('_NUMBER_', order?.order?.id ?? order?.id)
|
|
815
|
+
)
|
|
816
|
+
}
|
|
817
|
+
return
|
|
818
|
+
}
|
|
819
|
+
showToast(ToastType.Error, result)
|
|
820
|
+
} catch (err) {
|
|
821
|
+
setlogisticOrders({ ...logisticOrders, error: err.message })
|
|
822
|
+
showToast(ToastType.Error, err.message)
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
const handleChangeOrderStatus = async (status, orderIds, body = {}) => {
|
|
827
|
+
try {
|
|
828
|
+
delete body.id
|
|
829
|
+
const bodyToSend = Object.keys(body || {}).length > 0 ? body : { status }
|
|
830
|
+
const setOrderStatus = async (id) => {
|
|
831
|
+
try {
|
|
832
|
+
const { content: { result, error } } = await ordering.setAccessToken(session?.token).orders(id).save({ ...bodyToSend, id })
|
|
833
|
+
return error ? null : result
|
|
834
|
+
} catch {
|
|
835
|
+
return null
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
const result = await Promise.all(orderIds?.map(id => setOrderStatus(id)))
|
|
840
|
+
return result
|
|
841
|
+
} catch (err) {
|
|
842
|
+
return err?.message ?? err
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
const handleSendCustomerReview = async ({ customerId, orderIds, body, onClose }) => {
|
|
847
|
+
try {
|
|
848
|
+
const setCustomerReview = async (body) => {
|
|
849
|
+
try {
|
|
850
|
+
const response = await fetch(`${ordering.root}/users/${customerId}/user_reviews`, {
|
|
851
|
+
method: 'POST',
|
|
852
|
+
headers: {
|
|
853
|
+
Authorization: `Bearer ${session.token}`,
|
|
854
|
+
'Content-Type': 'application/json',
|
|
855
|
+
'X-App-X': ordering.appId,
|
|
856
|
+
'X-Socket-Id-X': socket?.getId()
|
|
857
|
+
},
|
|
858
|
+
body: JSON.stringify(body)
|
|
859
|
+
})
|
|
860
|
+
const { result, error } = await response.json()
|
|
861
|
+
return error ? null : result
|
|
862
|
+
} catch (err) {
|
|
863
|
+
return null
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
const result = await Promise.all(orderIds?.map(id => setCustomerReview({ ...body, order_id: id, user_id: customerId })))
|
|
868
|
+
if (result?.length) {
|
|
869
|
+
const orders = ordersGroup[currentTabSelected].orders
|
|
870
|
+
result?.map(order => {
|
|
871
|
+
let orderFound = orders.find(o => o.id === order.order_id)
|
|
872
|
+
const idxOrderFound = orders.findIndex(o => o.id === order.order_id)
|
|
873
|
+
|
|
874
|
+
if (orderFound) {
|
|
875
|
+
orderFound = { ...orderFound, user_review: order }
|
|
876
|
+
orders[idxOrderFound] = orderFound
|
|
877
|
+
setOrdersGroup({ ...ordersGroup, orders })
|
|
878
|
+
}
|
|
879
|
+
})
|
|
880
|
+
showToast(
|
|
881
|
+
ToastType.Success,
|
|
882
|
+
t('ORDERS_SUCCESSFULLY_REVIEWED', 'Orders successfully reviewed')
|
|
883
|
+
)
|
|
884
|
+
}
|
|
885
|
+
onClose && onClose()
|
|
886
|
+
return result
|
|
887
|
+
} catch (err) {
|
|
888
|
+
return err?.message ?? err
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const getBusinessesIDs = async () => {
|
|
893
|
+
const propsToFetch = ['id', 'name']
|
|
894
|
+
try {
|
|
895
|
+
const { content: { error, result } } = await ordering.businesses().asDashboard().select(propsToFetch).get()
|
|
896
|
+
if (!error) {
|
|
897
|
+
const _businessIDs = result.length > 0 && result.map(({ id }) => id)
|
|
898
|
+
setBusinessIDs(_businessIDs)
|
|
899
|
+
}
|
|
900
|
+
} catch (err) {
|
|
901
|
+
if (err.constructor.name !== 'Cancel') {
|
|
902
|
+
setOrdersGroup({
|
|
903
|
+
...ordersGroup,
|
|
904
|
+
[currentTabSelected]: {
|
|
905
|
+
...ordersGroup[currentTabSelected],
|
|
906
|
+
loading: false,
|
|
907
|
+
error: [err?.message ?? 'ERROR']
|
|
908
|
+
}
|
|
909
|
+
})
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
useEffect(() => {
|
|
915
|
+
if (session?.user?.level !== 2) return
|
|
916
|
+
getBusinessesIDs()
|
|
917
|
+
}, [])
|
|
918
|
+
|
|
919
|
+
useEffect(() => {
|
|
920
|
+
setCurrentFilters(ordersGroup[currentTabSelected]?.currentFilter)
|
|
921
|
+
if (currentTabSelected === 'logisticOrders') {
|
|
922
|
+
loadLogisticOrders(!!logisticOrders?.orders)
|
|
923
|
+
} else if (!ordersGroup[currentTabSelected]?.fetched && props.isNetConnected) {
|
|
924
|
+
loadOrders({ newFetchCurrent: true })
|
|
925
|
+
}
|
|
926
|
+
}, [currentTabSelected, props.isNetConnected])
|
|
927
|
+
|
|
928
|
+
useEffect(() => {
|
|
929
|
+
if (currentFilters && !isDriverApp) {
|
|
930
|
+
loadOrders({ newFetchCurrent: true })
|
|
931
|
+
}
|
|
932
|
+
}, [currentFilters])
|
|
933
|
+
|
|
934
|
+
useEffect(() => {
|
|
935
|
+
if (!filtered) return
|
|
936
|
+
loadOrders({ newFetch: true }, { allStatusses: true })
|
|
937
|
+
}, [filtered])
|
|
938
|
+
|
|
939
|
+
const handleActionEvent = (event, value) => {
|
|
940
|
+
const evts = {
|
|
941
|
+
order_added: 'order_added_notification',
|
|
942
|
+
update_order: 'order_updated_notification',
|
|
943
|
+
messages: 'message_added_notification',
|
|
944
|
+
request_register: 'request_register_notification',
|
|
945
|
+
request_update: 'request_update_notification'
|
|
946
|
+
}
|
|
947
|
+
events.emit(evts[event], value)
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
useEffect(() => {
|
|
951
|
+
if (!socket?.socket) return
|
|
952
|
+
const handleUpdateOrder = (order) => {
|
|
953
|
+
const isGiftCard = order?.products?.some(product => product?.type === 'gift_card')
|
|
954
|
+
if (isGiftCard && !isDriverApp) return
|
|
955
|
+
if (session?.user?.level === 2 && businessIDs.length > 0 && !businessIDs.includes(order.business_id)) return
|
|
956
|
+
events.emit('order_updated', order)
|
|
957
|
+
let orderFound = null
|
|
958
|
+
for (let i = 0; i < ordersStatusArray.length; i++) {
|
|
959
|
+
const status = ordersStatusArray[i]
|
|
960
|
+
if (order?.products) {
|
|
961
|
+
orderFound = ordersGroup[status]?.orders?.find((_order) => _order.id === order.id)
|
|
962
|
+
}
|
|
963
|
+
if (orderFound) break
|
|
964
|
+
}
|
|
965
|
+
if (notificationStatusses.includes(order?.status)) {
|
|
966
|
+
showToast(
|
|
967
|
+
ToastType.Info,
|
|
968
|
+
t('SPECIFIC_ORDER_UPDATED', 'Your order number _NUMBER_ has updated').replace('_NUMBER_', order.id),
|
|
969
|
+
1000
|
|
970
|
+
)
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (!orderFound) {
|
|
974
|
+
if (
|
|
975
|
+
!order?.products ||
|
|
976
|
+
!order?.summary ||
|
|
977
|
+
typeof order?.status !== 'number' ||
|
|
978
|
+
!order?.customer ||
|
|
979
|
+
!order?.business ||
|
|
980
|
+
((!order?.paymethod && !order?.payment_events?.some(e => e.event === 'payment')) && order?.total !== 0)
|
|
981
|
+
) {
|
|
982
|
+
return
|
|
983
|
+
}
|
|
984
|
+
delete order.total
|
|
985
|
+
delete order.subtotal
|
|
986
|
+
const currentFilter = ordersGroup[getStatusById(order?.status) ?? '']?.currentFilter
|
|
987
|
+
!currentFilter.includes(order.status)
|
|
988
|
+
? actionOrderToTab(order, getStatusById(order?.status), 'remove')
|
|
989
|
+
: actionOrderToTab(order, getStatusById(order?.status), 'add')
|
|
990
|
+
|
|
991
|
+
return
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
if (
|
|
995
|
+
orderFound.id === order.id &&
|
|
996
|
+
orderFound?.driver?.id !== order?.driver?.id &&
|
|
997
|
+
session?.user?.level === 4
|
|
998
|
+
) {
|
|
999
|
+
actionOrderToTab(orderFound, getStatusById(orderFound.status), 'remove')
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
if (orderFound.id === order.id) {
|
|
1003
|
+
delete order.total
|
|
1004
|
+
delete order.subtotal
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
if (!order?.status && order?.status !== 0) {
|
|
1008
|
+
Object.assign(orderFound, order)
|
|
1009
|
+
} else {
|
|
1010
|
+
const newOrderStatus = getStatusById(order?.status) ?? ''
|
|
1011
|
+
const currentOrderStatus = getStatusById(orderFound?.status) ?? ''
|
|
1012
|
+
|
|
1013
|
+
const currentFilter = ordersGroup[newOrderStatus]?.currentFilter
|
|
1014
|
+
Object.assign(orderFound, order)
|
|
1015
|
+
|
|
1016
|
+
if (newOrderStatus !== currentOrderStatus) {
|
|
1017
|
+
actionOrderToTab(orderFound, currentOrderStatus, 'remove')
|
|
1018
|
+
|
|
1019
|
+
const total = ordersGroup[newOrderStatus].pagination.total ?? null
|
|
1020
|
+
|
|
1021
|
+
if (
|
|
1022
|
+
currentFilter.includes(orderFound.status) &&
|
|
1023
|
+
total !== null
|
|
1024
|
+
) {
|
|
1025
|
+
actionOrderToTab(orderFound, newOrderStatus, 'add')
|
|
1026
|
+
}
|
|
1027
|
+
} else {
|
|
1028
|
+
!currentFilter.includes(orderFound.status) || (orderFound?.driver === null && isDriverApp)
|
|
1029
|
+
? actionOrderToTab(orderFound, newOrderStatus, 'remove')
|
|
1030
|
+
: actionOrderToTab(orderFound, newOrderStatus, 'update')
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
const handleAddNewOrder = (order) => {
|
|
1036
|
+
const isGiftCard = order?.products?.some(product => product?.type === 'gift_card')
|
|
1037
|
+
if (isGiftCard && !isDriverApp) return
|
|
1038
|
+
events.emit('order_added', order)
|
|
1039
|
+
handleActionEvent('order_added', order)
|
|
1040
|
+
if (notificationStatusses.includes(order?.status)) {
|
|
1041
|
+
showToast(
|
|
1042
|
+
ToastType.Info,
|
|
1043
|
+
t('SPECIFIC_ORDER_ORDERED', 'Order _NUMBER_ has been ordered').replace('_NUMBER_', order.id),
|
|
1044
|
+
1000
|
|
1045
|
+
)
|
|
1046
|
+
}
|
|
1047
|
+
const status = getStatusById(order?.status) ?? ''
|
|
1048
|
+
actionOrderToTab(order, status, 'add')
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
const handleReceiveMessage = (message) => {
|
|
1052
|
+
if (message?.id !== recentlyReceivedMessage?.id) {
|
|
1053
|
+
handleActionEvent('messages', message)
|
|
1054
|
+
setRecentlyReceivedMessage(message)
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
socket.on('orders_register', handleAddNewOrder)
|
|
1058
|
+
socket.on('order_assigned', handleAddNewOrder)
|
|
1059
|
+
socket.on('update_order', handleUpdateOrder)
|
|
1060
|
+
socket.on('message', handleReceiveMessage)
|
|
1061
|
+
|
|
1062
|
+
return () => {
|
|
1063
|
+
socket.off('orders_register', handleAddNewOrder)
|
|
1064
|
+
socket.off('order_assigned', handleAddNewOrder)
|
|
1065
|
+
socket.off('update_order', handleUpdateOrder)
|
|
1066
|
+
socket.off('message', handleReceiveMessage)
|
|
1067
|
+
}
|
|
1068
|
+
}, [JSON.stringify(ordersGroup), socket?.socket, session])
|
|
1069
|
+
|
|
1070
|
+
const handleAddAssignRequest = useCallback(
|
|
1071
|
+
(order) => {
|
|
1072
|
+
setOrderLogisticAdded(order)
|
|
1073
|
+
const isSameEvent = orderLogisticAdded?.id === order?.id && orderLogisticAdded.status === order?.status
|
|
1074
|
+
if (!order?.locked && !isSameEvent) {
|
|
1075
|
+
handleActionEvent('request_register', order)
|
|
1076
|
+
}
|
|
1077
|
+
setlogisticOrders((prevState) => ({
|
|
1078
|
+
...prevState,
|
|
1079
|
+
orders: sortOrders([...prevState?.orders, order].filter((order, index, hash) => { // remove possibles duplicates
|
|
1080
|
+
const val = JSON.stringify(order)
|
|
1081
|
+
return index === hash.findIndex(_order => {
|
|
1082
|
+
return JSON.stringify(_order) === val
|
|
1083
|
+
})
|
|
1084
|
+
}))
|
|
1085
|
+
}))
|
|
1086
|
+
showToast(
|
|
1087
|
+
ToastType.Info,
|
|
1088
|
+
t('SPECIFIC_LOGISTIC_ORDER_ORDERED', 'Logisitc order _NUMBER_ has been ordered').replace('_NUMBER_', order?.order?.id ?? order.id),
|
|
1089
|
+
1000
|
|
1090
|
+
)
|
|
1091
|
+
},
|
|
1092
|
+
[logisticOrders]
|
|
1093
|
+
)
|
|
1094
|
+
|
|
1095
|
+
const handleDeleteAssignRequest = useCallback(
|
|
1096
|
+
(order) => {
|
|
1097
|
+
setlogisticOrders(prevState => ({
|
|
1098
|
+
...prevState,
|
|
1099
|
+
orders: prevState?.orders?.some(_order => _order?.id === order?.id)
|
|
1100
|
+
? sortOrders([...prevState?.orders?.filter(_order => _order?.id !== order?.id), { ...prevState?.orders?.find(_order => _order?.id === order?.id), expired: true }])
|
|
1101
|
+
: sortOrders(prevState?.orders)
|
|
1102
|
+
}))
|
|
1103
|
+
},
|
|
1104
|
+
[logisticOrders]
|
|
1105
|
+
)
|
|
1106
|
+
|
|
1107
|
+
const handleUpdateAssignRequest = useCallback(
|
|
1108
|
+
(order) => {
|
|
1109
|
+
setOrderLogisticUpdated(order)
|
|
1110
|
+
const isSameEvent = orderLogisticUpdated?.id === order?.id && orderLogisticUpdated.status === order?.status
|
|
1111
|
+
if (!order?.locked && !isSameEvent) {
|
|
1112
|
+
handleActionEvent('request_update', order)
|
|
1113
|
+
}
|
|
1114
|
+
setlogisticOrders(prevState => ({
|
|
1115
|
+
...prevState,
|
|
1116
|
+
orders: prevState?.orders?.some(_order => _order?.id === order?.id)
|
|
1117
|
+
? sortOrders([...prevState?.orders?.filter(_order => _order?.id !== order?.id), { ...prevState?.orders?.find(_order => _order?.id === order?.id), ...order }])
|
|
1118
|
+
: sortOrders(prevState?.orders)
|
|
1119
|
+
}))
|
|
1120
|
+
showToast(
|
|
1121
|
+
ToastType.Info,
|
|
1122
|
+
t('SPECIFIC_LOGISTIC_ORDER_UPDATED', 'Your logisitc order number _NUMBER_ has updated').replace('_NUMBER_', order?.order?.id ?? order.id),
|
|
1123
|
+
1000
|
|
1124
|
+
)
|
|
1125
|
+
},
|
|
1126
|
+
[logisticOrders]
|
|
1127
|
+
)
|
|
1128
|
+
|
|
1129
|
+
useEffect(() => {
|
|
1130
|
+
if (isLogisticActivated) {
|
|
1131
|
+
socket.on('request_register', handleAddAssignRequest)
|
|
1132
|
+
socket.on('request_update', handleUpdateAssignRequest)
|
|
1133
|
+
socket.on('request_cancel', handleDeleteAssignRequest)
|
|
1134
|
+
}
|
|
1135
|
+
return () => {
|
|
1136
|
+
socket.off('request_register')
|
|
1137
|
+
socket.off('request_update')
|
|
1138
|
+
socket.off('request_cancel')
|
|
1139
|
+
}
|
|
1140
|
+
}, [socket, session, isLogisticActivated])
|
|
1141
|
+
|
|
1142
|
+
useEffect(() => {
|
|
1143
|
+
if (!session.user) return
|
|
1144
|
+
|
|
1145
|
+
const userId = session.user.id
|
|
1146
|
+
const userLevel = session.user.level
|
|
1147
|
+
|
|
1148
|
+
const ordersRoom = userLevel === 0
|
|
1149
|
+
? 'orders'
|
|
1150
|
+
: `orders_${userId}`
|
|
1151
|
+
|
|
1152
|
+
const requestsRoom = `requests_${userId}`
|
|
1153
|
+
const groupsRoom = `ordergroups_${userId}`
|
|
1154
|
+
const messagesOrdersRoom = userLevel === 0 ? 'messages_orders' : `messages_orders_${userId}`
|
|
1155
|
+
const joinRooms = () => {
|
|
1156
|
+
socket.join(ordersRoom)
|
|
1157
|
+
socket.join(requestsRoom)
|
|
1158
|
+
socket.join(groupsRoom)
|
|
1159
|
+
socket.join(messagesOrdersRoom)
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
const leaveRooms = () => {
|
|
1163
|
+
socket.leave(ordersRoom)
|
|
1164
|
+
socket.leave(requestsRoom)
|
|
1165
|
+
socket.leave(groupsRoom)
|
|
1166
|
+
socket.leave(messagesOrdersRoom)
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
socket.on('disconnect', joinRooms)
|
|
1170
|
+
|
|
1171
|
+
joinRooms()
|
|
1172
|
+
|
|
1173
|
+
return () => {
|
|
1174
|
+
leaveRooms()
|
|
1175
|
+
socket.off('disconnect', joinRooms)
|
|
1176
|
+
}
|
|
1177
|
+
}, [socket, session])
|
|
1178
|
+
|
|
1179
|
+
useEffect(() => {
|
|
1180
|
+
const request = requestsState?.orders
|
|
1181
|
+
return () => {
|
|
1182
|
+
request && request.cancel && request.cancel()
|
|
1183
|
+
}
|
|
1184
|
+
}, [requestsState?.orders])
|
|
1185
|
+
|
|
1186
|
+
useEffect(() => {
|
|
1187
|
+
const handleCustomerReviewed = (review) => {
|
|
1188
|
+
let orderFound = null
|
|
1189
|
+
for (let i = 0; i < ordersStatusArray.length; i++) {
|
|
1190
|
+
const status = ordersStatusArray[i]
|
|
1191
|
+
orderFound = ordersGroup[status]?.orders?.find((_order) => _order.id === review.order_id)
|
|
1192
|
+
if (orderFound) break
|
|
1193
|
+
}
|
|
1194
|
+
if (orderFound) {
|
|
1195
|
+
const newOrderStatus = getStatusById(orderFound?.status) ?? ''
|
|
1196
|
+
orderFound.user_review = review
|
|
1197
|
+
actionOrderToTab(orderFound, newOrderStatus, 'update')
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
events.on('customer_reviewed', handleCustomerReviewed)
|
|
1201
|
+
return () => {
|
|
1202
|
+
events.off('customer_reviewed', handleCustomerReviewed)
|
|
1203
|
+
}
|
|
1204
|
+
}, [ordersGroup])
|
|
1205
|
+
|
|
1206
|
+
useEffect(() => {
|
|
1207
|
+
setCurrentTabSelected(combineTabs ? 'active' : 'pending')
|
|
1208
|
+
}, [combineTabs])
|
|
1209
|
+
|
|
1210
|
+
return (
|
|
1211
|
+
<>
|
|
1212
|
+
{UIComponent && (
|
|
1213
|
+
<UIComponent
|
|
1214
|
+
{...props}
|
|
1215
|
+
currentFilters={currentFilters}
|
|
1216
|
+
setCurrentFilters={setCurrentFilters}
|
|
1217
|
+
currentTabSelected={currentTabSelected}
|
|
1218
|
+
setCurrentTabSelected={handleSelectCurrentTab}
|
|
1219
|
+
ordersGroup={ordersGroup}
|
|
1220
|
+
setOrdersGroup={setOrdersGroup}
|
|
1221
|
+
logisticOrders={logisticOrders}
|
|
1222
|
+
messages={messages}
|
|
1223
|
+
setCombineTabsState={setCombineTabsState}
|
|
1224
|
+
ordersDeleted={ordersDeleted}
|
|
1225
|
+
setOrdersDeleted={setOrdersDeleted}
|
|
1226
|
+
setMessages={setMessages}
|
|
1227
|
+
loadOrders={loadOrders}
|
|
1228
|
+
loadLogisticOrders={loadLogisticOrders}
|
|
1229
|
+
deleteOrders={deleteOrders}
|
|
1230
|
+
loadMessages={loadMessages}
|
|
1231
|
+
loadMoreOrders={loadMoreOrders}
|
|
1232
|
+
handleClickOrder={handleClickOrder}
|
|
1233
|
+
handleClickLogisticOrder={handleClickLogisticOrder}
|
|
1234
|
+
filtered={filtered}
|
|
1235
|
+
onFiltered={setFiltered}
|
|
1236
|
+
handleChangeOrderStatus={handleChangeOrderStatus}
|
|
1237
|
+
handleSendCustomerReview={handleSendCustomerReview}
|
|
1238
|
+
ordersFormatted={formatOrdersGrouped(ordersGroup[currentTabSelected]?.orders)}
|
|
1239
|
+
isLogisticActivated={isLogisticActivated}
|
|
1240
|
+
ordersFiltered={ordersFiltered}
|
|
1241
|
+
/>
|
|
1242
|
+
)}
|
|
1243
|
+
</>
|
|
1244
|
+
)
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
OrderListGroups.defaultProps = {
|
|
1248
|
+
orderBy: '-id',
|
|
1249
|
+
orderDirection: 'desc',
|
|
1250
|
+
isNetConnected: true,
|
|
1251
|
+
paginationSettings: { initialPage: 1, pageSize: 10, controlType: 'infinity' },
|
|
1252
|
+
beforeComponents: [],
|
|
1253
|
+
afterComponents: [],
|
|
1254
|
+
beforeElements: [],
|
|
1255
|
+
afterElements: []
|
|
1256
|
+
}
|