npm-pkg-hook 1.12.7 → 1.12.9
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 +0 -0
- package/.env +5 -0
- package/.github/pull_request_template.md +18 -0
- package/.github/workflows/pepeline.yaml +30 -0
- package/dist/index.js +47752 -10080
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +47068 -9612
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mts +153 -0
- package/expire.json +1 -0
- package/jsconfig.json +28 -0
- package/package.json +24 -61
- package/script.txt +7 -0
- package/src/config/client/errors.ts +39 -0
- package/src/config/client/index.ts +1 -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/cookies/index.ts +3 -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/helpers/index.ts +7 -0
- package/src/hooks/getCategoriesWithProduct/index.ts +62 -0
- 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 +153 -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/statusOpenStores/helpers/index.ts +124 -0
- package/src/hooks/statusOpenStores/index.ts +221 -0
- package/src/hooks/updateExtProductFoodsOptional/index.ts +49 -0
- 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/useAnimationFrame/index.ts +45 -0
- package/src/hooks/useAnimationText/index.ts +31 -0
- package/src/hooks/useAsideCart/helpers/index.ts +22 -0
- package/src/hooks/useAsideCart/index.ts +217 -0
- package/src/hooks/useAsideCart/queries.ts +10 -0
- package/src/hooks/useBanner/index.ts +20 -0
- package/src/hooks/useCart/index.ts +2 -0
- package/src/hooks/useCart/queries.ts +174 -0
- package/src/hooks/useCart/useCart/helpers/index.ts +79 -0
- package/src/hooks/useCart/useCart/index.ts +424 -0
- package/src/hooks/useCart/useGetCart/index.ts +34 -0
- package/src/hooks/useCatWithProduct/index.ts +54 -0
- package/src/hooks/useCatWithProduct/queries.ts +200 -0
- package/src/hooks/useCatWithProduct/types/index.ts +104 -0
- package/src/hooks/useCatWithProductClient/index.ts +57 -0
- package/src/hooks/useCatWithProductClient/queries.ts +56 -0
- package/src/hooks/useCategoriesProduct/index.ts +14 -0
- package/src/hooks/useCategoriesProduct/queries.ts +16 -0
- package/src/hooks/useCategoryInStore/index.ts +167 -0
- package/src/hooks/useCategoryInStore/queries.ts +78 -0
- package/src/hooks/useCategoryStore/index.ts +8 -0
- package/src/hooks/useCategoryStore/queries.ts +16 -0
- package/src/hooks/useChartData/index.ts +171 -0
- package/src/hooks/useChartData/useChartData/index.ts +200 -0
- package/src/hooks/useChartData/useChartDataAllOrders/index.ts +94 -0
- package/src/hooks/useChatRoomSubscription/index.ts +28 -0
- package/src/hooks/useCheckbox/index.ts +115 -0
- package/src/hooks/useCities/index.ts +14 -0
- package/src/hooks/useCities/queries.ts +12 -0
- package/src/hooks/useClients/index.ts +97 -0
- 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 +22 -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.ts +52 -0
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.ts +182 -0
- 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.ts +32 -0
- package/src/hooks/useDeleteSubProductOptional/queries.ts +10 -0
- 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/helpers/index.ts +51 -0
- package/src/hooks/useDessert/index.ts +529 -0
- 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.ts +79 -0
- package/src/hooks/useDropzone/index.ts +94 -0
- package/src/hooks/useDynamicAuth/index.ts +14 -0
- package/src/hooks/useDynamicAuth/queries.ts +24 -0
- package/src/hooks/useEditCategory/index.ts +41 -0
- package/src/hooks/useEditOneExtProductFoodOptional/index.ts +28 -0
- package/src/hooks/useEditOneExtProductFoodOptional/queries.ts +16 -0
- package/src/hooks/useEditSubProductOptional/index.ts +12 -0
- package/src/hooks/useEditSubProductOptional/queries.ts +10 -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.ts +34 -0
- package/src/hooks/useFavoriteStores/index.ts +31 -0
- package/src/hooks/useFavoriteStores/queries.ts +54 -0
- package/src/hooks/useFetchJson/index.ts +25 -0
- package/src/hooks/useFetchMoreInteractions/index.jsx +39 -0
- package/src/hooks/useFilterConfigs/index.ts +173 -0
- package/src/hooks/useFingerprintjs/index.ts +197 -0
- package/src/hooks/useFormTools/index.ts +143 -0
- package/src/hooks/useFormatDate/index.ts +91 -0
- package/src/hooks/useFormatNumberPhone/index.ts +23 -0
- package/src/hooks/useFullScreenMode/index.ts +61 -0
- package/src/hooks/useGenerateNumberArray/index.ts +17 -0
- package/src/hooks/useGetAllLocationUser/index.ts +13 -0
- package/src/hooks/useGetAllLocationUser/queries.ts +44 -0
- package/src/hooks/useGetAllSales/index.ts +26 -0
- package/src/hooks/useGetCookies/index.ts +43 -0
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.ts +15 -0
- package/src/hooks/useGetFoodRecomended/index.ts +33 -0
- package/src/hooks/useGetFoodRecomended/queries.ts +47 -0
- package/src/hooks/useGetMessagesToRoom/index.ts +23 -0
- package/src/hooks/useGetMinPrice/index.ts +13 -0
- package/src/hooks/useGetMinPrice/queries.ts +7 -0
- package/src/hooks/useGetOneStoreRating/index.ts +41 -0
- package/src/hooks/useGetOneStoreRating/queries.ts +18 -0
- package/src/hooks/useGetSalesAmountToday/index.ts +31 -0
- package/src/hooks/useGetStoreCookie/index.ts +21 -0
- package/src/hooks/useGoogleLogin/index.ts +169 -0
- package/src/hooks/useGoogleLogin/loadScript.ts +15 -0
- package/src/hooks/useGoogleLogin/removeScript.ts +7 -0
- package/src/hooks/useHover/index.ts +32 -0
- package/src/hooks/useImageOptimization/index.ts +32 -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.ts +55 -0
- package/src/hooks/useImagesStore/index.ts +227 -0
- package/src/hooks/useImagesStore/queries.ts +193 -0
- 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/useInnerHtml/index.ts +39 -0
- package/src/hooks/useIntersection/index.ts +84 -0
- 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/useKeypress/index.ts +28 -0
- package/src/hooks/useLazyScript/index.ts +74 -0
- package/src/hooks/useLocalBackendIp/index.ts +34 -0
- package/src/hooks/useLocalSorage/index.ts +36 -0
- package/src/hooks/useLocationManager/index.ts +63 -0
- package/src/hooks/useLocationNavigate/index.ts +54 -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/helpers/mock.ts +0 -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 +29 -0
- package/src/hooks/useModules/index.ts +124 -0
- package/src/hooks/useMouse/index.ts +55 -0
- package/src/hooks/useMutateHeight/index.ts +36 -0
- package/src/hooks/useOrderClient/index.ts +5 -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/useOrdersFromStore/index.ts +78 -0
- 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.ts +964 -0
- 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/index.ts +3 -0
- package/src/hooks/useProviders/queries.ts +31 -0
- package/src/hooks/useProviders/useProvidersCreateStore/index.ts +13 -0
- package/src/hooks/useProviders/useProvidersDataStore/index.ts +25 -0
- package/src/hooks/useProvidersStore/index.ts +25 -0
- package/src/hooks/useProvidersStore/queries.ts +31 -0
- 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.ts +54 -0
- package/src/hooks/useRatingArrayData/queries.ts +19 -0
- package/src/hooks/useReactToPrint/index.txt +1223 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.ts +24 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.ts +48 -0
- package/src/hooks/useReport/index.ts +48 -0
- package/src/hooks/useReport/queries.ts +72 -0
- 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.ts +81 -0
- 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.ts +532 -0
- 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.ts +38 -0
- package/src/hooks/useSaveAvailableProduct/index.ts +32 -0
- package/src/hooks/useSaveAvailableProduct/queries.ts +10 -0
- package/src/hooks/useSaveLocation/index.ts +17 -0
- package/src/hooks/useSaveLocation/queries.ts +19 -0
- package/src/hooks/useSchedule/index.ts +35 -0
- package/src/hooks/useSchedule/queries.ts +43 -0
- package/src/hooks/useSchedule/schedule.ts +79 -0
- package/src/hooks/useScheduleData/index.ts +135 -0
- package/src/hooks/useScroll/index.ts +56 -0
- package/src/hooks/useScrollRotate/index.ts +16 -0
- package/src/hooks/useSetImageProducts/index.ts +59 -0
- package/src/hooks/useSetImageProducts/queries.ts +18 -0
- package/src/hooks/useSetSession/index.ts +44 -0
- package/src/hooks/useSetState/index.ts +24 -0
- 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.ts +195 -0
- package/src/hooks/useStatusOrdersClient/helpers/index.ts +14 -0
- package/src/hooks/useStatusOrdersClient/index.ts +18 -0
- package/src/hooks/useStatusOrdersClient/queries.ts +80 -0
- 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.ts +163 -0
- package/src/hooks/useStoreCalendar/index.ts +5 -0
- package/src/hooks/useStoreContacts/index.ts +53 -0
- package/src/hooks/useStoreContacts/queries.ts +48 -0
- 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.ts +39 -0
- 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.ts +131 -0
- package/src/hooks/useUpdateCartCookie/index.ts +60 -0
- package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
- package/src/hooks/useUpdateExistingOrders/index.ts +85 -0
- 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.ts +24 -0
- package/src/hooks/useUser/queries.ts +131 -0
- package/src/hooks/useWeeklyStockMovement/helpers/index.ts +32 -0
- package/src/hooks/useWeeklyStockMovement/index.ts +52 -0
- package/src/hooks/useWindowSize/index.ts +45 -0
- package/src/index.ts +8 -0
- package/src/mock/dessert/index.ts +16 -0
- package/src/mock/index.ts +1 -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 +16 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +24 -0
- package/dist/index.cjs +0 -20089
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const UPDATE_MULTIPLE_PRODUCTS = gql`
|
|
4
|
+
mutation updateMultipleProducts($input: [InputProductFood]) {
|
|
5
|
+
updateMultipleProducts(input: $input) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
errors {
|
|
9
|
+
path
|
|
10
|
+
message
|
|
11
|
+
type
|
|
12
|
+
context {
|
|
13
|
+
limit
|
|
14
|
+
value
|
|
15
|
+
label
|
|
16
|
+
key
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
data {
|
|
20
|
+
pId
|
|
21
|
+
sizeId
|
|
22
|
+
colorId
|
|
23
|
+
cId
|
|
24
|
+
dId
|
|
25
|
+
ctId
|
|
26
|
+
fId
|
|
27
|
+
pName
|
|
28
|
+
pCode
|
|
29
|
+
ProPrice
|
|
30
|
+
carProId
|
|
31
|
+
ProDescuento
|
|
32
|
+
ProUniDisponibles
|
|
33
|
+
ValueDelivery
|
|
34
|
+
ProDescription
|
|
35
|
+
ProProtegido
|
|
36
|
+
ProAssurance
|
|
37
|
+
ProStar
|
|
38
|
+
pState
|
|
39
|
+
ProImage
|
|
40
|
+
ProWidth
|
|
41
|
+
ProHeight
|
|
42
|
+
ProLength
|
|
43
|
+
ProWeight
|
|
44
|
+
ProQuantity
|
|
45
|
+
ProOutstanding
|
|
46
|
+
ProDelivery
|
|
47
|
+
ProVoltaje
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './parseNumber'
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a formatted number (string or number) and converts it into a float with two decimal places.
|
|
3
|
+
* @param {string|number} value - The number to parse (e.g., "1.500,00", "1500.00", 1500).
|
|
4
|
+
* @returns {string} Parsed number as a string in the format "1500.00".
|
|
5
|
+
* @throws Will throw an error if the input is not a valid formatted number.
|
|
6
|
+
*/
|
|
7
|
+
export const parseNumber = (value: string | number) => {
|
|
8
|
+
// Convert value to string if it's a number
|
|
9
|
+
const stringValue = typeof value === 'number' ? value.toString() : value
|
|
10
|
+
|
|
11
|
+
if (typeof stringValue !== 'string') {
|
|
12
|
+
throw new TypeError('Input must be a string or number')
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Remove thousands separators and adjust decimal separator
|
|
16
|
+
const sanitizedValue = stringValue
|
|
17
|
+
.replace(/\./g, '') // Removes thousands separators (.)
|
|
18
|
+
.replace(',', '.') // Changes comma to period for decimal
|
|
19
|
+
|
|
20
|
+
// Parse the sanitized value as a float
|
|
21
|
+
const parsedNumber = parseFloat(sanitizedValue)
|
|
22
|
+
if (isNaN(parsedNumber)) {
|
|
23
|
+
throw new TypeError('Invalid number format')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Format the number with two decimal places
|
|
27
|
+
return parsedNumber.toFixed(2)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Example usage:
|
|
31
|
+
console.log(parseNumber('1.500,00')) // "1500.00"
|
|
32
|
+
console.log(parseNumber('1500.00')) // "1500.00"
|
|
33
|
+
console.log(parseNumber('1,500.50')) // "1500.50"
|
|
34
|
+
console.log(parseNumber('500')) // "500.00"
|
|
35
|
+
console.log(parseNumber('0,50')) // "0.50"
|
|
36
|
+
console.log(parseNumber(1500)) // "1500.00"
|
|
37
|
+
console.log(parseNumber(1500.5)) // "1500.50"
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export const validateProductDataExcel = (product, productIndex) => {
|
|
2
|
+
const expectedHeaders = [
|
|
3
|
+
{
|
|
4
|
+
name: 'NOMBRE',
|
|
5
|
+
required: true,
|
|
6
|
+
types: ['string']
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
name: 'PRECIO_AL_PUBLICO',
|
|
10
|
+
required: false,
|
|
11
|
+
types: ['number', 'string']
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
name: 'VALOR_DE_COMPRA',
|
|
15
|
+
required: false,
|
|
16
|
+
types: ['number', 'string']
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'CANTIDAD',
|
|
20
|
+
required: true,
|
|
21
|
+
types: ['number']
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'DESCRIPCION',
|
|
25
|
+
required: true,
|
|
26
|
+
types: ['string']
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'DESCUENTO',
|
|
30
|
+
required: false,
|
|
31
|
+
types: ['number', 'string']
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'CATEGORIA',
|
|
35
|
+
required: false,
|
|
36
|
+
types: ['string']
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'CODIGO_DE_BARRAS',
|
|
40
|
+
required: false,
|
|
41
|
+
types: ['string', 'number']
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'IMPUESTO (%)',
|
|
45
|
+
required: false,
|
|
46
|
+
types: ['number', 'string']
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
const errors = []
|
|
51
|
+
|
|
52
|
+
// Validar encabezados requeridos y tipos
|
|
53
|
+
expectedHeaders.forEach(({ name, required, types }) => {
|
|
54
|
+
const value = product[name]
|
|
55
|
+
|
|
56
|
+
if (required && (value === undefined || value === null)) {
|
|
57
|
+
errors.push(`Producto ${productIndex + 1}: Falta la columna requerida: ${name}.`)
|
|
58
|
+
} else if (value !== undefined && value !== null) {
|
|
59
|
+
const isValidType = types.some(type => {
|
|
60
|
+
if (type === 'number') {
|
|
61
|
+
return typeof value === 'number' && !isNaN(value)
|
|
62
|
+
}
|
|
63
|
+
return typeof value === type
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
if (!isValidType) {
|
|
67
|
+
errors.push(`Producto ${productIndex + 1}: El campo ${name} debe ser de tipo ${types.join(' o ')}.`)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
return errors // Retorna todos los errores encontrados
|
|
73
|
+
}
|
|
@@ -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, quantityChange) => {
|
|
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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useMutation, useQuery } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
import { GET_USER, GET_USER_PROFILE, SET_USER_PROFILE } from './queries'
|
|
4
|
+
|
|
5
|
+
export const useUser = (email) => {
|
|
6
|
+
const { data, loading, error } = useQuery(GET_USER, email !== ''
|
|
7
|
+
? {
|
|
8
|
+
variables: {
|
|
9
|
+
email
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
: {})
|
|
13
|
+
return [data?.getUser, { loading, error }]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const useUserProfile = () => {
|
|
17
|
+
const { data, loading, error } = useQuery(GET_USER_PROFILE)
|
|
18
|
+
return [data, { loading, error }]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const useSetUserProfile = () => {
|
|
22
|
+
const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
|
|
23
|
+
return [setUserProfile, { loading, error }]
|
|
24
|
+
}
|