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,529 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect
|
|
4
|
+
} from 'react'
|
|
5
|
+
|
|
6
|
+
import { MockData } from '../../mock'
|
|
7
|
+
import { RandomCode, updateCacheMod } from '../../utils'
|
|
8
|
+
import { useUpdateExtProductFoodsOptional } from '../updateExtProductFoodsOptional'
|
|
9
|
+
import { useDeleteSubProductOptional } from '../useDeleteSubProductOptional'
|
|
10
|
+
import { useEditSubProductOptional } from '../useEditSubProductOptional'
|
|
11
|
+
import { useRemoveExtraProductFoodsOptional } from '../useRemoveExtraProductFoodsOptional'
|
|
12
|
+
import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
|
|
13
|
+
import { useUpdateExtProductFoodsSubOptional } from '../useUpdateExtProductFoodsSubOptional'
|
|
14
|
+
|
|
15
|
+
import { transformDataToDessert } from './helpers'
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
export const useDessert = ({
|
|
19
|
+
pId = null,
|
|
20
|
+
initialData = null,
|
|
21
|
+
sendNotification = (args) => { return args }
|
|
22
|
+
}) => {
|
|
23
|
+
const [selectedExtra, setSelectedExtra] = useState({})
|
|
24
|
+
const [openModalEditExtra, setOpenModalEditExtra] = useState(false)
|
|
25
|
+
const [selectedItem, setSelectedItem] = useState({})
|
|
26
|
+
|
|
27
|
+
// Initialize state variables using the useState hook
|
|
28
|
+
const [setCheck, setChecker] = useState({
|
|
29
|
+
exState: false
|
|
30
|
+
}) // State for checkboxes
|
|
31
|
+
const [valueItems, setValueItems] = useState('') // State for input values
|
|
32
|
+
const [title, setTitle] = useState('') // State for title input value
|
|
33
|
+
// Initialize the data state with the transformedData or MockData
|
|
34
|
+
const [data, setData] = useState(MockData)
|
|
35
|
+
const handleCleanData = () => {
|
|
36
|
+
setData(MockData)
|
|
37
|
+
}
|
|
38
|
+
const dataListIds = data?.listIds?.filter(x => {return x !== '01list'})
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Checks if all required lists have the maximum number of cards.
|
|
42
|
+
*
|
|
43
|
+
* @return {boolean} Returns true if all required lists have the maximum number of cards, otherwise false.
|
|
44
|
+
*/
|
|
45
|
+
const isCompleteRequired = dataListIds?.every(listID => {
|
|
46
|
+
try {
|
|
47
|
+
if (!Array.isArray(dataListIds) || data === null) {
|
|
48
|
+
throw new Error('Invalid arguments. dataListIds must be an array and data must be a non-null object.')
|
|
49
|
+
}
|
|
50
|
+
const list = data.lists[listID]
|
|
51
|
+
// If list or list.cards is missing, assume the list is not complete
|
|
52
|
+
const verifiEmpyRequireCard = list?.cards?.length
|
|
53
|
+
if (list && list?.cards) {
|
|
54
|
+
return Number(verifiEmpyRequireCard) === Number(list.numberLimit)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// If list or list.cards is missing, assume the list is not complete
|
|
58
|
+
return false
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return false
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// Use useEffect to update the data state when the initialData prop changes
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (initialData) {
|
|
67
|
+
// Only update the data state if it's different from initialData
|
|
68
|
+
if (JSON.stringify(data) !== JSON.stringify(transformDataToDessert(initialData))) {
|
|
69
|
+
const transformedInitialData = transformDataToDessert(initialData)
|
|
70
|
+
setData(transformedInitialData)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, [initialData]) // Include data as a dependency
|
|
74
|
+
|
|
75
|
+
// Filter the 'listIds' from 'data' and store the filtered result in 'dataListIds'
|
|
76
|
+
// Here, it seems to exclude a specific list ID ('01list') from the listIds.
|
|
77
|
+
|
|
78
|
+
// HOOKS
|
|
79
|
+
const { handleMutateExtProductFoodsSubOptional } = useUpdateExtProductFoodsSubOptional({
|
|
80
|
+
sendNotification
|
|
81
|
+
})
|
|
82
|
+
const { handleUpdateExtProduct } = useUpdateExtProductFoodsOptional()
|
|
83
|
+
const { DeleteExtProductFoodsOptional } = useRemoveExtraProductFoodsOptional()
|
|
84
|
+
const [DeleteExtFoodSubsOptional] = useDeleteSubProductOptional()
|
|
85
|
+
const [editExtFoodSubsOptional, { loading: loadingEditSubOptional }] = useEditSubProductOptional()
|
|
86
|
+
|
|
87
|
+
// HANDLESS
|
|
88
|
+
/**
|
|
89
|
+
* Handles checkbox changes and updates the setCheck state accordingly.
|
|
90
|
+
* @param {Event} e - The checkbox change event object.
|
|
91
|
+
*/
|
|
92
|
+
const handleCheck = (e) => {
|
|
93
|
+
// Extract the 'name' and 'checked' properties from the event target (checkbox)
|
|
94
|
+
const { name, checked } = e.target
|
|
95
|
+
|
|
96
|
+
// Update the setCheck state with the new value for the checkbox identified by the 'name' property
|
|
97
|
+
setChecker({ ...setCheck, [name]: checked })
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Handles the removal of a list from the data state and performs additional operations if needed.
|
|
102
|
+
* @param {number} i - The index of the list to be removed.
|
|
103
|
+
* @param {string} listID - The ID of the list to be removed (optional).
|
|
104
|
+
* @throws {Error} Will throw an error if the provided index (i) is not a non-negative number.
|
|
105
|
+
* @throws {Error} Will throw an error if the provided index (i) is out of range.
|
|
106
|
+
* @throws {Error} Will throw an error if the provided listID is invalid (optional validation).
|
|
107
|
+
*/
|
|
108
|
+
const handleRemoveList = (i, listID) => {
|
|
109
|
+
// Validate that the provided index (i) is a non-negative number
|
|
110
|
+
if (typeof i !== 'number' || i < 0) {
|
|
111
|
+
throw new Error('Invalid index provided. The index must be a non-negative number.')
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Make a copy of the listIds array from the data state
|
|
115
|
+
const listIdsCopy = [...data.listIds]
|
|
116
|
+
|
|
117
|
+
// Validate that the provided index (i) is within the range of the listIds array
|
|
118
|
+
if (i >= listIdsCopy.length) {
|
|
119
|
+
throw new Error('Invalid index provided. The index is out of range.')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Remove the list with the specified index from the listIdsCopy array
|
|
123
|
+
const Lines = data?.listIds.filter((_, index) => {return index !== i})?.filter(x => {return x !== '01list'})
|
|
124
|
+
// Update the data state with the modified listIdsCopy array
|
|
125
|
+
setData({
|
|
126
|
+
listIds: listID ? Lines.filter((subItem) => { return subItem !== listID }) : Lines,
|
|
127
|
+
lists: {
|
|
128
|
+
...data.lists
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
// Perform additional operations if a valid listID is provided
|
|
133
|
+
if (listID) {
|
|
134
|
+
try {
|
|
135
|
+
// Assuming DeleteExtProductFoodsOptional is a function that deletes an external product
|
|
136
|
+
// Call the function to delete the external product using the provided listID
|
|
137
|
+
DeleteExtProductFoodsOptional({
|
|
138
|
+
variables: {
|
|
139
|
+
state: 1,
|
|
140
|
+
opExPid: listID,
|
|
141
|
+
isCustomOpExPid: true
|
|
142
|
+
},
|
|
143
|
+
update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
|
|
144
|
+
return updateCacheMod({
|
|
145
|
+
cache,
|
|
146
|
+
query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
147
|
+
nameFun: 'ExtProductFoodsOptionalAll',
|
|
148
|
+
dataNew: ExtProductFoodsOptionalAll
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
} catch (error) {
|
|
153
|
+
// Handle any errors that may occur during the deletion process
|
|
154
|
+
throw new Error('An error occurred while deleting the external product.')
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Removes a specific item from a list within the data state.
|
|
161
|
+
* @param {Object} params - The parameters for removing the item.
|
|
162
|
+
* @param {string} params.listID - The ID of the list from which the item will be removed.
|
|
163
|
+
* @param {string} params.id - The ID of the item to be removed.
|
|
164
|
+
* @param params.isCustomSubOpExPid
|
|
165
|
+
* @throws {Error} Will throw an error if the provided listID does not exist in the data state.
|
|
166
|
+
* @throws {Error} Will throw an error if the provided listID exists but the corresponding list does not have a cards array.
|
|
167
|
+
*/
|
|
168
|
+
const removeOneItem = ({
|
|
169
|
+
listID = '',
|
|
170
|
+
id = '',
|
|
171
|
+
isCustomSubOpExPid = false
|
|
172
|
+
}) => {
|
|
173
|
+
try {
|
|
174
|
+
const forRemove = Boolean(listID && id)
|
|
175
|
+
if (forRemove) {
|
|
176
|
+
DeleteExtFoodSubsOptional({
|
|
177
|
+
variables: {
|
|
178
|
+
isCustomSubOpExPid,
|
|
179
|
+
opSubExPid: id,
|
|
180
|
+
state: 1
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
}
|
|
184
|
+
// Ensure the provided listID exists in the data state
|
|
185
|
+
if (!data.lists[listID]) {
|
|
186
|
+
throw new Error(`List with ID "${listID}" does not exist.`)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Ensure the list has a cards array
|
|
190
|
+
if (!Array.isArray(data.lists[listID].cards)) {
|
|
191
|
+
throw new Error(`List with ID "${listID}" does not have a valid cards array.`)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Get the current list from the data state using the provided listID
|
|
195
|
+
const currentList = data.lists[listID]
|
|
196
|
+
|
|
197
|
+
// Filter out the item with the specified ID from the current list's cards array
|
|
198
|
+
const filteredCart = currentList?.cards?.filter((cart) => {return cart.id !== id})
|
|
199
|
+
|
|
200
|
+
// Update the current list's cards with the filtered array to remove the specified item
|
|
201
|
+
setData({
|
|
202
|
+
listIds: [...data.listIds],
|
|
203
|
+
lists: {
|
|
204
|
+
...data.lists,
|
|
205
|
+
[listID]: {
|
|
206
|
+
...currentList,
|
|
207
|
+
cards: filteredCart
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
} catch (error) {
|
|
212
|
+
console.error(error)
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Edits a single item within a list.
|
|
218
|
+
*
|
|
219
|
+
* The `editOneItem` function is responsible for editing the title of a specific item in a list.
|
|
220
|
+
* It first updates the state of the selected item, then searches for the item in the current list
|
|
221
|
+
* using its ID, and compares the existing title with the new title provided. If the title is
|
|
222
|
+
* different and not null, it makes an API call (`editExtFoodSubsOptional`) to update the
|
|
223
|
+
* title in the database. If the update is successful, a success notification is sent, and
|
|
224
|
+
* the local state is updated to reflect the changes in the item. The function handles errors
|
|
225
|
+
* internally and logs them to the console.
|
|
226
|
+
*
|
|
227
|
+
* @param {Object} params - Parameters for editing an item.
|
|
228
|
+
* @param {string} params.listID - The ID of the list containing the item to be edited.
|
|
229
|
+
* @param {string} params.id - The ID of the specific item to be edited.
|
|
230
|
+
* @param {string|null} [params.title=null] - The new title for the item. If null, no
|
|
231
|
+
* update is performed.
|
|
232
|
+
*/
|
|
233
|
+
const editOneItem = ({
|
|
234
|
+
listID = '',
|
|
235
|
+
id = '',
|
|
236
|
+
title = null
|
|
237
|
+
}) => {
|
|
238
|
+
try {
|
|
239
|
+
setSelectedItem(() => {
|
|
240
|
+
return { listID, id }
|
|
241
|
+
})
|
|
242
|
+
const currentList = data.lists[listID]
|
|
243
|
+
const findItem = currentList?.cards?.find(item => { return item.id === id })
|
|
244
|
+
const checkDifferentText = findItem?.title !== title
|
|
245
|
+
if (title && checkDifferentText) {
|
|
246
|
+
editExtFoodSubsOptional({
|
|
247
|
+
variables: {
|
|
248
|
+
isCustomSubOpExPid: false,
|
|
249
|
+
opSubExPid: id,
|
|
250
|
+
OptionalSubProName: title
|
|
251
|
+
}
|
|
252
|
+
}).then(({ data: response }) => {
|
|
253
|
+
const { editExtFoodSubsOptional } = response || {}
|
|
254
|
+
const { success } = editExtFoodSubsOptional || { success: false }
|
|
255
|
+
if (success) {
|
|
256
|
+
sendNotification({
|
|
257
|
+
description: 'El sub item actualizado con éxito',
|
|
258
|
+
title: 'Actualizado',
|
|
259
|
+
backgroundColor: 'success'
|
|
260
|
+
})
|
|
261
|
+
const currentList = data.lists[listID]
|
|
262
|
+
const updatedCards = currentList?.cards?.map((card) => {
|
|
263
|
+
if (card.id === id) {
|
|
264
|
+
return {
|
|
265
|
+
...card,
|
|
266
|
+
title
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return card
|
|
270
|
+
})
|
|
271
|
+
setData({
|
|
272
|
+
listIds: [...data.listIds],
|
|
273
|
+
lists: {
|
|
274
|
+
...data.lists,
|
|
275
|
+
[listID]: {
|
|
276
|
+
...currentList,
|
|
277
|
+
cards: updatedCards
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.error(error)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const updateListById = (listId, updatedFields) => {
|
|
290
|
+
setData((prevData) => {
|
|
291
|
+
const updatedLists = {
|
|
292
|
+
...prevData.lists,
|
|
293
|
+
[listId]: {
|
|
294
|
+
...prevData.lists[listId],
|
|
295
|
+
...updatedFields
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
...prevData,
|
|
301
|
+
lists: updatedLists
|
|
302
|
+
}
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Edit a extra.
|
|
307
|
+
* @async
|
|
308
|
+
* @param {Object} options - Opciones para la edición del extra.
|
|
309
|
+
* @param {string} options.id - ID del extra.
|
|
310
|
+
* @param {number|null} options.numberLimit - Límite de número para el extra.
|
|
311
|
+
* @param {string} options.title - Título del extra.
|
|
312
|
+
* @param {boolean} options.required - Indica si el extra es requerido.
|
|
313
|
+
* @throws {Error} Se lanza un error si no se proporciona un ID válido.
|
|
314
|
+
* @returns {Promise<void>}
|
|
315
|
+
*/
|
|
316
|
+
const editOneExtra = async ({
|
|
317
|
+
id = '',
|
|
318
|
+
numberLimit = null,
|
|
319
|
+
title,
|
|
320
|
+
required
|
|
321
|
+
}) => {
|
|
322
|
+
try {
|
|
323
|
+
if (id) {
|
|
324
|
+
const response = await handleUpdateExtProduct({
|
|
325
|
+
opExPid: id,
|
|
326
|
+
code: id,
|
|
327
|
+
OptionalProName: title,
|
|
328
|
+
required: required ? 1 : 0,
|
|
329
|
+
numbersOptionalOnly: numberLimit
|
|
330
|
+
})
|
|
331
|
+
const { data } = response || {}
|
|
332
|
+
if (!data?.updateExtProductOptional) {
|
|
333
|
+
return sendNotification({
|
|
334
|
+
description: 'Ocurrió un error, intenta de nuevo',
|
|
335
|
+
title: 'Error',
|
|
336
|
+
backgroundColor: 'warning'
|
|
337
|
+
})
|
|
338
|
+
}
|
|
339
|
+
const { success, message } = data?.updateExtProductOptional || {}
|
|
340
|
+
if (success) {
|
|
341
|
+
setSelectedExtra({})
|
|
342
|
+
setOpenModalEditExtra(false)
|
|
343
|
+
sendNotification({
|
|
344
|
+
description: message,
|
|
345
|
+
title: 'Actualizado',
|
|
346
|
+
backgroundColor: 'success'
|
|
347
|
+
})
|
|
348
|
+
return updateListById(id, {
|
|
349
|
+
title,
|
|
350
|
+
numberLimit,
|
|
351
|
+
required: required ? 1 : 0
|
|
352
|
+
})
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if (!id) {
|
|
357
|
+
return sendNotification({
|
|
358
|
+
description: 'Ocurrió un error, intenta de nuevo',
|
|
359
|
+
title: 'Error',
|
|
360
|
+
backgroundColor: 'warning'
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
} catch (error) {
|
|
364
|
+
setSelectedExtra({})
|
|
365
|
+
setOpenModalEditExtra(false)
|
|
366
|
+
sendNotification({
|
|
367
|
+
description: 'Ocurrió un error, intenta de nuevo',
|
|
368
|
+
title: 'Error',
|
|
369
|
+
backgroundColor: 'warning'
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
const addCard = async (title, listId) => {
|
|
375
|
+
const id = RandomCode(9)
|
|
376
|
+
const newCard = {
|
|
377
|
+
id,
|
|
378
|
+
title,
|
|
379
|
+
numberLimit: 5,
|
|
380
|
+
value: '',
|
|
381
|
+
required: setCheck.exState ? 1 : 0
|
|
382
|
+
}
|
|
383
|
+
const list = data.lists[listId]
|
|
384
|
+
list.cards = [...list.cards, newCard]
|
|
385
|
+
setData({
|
|
386
|
+
...data,
|
|
387
|
+
lists: {
|
|
388
|
+
...data.lists,
|
|
389
|
+
[listId]: list
|
|
390
|
+
}
|
|
391
|
+
})
|
|
392
|
+
handleMutateExtProductFoodsSubOptional({
|
|
393
|
+
pId,
|
|
394
|
+
title,
|
|
395
|
+
listId,
|
|
396
|
+
id,
|
|
397
|
+
state: 1
|
|
398
|
+
})
|
|
399
|
+
setTitle('')
|
|
400
|
+
}
|
|
401
|
+
const handleAdd = ({ listId }) => {
|
|
402
|
+
if (valueItems !== '' && valueItems.trim() !== '') {
|
|
403
|
+
addCard(valueItems, listId)
|
|
404
|
+
}
|
|
405
|
+
setValueItems('')
|
|
406
|
+
// Reset the value of all lists in dataListIds to 0 in a single setData call
|
|
407
|
+
setData(prevData => {
|
|
408
|
+
const updatedLists = Object.fromEntries(
|
|
409
|
+
Object.entries(prevData.lists).map(([listId, list]) => {
|
|
410
|
+
if (dataListIds.includes(listId)) {
|
|
411
|
+
return [listId, { ...list, value: '' }]
|
|
412
|
+
}
|
|
413
|
+
return [listId, list]
|
|
414
|
+
})
|
|
415
|
+
)
|
|
416
|
+
return {
|
|
417
|
+
...prevData,
|
|
418
|
+
lists: updatedLists
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Handles the addition of a new list with the given title and number limit.
|
|
425
|
+
* @param {Object} params - The parameters for adding the new list.
|
|
426
|
+
* @param {string} params.title - The title of the new list.
|
|
427
|
+
* @param {number} params.numberLimit - The number limit for the new list.
|
|
428
|
+
*/
|
|
429
|
+
const handleAddList = async ({ title, numberLimit }) => {
|
|
430
|
+
// Check if the title is not empty
|
|
431
|
+
if (title.trim() === '') {
|
|
432
|
+
sendNotification({
|
|
433
|
+
description: 'El titulo no debe estar vacío',
|
|
434
|
+
title: 'Error',
|
|
435
|
+
backgroundColor: 'warning'
|
|
436
|
+
})
|
|
437
|
+
return // Termina la función si el título está vacío
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Generate a new list ID using the RandomCode function (must be implemented elsewhere)
|
|
441
|
+
const newListId = RandomCode(9)
|
|
442
|
+
|
|
443
|
+
// Determine if the list is required based on the setCheck.exState state
|
|
444
|
+
const required = setCheck.exState ? 1 : 0
|
|
445
|
+
|
|
446
|
+
// Add the new list to the beginning of the data state
|
|
447
|
+
setData(prevData => {return {
|
|
448
|
+
listIds: [newListId, ...prevData.listIds], // Agrega el nuevo ID al principio del array
|
|
449
|
+
lists: {
|
|
450
|
+
...prevData.lists,
|
|
451
|
+
[newListId]: {
|
|
452
|
+
id: newListId,
|
|
453
|
+
title,
|
|
454
|
+
required,
|
|
455
|
+
numberLimit,
|
|
456
|
+
value: '',
|
|
457
|
+
cards: []
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}})
|
|
461
|
+
|
|
462
|
+
// Update the external product with the information of the new list
|
|
463
|
+
handleUpdateExtProduct({
|
|
464
|
+
pId,
|
|
465
|
+
code: newListId,
|
|
466
|
+
OptionalProName: title,
|
|
467
|
+
required,
|
|
468
|
+
numbersOptionalOnly: numberLimit
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
// Clear the title field after adding the list
|
|
472
|
+
setTitle('')
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Handles the change of items in a specific list.
|
|
477
|
+
* @param {Object} params - The parameters for handling the change.
|
|
478
|
+
* @param {string} params.listID - The ID of the list where the change is happening.
|
|
479
|
+
* @param {Object} params.value - The event object containing the new value for the list items.
|
|
480
|
+
*/
|
|
481
|
+
const handleChangeItems = ({ listID, value: e }) => {
|
|
482
|
+
const value = e.target.value
|
|
483
|
+
setValueItems(value)
|
|
484
|
+
|
|
485
|
+
// Get the current list from the data state using the provided listID
|
|
486
|
+
const currentList = data.lists[listID]
|
|
487
|
+
|
|
488
|
+
// Update the value of the current list with the new value
|
|
489
|
+
setData({
|
|
490
|
+
listIds: [...data.listIds],
|
|
491
|
+
lists: {
|
|
492
|
+
...data.lists,
|
|
493
|
+
[listID]: {
|
|
494
|
+
...currentList,
|
|
495
|
+
value
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
// Note: The return statement seems to be unnecessary, and the map function doesn't serve a purpose here.
|
|
501
|
+
// If you want to map through dataListIds for some other reason, you should use it separately from this function.
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return {
|
|
505
|
+
addCard,
|
|
506
|
+
data,
|
|
507
|
+
dataListIds,
|
|
508
|
+
loadingEditSubOptional,
|
|
509
|
+
isCompleteRequired,
|
|
510
|
+
handleAdd,
|
|
511
|
+
handleAddList,
|
|
512
|
+
handleChangeItems,
|
|
513
|
+
handleCheck,
|
|
514
|
+
handleRemoveList,
|
|
515
|
+
removeOneItem,
|
|
516
|
+
editOneExtra,
|
|
517
|
+
editOneItem,
|
|
518
|
+
setCheck,
|
|
519
|
+
selectedItem,
|
|
520
|
+
setData,
|
|
521
|
+
handleCleanData,
|
|
522
|
+
setTitle,
|
|
523
|
+
title,
|
|
524
|
+
selectedExtra,
|
|
525
|
+
openModalEditExtra,
|
|
526
|
+
setSelectedExtra,
|
|
527
|
+
setOpenModalEditExtra
|
|
528
|
+
}
|
|
529
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export const transformData = (dataExtra) => {
|
|
2
|
+
const transformedData = dataExtra?.map(item => {return {
|
|
3
|
+
extraName: item.extraName || '',
|
|
4
|
+
extraPrice: item?.extraPrice?.toString() || '',
|
|
5
|
+
exState: Boolean(item.exState),
|
|
6
|
+
forEdit: true,
|
|
7
|
+
...item
|
|
8
|
+
}})
|
|
9
|
+
|
|
10
|
+
return transformedData
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const MAX_INTEGER = 999999999999.99
|
|
14
|
+
/**
|
|
15
|
+
* Validate if a number is within a specified range.
|
|
16
|
+
* @param {number} num - The number to validate.
|
|
17
|
+
* @returns {boolean} - True if the number is within the range, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export const isWithinRange = (num) => {
|
|
20
|
+
// Verificar si el número está dentro del rango permitido.
|
|
21
|
+
return num >= MAX_INTEGER
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Find objects in the array where the value of 'extraPrice' exceeds the specified range.
|
|
26
|
+
* @param {array} arr - The array to search.
|
|
27
|
+
* @returns {array} - An array containing the indices and objects of the items exceeding the range.
|
|
28
|
+
*/
|
|
29
|
+
export const findNumbersExceedingRange = (arr) => {
|
|
30
|
+
return arr.reduce((acc, item, index) => {
|
|
31
|
+
const extraPrice = typeof item.extraPrice === 'number' ? item.extraPrice : parseFloat(item.extraPrice.replace(/\./g, ''))
|
|
32
|
+
if (isWithinRange(extraPrice)) {
|
|
33
|
+
acc.push({ index, item })
|
|
34
|
+
}
|
|
35
|
+
return acc
|
|
36
|
+
}, [])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const updateErrorFieldByIndex = ({
|
|
40
|
+
setLine = (array) => {
|
|
41
|
+
return array
|
|
42
|
+
},
|
|
43
|
+
checkNumberRange = []
|
|
44
|
+
} = {
|
|
45
|
+
setLine: (array) => {
|
|
46
|
+
return array
|
|
47
|
+
},
|
|
48
|
+
checkNumberRange: []
|
|
49
|
+
}) => {
|
|
50
|
+
setLine(prevLineItems => {
|
|
51
|
+
// Crea una copia del estado anterior de LineItems
|
|
52
|
+
const updatedLineItems = { ...prevLineItems }
|
|
53
|
+
|
|
54
|
+
// Utiliza map para iterar sobre cada elemento en checkNumberRange
|
|
55
|
+
const updatedLines = updatedLineItems.Lines.map((line, index) => {
|
|
56
|
+
// Verifica si el índice está dentro del rango de LineItems.Lines
|
|
57
|
+
if (checkNumberRange.some(item => {return item.index === index})) {
|
|
58
|
+
// Crea una copia del elemento actual
|
|
59
|
+
const updatedLine = { ...line }
|
|
60
|
+
|
|
61
|
+
// Actualiza el campo 'error' del elemento a true
|
|
62
|
+
updatedLine.error = true
|
|
63
|
+
updatedLine.messageError = 'El precio no puede ser mayor a 999999999999.99'
|
|
64
|
+
|
|
65
|
+
// Devuelve el elemento actualizado
|
|
66
|
+
return updatedLine
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Si el índice no está en checkNumberRange, devuelve el elemento sin cambios
|
|
70
|
+
return line
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
// Actualiza el array Lines en el estado de LineItems con los elementos actualizados
|
|
74
|
+
return { ...updatedLineItems, Lines: updatedLines }
|
|
75
|
+
})
|
|
76
|
+
}
|