npm-pkg-hook 1.3.8 → 1.4.0
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 +2 -10
- package/.env +5 -1
- package/dist/index.js +17953 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +17711 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +154 -0
- package/expire.json +1 -0
- package/index.d.ts +2 -0
- package/jest.config.ts +9 -0
- package/package.json +45 -36
- package/src/config/client/errors.ts +39 -0
- package/src/config/content/en.json +5 -0
- package/src/config/content/es.json +5 -0
- package/src/config/content/index.ts +16 -0
- package/src/hooks/addTenMinutes/index.ts +14 -0
- package/src/hooks/calculateLogLatHaversine/index.ts +41 -0
- package/src/hooks/completeSchedules/index.ts +22 -0
- package/src/hooks/convertToMilitaryTime/index.ts +18 -0
- package/src/hooks/generateStoreURL/index.ts +41 -0
- package/src/hooks/generateTemplate/index.ts +66 -0
- package/src/hooks/getCardType/index.ts +24 -0
- package/src/hooks/getCategoriesWithProduct/{index.js → index.ts} +7 -7
- package/src/hooks/getGlobalSession/index.ts +69 -0
- package/src/hooks/getSession/index.ts +72 -0
- package/src/hooks/getTodayTimestamps/index.ts +70 -0
- package/src/hooks/getTotalHours/index.ts +76 -0
- package/src/hooks/handleLogin/index.ts +14 -0
- package/src/hooks/index.ts +154 -0
- package/src/hooks/isTokenExpired/index.ts +17 -0
- package/src/hooks/newMessageSubscription/index.ts +28 -0
- package/src/hooks/newStoreOrderSubscription/index.ts +26 -0
- package/src/hooks/{useStatusOpenStore/helpers/index.js → statusOpenStores/helpers/index.ts} +24 -1
- package/src/hooks/statusOpenStores/index.ts +221 -0
- package/src/hooks/updateExtProductFoodsOptional/{index.js → index.ts} +15 -6
- package/src/hooks/useAcumulateDate/index.ts +18 -0
- package/src/hooks/useAllStoresPendingToRegister/index.ts +37 -0
- package/src/hooks/useAmountInput/index.ts +127 -0
- package/src/hooks/useAnimationText/{index.jsx → index.ts} +2 -2
- package/src/hooks/useAsideCart/index.ts +217 -0
- package/src/hooks/useBanner/{index.js → index.ts} +2 -1
- package/src/hooks/useCart/{queries.js → queries.ts} +11 -1
- package/src/hooks/useCart/useCart/helpers/{index.js → index.ts} +10 -6
- package/src/hooks/useCart/useCart/{index.js → index.ts} +58 -44
- package/src/hooks/useCart/useGetCart/{index.js → index.ts} +6 -3
- package/src/hooks/useCatWithProduct/{index.js → index.ts} +17 -7
- package/src/hooks/useCatWithProduct/{queries.js → queries.ts} +50 -23
- package/src/hooks/useCatWithProduct/types/index.ts +104 -0
- package/src/hooks/useCatWithProductClient/{index.js → index.ts} +19 -18
- package/src/hooks/useCatWithProductClient/{queries.js → queries.ts} +1 -0
- package/src/hooks/useCategoriesProduct/{index.js → index.ts} +3 -1
- package/src/hooks/useCategoriesProduct/{queries.js → queries.ts} +2 -2
- package/src/hooks/useCategoryInStore/index.ts +167 -0
- package/src/hooks/useCategoryInStore/{queries.js → queries.ts} +2 -2
- package/src/hooks/useCategoryStore/{index.js → index.ts} +4 -3
- package/src/hooks/useCategoryStore/{queries.js → queries.ts} +2 -2
- package/src/hooks/useChartData/{index.js → index.ts} +31 -34
- package/src/hooks/useChartData/useChartData/{index.js → index.ts} +31 -30
- package/src/hooks/useChartData/useChartDataAllOrders/{index.js → index.ts} +4 -4
- package/src/hooks/useChatRoomSubscription/index.ts +28 -0
- package/src/hooks/useCheckbox/{index.js → index.ts} +1 -1
- package/src/hooks/useCities/index.ts +14 -0
- package/src/hooks/useCities/queries.ts +12 -0
- package/src/hooks/useClients/{index.js → index.ts} +36 -10
- package/src/hooks/useClients/queries.ts +215 -0
- package/src/hooks/useColorByLetters/helpers/alea.ts +73 -0
- package/src/hooks/useColorByLetters/helpers/colors.ts +45 -0
- package/src/hooks/useColorByLetters/helpers/index.ts +24 -0
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.ts +118 -0
- package/src/hooks/useColorByLetters/index.ts +24 -0
- package/src/hooks/useConnection/index.ts +24 -0
- package/src/hooks/useCountries/index.ts +20 -0
- package/src/hooks/useCountries/queries.ts +12 -0
- package/src/hooks/useCreateDeliveryTime/index.ts +51 -0
- package/src/hooks/useCreateOrderStatusType/index.ts +134 -0
- package/src/hooks/useCreateProduct/helpers/index.ts +23 -0
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/{index.js → index.ts} +1 -1
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/{index.js → index.ts} +14 -8
- package/src/hooks/useCreateProduct/index.ts +337 -0
- package/src/hooks/useCreateStorePendingToRegister/index.ts +17 -0
- package/src/hooks/useCreateStorePendingToRegister/queries.ts +10 -0
- package/src/hooks/useDashboardComponents/index.ts +50 -0
- package/src/hooks/useDeleteExtraProductFoods/index.ts +13 -0
- package/src/hooks/useDeleteSubProductOptional/{index.js → index.ts} +5 -3
- package/src/hooks/useDeliveryTime/index.ts +29 -0
- package/src/hooks/useDepartments/index.ts +14 -0
- package/src/hooks/useDepartments/queries.ts +13 -0
- package/src/hooks/useDessert/{index.js → index.ts} +162 -114
- package/src/hooks/useDessertWithPrice/helpers/index.ts +76 -0
- package/src/hooks/useDessertWithPrice/index.ts +381 -0
- package/src/hooks/useDessertWithPrice/queries.ts +18 -0
- package/src/hooks/useDevWS/index.ts +53 -0
- package/src/hooks/useDevices/index.ts +2 -0
- package/src/hooks/useDevices/queries.ts +28 -0
- package/src/hooks/useDevices/useGetDevices.ts +28 -0
- package/src/hooks/useDevices/useRegisterDevices.ts +75 -0
- package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +21 -0
- package/src/hooks/useDownloadReports/index.ts +2 -0
- package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +105 -0
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +116 -0
- package/src/hooks/useDrag/{index.js → index.ts} +16 -0
- package/src/hooks/useDropzone/{index.js → index.ts} +2 -2
- package/src/hooks/useDynamicAuth/{index.js → index.ts} +2 -1
- package/src/hooks/useEditCategory/{index.js → index.ts} +14 -14
- package/src/hooks/useEditOneExtProductFoodOptional/index.ts +28 -0
- package/src/hooks/useEditOneExtProductFoodOptional/{queries.js → queries.ts} +2 -2
- package/src/hooks/useEditSubProductOptional/index.ts +12 -0
- package/src/hooks/useEmployee/index.ts +18 -0
- package/src/hooks/useEmployee/queries.ts +85 -0
- package/src/hooks/useEmployee/useCreateEmployee.ts +90 -0
- package/src/hooks/useEvent/{index.js → index.ts} +1 -0
- package/src/hooks/useFavoriteStores/index.ts +31 -0
- package/src/hooks/useFavoriteStores/queries.ts +54 -0
- package/src/hooks/useFetchMoreInteractions/index.jsx +26 -26
- package/src/hooks/useFilterConfigs/index.ts +173 -0
- package/src/hooks/useFingerprintjs/{index.js → index.ts} +32 -7
- package/src/hooks/useFormTools/index.ts +143 -0
- package/src/hooks/useFormatDate/index.ts +91 -0
- package/src/hooks/useFullScreenMode/{index.js → index.ts} +1 -5
- package/src/hooks/useGetAllLocationUser/index.ts +13 -0
- package/src/hooks/useGetAllLocationUser/queries.ts +44 -0
- package/src/hooks/{useSales/useGetAllSales/index.js → useGetAllSales/index.ts} +3 -2
- package/src/hooks/useGetCookies/index.ts +43 -0
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/{index.js → index.ts} +2 -1
- package/src/hooks/useGetFoodRecomended/{index.js → index.ts} +2 -1
- package/src/hooks/useGetMessagesToRoom/index.ts +23 -0
- package/src/hooks/useGetMinPrice/{index.js → index.ts} +2 -1
- package/src/hooks/useGetOneStoreRating/{index.js → index.ts} +2 -1
- package/src/hooks/useGetSalesAmountToday/index.ts +31 -0
- package/src/hooks/useGetStoreCookie/index.ts +21 -0
- package/src/hooks/useGoogleLogin/{index.js → index.ts} +14 -5
- package/src/hooks/useHover/{index.js → index.ts} +3 -0
- package/src/hooks/useImageOptimization/{index.js → index.ts} +4 -0
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +146 -0
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +54 -0
- package/src/hooks/useImageUploaderProduct/helper/index.ts +5 -0
- package/src/hooks/useImageUploaderProduct/index.ts +295 -0
- package/src/hooks/useImageWeight/{index.js → index.ts} +4 -0
- package/src/hooks/useImagesStore/index.ts +227 -0
- package/src/hooks/useImagesStore/{queries.js → queries.ts} +4 -68
- package/src/hooks/useImagesStore/utils/index.ts +4 -0
- package/src/hooks/useIncomingOrders/index.ts +11 -0
- package/src/hooks/useIncomingOrders/queries.ts +87 -0
- package/src/hooks/useIntersection/{index.js → index.ts} +1 -1
- package/src/hooks/useInventory/index.ts +2 -0
- package/src/hooks/useInventory/queries.ts +58 -0
- package/src/hooks/useInventory/useGetProductsInStock.ts +16 -0
- package/src/hooks/useInventory/useUpdateManageStock.ts +41 -0
- package/src/hooks/useLazyScript/{index.js → index.ts} +3 -0
- package/src/hooks/useLocalBackendIp/index.ts +34 -0
- package/src/hooks/useLocalSorage/{index.js → index.ts} +3 -3
- package/src/hooks/useLocationManager/index.ts +63 -0
- package/src/hooks/useLoginEmployeeInStore/index.ts +38 -0
- package/src/hooks/useLogout/helpers/BroadcastChannel.ts +74 -0
- package/src/hooks/useLogout/helpers/apiBaseUrl.ts +12 -0
- package/src/hooks/useLogout/helpers/fetchData.ts +37 -0
- package/src/hooks/useLogout/helpers/getCsrfToken.ts +37 -0
- package/src/hooks/useLogout/helpers/index.ts +65 -0
- package/src/hooks/useLogout/helpers/logger.ts +88 -0
- package/src/hooks/useLogout/helpers/parseUrl.ts +39 -0
- package/src/hooks/useLogout/index.ts +105 -0
- package/src/hooks/useManageNewOrder/helpers/index.ts +45 -0
- package/src/hooks/useManageNewOrder/index.ts +104 -0
- package/src/hooks/useManageQueryParams/index.ts +120 -0
- package/src/hooks/useMobile/index.ts +65 -0
- package/src/hooks/useModules/helpers/index.ts +1 -0
- package/src/hooks/useModules/helpers/validateModules.ts +43 -0
- package/src/hooks/useModules/index.ts +124 -0
- package/src/hooks/useMouse/index.ts +55 -0
- package/src/hooks/useOrderStatusTypes/index.ts +2 -0
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +133 -0
- package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +99 -0
- package/src/hooks/useOrders/index.ts +3 -0
- package/src/hooks/useOrders/queries.ts +99 -0
- package/src/hooks/useOrders/useChangeOrderState/index.ts +128 -0
- package/src/hooks/useOrders/{index.js → useOrdersFromStore/index.ts} +20 -18
- package/src/hooks/usePWAInstall/index.ts +38 -0
- package/src/hooks/usePaymentMethod/index.ts +3 -0
- package/src/hooks/usePaymentMethod/paymentMethod.gql.ts +62 -0
- package/src/hooks/usePaymentMethod/paymentMethod.types.ts +28 -0
- package/src/hooks/usePaymentMethod/useCreatePaymentMethod/index.ts +25 -0
- package/src/hooks/usePaymentMethod/useGetAllPaymentMethods/index.ts +19 -0
- package/src/hooks/usePaymentMethod/useGetPaymentMethod/index.ts +26 -0
- package/src/hooks/usePortFetcher/index.ts +33 -0
- package/src/hooks/usePrintSaleTicket/index.ts +68 -0
- package/src/hooks/useProductsFood/index.ts +341 -0
- package/src/hooks/useProductsFood/{queriesStore.js → queriesStore.ts} +151 -84
- package/src/hooks/useProductsFood/types/index.ts +0 -0
- package/src/hooks/useProductsFood/useEditProduct.ts +49 -0
- package/src/hooks/useProductsFood/usetagsProducts.ts +101 -0
- package/src/hooks/useProviders/useProvidersCreateStore/{index.js → index.ts} +2 -1
- package/src/hooks/useProviders/useProvidersDataStore/{index.js → index.ts} +2 -1
- package/src/hooks/useProvidersStore/{index.js → index.ts} +2 -1
- package/src/hooks/usePushNotificationOrder/index.ts +52 -0
- package/src/hooks/usePushNotifications/helpers/index.ts +123 -0
- package/src/hooks/usePushNotifications/index.ts +150 -0
- package/src/hooks/useQueryLocationsMap/index.ts +20 -0
- package/src/hooks/useQueryLocationsMap/queries.ts +40 -0
- package/src/hooks/useRatingArrayData/{index.js → index.ts} +4 -4
- package/src/hooks/useRatingArrayData/{queries.js → queries.ts} +1 -1
- package/src/hooks/useReactToPrint/index.ts +4 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/{index.js → index.ts} +2 -1
- package/src/hooks/useRemoveExtraProductFoodsOptional/{queries.js → queries.ts} +4 -4
- package/src/hooks/useReport/{index.js → index.ts} +5 -5
- package/src/hooks/useReport/{queries.js → queries.ts} +4 -55
- package/src/hooks/useRestaurant/helpers/index.ts +28 -0
- package/src/hooks/useRestaurant/helpers/manageStatusOpen.ts +26 -0
- package/src/hooks/useRestaurant/index.ts +71 -0
- package/src/hooks/useRestaurant/{queries.js → queries.ts} +2 -1
- package/src/hooks/useRoads/index.ts +20 -0
- package/src/hooks/useRoads/queries.ts +13 -0
- package/src/hooks/useRoles/index.ts +4 -0
- package/src/hooks/useRoles/queries.ts +70 -0
- package/src/hooks/useRoles/useCreateRole.ts +40 -0
- package/src/hooks/useRoles/useGetRoles.ts +37 -0
- package/src/hooks/useRoles/useRemoveRoles.ts +40 -0
- package/src/hooks/useRoles/useUpdateRolesPriority.ts +44 -0
- package/src/hooks/useSales/helpers/add-product.utils.ts +120 -0
- package/src/hooks/useSales/helpers/apply-discount-to-cart.utils.ts +292 -0
- package/src/hooks/useSales/helpers/comment-product.utils.ts +41 -0
- package/src/hooks/useSales/helpers/constants/index.ts +38 -0
- package/src/hooks/useSales/helpers/extras.utils.ts +42 -0
- package/src/hooks/useSales/helpers/filterProductsByCarProId.utils.ts +17 -0
- package/src/hooks/useSales/helpers/increment-product-quantity.utils.ts +76 -0
- package/src/hooks/useSales/helpers/index.ts +3 -0
- package/src/hooks/useSales/helpers/initializer.utils.ts +22 -0
- package/src/hooks/useSales/helpers/isStockInsufficient.ts +3 -0
- package/src/hooks/useSales/helpers/remove-product.utils.test.ts +49 -0
- package/src/hooks/useSales/helpers/remove-product.utils.ts +34 -0
- package/src/hooks/useSales/helpers/resolveProduct.ts +29 -0
- package/src/hooks/useSales/helpers/useAddToCart.ts +64 -0
- package/src/hooks/useSales/index.ts +1418 -0
- package/src/hooks/useSales/{queries.js → queries.ts} +256 -166
- package/src/hooks/useSales/types/index.ts +206 -0
- package/src/hooks/useSales/types/use-sales.types.ts +8 -0
- package/src/hooks/useSales/useGetSale.ts +21 -0
- package/src/hooks/useSales/useTotalSales.ts +24 -0
- package/src/hooks/useSaveAvailableProduct/helpers/{index.js → index.ts} +4 -4
- package/src/hooks/useSaveAvailableProduct/{index.js → index.ts} +7 -1
- package/src/hooks/useSaveLocation/index.ts +17 -0
- package/src/hooks/useSaveLocation/queries.ts +19 -0
- package/src/hooks/useSchedule/{index.jsx → index.ts} +16 -4
- package/src/hooks/useSchedule/{index.js → schedule.ts} +22 -15
- package/src/hooks/useScheduleData/{index.js → index.ts} +21 -9
- package/src/hooks/useSetImageProducts/index.ts +59 -0
- package/src/hooks/useSetImageProducts/queries.ts +18 -0
- package/src/hooks/useSetSession/{index.js → index.ts} +16 -17
- package/src/hooks/useSetupSchedule/helpers/index.ts +85 -0
- package/src/hooks/useSetupSchedule/index.ts +284 -0
- package/src/hooks/useStatusOpenStore/helpers/index.ts +124 -0
- package/src/hooks/useStatusOpenStore/{index.js → index.ts} +39 -16
- package/src/hooks/useStatusOrdersClient/{index.js → index.ts} +3 -2
- package/src/hooks/useStatusOrdersClient/{queries.js → queries.ts} +2 -2
- package/src/hooks/useStock/index.ts +1 -0
- package/src/hooks/useStock/useStockUpdatedAllSubscription.ts +40 -0
- package/src/hooks/useStockMovements/helpers/index.ts +16 -0
- package/src/hooks/useStockMovements/index.ts +39 -0
- package/src/hooks/useStore/index.ts +83 -0
- package/src/hooks/useStore/{queries.js → queries.ts} +71 -71
- package/src/hooks/useStoreContacts/{index.js → index.ts} +11 -5
- package/src/hooks/useStoreTable/index.ts +2 -0
- package/src/hooks/useStoreTable/queries.ts +47 -0
- package/src/hooks/useStoreTable/useStoreTableCreate.ts +77 -0
- package/src/hooks/useStoreTable/useStoreTables.ts +15 -0
- package/src/hooks/useSubscriptionValidation/index.ts +112 -0
- package/src/hooks/useTagProducts/index.ts +3 -0
- package/src/hooks/useTagProducts/useDeleteOneTag.ts +106 -0
- package/src/hooks/useTagProducts/useGetAllTags.ts +68 -0
- package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +157 -0
- package/src/hooks/useTheme/index.ts +65 -0
- package/src/hooks/useTimeAgo/{useTimeAgo.js → useTimeAgo.ts} +7 -7
- package/src/hooks/useTokenCards/index.ts +45 -0
- package/src/hooks/useTopProductsMovements/index.ts +27 -0
- package/src/hooks/useTotalAllSales/index.ts +25 -0
- package/src/hooks/useTotalProductsInStock/index.ts +23 -0
- package/src/hooks/useTotalProductsSold/index.ts +23 -0
- package/src/hooks/useTotalProductsSolded/index.ts +20 -0
- package/src/hooks/useUpdateCart/{index.js → index.ts} +3 -2
- package/src/hooks/useUpdateCartCookie/index.ts +60 -0
- package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
- package/src/hooks/useUpdateExistingOrders/{index.js → index.ts} +5 -11
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.ts +61 -0
- package/src/hooks/useUpdateModuleOrder/index.ts +37 -0
- package/src/hooks/useUpdateMultipleExtProduct/index.ts +34 -0
- package/src/hooks/useUpdateMultipleExtProduct/queries.ts +33 -0
- package/src/hooks/useUpdateMultipleProducts/index.ts +117 -0
- package/src/hooks/useUpdateMultipleProducts/queries.ts +51 -0
- package/src/hooks/useUploadProducts/helpers/index.ts +1 -0
- package/src/hooks/useUploadProducts/helpers/parseNumber.ts +37 -0
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.ts +73 -0
- package/src/hooks/useUploadProducts/index.ts +442 -0
- package/src/hooks/useUpsertGoal/index.ts +68 -0
- package/src/hooks/useUser/{index.js → index.ts} +11 -4
- package/src/hooks/useUser/{queries.js → queries.ts} +9 -4
- package/src/hooks/useWeeklyStockMovement/helpers/index.ts +32 -0
- package/src/hooks/useWeeklyStockMovement/index.ts +52 -0
- package/src/hooks/useWindowSize/{index.js → index.ts} +9 -2
- package/src/index.ts +12 -0
- package/src/security/index.ts +1 -0
- package/src/services/index.ts +1 -0
- package/src/utils/UtilDateRange.ts +56 -0
- package/src/utils/generateCode.ts +222 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/utils.ts +344 -0
- package/tsconfig.eslint.json +17 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +24 -0
- package/.eslintrc.js +0 -38
- package/.eslintrc.json +0 -127
- package/next.config.js +0 -126
- package/src/config/client/errors.js +0 -26
- package/src/hooks/getGlobalSession/index.js +0 -49
- package/src/hooks/getSession/index.js +0 -18
- package/src/hooks/handleLogin/index.js +0 -10
- package/src/hooks/index.js +0 -77
- package/src/hooks/useAcumulateDate/index.js +0 -16
- package/src/hooks/useAsideCart/index.js +0 -155
- package/src/hooks/useCategoryInStore/index.js +0 -98
- package/src/hooks/useClients/queries.js +0 -127
- package/src/hooks/useConnection/index.js +0 -22
- package/src/hooks/useCreateProduct/index.js +0 -291
- package/src/hooks/useDevices/index.js +0 -35
- package/src/hooks/useDevices/queries.js +0 -19
- package/src/hooks/useEditOneExtProductFoodOptional/index.js +0 -28
- package/src/hooks/useEditSubProductOptional/index.js +0 -11
- package/src/hooks/useEmployee/index.js +0 -13
- package/src/hooks/useEmployee/queries.js +0 -17
- package/src/hooks/useFavoriteStores/index.js +0 -19
- package/src/hooks/useFavoriteStores/queries.js +0 -47
- package/src/hooks/useFormTools/index.js +0 -100
- package/src/hooks/useFormatDate/index.js +0 -33
- package/src/hooks/useGetStoreCookie/index.js +0 -22
- package/src/hooks/useImagesStore/index.js +0 -183
- package/src/hooks/useLogout/helpers/BroadcastChannel.js +0 -32
- package/src/hooks/useLogout/helpers/apiBaseUrl.js +0 -8
- package/src/hooks/useLogout/helpers/fetchData.js +0 -29
- package/src/hooks/useLogout/helpers/getCsrfToken.js +0 -30
- package/src/hooks/useLogout/helpers/index.js +0 -54
- package/src/hooks/useLogout/helpers/logger.js +0 -72
- package/src/hooks/useLogout/helpers/parseUrl.js +0 -36
- package/src/hooks/useLogout/index.js +0 -46
- package/src/hooks/useManageQueryParams/index.js +0 -37
- package/src/hooks/useMobile/index.js +0 -39
- package/src/hooks/useOrders/queries.js +0 -328
- package/src/hooks/useProductsFood/index.js +0 -234
- package/src/hooks/useProductsFood/useEditProduct.js +0 -8
- package/src/hooks/useProductsFood/usetagsProducts.js +0 -94
- package/src/hooks/useRestaurant/index.js +0 -19
- package/src/hooks/useSales/helpers/index.js +0 -8
- package/src/hooks/useSales/index.js +0 -1102
- package/src/hooks/useSales/useGetSale.js +0 -13
- package/src/hooks/useSales/useTotalSales.js +0 -24
- package/src/hooks/useStore/index.js +0 -70
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -38
- package/src/index.jsx +0 -4
- package/src/utils/index.js +0 -141
- /package/src/config/client/{index.js → index.ts} +0 -0
- /package/src/hooks/getCategoriesWithProduct/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useAnimationFrame/{index.js → index.ts} +0 -0
- /package/src/hooks/useAsideCart/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useAsideCart/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useCart/{index.js → index.ts} +0 -0
- /package/src/hooks/useDeleteSubProductOptional/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useDessert/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useDynamicAuth/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useEditSubProductOptional/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useFetchJson/{index.js → index.ts} +0 -0
- /package/src/hooks/useFormatNumberPhone/{index.js → index.ts} +0 -0
- /package/src/hooks/useGenerateNumberArray/{index.js → index.ts} +0 -0
- /package/src/hooks/useGetFoodRecomended/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGetMinPrice/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGetOneStoreRating/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGoogleLogin/{loadScript.js → loadScript.ts} +0 -0
- /package/src/hooks/useGoogleLogin/{removeScript.js → removeScript.ts} +0 -0
- /package/src/hooks/useInnerHtml/{index.js → index.ts} +0 -0
- /package/src/hooks/useKeypress/{index.js → index.ts} +0 -0
- /package/src/hooks/useLocationNavigate/{index.js → index.ts} +0 -0
- /package/src/{security/index.js → hooks/useManageNewOrder/helpers/mock.ts} +0 -0
- /package/src/hooks/useMutateHeight/{index.js → index.ts} +0 -0
- /package/src/hooks/useOrderClient/{index.js → index.ts} +0 -0
- /package/src/hooks/useProviders/{index.js → index.ts} +0 -0
- /package/src/hooks/useProviders/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useProvidersStore/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useReactToPrint/{index.js → index.txt} +0 -0
- /package/src/hooks/useSaveAvailableProduct/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useSchedule/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useScroll/{index.js → index.ts} +0 -0
- /package/src/hooks/useScrollRotate/{index.js → index.ts} +0 -0
- /package/src/hooks/useSetState/{index.js → index.ts} +0 -0
- /package/src/hooks/useStatusOrdersClient/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useStoreCalendar/{index.js → index.ts} +0 -0
- /package/src/hooks/useStoreContacts/{queries.js → queries.ts} +0 -0
- /package/src/mock/dessert/{index.js → index.ts} +0 -0
- /package/src/mock/{index.js → index.ts} +0 -0
|
@@ -1,1102 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useApolloClient,
|
|
3
|
-
useLazyQuery,
|
|
4
|
-
useMutation
|
|
5
|
-
} from '@apollo/client'
|
|
6
|
-
import {
|
|
7
|
-
useCallback,
|
|
8
|
-
useEffect,
|
|
9
|
-
useReducer,
|
|
10
|
-
useMemo,
|
|
11
|
-
useState
|
|
12
|
-
} from 'react'
|
|
13
|
-
import { Cookies } from '../../cookies'
|
|
14
|
-
import { RandomCode, getCurrentDomain } from '../../utils'
|
|
15
|
-
import { useFormatDate } from '../useFormatDate'
|
|
16
|
-
import { useProductsFood } from '../useProductsFood'
|
|
17
|
-
import {
|
|
18
|
-
GET_ALL_EXTRA_PRODUCT,
|
|
19
|
-
GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
20
|
-
GET_ONE_PRODUCTS_FOOD
|
|
21
|
-
} from '../useProductsFood/queriesStore'
|
|
22
|
-
import { useStore } from '../useStore'
|
|
23
|
-
import {
|
|
24
|
-
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
25
|
-
GET_ALL_COUNT_SALES
|
|
26
|
-
} from './queries'
|
|
27
|
-
import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
28
|
-
import { useGetSale } from './useGetSale'
|
|
29
|
-
import { convertToIntegerOrFloat } from './helpers'
|
|
30
|
-
import { useCatWithProduct } from './../useCatWithProduct/index';
|
|
31
|
-
import { useCheckboxState } from '../useCheckbox';
|
|
32
|
-
export * from './useGetAllSales'
|
|
33
|
-
export { GET_ALL_COUNT_SALES } from './queries'
|
|
34
|
-
|
|
35
|
-
const initialState = {
|
|
36
|
-
PRODUCT: [],
|
|
37
|
-
totalPrice: 0,
|
|
38
|
-
sortBy: null,
|
|
39
|
-
itemsInCart: 0,
|
|
40
|
-
animateType: '',
|
|
41
|
-
startAnimateUp: '',
|
|
42
|
-
priceRange: 0,
|
|
43
|
-
counter: 0,
|
|
44
|
-
totalAmount: 0,
|
|
45
|
-
payMethodPState: 0
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const initializer = (initialValue = initialState) => {
|
|
49
|
-
return (
|
|
50
|
-
JSON.parse(
|
|
51
|
-
Cookies.get(process.env.LOCAL_SALES_STORE) || JSON.stringify(initialState)
|
|
52
|
-
) || initialValue
|
|
53
|
-
)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const useSales = ({
|
|
57
|
-
disabled,
|
|
58
|
-
sendNotification,
|
|
59
|
-
router,
|
|
60
|
-
setAlertBox
|
|
61
|
-
}) => {
|
|
62
|
-
const domain = getCurrentDomain()
|
|
63
|
-
const [loadingSale, setLoadingSale] = useState(false)
|
|
64
|
-
const [errorSale, setErrorSale] = useState(false)
|
|
65
|
-
const [modalItem, setModalItem] = useState(false)
|
|
66
|
-
const [openCommentModal, setOpenCommentModal] = useState(false)
|
|
67
|
-
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
68
|
-
const saveDataState = JSON.parse(Cookies.get(keyToSaveData) || '[]')
|
|
69
|
-
const [search, setSearch] = useState('')
|
|
70
|
-
const [datCat] = useCatWithProduct({})
|
|
71
|
-
const {
|
|
72
|
-
checkedItems,
|
|
73
|
-
disabledItems,
|
|
74
|
-
setCheckedItems,
|
|
75
|
-
handleChangeCheck
|
|
76
|
-
} = useCheckboxState(datCat, [], [])
|
|
77
|
-
const arr = checkedItems ? Array.from(checkedItems) : []
|
|
78
|
-
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
79
|
-
const [showMore, setShowMore] = useState(100)
|
|
80
|
-
const [inputValue, setInputValue] = useState('')
|
|
81
|
-
// eslint-disable-next-line no-unused-vars
|
|
82
|
-
const [_, setFilteredList] = useState([])
|
|
83
|
-
const [delivery, setDelivery] = useState(false)
|
|
84
|
-
const [print, setPrint] = useState(false)
|
|
85
|
-
const [errors, setErrors] = useState({})
|
|
86
|
-
const [values, setValues] = useState({
|
|
87
|
-
comment: '',
|
|
88
|
-
change: '',
|
|
89
|
-
cliId: '',
|
|
90
|
-
valueDelivery: ''
|
|
91
|
-
})
|
|
92
|
-
const [dataStore] = useStore()
|
|
93
|
-
const { createdAt } = dataStore || {}
|
|
94
|
-
const [code, setCode] = useState(null)
|
|
95
|
-
const [openCurrentSale, setOpenCurrentSale] = useState(null)
|
|
96
|
-
const [oneProductToComment, setOneProductToComment] = useState({})
|
|
97
|
-
const [sumExtraProducts, setSumExtraProducts] = useState(0)
|
|
98
|
-
const { yearMonthDay } = useFormatDate({ date: createdAt })
|
|
99
|
-
const [valuesDates, setValuesDates] = useState(() => {
|
|
100
|
-
return { fromDate: yearMonthDay, toDate: '' }
|
|
101
|
-
})
|
|
102
|
-
const [loadingExtraProduct, setLoadingExtraProduct] = useState(false)
|
|
103
|
-
const [dataOptional, setDataOptional] = useState([])
|
|
104
|
-
const [dataExtra, setDataExtra] = useState([])
|
|
105
|
-
|
|
106
|
-
const [registerSalesStore, { loading: loadingRegisterSale }] = useMutation(
|
|
107
|
-
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
108
|
-
{
|
|
109
|
-
onCompleted: (data) => {
|
|
110
|
-
const message = `${data?.registerSalesStore?.Response?.message}`
|
|
111
|
-
const error = data?.registerSalesStore?.Response.success
|
|
112
|
-
? 'Éxito'
|
|
113
|
-
: 'Error'
|
|
114
|
-
sendNotification({
|
|
115
|
-
backgroundColor: error ? 'success' : 'error',
|
|
116
|
-
title: error,
|
|
117
|
-
description: message
|
|
118
|
-
})
|
|
119
|
-
setAlertBox({ message, type: 'success' })
|
|
120
|
-
setOpenCurrentSale(data?.registerSalesStore?.Response.success)
|
|
121
|
-
},
|
|
122
|
-
onError: (error) => {
|
|
123
|
-
sendNotification({
|
|
124
|
-
backgroundColor: 'error',
|
|
125
|
-
title: error || 'Lo sentimo',
|
|
126
|
-
description: 'ha ocurrido un error'
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
)
|
|
131
|
-
const [product, setProduct] = useState({
|
|
132
|
-
PRODUCT: {}
|
|
133
|
-
})
|
|
134
|
-
const [productFoodsOne, { data: dataProduct }] = useLazyQuery(
|
|
135
|
-
GET_ONE_PRODUCTS_FOOD
|
|
136
|
-
)
|
|
137
|
-
const [ExtProductFoodsSubOptionalAll] = useLazyQuery(
|
|
138
|
-
GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
139
|
-
{
|
|
140
|
-
onError: () => {
|
|
141
|
-
setDataOptional([])
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
)
|
|
145
|
-
const [ExtProductFoodsAll] = useLazyQuery(GET_ALL_EXTRA_PRODUCT, {
|
|
146
|
-
onError: () => {
|
|
147
|
-
setDataExtra([])
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
const [productsFood, { loading, fetchMore }] = useProductsFood({
|
|
151
|
-
search: search?.length >= 4 ? search : '',
|
|
152
|
-
gender: [],
|
|
153
|
-
desc: [],
|
|
154
|
-
categories: arr || [],
|
|
155
|
-
toDate: valuesDates?.toDate,
|
|
156
|
-
fromDate: valuesDates?.fromDate,
|
|
157
|
-
max: showMore,
|
|
158
|
-
min: 0
|
|
159
|
-
})
|
|
160
|
-
const max = productsFood?.reduce(function (a, b) {
|
|
161
|
-
return Math.max(a, b?.ProPrice || 0)
|
|
162
|
-
}, 0)
|
|
163
|
-
const initialStateSales = {
|
|
164
|
-
PRODUCT: [],
|
|
165
|
-
totalPrice: 0,
|
|
166
|
-
sortBy: null,
|
|
167
|
-
itemsInCart: 0,
|
|
168
|
-
animateType: '',
|
|
169
|
-
startAnimateUp: '',
|
|
170
|
-
priceRange: max || 0,
|
|
171
|
-
counter: 0,
|
|
172
|
-
totalAmount: 0,
|
|
173
|
-
payMethodPState: 0
|
|
174
|
-
}
|
|
175
|
-
// HANDLESS
|
|
176
|
-
// FILTER PRODUCT DATA_DB
|
|
177
|
-
const handlePrint = ({ callback }) => {
|
|
178
|
-
if (disabled) {
|
|
179
|
-
return sendNotification({
|
|
180
|
-
title: 'Error',
|
|
181
|
-
description: 'Esta es la descr',
|
|
182
|
-
backgroundColor: 'error'
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
setPrint(!print)
|
|
186
|
-
}
|
|
187
|
-
const handleChangeFilter = (e) => {
|
|
188
|
-
return setSearch(e.target.value)
|
|
189
|
-
}
|
|
190
|
-
const handleChange = (e, error) => {
|
|
191
|
-
const { name, value } = e.target;
|
|
192
|
-
setErrors({ ...errors, [e.target.name]: error })
|
|
193
|
-
setValues((prevValues) => ({
|
|
194
|
-
...prevValues,
|
|
195
|
-
[name]: value,
|
|
196
|
-
}));
|
|
197
|
-
}
|
|
198
|
-
const onChangeInput = (e) => {
|
|
199
|
-
return setValuesDates({ ...valuesDates, [e.target.name]: e.target.value })
|
|
200
|
-
}
|
|
201
|
-
const handleChangeFilterProduct = (e) => {
|
|
202
|
-
const text = searchedInput(e.target.value)
|
|
203
|
-
if (text === undefined || text === '') {
|
|
204
|
-
return
|
|
205
|
-
}
|
|
206
|
-
const filteredData = handleList(text)
|
|
207
|
-
setFilteredList(filteredData)
|
|
208
|
-
}
|
|
209
|
-
const handleComment = (product) => {
|
|
210
|
-
if (product) {
|
|
211
|
-
setOneProductToComment(product)
|
|
212
|
-
setValues({
|
|
213
|
-
...values,
|
|
214
|
-
comment: product?.comment || ''
|
|
215
|
-
})
|
|
216
|
-
}
|
|
217
|
-
setOpenCommentModal(!openCommentModal)
|
|
218
|
-
}
|
|
219
|
-
const handleChangeNumber = useCallback(
|
|
220
|
-
(state, action) => {
|
|
221
|
-
const event = action.payload
|
|
222
|
-
const { value, index, id } = event || {}
|
|
223
|
-
const productExist = productsFood?.find((items) => {
|
|
224
|
-
return items.pId === id
|
|
225
|
-
})
|
|
226
|
-
const OneProduct = state?.PRODUCT.find((items) => {
|
|
227
|
-
return items.pId === id
|
|
228
|
-
})
|
|
229
|
-
if (value <= 0) {
|
|
230
|
-
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: OneProduct })
|
|
231
|
-
}
|
|
232
|
-
const finalQuantity = (state.PRODUCT.ProQuantity = value || 0)
|
|
233
|
-
const ARR_PRODUCT = state?.PRODUCT?.map((items, i) => {
|
|
234
|
-
return i === index
|
|
235
|
-
? {
|
|
236
|
-
...items,
|
|
237
|
-
ProQuantity: finalQuantity,
|
|
238
|
-
ProPrice: value
|
|
239
|
-
? value * productExist?.ProPrice
|
|
240
|
-
: productExist?.ProPrice
|
|
241
|
-
}
|
|
242
|
-
: items
|
|
243
|
-
})
|
|
244
|
-
return {
|
|
245
|
-
...state,
|
|
246
|
-
PRODUCT: ARR_PRODUCT,
|
|
247
|
-
counter: state.counter + 1
|
|
248
|
-
}
|
|
249
|
-
},
|
|
250
|
-
[productsFood]
|
|
251
|
-
)
|
|
252
|
-
const PRODUCT = (state, action) => {
|
|
253
|
-
const productExist = state.PRODUCT.find((items) => {
|
|
254
|
-
return items.pId === action.id
|
|
255
|
-
})
|
|
256
|
-
const OurProduct = productsFood?.find((items) => {
|
|
257
|
-
return items.pId === action.id
|
|
258
|
-
})
|
|
259
|
-
const isFree = productExist?.free
|
|
260
|
-
|
|
261
|
-
switch (action.type) {
|
|
262
|
-
case 'ADD_TO_CART':
|
|
263
|
-
return addToCartFunc(state, action)
|
|
264
|
-
case 'ADD_PRODUCT':
|
|
265
|
-
return {
|
|
266
|
-
...state,
|
|
267
|
-
// eslint-disable-next-line
|
|
268
|
-
PRODUCT: [...state?.PRODUCT, action?.payload],
|
|
269
|
-
}
|
|
270
|
-
case 'REMOVE_PRODUCT':
|
|
271
|
-
return removeFunc(state, action)
|
|
272
|
-
case 'REMOVE_PRODUCT_TO_CART':
|
|
273
|
-
return {
|
|
274
|
-
...state,
|
|
275
|
-
PRODUCT: state?.PRODUCT?.filter((t) => {
|
|
276
|
-
return t.pId !== action?.payload.pId
|
|
277
|
-
}),
|
|
278
|
-
counter: state.counter - action.payload.ProQuantity
|
|
279
|
-
}
|
|
280
|
-
case 'ON_CHANGE': {
|
|
281
|
-
return handleChangeNumber(state, action)
|
|
282
|
-
}
|
|
283
|
-
case 'REMOVE_ALL_PRODUCTS':
|
|
284
|
-
setValues({
|
|
285
|
-
comment: '',
|
|
286
|
-
change: '',
|
|
287
|
-
valueDelivery: ''
|
|
288
|
-
})
|
|
289
|
-
return {
|
|
290
|
-
...state,
|
|
291
|
-
PRODUCT: [],
|
|
292
|
-
sortBy: null,
|
|
293
|
-
counter: 0
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
case 'TOGGLE_FREE_PRODUCT':
|
|
297
|
-
return toggleFreeProducts(state, action)
|
|
298
|
-
case 'INCREMENT':
|
|
299
|
-
return {
|
|
300
|
-
...state,
|
|
301
|
-
counter: state.counter + 1,
|
|
302
|
-
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
303
|
-
return items.pId === action.id
|
|
304
|
-
? {
|
|
305
|
-
...items,
|
|
306
|
-
ProQuantity: items.ProQuantity + 1,
|
|
307
|
-
ProPrice: isFree
|
|
308
|
-
? 0
|
|
309
|
-
: (productExist.ProQuantity + 1) * OurProduct?.ProPrice
|
|
310
|
-
}
|
|
311
|
-
: items
|
|
312
|
-
})
|
|
313
|
-
}
|
|
314
|
-
case 'PUT_COMMENT':
|
|
315
|
-
return commentProducts(state, action)
|
|
316
|
-
case 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT':
|
|
317
|
-
return handleUpdateAllExtraAndOptional(state, action)
|
|
318
|
-
case 'PRICE_RANGE':
|
|
319
|
-
return {
|
|
320
|
-
...state,
|
|
321
|
-
priceRange: action.payload
|
|
322
|
-
}
|
|
323
|
-
case 'SORT':
|
|
324
|
-
return { ...state, sortBy: action.payload }
|
|
325
|
-
case 'DECREMENT':
|
|
326
|
-
return {
|
|
327
|
-
...state
|
|
328
|
-
// counter: state.counter - 1,
|
|
329
|
-
// PRODUCT: state?.PRODUCT?.map((items) => {
|
|
330
|
-
// return items.pId === action.id ? {
|
|
331
|
-
// ...items,
|
|
332
|
-
// ProQuantity: items.ProQuantity - 1,
|
|
333
|
-
// // ProPrice: ((productExist.ProQuantity + 1) * OurProduct?.ProPrice),
|
|
334
|
-
// } : items
|
|
335
|
-
// })
|
|
336
|
-
}
|
|
337
|
-
case 'PAYMENT_METHOD_TRANSACTION':
|
|
338
|
-
return {
|
|
339
|
-
...state,
|
|
340
|
-
payMethodPState: 1
|
|
341
|
-
}
|
|
342
|
-
case 'PAYMENT_METHOD_MONEY':
|
|
343
|
-
return {
|
|
344
|
-
...state,
|
|
345
|
-
payMethodPState: 0
|
|
346
|
-
}
|
|
347
|
-
default:
|
|
348
|
-
return state
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
const [data, dispatch] = useReducer(PRODUCT, initialStateSales, initializer)
|
|
352
|
-
const handleRemoveValue = useCallback(({ name, value, pId }) => {
|
|
353
|
-
setValues({
|
|
354
|
-
...values,
|
|
355
|
-
[name]: value ?? ''
|
|
356
|
-
})
|
|
357
|
-
sendNotification({
|
|
358
|
-
backgroundColor: 'sucess',
|
|
359
|
-
title: 'Comentario eliminado',
|
|
360
|
-
description: 'Has eliminado el comentario!'
|
|
361
|
-
})
|
|
362
|
-
return dispatch({
|
|
363
|
-
type: 'PUT_COMMENT',
|
|
364
|
-
payload: pId,
|
|
365
|
-
value: ''
|
|
366
|
-
})
|
|
367
|
-
}, [])
|
|
368
|
-
useEffect(() => {
|
|
369
|
-
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
|
|
370
|
-
}, [data, domain])
|
|
371
|
-
|
|
372
|
-
const handleAddOptional = ({ exOptional = null, codeCategory = null }) => {
|
|
373
|
-
if (!exOptional || !codeCategory) return
|
|
374
|
-
const item = dataOptional.find((item) => item.code === codeCategory)
|
|
375
|
-
if (!item) return
|
|
376
|
-
const idx = item.ExtProductFoodsSubOptionalAll.findIndex(
|
|
377
|
-
(el) => el.opSubExPid === exOptional
|
|
378
|
-
)
|
|
379
|
-
if (item && idx !== -1) {
|
|
380
|
-
const updatedItem = {
|
|
381
|
-
...item,
|
|
382
|
-
ExtProductFoodsSubOptionalAll: [
|
|
383
|
-
...item.ExtProductFoodsSubOptionalAll.slice(0, idx),
|
|
384
|
-
{
|
|
385
|
-
...item.ExtProductFoodsSubOptionalAll[idx],
|
|
386
|
-
check: !item.ExtProductFoodsSubOptionalAll[idx].check
|
|
387
|
-
},
|
|
388
|
-
...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
|
|
389
|
-
]
|
|
390
|
-
}
|
|
391
|
-
const newData = dataOptional.map((el) =>
|
|
392
|
-
el.code === codeCategory ? updatedItem : el
|
|
393
|
-
)
|
|
394
|
-
setDataOptional(() => [...newData])
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
function handleUpdateAllExtraAndOptional (state, action) {
|
|
399
|
-
return {
|
|
400
|
-
...state,
|
|
401
|
-
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
402
|
-
return items.pId === action.payload
|
|
403
|
-
? {
|
|
404
|
-
...items,
|
|
405
|
-
dataOptional: action.dataOptional || [],
|
|
406
|
-
dataExtra: action.dataExtra || []
|
|
407
|
-
}
|
|
408
|
-
: items
|
|
409
|
-
})
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Description
|
|
415
|
-
* @returns {any}
|
|
416
|
-
* */
|
|
417
|
-
useEffect(() => {
|
|
418
|
-
const arr =
|
|
419
|
-
dataExtra?.length > 0
|
|
420
|
-
? dataExtra?.filter((p) => {
|
|
421
|
-
return p.quantity !== 0
|
|
422
|
-
})
|
|
423
|
-
: []
|
|
424
|
-
const val = arr.findIndex((item) => item.quantity !== 0)
|
|
425
|
-
if (val === -1) {
|
|
426
|
-
setSumExtraProducts(0)
|
|
427
|
-
}
|
|
428
|
-
function sumNewExtraPrice () {
|
|
429
|
-
let sum = 0
|
|
430
|
-
arr.forEach((obj) => {
|
|
431
|
-
sum += obj.newExtraPrice ?? 0
|
|
432
|
-
})
|
|
433
|
-
if (arr.length === 0) {
|
|
434
|
-
setSumExtraProducts(0)
|
|
435
|
-
}
|
|
436
|
-
setSumExtraProducts(sum)
|
|
437
|
-
return sum
|
|
438
|
-
}
|
|
439
|
-
if (arr.length > 0) {
|
|
440
|
-
sumNewExtraPrice()
|
|
441
|
-
}
|
|
442
|
-
}, [dataExtra])
|
|
443
|
-
|
|
444
|
-
function handleUpdateAllExtra () {
|
|
445
|
-
try {
|
|
446
|
-
if (!product?.PRODUCT?.pId) {
|
|
447
|
-
return sendNotification({
|
|
448
|
-
title: 'Error',
|
|
449
|
-
backgroundColor: 'error',
|
|
450
|
-
description: 'Ha ocurrido un error'
|
|
451
|
-
})
|
|
452
|
-
}
|
|
453
|
-
const filteredDataOptional = dataOptional
|
|
454
|
-
.map((obj) => {
|
|
455
|
-
const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
|
|
456
|
-
(subObj) => subObj?.check === true
|
|
457
|
-
)
|
|
458
|
-
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
459
|
-
if (filteredSubOptions?.length === 0) {
|
|
460
|
-
return null
|
|
461
|
-
}
|
|
462
|
-
return { ...obj, ExtProductFoodsSubOptionalAll: filteredSubOptions }
|
|
463
|
-
})
|
|
464
|
-
.filter((obj) => obj !== null) // Elimine todos los objetos nulos del arreglo
|
|
465
|
-
const filteredDataExtra = dataExtra?.filter((p) => p?.quantity !== undefined && p?.quantity !== 0);
|
|
466
|
-
if (product?.PRODUCT?.pId) {
|
|
467
|
-
dispatch({
|
|
468
|
-
type: 'PUT_EXTRA_PRODUCTS_AND_OPTIONAL_PRODUCT',
|
|
469
|
-
payload: product.PRODUCT.pId,
|
|
470
|
-
dataOptional: filteredDataOptional,
|
|
471
|
-
dataExtra: filteredDataExtra
|
|
472
|
-
})
|
|
473
|
-
}
|
|
474
|
-
} catch (_error) {
|
|
475
|
-
return sendNotification({
|
|
476
|
-
title: 'Error',
|
|
477
|
-
backgroundColor: 'error',
|
|
478
|
-
description: 'No se puedo actualizar el producto'
|
|
479
|
-
})
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
function handleIncrementExtra({ Adicionales, index }) {
|
|
484
|
-
const { pId } = product?.PRODUCT || {};
|
|
485
|
-
const exPid = Adicionales.exPid || null;
|
|
486
|
-
|
|
487
|
-
if (exPid && pId) {
|
|
488
|
-
const newExtra = dataExtra.map((producto) => {
|
|
489
|
-
if (exPid === producto.exPid) {
|
|
490
|
-
const initialQuantity = producto?.quantity ? producto?.quantity : 0;
|
|
491
|
-
const newQuantity = initialQuantity + 1;
|
|
492
|
-
const newExtraPrice = producto.extraPrice * newQuantity;
|
|
493
|
-
|
|
494
|
-
return {
|
|
495
|
-
...producto,
|
|
496
|
-
quantity: newQuantity,
|
|
497
|
-
newExtraPrice: newExtraPrice,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
return producto;
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
setDataExtra(newExtra);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
function handleDecrementExtra ({ Adicionales, index }) {
|
|
509
|
-
const { pId } = product?.PRODUCT || {}
|
|
510
|
-
const exPid = Adicionales.exPid || null
|
|
511
|
-
|
|
512
|
-
// Comprobar que el objeto Adicionales existe en dataExtra
|
|
513
|
-
const extraIndex = dataExtra.findIndex((extra) => extra.exPid === exPid)
|
|
514
|
-
if (extraIndex === -1) {
|
|
515
|
-
return
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
if (pId && exPid && extraIndex !== -1) {
|
|
519
|
-
const newExtra = dataExtra.map((producto, i) => {
|
|
520
|
-
if (exPid === producto.exPid) {
|
|
521
|
-
// Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
|
|
522
|
-
const { quantity = 0, extraPrice = 0 } = producto
|
|
523
|
-
|
|
524
|
-
// Calcula la nueva cantidad, evitando que sea negativa
|
|
525
|
-
const newQuantity = Math.max(quantity - 1, 0)
|
|
526
|
-
|
|
527
|
-
// Calcula el nuevo precio extra
|
|
528
|
-
const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
|
|
529
|
-
|
|
530
|
-
return {
|
|
531
|
-
...producto,
|
|
532
|
-
quantity: newQuantity,
|
|
533
|
-
newExtraPrice
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
return producto
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
// Actualiza el estado de dataExtra con el nuevo array
|
|
540
|
-
setDataExtra(newExtra)
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
/**
|
|
544
|
-
* Agrega un producto al carrito de compras.
|
|
545
|
-
* @param {Object} state - Estado actual del carrito.
|
|
546
|
-
* @param {Object} action - Acción que contiene los datos del producto a agregar.
|
|
547
|
-
* @param {string} action.payload.pId - ID del producto.
|
|
548
|
-
* @param {string} action.payload.pName - Nombre del producto.
|
|
549
|
-
* @param {string[]} action.payload.getOneTags - Etiquetas del producto.
|
|
550
|
-
* @param {string} action.payload.ProDescription - Descripción del producto.
|
|
551
|
-
* @param {string} action.payload.ProImage - URL de la imagen del producto.
|
|
552
|
-
* @param {number} action.payload.ProPrice - Precio del producto.
|
|
553
|
-
* @returns {Object} Nuevo estado del carrito con el producto agregado.
|
|
554
|
-
*/
|
|
555
|
-
function addToCartFunc (state, action) {
|
|
556
|
-
const {
|
|
557
|
-
pId,
|
|
558
|
-
pName,
|
|
559
|
-
getOneTags,
|
|
560
|
-
ProDescription,
|
|
561
|
-
ProImage,
|
|
562
|
-
ProPrice
|
|
563
|
-
} = action.payload
|
|
564
|
-
|
|
565
|
-
const productExist = state?.PRODUCT.find((item) => item.pId === pId)
|
|
566
|
-
const OurProduct = productsFood?.find((item) => item.pId === pId)
|
|
567
|
-
const isFree = productExist?.free
|
|
568
|
-
|
|
569
|
-
const updatedProduct = {
|
|
570
|
-
pId,
|
|
571
|
-
pName,
|
|
572
|
-
getOneTags,
|
|
573
|
-
unitPrice: OurProduct?.ProPrice,
|
|
574
|
-
ProDescription,
|
|
575
|
-
ProImage,
|
|
576
|
-
ProPrice,
|
|
577
|
-
ProQuantity: 1
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
if (!productExist) {
|
|
581
|
-
return {
|
|
582
|
-
...state,
|
|
583
|
-
counter: state.counter + 1,
|
|
584
|
-
totalAmount: state.totalAmount + ProPrice,
|
|
585
|
-
startAnimateUp: 'start-animate-up',
|
|
586
|
-
PRODUCT: [...state.PRODUCT, updatedProduct]
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
return {
|
|
590
|
-
...state,
|
|
591
|
-
counter: state.counter + 1,
|
|
592
|
-
totalAmount: state.totalAmount + ProPrice,
|
|
593
|
-
startAnimateUp: 'start-animate-up',
|
|
594
|
-
PRODUCT: state.PRODUCT.map((item) => {
|
|
595
|
-
if (item.pId === pId) {
|
|
596
|
-
return {
|
|
597
|
-
...item,
|
|
598
|
-
getOneTags: OurProduct.genderTags,
|
|
599
|
-
unitPrice: OurProduct?.ProPrice,
|
|
600
|
-
ProPrice: isFree ? 0 : (productExist.ProQuantity + 1) * OurProduct?.ProPrice,
|
|
601
|
-
ProQuantity: productExist.ProQuantity + +1,
|
|
602
|
-
free: !!isFree
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
|
-
return item
|
|
606
|
-
})
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
function removeFunc (state, action) {
|
|
611
|
-
const productExist = state?.PRODUCT.find((items) => {
|
|
612
|
-
return items.pId === action.payload.pId
|
|
613
|
-
})
|
|
614
|
-
const OurProduct = productsFood.find((items) => {
|
|
615
|
-
return items.pId === action.payload.pId
|
|
616
|
-
})
|
|
617
|
-
return {
|
|
618
|
-
...state,
|
|
619
|
-
counter: state.counter - 1,
|
|
620
|
-
totalAmount: state.totalAmount - action.payload.ProPrice,
|
|
621
|
-
PRODUCT:
|
|
622
|
-
action.payload.ProQuantity > 1
|
|
623
|
-
? state.PRODUCT.map((items) => {
|
|
624
|
-
return items.pId === action.payload.pId
|
|
625
|
-
? {
|
|
626
|
-
...items,
|
|
627
|
-
pId: action.payload.pId,
|
|
628
|
-
ProQuantity: items.ProQuantity - 1,
|
|
629
|
-
ProPrice: productExist.ProPrice - OurProduct?.ProPrice
|
|
630
|
-
}
|
|
631
|
-
: items
|
|
632
|
-
})
|
|
633
|
-
: state.PRODUCT.filter((items) => {
|
|
634
|
-
return items.pId !== action.payload.pId
|
|
635
|
-
})
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
// TOGGLE_FREE_PRODUCT
|
|
640
|
-
function toggleFreeProducts (state, action) {
|
|
641
|
-
const productExist = productsFood.find((items) => {
|
|
642
|
-
return items.pId === action.payload.pId
|
|
643
|
-
})
|
|
644
|
-
return {
|
|
645
|
-
...state,
|
|
646
|
-
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
647
|
-
return items.pId === action.payload.pId
|
|
648
|
-
? {
|
|
649
|
-
...items,
|
|
650
|
-
free: !items.free,
|
|
651
|
-
ProPrice: items.ProPrice
|
|
652
|
-
? 0
|
|
653
|
-
: items.ProQuantity * productExist?.ProPrice
|
|
654
|
-
}
|
|
655
|
-
: items
|
|
656
|
-
})
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
// COMMENT_FREE_PRODUCT
|
|
661
|
-
function commentProducts (state, action, deleteValue) {
|
|
662
|
-
if (values.comment) {
|
|
663
|
-
sendNotification({
|
|
664
|
-
backgroundColor: 'success',
|
|
665
|
-
title: deleteValue ? 'Comentario eliminado' : 'Producto comentado',
|
|
666
|
-
description: deleteValue ? 'Has eliminado el comentario!' : 'Has comentado!'
|
|
667
|
-
})
|
|
668
|
-
}
|
|
669
|
-
setOpenCommentModal(!openCommentModal)
|
|
670
|
-
return {
|
|
671
|
-
...state,
|
|
672
|
-
PRODUCT: state?.PRODUCT?.map((items) => {
|
|
673
|
-
return items.pId === action.payload
|
|
674
|
-
? {
|
|
675
|
-
...items,
|
|
676
|
-
comment: deleteValue ? '' : values.comment
|
|
677
|
-
}
|
|
678
|
-
: items
|
|
679
|
-
})
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
const getSortedProduct = useCallback((data, sort) => {
|
|
684
|
-
if (sort && sort === 'PRICE_HIGH_TO_LOW') {
|
|
685
|
-
return data.sort((a, b) => {
|
|
686
|
-
return b.ProPrice - a.ProPrice
|
|
687
|
-
})
|
|
688
|
-
}
|
|
689
|
-
if (sort && sort === 'PRICE_LOW_TO_HIGH') {
|
|
690
|
-
return data.sort((a, b) => {
|
|
691
|
-
return a.ProPrice - b.ProPrice
|
|
692
|
-
})
|
|
693
|
-
}
|
|
694
|
-
return data
|
|
695
|
-
}, [])
|
|
696
|
-
|
|
697
|
-
const PriceRangeFunc = (products, price) => {
|
|
698
|
-
return (
|
|
699
|
-
products?.length > 0 &&
|
|
700
|
-
products?.filter((items) => {
|
|
701
|
-
return items?.ProPrice >= price
|
|
702
|
-
})
|
|
703
|
-
)
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
const sortedProduct = useMemo(() => {
|
|
707
|
-
return getSortedProduct(data.PRODUCT, data.sortBy)
|
|
708
|
-
}, [data.PRODUCT, data.sortBy, getSortedProduct])
|
|
709
|
-
|
|
710
|
-
const finalFilter = PriceRangeFunc(sortedProduct, data.priceRange)
|
|
711
|
-
|
|
712
|
-
const handleList = (text) => {
|
|
713
|
-
const inputText = text.toLowerCase()
|
|
714
|
-
let dataList = []
|
|
715
|
-
dataList = finalFilter.filter((item) => {
|
|
716
|
-
return item.pName.toLowerCase().includes(inputText)
|
|
717
|
-
})
|
|
718
|
-
return dataList
|
|
719
|
-
}
|
|
720
|
-
const searchedInput = (words) => {
|
|
721
|
-
setInputValue(words)
|
|
722
|
-
const n = words.split(' ')
|
|
723
|
-
if (n.length !== 0) {
|
|
724
|
-
if (n[n.length - 1] === '') {
|
|
725
|
-
n.pop()
|
|
726
|
-
}
|
|
727
|
-
return n[n.length - 1]
|
|
728
|
-
}
|
|
729
|
-
return ''
|
|
730
|
-
}
|
|
731
|
-
const arrayProduct =
|
|
732
|
-
data?.PRODUCT?.length > 0
|
|
733
|
-
? data?.PRODUCT?.map((product) => {
|
|
734
|
-
const filteredDataExtra =
|
|
735
|
-
product?.dataExtra?.map(({ __typename, ...rest }) => rest) ?? []
|
|
736
|
-
const dataOptional = product?.dataOptional?.map(
|
|
737
|
-
({ __typename, ...product }) => {
|
|
738
|
-
const { ExtProductFoodsSubOptionalAll, ...rest } = product
|
|
739
|
-
const adjustedSubOptionalAll = ExtProductFoodsSubOptionalAll?.map(
|
|
740
|
-
(subOption) => {
|
|
741
|
-
const { __typename, ...subOptionRest } = subOption
|
|
742
|
-
return subOptionRest
|
|
743
|
-
}
|
|
744
|
-
)
|
|
745
|
-
return {
|
|
746
|
-
...rest,
|
|
747
|
-
ExtProductFoodsSubOptionalAll: adjustedSubOptionalAll
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
)
|
|
751
|
-
const refCodePid = RandomCode(20)
|
|
752
|
-
return {
|
|
753
|
-
pId: product?.pId,
|
|
754
|
-
refCodePid,
|
|
755
|
-
id: values?.cliId,
|
|
756
|
-
cantProducts: parseInt(
|
|
757
|
-
product?.ProQuantity ? product?.ProQuantity : 0
|
|
758
|
-
),
|
|
759
|
-
comments: product?.comment ?? '',
|
|
760
|
-
dataOptional: dataOptional ?? [],
|
|
761
|
-
dataExtra: filteredDataExtra || [],
|
|
762
|
-
ProPrice: product.ProPrice
|
|
763
|
-
}
|
|
764
|
-
})
|
|
765
|
-
: []
|
|
766
|
-
const finalArrayProduct = arrayProduct.map((item) => {
|
|
767
|
-
const totalExtra = item.dataExtra.reduce(
|
|
768
|
-
(accumulator, extra) => accumulator + extra.newExtraPrice,
|
|
769
|
-
0
|
|
770
|
-
)
|
|
771
|
-
return { ...item, totalExtra }
|
|
772
|
-
})
|
|
773
|
-
|
|
774
|
-
let totalSale = 0
|
|
775
|
-
function sumProPriceAndTotalExtra (data) {
|
|
776
|
-
return data.map((item) => {
|
|
777
|
-
const totalExtra = item.dataExtra.reduce((acc, curr) => {
|
|
778
|
-
const newExtraPrice = parseFloat(curr.newExtraPrice)
|
|
779
|
-
if (isNaN(newExtraPrice)) {
|
|
780
|
-
return acc
|
|
781
|
-
}
|
|
782
|
-
return acc + newExtraPrice
|
|
783
|
-
}, 0)
|
|
784
|
-
const total = item.ProPrice + totalExtra
|
|
785
|
-
return { ...item, totalExtra, total }
|
|
786
|
-
})
|
|
787
|
-
}
|
|
788
|
-
useEffect(() => {
|
|
789
|
-
const dataCountTotal = sumProPriceAndTotalExtra(finalArrayProduct)
|
|
790
|
-
dataCountTotal.forEach((a) => {
|
|
791
|
-
const { total } = a || {}
|
|
792
|
-
totalSale += total
|
|
793
|
-
setTotalProductPrice(Math.abs(totalSale))
|
|
794
|
-
})
|
|
795
|
-
if (data.PRODUCT.length === 0) {
|
|
796
|
-
setTotalProductPrice(0)
|
|
797
|
-
}
|
|
798
|
-
}, [totalProductPrice, totalSale, data, finalArrayProduct])
|
|
799
|
-
|
|
800
|
-
const [discount, setDiscount] = useState({
|
|
801
|
-
price: totalProductPrice || 0,
|
|
802
|
-
discount: 0
|
|
803
|
-
})
|
|
804
|
-
|
|
805
|
-
function applyDiscount (percentage) {
|
|
806
|
-
const validateCondition =
|
|
807
|
-
isNaN(percentage) || percentage < 0 || percentage > 100
|
|
808
|
-
|
|
809
|
-
if (validateCondition) {
|
|
810
|
-
return sendNotification({
|
|
811
|
-
title: 'Error',
|
|
812
|
-
backgroundColor: 'error',
|
|
813
|
-
description: 'el descuento debe ser un número entre 0 y 100%'
|
|
814
|
-
})
|
|
815
|
-
}
|
|
816
|
-
const decimal = parseFloat(percentage) / 100
|
|
817
|
-
const result = decimal * parseFloat(totalProductPrice)
|
|
818
|
-
setDiscount({ price: result, discount: percentage })
|
|
819
|
-
|
|
820
|
-
return { price: result, discount: percentage }
|
|
821
|
-
}
|
|
822
|
-
const totalProductsPrice = totalProductPrice
|
|
823
|
-
const client = useApolloClient()
|
|
824
|
-
const { getOnePedidoStore } = useGetSale()
|
|
825
|
-
const handleSubmit = () => {
|
|
826
|
-
|
|
827
|
-
if (errors?.change || errors?.valueDelivery) {
|
|
828
|
-
return sendNotification({
|
|
829
|
-
title: 'error',
|
|
830
|
-
backgroundColor: 'warning',
|
|
831
|
-
description: 'Completa los campos requeridos'
|
|
832
|
-
})
|
|
833
|
-
}
|
|
834
|
-
setLoadingSale(true)
|
|
835
|
-
const code = RandomCode(10)
|
|
836
|
-
setCode(code)
|
|
837
|
-
function convertirAEntero(cadena) {
|
|
838
|
-
if (typeof cadena === 'string') {
|
|
839
|
-
const numeroEntero = parseInt(cadena?.replace('.', ''));
|
|
840
|
-
return numeroEntero
|
|
841
|
-
}
|
|
842
|
-
return cadena || 0
|
|
843
|
-
}
|
|
844
|
-
return registerSalesStore({
|
|
845
|
-
variables: {
|
|
846
|
-
input: finalArrayProduct || [],
|
|
847
|
-
id: values?.cliId,
|
|
848
|
-
pCodeRef: code,
|
|
849
|
-
change: convertirAEntero(values.change),
|
|
850
|
-
valueDelivery: convertirAEntero(values.valueDelivery),
|
|
851
|
-
payMethodPState: data.payMethodPState,
|
|
852
|
-
pickUp: 1,
|
|
853
|
-
discount: discount.discount || 0,
|
|
854
|
-
totalProductsPrice: convertirAEntero(totalProductsPrice) || 0
|
|
855
|
-
}
|
|
856
|
-
})
|
|
857
|
-
.then((responseRegisterR) => {
|
|
858
|
-
if (responseRegisterR) {
|
|
859
|
-
const { data } = responseRegisterR || {}
|
|
860
|
-
const { registerSalesStore } = data || {}
|
|
861
|
-
const { Response } = registerSalesStore || {}
|
|
862
|
-
if (Response && Response.success === true) {
|
|
863
|
-
setPrint(false)
|
|
864
|
-
client.query({
|
|
865
|
-
query: GET_ALL_COUNT_SALES,
|
|
866
|
-
fetchPolicy: 'network-only',
|
|
867
|
-
onCompleted: (data) => {
|
|
868
|
-
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
869
|
-
}
|
|
870
|
-
})
|
|
871
|
-
getOnePedidoStore({
|
|
872
|
-
variables: {
|
|
873
|
-
pCodeRef: code || ''
|
|
874
|
-
}
|
|
875
|
-
}).then((responseSale) => {
|
|
876
|
-
if (responseSale?.data?.getOnePedidoStore) {
|
|
877
|
-
const currentSale = responseSale?.data?.getOnePedidoStore || {}
|
|
878
|
-
const inComingCodeRef = currentSale?.pCodeRef || null
|
|
879
|
-
if (!inComingCodeRef) return
|
|
880
|
-
client.cache.modify({
|
|
881
|
-
fields: {
|
|
882
|
-
getAllOrdersFromStore (existingOrders = []) {
|
|
883
|
-
try {
|
|
884
|
-
const newGetAllOrdersFromStore = updateExistingOrders(existingOrders, inComingCodeRef, 4, currentSale)
|
|
885
|
-
return newGetAllOrdersFromStore
|
|
886
|
-
} catch (e) {
|
|
887
|
-
return existingOrders
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
})
|
|
892
|
-
}
|
|
893
|
-
})
|
|
894
|
-
router.push(
|
|
895
|
-
{
|
|
896
|
-
query: {
|
|
897
|
-
...router.query,
|
|
898
|
-
saleId: code
|
|
899
|
-
}
|
|
900
|
-
},
|
|
901
|
-
undefined,
|
|
902
|
-
{ shallow: true }
|
|
903
|
-
)
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
setLoadingSale(false)
|
|
907
|
-
})
|
|
908
|
-
.catch(() => {
|
|
909
|
-
setLoadingSale(false)
|
|
910
|
-
setErrorSale(true)
|
|
911
|
-
setPrint(false)
|
|
912
|
-
})
|
|
913
|
-
.finally(() => {
|
|
914
|
-
setPrint(false)
|
|
915
|
-
setLoadingSale(false)
|
|
916
|
-
})
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
const handleProduct = async (PRODUCT) => {
|
|
920
|
-
setLoadingExtraProduct(true)
|
|
921
|
-
const { pId } = PRODUCT || {}
|
|
922
|
-
try {
|
|
923
|
-
const originalArray = data.PRODUCT.find((item) => {
|
|
924
|
-
return item.pId === pId
|
|
925
|
-
})
|
|
926
|
-
// OPTIONAL
|
|
927
|
-
productFoodsOne({ variables: { pId } })
|
|
928
|
-
const optionalAll = await ExtProductFoodsSubOptionalAll({
|
|
929
|
-
variables: { pId }
|
|
930
|
-
})
|
|
931
|
-
const optionalFetch = optionalAll.data.ExtProductFoodsOptionalAll
|
|
932
|
-
setDataOptional(optionalFetch || [])
|
|
933
|
-
const existOptionalCookies = originalArray?.dataOptional
|
|
934
|
-
const filteredDataOptional = existOptionalCookies?.length
|
|
935
|
-
? existOptionalCookies
|
|
936
|
-
?.map((obj) => {
|
|
937
|
-
const filteredSubOptions =
|
|
938
|
-
obj.ExtProductFoodsSubOptionalAll.filter(
|
|
939
|
-
(subObj) => subObj.check === true
|
|
940
|
-
)
|
|
941
|
-
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
942
|
-
if (filteredSubOptions.length === 0) {
|
|
943
|
-
return null
|
|
944
|
-
}
|
|
945
|
-
return {
|
|
946
|
-
...obj,
|
|
947
|
-
ExtProductFoodsSubOptionalAll: filteredSubOptions
|
|
948
|
-
}
|
|
949
|
-
})
|
|
950
|
-
.filter((obj) => obj !== null)
|
|
951
|
-
: []
|
|
952
|
-
|
|
953
|
-
// Actualizar optionalAll.data.ExtProductFoodsSubOptionalAll con los valores actualizados de originalArray2.ExtProductFoodsSubOptionalAll
|
|
954
|
-
if (optionalFetch && filteredDataOptional) {
|
|
955
|
-
const updateOption = optionalFetch
|
|
956
|
-
.map((obj) => {
|
|
957
|
-
const matchingArray = filteredDataOptional.find(
|
|
958
|
-
(o) => o && o.opExPid === obj.opExPid
|
|
959
|
-
)
|
|
960
|
-
if (!matchingArray) {
|
|
961
|
-
return obj
|
|
962
|
-
}
|
|
963
|
-
const extProductFoodsSubOptionalAll =
|
|
964
|
-
obj.ExtProductFoodsSubOptionalAll || []
|
|
965
|
-
const updateExtProductFoodsSubOptionalAll =
|
|
966
|
-
extProductFoodsSubOptionalAll.map((subObj) => {
|
|
967
|
-
const newItem =
|
|
968
|
-
matchingArray.ExtProductFoodsSubOptionalAll.find(
|
|
969
|
-
(newItem) =>
|
|
970
|
-
newItem && newItem.opSubExPid === subObj.opSubExPid
|
|
971
|
-
)
|
|
972
|
-
if (newItem) {
|
|
973
|
-
return {
|
|
974
|
-
...subObj,
|
|
975
|
-
check: true
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
return subObj
|
|
979
|
-
})
|
|
980
|
-
return {
|
|
981
|
-
...obj,
|
|
982
|
-
ExtProductFoodsSubOptionalAll:
|
|
983
|
-
updateExtProductFoodsSubOptionalAll
|
|
984
|
-
}
|
|
985
|
-
})
|
|
986
|
-
.filter((obj) => obj)
|
|
987
|
-
if (existOptionalCookies) {
|
|
988
|
-
setDataOptional(updateOption || [])
|
|
989
|
-
} else {
|
|
990
|
-
setDataOptional(optionalAll.data.ExtProductFoodsOptionalAll || [])
|
|
991
|
-
}
|
|
992
|
-
}
|
|
993
|
-
// NO OPTIONAL
|
|
994
|
-
const extProduct = await ExtProductFoodsAll({ variables: { pId } })
|
|
995
|
-
let finalData
|
|
996
|
-
if (!originalArray?.dataExtra) {
|
|
997
|
-
finalData = extProduct?.data?.ExtProductFoodsAll
|
|
998
|
-
} else {
|
|
999
|
-
const filteredData = originalArray.dataExtra.filter((item) =>
|
|
1000
|
-
extProduct?.data?.ExtProductFoodsAll.some(
|
|
1001
|
-
(newItem) => newItem.exPid === item.exPid
|
|
1002
|
-
)
|
|
1003
|
-
)
|
|
1004
|
-
finalData = originalArray?.dataExtra?.concat(
|
|
1005
|
-
extProduct?.data?.ExtProductFoodsAll?.filter(
|
|
1006
|
-
(item) =>
|
|
1007
|
-
!filteredData?.some(
|
|
1008
|
-
(filteredItem) => filteredItem.exPid === item.exPid
|
|
1009
|
-
)
|
|
1010
|
-
)
|
|
1011
|
-
)
|
|
1012
|
-
}
|
|
1013
|
-
setDataExtra(finalData)
|
|
1014
|
-
setProduct(() => {
|
|
1015
|
-
return {
|
|
1016
|
-
PRODUCT
|
|
1017
|
-
}
|
|
1018
|
-
})
|
|
1019
|
-
setLoadingExtraProduct(false)
|
|
1020
|
-
} catch (error) {
|
|
1021
|
-
setLoadingExtraProduct(false)
|
|
1022
|
-
sendNotification({
|
|
1023
|
-
title: 'error',
|
|
1024
|
-
backgroundColor: 'error',
|
|
1025
|
-
description: error || 'Lo sentimos, ocurrió un error'
|
|
1026
|
-
})
|
|
1027
|
-
}
|
|
1028
|
-
}
|
|
1029
|
-
const handleCleanFilter = () => {
|
|
1030
|
-
setValues({})
|
|
1031
|
-
setValuesDates({ fromDate: yearMonthDay, toDate: '' })
|
|
1032
|
-
}
|
|
1033
|
-
const disabledModalItems = dataOptional?.length > 0 || dataExtra?.length > 0
|
|
1034
|
-
return {
|
|
1035
|
-
loading: loading || loadingSale,
|
|
1036
|
-
loadingExtraProduct,
|
|
1037
|
-
disabledModalItems: !disabledModalItems,
|
|
1038
|
-
loadingRegisterSale,
|
|
1039
|
-
errorSale,
|
|
1040
|
-
openCurrentSale,
|
|
1041
|
-
code,
|
|
1042
|
-
totalProductPrice,
|
|
1043
|
-
saveDataState,
|
|
1044
|
-
product,
|
|
1045
|
-
data,
|
|
1046
|
-
openCommentModal,
|
|
1047
|
-
inputValue,
|
|
1048
|
-
arrayProduct,
|
|
1049
|
-
delivery,
|
|
1050
|
-
valuesDates,
|
|
1051
|
-
print,
|
|
1052
|
-
finalFilter,
|
|
1053
|
-
showMore,
|
|
1054
|
-
max,
|
|
1055
|
-
search,
|
|
1056
|
-
values,
|
|
1057
|
-
initialStateSales,
|
|
1058
|
-
productsFood,
|
|
1059
|
-
modalItem,
|
|
1060
|
-
sumExtraProducts,
|
|
1061
|
-
oneProductToComment: oneProductToComment ?? null,
|
|
1062
|
-
dataProduct: dataProduct?.productFoodsOne || {},
|
|
1063
|
-
dataOptional: dataOptional || [],
|
|
1064
|
-
dataExtra: dataExtra || [],
|
|
1065
|
-
fetchMore,
|
|
1066
|
-
discount,
|
|
1067
|
-
checkedItems,
|
|
1068
|
-
datCat,
|
|
1069
|
-
disabledItems,
|
|
1070
|
-
setCheckedItems,
|
|
1071
|
-
handleChangeCheck,
|
|
1072
|
-
errors,
|
|
1073
|
-
handleUpdateAllExtra,
|
|
1074
|
-
dispatch,
|
|
1075
|
-
handleComment,
|
|
1076
|
-
setModalItem,
|
|
1077
|
-
handleChangeFilter,
|
|
1078
|
-
handleProduct,
|
|
1079
|
-
handleChange,
|
|
1080
|
-
setOpenCurrentSale,
|
|
1081
|
-
setErrors,
|
|
1082
|
-
onChangeInput,
|
|
1083
|
-
handleRemoveValue,
|
|
1084
|
-
applyDiscount,
|
|
1085
|
-
setDelivery,
|
|
1086
|
-
setValues,
|
|
1087
|
-
setShowMore,
|
|
1088
|
-
PriceRangeFunc,
|
|
1089
|
-
handleCleanFilter,
|
|
1090
|
-
handleSubmit,
|
|
1091
|
-
handleChangeFilterProduct,
|
|
1092
|
-
handleDecrementExtra,
|
|
1093
|
-
setTotalProductPrice,
|
|
1094
|
-
setInputValue,
|
|
1095
|
-
getSortedProduct,
|
|
1096
|
-
handleAddOptional,
|
|
1097
|
-
handleIncrementExtra,
|
|
1098
|
-
setProduct,
|
|
1099
|
-
setPrint: handlePrint,
|
|
1100
|
-
PRODUCT
|
|
1101
|
-
}
|
|
1102
|
-
}
|