npm-pkg-hook 1.3.9 → 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
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import * as XLSX from 'xlsx'
|
|
3
|
+
|
|
4
|
+
import { RandomCode } from '../../utils'
|
|
5
|
+
|
|
6
|
+
import { validateProductDataExcel } from './helpers/validateProductDataExcel'
|
|
7
|
+
|
|
8
|
+
const STEPS = {
|
|
9
|
+
UPLOAD_FILE: 0,
|
|
10
|
+
UPLOAD_PRODUCTS: 1
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface UseUploadProductsProps {
|
|
14
|
+
sendNotification?: (notification: {
|
|
15
|
+
title: string
|
|
16
|
+
description: string
|
|
17
|
+
backgroundColor: 'success' | 'error' | 'info' | 'warning'
|
|
18
|
+
}) => void
|
|
19
|
+
}
|
|
20
|
+
export const useUploadProducts = ({
|
|
21
|
+
sendNotification = () => { return null }
|
|
22
|
+
}: UseUploadProductsProps) => {
|
|
23
|
+
const [data, setData] = useState([])
|
|
24
|
+
const [isLoading, setIsLoading] = useState(false)
|
|
25
|
+
const [active, setActive] = useState(STEPS.UPLOAD_FILE)
|
|
26
|
+
const [overActive, setOverActive] = useState(STEPS.UPLOAD_FILE)
|
|
27
|
+
|
|
28
|
+
const handleOverActive = (index: number) => {
|
|
29
|
+
setOverActive(index)
|
|
30
|
+
}
|
|
31
|
+
const readExcelFile = (file: File) => {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const reader = new FileReader()
|
|
34
|
+
reader.onload = (e) => {
|
|
35
|
+
if (!e.target || !(e.target.result instanceof ArrayBuffer)) {
|
|
36
|
+
return reject(new Error('Failed to read file as ArrayBuffer.'))
|
|
37
|
+
}
|
|
38
|
+
const data = new Uint8Array(e.target.result)
|
|
39
|
+
const workbook = XLSX.read(data, { type: 'array' })
|
|
40
|
+
const sheetName = workbook.SheetNames[0]
|
|
41
|
+
const worksheet = workbook.Sheets[sheetName]
|
|
42
|
+
const json = XLSX.utils.sheet_to_json(worksheet)
|
|
43
|
+
resolve(json)
|
|
44
|
+
}
|
|
45
|
+
reader.onerror = (error) => {return reject(error)}
|
|
46
|
+
reader.readAsArrayBuffer(file)
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const onChangeFiles = async (files: FileList) => {
|
|
51
|
+
setIsLoading(true) // Activa el loader al inicio
|
|
52
|
+
try {
|
|
53
|
+
const filePromises = Array.from(files).map(file => {return readExcelFile(file)})
|
|
54
|
+
const newData = await Promise.all(filePromises)
|
|
55
|
+
|
|
56
|
+
const newProducts = newData.flat().map((product, index) => {
|
|
57
|
+
// Assert product as a record to access its properties
|
|
58
|
+
const prod = product as Record<string, any>
|
|
59
|
+
const PRECIO_AL_PUBLICO = Number.isNaN(prod.PRECIO_AL_PUBLICO) ? 0 : prod.PRECIO_AL_PUBLICO
|
|
60
|
+
const VALOR_DE_COMPRA = Number.isNaN(prod.VALOR_DE_COMPRA) ? 0 : prod.VALOR_DE_COMPRA
|
|
61
|
+
const validationErrors = validateProductDataExcel(prod, index)
|
|
62
|
+
|
|
63
|
+
const code = RandomCode(9)
|
|
64
|
+
return {
|
|
65
|
+
...prod,
|
|
66
|
+
CANTIDAD: Number.isNaN(prod.CANTIDAD) ? 1 : prod.CANTIDAD,
|
|
67
|
+
ORIGINAL_CANTIDAD: Number.isNaN(prod.CANTIDAD) ? 1 : prod.CANTIDAD,
|
|
68
|
+
free: false,
|
|
69
|
+
product: prod?.DESCRIPCION,
|
|
70
|
+
pCode: code,
|
|
71
|
+
editing: false,
|
|
72
|
+
PRECIO_AL_PUBLICO,
|
|
73
|
+
ProImage: '/images/placeholder-image.webp',
|
|
74
|
+
VALOR_DE_COMPRA,
|
|
75
|
+
manageStock: true,
|
|
76
|
+
errors: validationErrors.length > 0 ? validationErrors : null
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Notificación de errores
|
|
81
|
+
newProducts.forEach(product => {
|
|
82
|
+
if (product.errors) {
|
|
83
|
+
// Enviar una notificación por cada error encontrado
|
|
84
|
+
product.errors.forEach(error => {
|
|
85
|
+
sendNotification({
|
|
86
|
+
description: error,
|
|
87
|
+
title: 'Error',
|
|
88
|
+
backgroundColor: 'error'
|
|
89
|
+
})
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// Validar el número total de productos antes de actualizar el estado
|
|
95
|
+
setData(prevData => {
|
|
96
|
+
const currentLength = prevData.length
|
|
97
|
+
const totalProducts = currentLength + newProducts.length
|
|
98
|
+
|
|
99
|
+
if (totalProducts > 100) {
|
|
100
|
+
sendNotification({
|
|
101
|
+
description: 'Cannot add more products. You have reached the 100-product limit.',
|
|
102
|
+
title: 'Error',
|
|
103
|
+
backgroundColor: 'error'
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// Calcular la cantidad de productos que se pueden agregar sin exceder el límite
|
|
107
|
+
const remainingSlots = 100 - currentLength
|
|
108
|
+
const productsToAdd = newProducts.slice(0, remainingSlots)
|
|
109
|
+
return [...prevData, ...productsToAdd]
|
|
110
|
+
}
|
|
111
|
+
// Agregar todos los nuevos productos si no se excede el límite
|
|
112
|
+
return [...prevData, ...newProducts]
|
|
113
|
+
|
|
114
|
+
})
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (error instanceof Error) {
|
|
117
|
+
sendNotification({
|
|
118
|
+
description: error.message,
|
|
119
|
+
title: 'Error',
|
|
120
|
+
backgroundColor: 'error'
|
|
121
|
+
})
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
sendNotification({
|
|
125
|
+
description: 'Un error ha ocurrido mientras se cargaba el archivo de productos.',
|
|
126
|
+
title: 'Error',
|
|
127
|
+
backgroundColor: 'error'
|
|
128
|
+
})
|
|
129
|
+
} finally {
|
|
130
|
+
setIsLoading(false)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const handleSetActive = (index) => {
|
|
135
|
+
if (typeof index !== 'number' || index < 0 || index >= Object.keys(STEPS).length) {
|
|
136
|
+
sendNotification({
|
|
137
|
+
description: 'Invalid step index',
|
|
138
|
+
title: 'Error',
|
|
139
|
+
backgroundColor: 'error'
|
|
140
|
+
})
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
if (active === STEPS.UPLOAD_FILE) {
|
|
144
|
+
setActive(data.length ? STEPS.UPLOAD_PRODUCTS : 0)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const updateProductQuantity = (index: number, quantityChange: number) => {
|
|
149
|
+
// Validar el índice
|
|
150
|
+
if (index < 0 || index >= data.length) {
|
|
151
|
+
console.warn('Invalid product index:', index)
|
|
152
|
+
return
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const newData = [...data]
|
|
156
|
+
const newQuantity = newData[index].CANTIDAD + quantityChange
|
|
157
|
+
|
|
158
|
+
// Actualizar la cantidad solo si es mayor o igual a 0
|
|
159
|
+
if (newQuantity < 0) {
|
|
160
|
+
console.warn('Quantity cannot be negative, no update performed.')
|
|
161
|
+
return // No permitir cantidades negativas
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Actualizar la cantidad
|
|
165
|
+
newData[index].CANTIDAD = newQuantity
|
|
166
|
+
newData[index].ORIGINAL_CANTIDAD = newQuantity
|
|
167
|
+
// Eliminar el producto si la nueva cantidad es 0
|
|
168
|
+
if (newData[index].CANTIDAD === 0) {
|
|
169
|
+
newData.splice(index, 1)
|
|
170
|
+
|
|
171
|
+
// Verificar si no quedan más productos
|
|
172
|
+
if (newData.length === 0) {
|
|
173
|
+
setActive(STEPS.UPLOAD_FILE) // Restablecer el estado activo a 0 si no hay productos
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
setData(newData)
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Toggle the 'free' status of a specific product in the data array.
|
|
181
|
+
* Performs validation to ensure the product index is valid.
|
|
182
|
+
*
|
|
183
|
+
* @param {number} productIndex - The index of the product to update.
|
|
184
|
+
*/
|
|
185
|
+
const handleCheckFree = (productIndex: number) => {
|
|
186
|
+
setData((prevData) => {
|
|
187
|
+
// Validar que el índice es un número válido
|
|
188
|
+
if (typeof productIndex !== 'number' || productIndex < 0 || productIndex >= prevData.length) {
|
|
189
|
+
console.warn('Invalid product index:', productIndex)
|
|
190
|
+
return prevData // Retorna el estado anterior si el índice es inválido
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Validar que el producto existe y que tiene la propiedad 'free'
|
|
194
|
+
const product = prevData[productIndex]
|
|
195
|
+
if (!product || typeof product.free === 'undefined') {
|
|
196
|
+
console.warn('Product or "free" property not found for index:', productIndex)
|
|
197
|
+
return prevData // Retorna el estado anterior si no se encuentra el producto
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// Evitar cambios innecesarios si el estado de 'free' no cambia
|
|
201
|
+
const updatedFreeStatus = !product.free
|
|
202
|
+
if (product.free === updatedFreeStatus) {
|
|
203
|
+
console.info('Product "free" status is already:', updatedFreeStatus)
|
|
204
|
+
return prevData // No actualiza si el estado es el mismo
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Crear una nueva copia de los datos actualizando solo el producto específico
|
|
208
|
+
return prevData.map((product, index) =>
|
|
209
|
+
{return index === productIndex
|
|
210
|
+
? {
|
|
211
|
+
...product,
|
|
212
|
+
free: updatedFreeStatus,
|
|
213
|
+
PRECIO_AL_PUBLICO: updatedFreeStatus ? 0 : product.oldPrice,
|
|
214
|
+
oldPrice: product.PRECIO_AL_PUBLICO
|
|
215
|
+
}
|
|
216
|
+
: product}
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
}
|
|
220
|
+
const handleCleanAllProducts = () => {
|
|
221
|
+
setData([])
|
|
222
|
+
setActive(STEPS.UPLOAD_FILE)
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Toggle the 'editing' status of a specific product in the data array.
|
|
226
|
+
* Validates the product index and only updates if necessary.
|
|
227
|
+
*
|
|
228
|
+
* @param {number} productIndex - The index of the product to update.
|
|
229
|
+
*/
|
|
230
|
+
const handleToggleEditingStatus = (productIndex) => {
|
|
231
|
+
setData((prevData) => {
|
|
232
|
+
// Validar que el índice es un número válido
|
|
233
|
+
if (typeof productIndex !== 'number' || productIndex < 0 || productIndex >= prevData.length) {
|
|
234
|
+
sendNotification({
|
|
235
|
+
description: `Invalid product index: ${productIndex}`,
|
|
236
|
+
title: 'Error',
|
|
237
|
+
backgroundColor: 'error'
|
|
238
|
+
})
|
|
239
|
+
return prevData // Retorna el estado anterior si el índice es inválido
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Validar que el producto existe y tiene la propiedad 'editing'
|
|
243
|
+
const product = prevData[productIndex]
|
|
244
|
+
if (!product || typeof product.editing === 'undefined') {
|
|
245
|
+
sendNotification({
|
|
246
|
+
description: `Product or "editing" property not found for index: ${productIndex}`,
|
|
247
|
+
title: 'Error',
|
|
248
|
+
backgroundColor: 'error'
|
|
249
|
+
})
|
|
250
|
+
return prevData // Retorna el estado anterior si no se encuentra el producto
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Evitar cambios innecesarios si el estado de 'editing' no cambia
|
|
254
|
+
const updatedEditingStatus = !product.editing
|
|
255
|
+
if (product.editing === updatedEditingStatus) {
|
|
256
|
+
sendNotification({
|
|
257
|
+
description: `Product "editing" status is already: ${updatedEditingStatus}`,
|
|
258
|
+
title: 'Info',
|
|
259
|
+
backgroundColor: 'info'
|
|
260
|
+
})
|
|
261
|
+
return prevData // No actualiza si el estado es el mismo
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Crear una nueva copia de los datos actualizando solo el producto específico
|
|
265
|
+
return prevData.map((product, index) => {
|
|
266
|
+
return index === productIndex
|
|
267
|
+
? {
|
|
268
|
+
...product,
|
|
269
|
+
editing: updatedEditingStatus
|
|
270
|
+
}
|
|
271
|
+
: product
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
})
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Confirm and update the quantity of a product in the data array.
|
|
279
|
+
* Only updates when the button is clicked.
|
|
280
|
+
*
|
|
281
|
+
* @param {number} productIndex - The index of the product to update.
|
|
282
|
+
*/
|
|
283
|
+
const handleSuccessUpdateQuantity = (productIndex) => {
|
|
284
|
+
const product = data[productIndex]
|
|
285
|
+
setData((prevData) => {
|
|
286
|
+
// Validar que `CANTIDAD` sea un número entero
|
|
287
|
+
const product = prevData[productIndex]
|
|
288
|
+
if (!Number.isInteger(product?.CANTIDAD)) {
|
|
289
|
+
sendNotification({
|
|
290
|
+
description: 'La cantidad debe ser un valor entero.',
|
|
291
|
+
title: 'Error',
|
|
292
|
+
backgroundColor: 'error'
|
|
293
|
+
})
|
|
294
|
+
return prevData // Retorna el estado anterior si `CANTIDAD` no es entero
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Crear una copia actualizada de prevData donde se actualiza `CANTIDAD` si es necesario
|
|
298
|
+
const updatedData = prevData.map((product, index) =>
|
|
299
|
+
{return index === productIndex
|
|
300
|
+
? { ...product, editing: false, ORIGINAL_CANTIDAD: product.CANTIDAD } // Actualización o cambio de estado
|
|
301
|
+
: product}
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
// Filtrar productos con CANTIDAD mayor a 0
|
|
305
|
+
const filteredData = updatedData.filter(product => {return product.CANTIDAD > 0})
|
|
306
|
+
|
|
307
|
+
// Cambiar el estado a `STEPS.UPLOAD_FILE` si no quedan productos
|
|
308
|
+
if (filteredData.length === 0) {
|
|
309
|
+
setActive(STEPS.UPLOAD_FILE)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
return filteredData
|
|
313
|
+
})
|
|
314
|
+
if (product.CANTIDAD !== data[productIndex].ORIGINAL_CANTIDAD) {
|
|
315
|
+
sendNotification({
|
|
316
|
+
description: `Cantidad actualizada con éxito para el producto ${product.NOMBRE} #${productIndex}.`,
|
|
317
|
+
title: 'Éxito',
|
|
318
|
+
backgroundColor: 'success'
|
|
319
|
+
})
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const handleChangeQuantity = (event, productIndex) => {
|
|
324
|
+
const { value } = event.target
|
|
325
|
+
setData((prevData) => {
|
|
326
|
+
if (typeof productIndex !== 'number' || productIndex < 0 || productIndex >= prevData.length) {
|
|
327
|
+
console.warn('Invalid product index:', productIndex)
|
|
328
|
+
return prevData // Retorna el estado anterior si el índice es inválido
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// Obtener la cantidad temporal para el producto
|
|
332
|
+
const newQuantity = value
|
|
333
|
+
if (isNaN(newQuantity) || newQuantity < 0) {
|
|
334
|
+
console.warn('Quantity must be a valid non-negative number.')
|
|
335
|
+
return prevData // Retorna sin cambios si la cantidad no es válida
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// Actualiza el array `data` con la nueva cantidad
|
|
339
|
+
return prevData.map((product, index) =>
|
|
340
|
+
{return index === productIndex
|
|
341
|
+
? { ...product, CANTIDAD: newQuantity }
|
|
342
|
+
: product}
|
|
343
|
+
)
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Restore the 'CANTIDAD' value to 'ORIGINAL_CANTIDAD' for a specific product.
|
|
348
|
+
* Validates the product index and only updates if necessary.
|
|
349
|
+
*
|
|
350
|
+
* @param {number} productIndex - The index of the product to restore quantity for.
|
|
351
|
+
*/
|
|
352
|
+
const handleCancelUpdateQuantity = (productIndex) => {
|
|
353
|
+
setData((prevData) => {
|
|
354
|
+
// Validar que el índice es un número válido
|
|
355
|
+
if (typeof productIndex !== 'number' || productIndex < 0 || productIndex >= prevData.length) {
|
|
356
|
+
console.warn('Invalid product index:', productIndex)
|
|
357
|
+
return prevData // Retorna el estado anterior si el índice es inválido
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Validar que el producto existe y tiene las propiedades 'CANTIDAD' y 'ORIGINAL_CANTIDAD'
|
|
361
|
+
const product = prevData[productIndex]
|
|
362
|
+
if (!product || typeof product.ORIGINAL_CANTIDAD === 'undefined') {
|
|
363
|
+
console.warn('Product or "ORIGINAL_CANTIDAD" property not found for index:', productIndex)
|
|
364
|
+
return prevData // Retorna el estado anterior si no se encuentra el producto o propiedad
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Crear una nueva copia de los datos actualizando solo el producto específico
|
|
368
|
+
return prevData.map((product, index) =>
|
|
369
|
+
{return index === productIndex
|
|
370
|
+
? { ...product, CANTIDAD: product.ORIGINAL_CANTIDAD, editing: false }
|
|
371
|
+
: product}
|
|
372
|
+
)
|
|
373
|
+
})
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Filters products with a quantity of 0 or less from the data array.
|
|
377
|
+
* Sends a notification if any products are found with invalid quantities.
|
|
378
|
+
*/
|
|
379
|
+
const filterInvalidQuantityProducts = () => {
|
|
380
|
+
setData((prevData) => {
|
|
381
|
+
// Filtrar productos con `CANTIDAD` mayor a 0
|
|
382
|
+
const validProducts = prevData.filter(product => {return product.CANTIDAD > 0})
|
|
383
|
+
|
|
384
|
+
// Notificar si hubo productos con cantidad no válida
|
|
385
|
+
if (validProducts.length < prevData.length) {
|
|
386
|
+
sendNotification({
|
|
387
|
+
description: 'Some products had a quantity of 0 or less and were removed.',
|
|
388
|
+
title: 'Invalid Products Removed',
|
|
389
|
+
backgroundColor: 'warning'
|
|
390
|
+
})
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return validProducts
|
|
394
|
+
})
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Compares uploaded products against response data to determine which were successfully uploaded.
|
|
399
|
+
* @param {Array} data - Original array of products with their details.
|
|
400
|
+
* @param {Array} response - Array of response objects from the `updateProducts` function.
|
|
401
|
+
* @returns {Object} Object containing arrays of successfully and unsuccessfully uploaded products.
|
|
402
|
+
*/
|
|
403
|
+
const getUploadResults = (data, response) => {
|
|
404
|
+
const uploadedCodes = new Set(
|
|
405
|
+
response
|
|
406
|
+
.filter((product) => {return product.success})
|
|
407
|
+
.map((product) => {return product.data.pCode})
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
const successfullyUploaded = data.filter((product) =>
|
|
411
|
+
{return uploadedCodes.has(product.pCode)}
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
const failedUploads = data.filter(
|
|
415
|
+
(product) => {return !uploadedCodes.has(product.pCode)}
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
return {
|
|
419
|
+
successfullyUploaded,
|
|
420
|
+
failedUploads
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return {
|
|
424
|
+
active,
|
|
425
|
+
STEPS,
|
|
426
|
+
isLoading,
|
|
427
|
+
data,
|
|
428
|
+
overActive,
|
|
429
|
+
handleOverActive,
|
|
430
|
+
handleCheckFree,
|
|
431
|
+
getUploadResults,
|
|
432
|
+
onChangeFiles,
|
|
433
|
+
handleChangeQuantity,
|
|
434
|
+
handleCancelUpdateQuantity,
|
|
435
|
+
handleToggleEditingStatus,
|
|
436
|
+
filterInvalidQuantityProducts,
|
|
437
|
+
handleSuccessUpdateQuantity,
|
|
438
|
+
updateProductQuantity,
|
|
439
|
+
handleCleanAllProducts,
|
|
440
|
+
setActive: handleSetActive
|
|
441
|
+
}
|
|
442
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL mutation to upsert (create or update) the daily goal.
|
|
5
|
+
*/
|
|
6
|
+
const UPSERT_GOAL = gql`
|
|
7
|
+
mutation UpsertGoal($input: CreateGoalInput!) {
|
|
8
|
+
upsertGoal(input: $input) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
data {
|
|
12
|
+
idStore
|
|
13
|
+
dailyGoal
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
`
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to handle the upsert of the daily goal.
|
|
21
|
+
* @param {Object} input - The goal data (e.g. dailyGoal).
|
|
22
|
+
* @param input.sendNotification
|
|
23
|
+
* @returns {{
|
|
24
|
+
* upsertGoal: (input: { dailyGoal: number }) => void,
|
|
25
|
+
* data: { success: boolean, message: string, dailyGoal: number } | undefined,
|
|
26
|
+
* loading: boolean,
|
|
27
|
+
* error: any
|
|
28
|
+
* }}
|
|
29
|
+
*/
|
|
30
|
+
export const useUpsertGoal = ({
|
|
31
|
+
sendNotification = () => {}
|
|
32
|
+
} = {}) => {
|
|
33
|
+
const [upsertGoalMutation, { data, loading, error }] = useMutation(UPSERT_GOAL, {
|
|
34
|
+
onCompleted (data) {
|
|
35
|
+
const { upsertGoal } = data || {}
|
|
36
|
+
sendNotification({
|
|
37
|
+
title: upsertGoal.success ? 'Exito' : 'Error',
|
|
38
|
+
description: upsertGoal?.message || 'Meta actualizada correctamente',
|
|
39
|
+
backgroundColor: upsertGoal.success ? 'success' : 'warning'
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
update (cache, { data: { upsertGoal } }) {
|
|
43
|
+
if (!upsertGoal?.success) return
|
|
44
|
+
|
|
45
|
+
cache.modify({
|
|
46
|
+
fields: {
|
|
47
|
+
getStore (dataOld = []) {
|
|
48
|
+
return {
|
|
49
|
+
...dataOld,
|
|
50
|
+
dailyGoal: upsertGoal.data.dailyGoal
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
const upsertGoal = (input) => {
|
|
58
|
+
upsertGoalMutation({
|
|
59
|
+
variables: { input }
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return [upsertGoal, {
|
|
64
|
+
data: data?.upsertGoal,
|
|
65
|
+
loading,
|
|
66
|
+
error
|
|
67
|
+
}]
|
|
68
|
+
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { useMutation, useQuery } from '@apollo/client'
|
|
1
|
+
import { useMutation, useQuery } from '@apollo/client'
|
|
2
|
+
|
|
2
3
|
import { GET_USER, GET_USER_PROFILE, SET_USER_PROFILE } from './queries'
|
|
3
4
|
|
|
4
|
-
export const useUser = () => {
|
|
5
|
-
const { data, loading, error } = useQuery(GET_USER
|
|
5
|
+
export const useUser = (email) => {
|
|
6
|
+
const { data, loading, error } = useQuery(GET_USER, email !== ''
|
|
7
|
+
? {
|
|
8
|
+
variables: {
|
|
9
|
+
email
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
: {})
|
|
6
13
|
return [data?.getUser, { loading, error }]
|
|
7
14
|
}
|
|
8
15
|
|
|
@@ -14,4 +21,4 @@ export const useUserProfile = () => {
|
|
|
14
21
|
export const useSetUserProfile = () => {
|
|
15
22
|
const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
|
|
16
23
|
return [setUserProfile, { loading, error }]
|
|
17
|
-
}
|
|
24
|
+
}
|
|
@@ -48,8 +48,8 @@ query getOneUserProfile($id: ID) {
|
|
|
48
48
|
`
|
|
49
49
|
|
|
50
50
|
export const GET_USER = gql`
|
|
51
|
-
query getUser($id: ID){
|
|
52
|
-
getUser(id: $id ){
|
|
51
|
+
query getUser($id: ID, $email: String){
|
|
52
|
+
getUser(id: $id email: $email){
|
|
53
53
|
id
|
|
54
54
|
name
|
|
55
55
|
username
|
|
@@ -61,14 +61,19 @@ uPhoNum
|
|
|
61
61
|
ULocation
|
|
62
62
|
upLat
|
|
63
63
|
uState
|
|
64
|
+
idRole
|
|
64
65
|
upLon
|
|
65
66
|
upIdeDoc
|
|
66
67
|
siteWeb
|
|
67
68
|
description
|
|
68
|
-
|
|
69
|
+
associateStore
|
|
69
70
|
role {
|
|
70
|
-
id
|
|
71
71
|
name
|
|
72
|
+
permissions
|
|
73
|
+
description
|
|
74
|
+
createdAt
|
|
75
|
+
updatedAt
|
|
76
|
+
|
|
72
77
|
}
|
|
73
78
|
}
|
|
74
79
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fills missing weeks for the last 7 weeks, ensuring continuous data.
|
|
3
|
+
* If a week is missing, it fills it with totalOut: 0 and percentageChange: "N/A".
|
|
4
|
+
*
|
|
5
|
+
* @param {Array} data - Array of weekly stock movement objects.
|
|
6
|
+
* @returns {Array} - Filled data ensuring the last 7 weeks are covered.
|
|
7
|
+
*/
|
|
8
|
+
export const fillLast7Weeks = (data) => {
|
|
9
|
+
const today = new Date()
|
|
10
|
+
const last7Weeks = []
|
|
11
|
+
|
|
12
|
+
// Generar las últimas 7 semanas (cada lunes)
|
|
13
|
+
for (let i = 6; i >= 0; i--) {
|
|
14
|
+
const weekDate = new Date(today)
|
|
15
|
+
weekDate.setDate(today.getDate() - today.getDay() - (i * 7) + 1) // Ajustar para que sea lunes
|
|
16
|
+
const weekStart = weekDate.toISOString().split('T')[0] // Formato YYYY-MM-DD
|
|
17
|
+
last7Weeks.push(weekStart)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Mapear los datos existentes para acceso rápido
|
|
21
|
+
const dataMap = new Map(data.map(item => {return [item.weekStart, item]}))
|
|
22
|
+
|
|
23
|
+
// Construir la nueva lista asegurando que todas las semanas estén presentes
|
|
24
|
+
return last7Weeks.map(weekStart => {return (
|
|
25
|
+
dataMap.get(weekStart) || {
|
|
26
|
+
weekStart,
|
|
27
|
+
totalOut: 0,
|
|
28
|
+
prevTotalOut: null,
|
|
29
|
+
percentageChange: 'N/A'
|
|
30
|
+
}
|
|
31
|
+
)})
|
|
32
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { gql, useQuery } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
import { fillLast7Weeks } from './helpers' // Asegúrate de importar el helper
|
|
4
|
+
|
|
5
|
+
const GET_WEEKLY_STOCK_MOVEMENT = gql`
|
|
6
|
+
query GetStockMovementPercentageChange {
|
|
7
|
+
getStockMovementWeeklyComparison {
|
|
8
|
+
weekStart
|
|
9
|
+
totalOut
|
|
10
|
+
prevTotalOut
|
|
11
|
+
percentageChange
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to fetch and format weekly stock movement data.
|
|
18
|
+
* @returns {Object} - { data, loading, error, formattedData }
|
|
19
|
+
*/
|
|
20
|
+
export const useWeeklyStockMovement = () => {
|
|
21
|
+
const { data, loading, error } = useQuery(GET_WEEKLY_STOCK_MOVEMENT)
|
|
22
|
+
|
|
23
|
+
// Transform data and fill missing weeks
|
|
24
|
+
const rawData = data?.getStockMovementWeeklyComparison || []
|
|
25
|
+
const formattedData = fillLast7Weeks(
|
|
26
|
+
rawData.map(item => {return {
|
|
27
|
+
...item,
|
|
28
|
+
percentageChange: formatPercentageChange(item.percentageChange)
|
|
29
|
+
}})
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
return [formattedData, { loading, error }]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Ensures percentageChange is a valid string percentage, clamping between -100% and 100%.
|
|
37
|
+
*
|
|
38
|
+
* @param {string | null} percentageChange - Raw percentage change value.
|
|
39
|
+
* @returns {string} - Formatted and clamped percentage change.
|
|
40
|
+
*/
|
|
41
|
+
const formatPercentageChange = (percentageChange) => {
|
|
42
|
+
if (percentageChange === null) return 'N/A'
|
|
43
|
+
|
|
44
|
+
// Convertir a número
|
|
45
|
+
let parsedValue = parseFloat(percentageChange)
|
|
46
|
+
|
|
47
|
+
// Clampear entre -100% y 100%
|
|
48
|
+
if (isNaN(parsedValue)) return 'N/A'
|
|
49
|
+
parsedValue = Math.max(-100, Math.min(100, parsedValue))
|
|
50
|
+
|
|
51
|
+
return `${parsedValue.toFixed(1)}`
|
|
52
|
+
}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { useState, useEffect } from 'react'
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* A custom React hook that provides the current window size.
|
|
5
|
+
* @returns An object containing the current window width and height
|
|
6
|
+
*/
|
|
3
7
|
export function useWindowSize () {
|
|
4
8
|
// Initialize state with undefined width/height so server and client renders match
|
|
5
9
|
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
|
|
6
|
-
const [windowSize, setWindowSize] = useState({
|
|
10
|
+
const [windowSize, setWindowSize] = useState<{ width: number | undefined; height: number | undefined }>({
|
|
7
11
|
width: undefined,
|
|
8
12
|
height: undefined
|
|
9
13
|
})
|
|
10
14
|
|
|
11
15
|
useEffect(() => {
|
|
12
16
|
// Handler to call on window resize
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
13
20
|
function handleResize () {
|
|
14
21
|
// Set window width/height to state
|
|
15
22
|
setWindowSize({
|
|
@@ -25,7 +32,7 @@ export function useWindowSize () {
|
|
|
25
32
|
handleResize()
|
|
26
33
|
|
|
27
34
|
// Remove event listener on cleanup
|
|
28
|
-
return () => window.removeEventListener('resize', handleResize)
|
|
35
|
+
return () => {return window.removeEventListener('resize', handleResize)}
|
|
29
36
|
}, []) // Empty array ensures that effect is only run on mount
|
|
30
37
|
|
|
31
38
|
return windowSize
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import pkg from '../package.json';
|
|
2
|
+
export * from './hooks/index'
|
|
3
|
+
export * from './utils'
|
|
4
|
+
export * from './utils/generateCode'
|
|
5
|
+
export * from './cookies'
|
|
6
|
+
export * from './security'
|
|
7
|
+
export * from './config/client'
|
|
8
|
+
export * from './cookies/index'
|
|
9
|
+
|
|
10
|
+
// Export the version from package.json
|
|
11
|
+
export const version = pkg.version;
|
|
12
|
+
|