npm-pkg-hook 1.12.3 → 1.12.7

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.
Files changed (315) hide show
  1. package/dist/index.cjs +20089 -0
  2. package/dist/index.js +19854 -0
  3. package/dist/index.mjs +19854 -0
  4. package/package.json +28 -6
  5. package/.babelrc +0 -0
  6. package/.env +0 -5
  7. package/.eslintrc.js +0 -38
  8. package/.eslintrc.json +0 -127
  9. package/.github/pull_request_template.md +0 -18
  10. package/.github/workflows/pepeline.yaml +0 -30
  11. package/expire.json +0 -1
  12. package/jsconfig.json +0 -28
  13. package/script.txt +0 -7
  14. package/src/config/client/errors.js +0 -26
  15. package/src/config/client/index.js +0 -1
  16. package/src/config/content/en.json +0 -5
  17. package/src/config/content/es.json +0 -5
  18. package/src/config/content/index.js +0 -16
  19. package/src/cookies/index.js +0 -3
  20. package/src/hooks/addTenMinutes/index.js +0 -14
  21. package/src/hooks/calculateLogLatHaversine/index.js +0 -30
  22. package/src/hooks/completeSchedules/index.js +0 -22
  23. package/src/hooks/convertToMilitaryTime/index.js +0 -14
  24. package/src/hooks/generateStoreURL/index.js +0 -38
  25. package/src/hooks/generateTemplate/index.js +0 -62
  26. package/src/hooks/getCardType/index.js +0 -24
  27. package/src/hooks/getCategoriesWithProduct/helpers/index.js +0 -7
  28. package/src/hooks/getCategoriesWithProduct/index.js +0 -62
  29. package/src/hooks/getGlobalSession/index.js +0 -49
  30. package/src/hooks/getSession/index.js +0 -18
  31. package/src/hooks/getTodayTimestamps/index.js +0 -64
  32. package/src/hooks/getTotalHours/index.js +0 -48
  33. package/src/hooks/handleLogin/index.js +0 -10
  34. package/src/hooks/index.ts +0 -146
  35. package/src/hooks/isTokenExpired/index.js +0 -17
  36. package/src/hooks/newMessageSubscription/index.js +0 -28
  37. package/src/hooks/newStoreOrderSubscription/index.js +0 -26
  38. package/src/hooks/statusOpenStores/helpers/index.js +0 -101
  39. package/src/hooks/statusOpenStores/index.js +0 -156
  40. package/src/hooks/updateExtProductFoodsOptional/index.js +0 -40
  41. package/src/hooks/useAcumulateDate/index.js +0 -16
  42. package/src/hooks/useAllStoresPendingToRegister/index.js +0 -34
  43. package/src/hooks/useAmountInput/index.ts +0 -117
  44. package/src/hooks/useAnimationFrame/index.js +0 -45
  45. package/src/hooks/useAnimationText/index.jsx +0 -31
  46. package/src/hooks/useAsideCart/helpers/index.js +0 -22
  47. package/src/hooks/useAsideCart/index.js +0 -214
  48. package/src/hooks/useAsideCart/queries.js +0 -10
  49. package/src/hooks/useBanner/index.js +0 -19
  50. package/src/hooks/useCart/index.js +0 -2
  51. package/src/hooks/useCart/queries.js +0 -174
  52. package/src/hooks/useCart/useCart/helpers/index.js +0 -75
  53. package/src/hooks/useCart/useCart/index.js +0 -412
  54. package/src/hooks/useCart/useGetCart/index.js +0 -33
  55. package/src/hooks/useCatWithProduct/index.js +0 -48
  56. package/src/hooks/useCatWithProduct/queries.js +0 -200
  57. package/src/hooks/useCatWithProductClient/index.js +0 -56
  58. package/src/hooks/useCatWithProductClient/queries.js +0 -56
  59. package/src/hooks/useCategoriesProduct/index.js +0 -13
  60. package/src/hooks/useCategoriesProduct/queries.js +0 -16
  61. package/src/hooks/useCategoryInStore/index.js +0 -100
  62. package/src/hooks/useCategoryInStore/queries.js +0 -78
  63. package/src/hooks/useCategoryStore/index.js +0 -7
  64. package/src/hooks/useCategoryStore/queries.js +0 -16
  65. package/src/hooks/useChartData/index.js +0 -170
  66. package/src/hooks/useChartData/useChartData/index.js +0 -199
  67. package/src/hooks/useChartData/useChartDataAllOrders/index.js +0 -94
  68. package/src/hooks/useChatRoomSubscription/index.js +0 -28
  69. package/src/hooks/useCheckbox/index.js +0 -115
  70. package/src/hooks/useCities/index.js +0 -13
  71. package/src/hooks/useCities/queries.js +0 -12
  72. package/src/hooks/useClients/index.js +0 -96
  73. package/src/hooks/useClients/queries.js +0 -212
  74. package/src/hooks/useColorByLetters/helpers/alea.js +0 -54
  75. package/src/hooks/useColorByLetters/helpers/colors.js +0 -45
  76. package/src/hooks/useColorByLetters/helpers/index.js +0 -18
  77. package/src/hooks/useColorByLetters/helpers/mersenne_twister.js +0 -118
  78. package/src/hooks/useColorByLetters/index.js +0 -27
  79. package/src/hooks/useConnection/index.js +0 -24
  80. package/src/hooks/useCountries/index.js +0 -19
  81. package/src/hooks/useCountries/queries.js +0 -12
  82. package/src/hooks/useCreateDeliveryTime/index.js +0 -51
  83. package/src/hooks/useCreateOrderStatusType/index.ts +0 -132
  84. package/src/hooks/useCreateProduct/helpers/index.js +0 -23
  85. package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +0 -52
  86. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +0 -176
  87. package/src/hooks/useCreateProduct/index.js +0 -334
  88. package/src/hooks/useCreateStorePendingToRegister/index.js +0 -13
  89. package/src/hooks/useCreateStorePendingToRegister/queries.js +0 -10
  90. package/src/hooks/useDashboardComponents/index.js +0 -50
  91. package/src/hooks/useDeleteExtraProductFoods/index.js +0 -12
  92. package/src/hooks/useDeleteSubProductOptional/index.js +0 -30
  93. package/src/hooks/useDeleteSubProductOptional/queries.js +0 -10
  94. package/src/hooks/useDeliveryTime/index.js +0 -27
  95. package/src/hooks/useDepartments/index.js +0 -13
  96. package/src/hooks/useDepartments/queries.js +0 -13
  97. package/src/hooks/useDessert/helpers/index.js +0 -51
  98. package/src/hooks/useDessert/index.js +0 -525
  99. package/src/hooks/useDessertWithPrice/helpers/index.js +0 -76
  100. package/src/hooks/useDessertWithPrice/index.js +0 -373
  101. package/src/hooks/useDessertWithPrice/queries.js +0 -18
  102. package/src/hooks/useDevWS/index.ts +0 -53
  103. package/src/hooks/useDevices/index.js +0 -2
  104. package/src/hooks/useDevices/queries.js +0 -28
  105. package/src/hooks/useDevices/useGetDevices.js +0 -28
  106. package/src/hooks/useDevices/useRegisterDevices.js +0 -75
  107. package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +0 -21
  108. package/src/hooks/useDownloadReports/index.ts +0 -2
  109. package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +0 -103
  110. package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +0 -115
  111. package/src/hooks/useDrag/index.js +0 -63
  112. package/src/hooks/useDropzone/index.js +0 -94
  113. package/src/hooks/useDynamicAuth/index.js +0 -13
  114. package/src/hooks/useDynamicAuth/queries.js +0 -24
  115. package/src/hooks/useEditCategory/index.js +0 -41
  116. package/src/hooks/useEditOneExtProductFoodOptional/index.js +0 -28
  117. package/src/hooks/useEditOneExtProductFoodOptional/queries.js +0 -16
  118. package/src/hooks/useEditSubProductOptional/index.js +0 -11
  119. package/src/hooks/useEditSubProductOptional/queries.js +0 -10
  120. package/src/hooks/useEmployee/index.js +0 -17
  121. package/src/hooks/useEmployee/queries.js +0 -85
  122. package/src/hooks/useEmployee/useCreateEmployee.js +0 -86
  123. package/src/hooks/useEvent/index.js +0 -34
  124. package/src/hooks/useFavoriteStores/index.js +0 -29
  125. package/src/hooks/useFavoriteStores/queries.js +0 -54
  126. package/src/hooks/useFetchJson/index.js +0 -25
  127. package/src/hooks/useFetchMoreInteractions/index.jsx +0 -39
  128. package/src/hooks/useFingerprintjs/index.js +0 -172
  129. package/src/hooks/useFormTools/index.js +0 -116
  130. package/src/hooks/useFormatDate/index.js +0 -86
  131. package/src/hooks/useFormatNumberPhone/index.js +0 -23
  132. package/src/hooks/useFullScreenMode/index.js +0 -65
  133. package/src/hooks/useGenerateNumberArray/index.js +0 -17
  134. package/src/hooks/useGetAllLocationUser/index.js +0 -12
  135. package/src/hooks/useGetAllLocationUser/queries.js +0 -44
  136. package/src/hooks/useGetCookies/index.js +0 -43
  137. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +0 -14
  138. package/src/hooks/useGetFoodRecomended/index.js +0 -32
  139. package/src/hooks/useGetFoodRecomended/queries.js +0 -47
  140. package/src/hooks/useGetMessagesToRoom/index.js +0 -23
  141. package/src/hooks/useGetMinPrice/index.js +0 -12
  142. package/src/hooks/useGetMinPrice/queries.js +0 -7
  143. package/src/hooks/useGetOneStoreRating/index.js +0 -40
  144. package/src/hooks/useGetOneStoreRating/queries.js +0 -18
  145. package/src/hooks/useGetSalesAmountToday/index.js +0 -31
  146. package/src/hooks/useGetStoreCookie/index.js +0 -21
  147. package/src/hooks/useGoogleLogin/index.js +0 -160
  148. package/src/hooks/useGoogleLogin/loadScript.js +0 -15
  149. package/src/hooks/useGoogleLogin/removeScript.js +0 -7
  150. package/src/hooks/useHover/index.js +0 -29
  151. package/src/hooks/useImageOptimization/index.js +0 -28
  152. package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +0 -130
  153. package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +0 -53
  154. package/src/hooks/useImageUploaderProduct/helper/index.ts +0 -5
  155. package/src/hooks/useImageUploaderProduct/index.ts +0 -292
  156. package/src/hooks/useImageWeight/index.js +0 -51
  157. package/src/hooks/useImagesStore/index.js +0 -225
  158. package/src/hooks/useImagesStore/queries.js +0 -193
  159. package/src/hooks/useImagesStore/utils/index.js +0 -4
  160. package/src/hooks/useIncomingOrders/index.js +0 -10
  161. package/src/hooks/useIncomingOrders/queries.js +0 -87
  162. package/src/hooks/useInnerHtml/index.js +0 -39
  163. package/src/hooks/useIntersection/index.js +0 -84
  164. package/src/hooks/useInventory/index.js +0 -2
  165. package/src/hooks/useInventory/queries.js +0 -58
  166. package/src/hooks/useInventory/useGetProductsInStock.js +0 -15
  167. package/src/hooks/useInventory/useUpdateManageStock.js +0 -41
  168. package/src/hooks/useKeypress/index.js +0 -28
  169. package/src/hooks/useLazyScript/index.js +0 -71
  170. package/src/hooks/useLocalBackendIp/index.js +0 -34
  171. package/src/hooks/useLocalSorage/index.js +0 -36
  172. package/src/hooks/useLocationManager/index.js +0 -63
  173. package/src/hooks/useLocationNavigate/index.js +0 -54
  174. package/src/hooks/useLoginEmployeeInStore/index.js +0 -38
  175. package/src/hooks/useLogout/helpers/BroadcastChannel.js +0 -31
  176. package/src/hooks/useLogout/helpers/apiBaseUrl.js +0 -8
  177. package/src/hooks/useLogout/helpers/fetchData.js +0 -28
  178. package/src/hooks/useLogout/helpers/getCsrfToken.js +0 -30
  179. package/src/hooks/useLogout/helpers/index.js +0 -57
  180. package/src/hooks/useLogout/helpers/logger.js +0 -70
  181. package/src/hooks/useLogout/helpers/parseUrl.js +0 -36
  182. package/src/hooks/useLogout/index.js +0 -96
  183. package/src/hooks/useManageNewOrder/helpers/index.js +0 -45
  184. package/src/hooks/useManageNewOrder/helpers/mock.js +0 -0
  185. package/src/hooks/useManageNewOrder/index.js +0 -102
  186. package/src/hooks/useManageQueryParams/index.js +0 -40
  187. package/src/hooks/useMobile/index.js +0 -65
  188. package/src/hooks/useModules/helpers/index.js +0 -1
  189. package/src/hooks/useModules/helpers/validateModules.js +0 -29
  190. package/src/hooks/useModules/index.js +0 -58
  191. package/src/hooks/useMouse/index.ts +0 -50
  192. package/src/hooks/useMutateHeight/index.js +0 -36
  193. package/src/hooks/useOrderClient/index.js +0 -5
  194. package/src/hooks/useOrderStatusTypes/index.ts +0 -2
  195. package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +0 -133
  196. package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +0 -97
  197. package/src/hooks/useOrders/index.js +0 -3
  198. package/src/hooks/useOrders/queries.js +0 -89
  199. package/src/hooks/useOrders/useChangeOrderState/index.ts +0 -125
  200. package/src/hooks/useOrders/useOrdersFromStore/index.ts +0 -77
  201. package/src/hooks/usePWAInstall/index.js +0 -38
  202. package/src/hooks/usePortFetcher/index.ts +0 -33
  203. package/src/hooks/useProductsFood/index.js +0 -253
  204. package/src/hooks/useProductsFood/queriesStore.js +0 -964
  205. package/src/hooks/useProductsFood/useEditProduct.js +0 -48
  206. package/src/hooks/useProductsFood/usetagsProducts.js +0 -98
  207. package/src/hooks/useProviders/index.js +0 -3
  208. package/src/hooks/useProviders/queries.js +0 -31
  209. package/src/hooks/useProviders/useProvidersCreateStore/index.js +0 -12
  210. package/src/hooks/useProviders/useProvidersDataStore/index.js +0 -24
  211. package/src/hooks/useProvidersStore/index.js +0 -24
  212. package/src/hooks/useProvidersStore/queries.js +0 -31
  213. package/src/hooks/usePushNotificationOrder/index.js +0 -52
  214. package/src/hooks/usePushNotifications/helpers/index.js +0 -114
  215. package/src/hooks/usePushNotifications/index.js +0 -149
  216. package/src/hooks/useQueryLocationsMap/index.js +0 -19
  217. package/src/hooks/useQueryLocationsMap/queries.js +0 -40
  218. package/src/hooks/useRatingArrayData/index.js +0 -54
  219. package/src/hooks/useRatingArrayData/queries.js +0 -19
  220. package/src/hooks/useReactToPrint/index.js +0 -1223
  221. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +0 -23
  222. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +0 -48
  223. package/src/hooks/useReport/index.js +0 -47
  224. package/src/hooks/useReport/queries.js +0 -123
  225. package/src/hooks/useRestaurant/helpers/index.js +0 -24
  226. package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +0 -26
  227. package/src/hooks/useRestaurant/index.js +0 -69
  228. package/src/hooks/useRestaurant/queries.js +0 -81
  229. package/src/hooks/useRoads/index.js +0 -19
  230. package/src/hooks/useRoads/queries.js +0 -13
  231. package/src/hooks/useRoles/index.js +0 -4
  232. package/src/hooks/useRoles/queries.js +0 -70
  233. package/src/hooks/useRoles/useCreateRole.js +0 -37
  234. package/src/hooks/useRoles/useGetRoles.js +0 -36
  235. package/src/hooks/useRoles/useRemoveRoles.js +0 -40
  236. package/src/hooks/useRoles/useUpdateRolesPriority.js +0 -44
  237. package/src/hooks/useSales/helpers/index.js +0 -55
  238. package/src/hooks/useSales/index.js +0 -1381
  239. package/src/hooks/useSales/queries.js +0 -424
  240. package/src/hooks/useSales/useGetAllSales/index.js +0 -25
  241. package/src/hooks/useSales/useGetSale.js +0 -13
  242. package/src/hooks/useSales/useTotalSales.js +0 -23
  243. package/src/hooks/useSaveAvailableProduct/helpers/index.js +0 -38
  244. package/src/hooks/useSaveAvailableProduct/index.js +0 -31
  245. package/src/hooks/useSaveAvailableProduct/queries.js +0 -10
  246. package/src/hooks/useSaveLocation/index.js +0 -16
  247. package/src/hooks/useSaveLocation/queries.js +0 -19
  248. package/src/hooks/useSchedule/index.js +0 -78
  249. package/src/hooks/useSchedule/index.jsx +0 -22
  250. package/src/hooks/useSchedule/queries.js +0 -43
  251. package/src/hooks/useScheduleData/index.js +0 -123
  252. package/src/hooks/useScroll/index.js +0 -56
  253. package/src/hooks/useScrollRotate/index.js +0 -16
  254. package/src/hooks/useSetImageProducts/index.js +0 -57
  255. package/src/hooks/useSetImageProducts/queries.js +0 -18
  256. package/src/hooks/useSetSession/index.js +0 -44
  257. package/src/hooks/useSetState/index.js +0 -24
  258. package/src/hooks/useSetupSchedule/helpers/index.js +0 -85
  259. package/src/hooks/useSetupSchedule/index.js +0 -272
  260. package/src/hooks/useStatusOpenStore/helpers/index.js +0 -101
  261. package/src/hooks/useStatusOpenStore/index.js +0 -179
  262. package/src/hooks/useStatusOrdersClient/helpers/index.js +0 -14
  263. package/src/hooks/useStatusOrdersClient/index.js +0 -17
  264. package/src/hooks/useStatusOrdersClient/queries.js +0 -80
  265. package/src/hooks/useStockMovements/helpers/index.js +0 -16
  266. package/src/hooks/useStockMovements/index.js +0 -38
  267. package/src/hooks/useStore/index.js +0 -80
  268. package/src/hooks/useStore/queries.js +0 -163
  269. package/src/hooks/useStoreCalendar/index.js +0 -5
  270. package/src/hooks/useStoreContacts/index.js +0 -47
  271. package/src/hooks/useStoreContacts/queries.js +0 -48
  272. package/src/hooks/useStoreTable/index.js +0 -2
  273. package/src/hooks/useStoreTable/queries.js +0 -47
  274. package/src/hooks/useStoreTable/useStoreTableCreate.js +0 -76
  275. package/src/hooks/useStoreTable/useStoreTables.js +0 -14
  276. package/src/hooks/useSubscriptionValidation/index.js +0 -41
  277. package/src/hooks/useTagProducts/index.ts +0 -3
  278. package/src/hooks/useTagProducts/useDeleteOneTag.ts +0 -106
  279. package/src/hooks/useTagProducts/useGetAllTags.ts +0 -68
  280. package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +0 -156
  281. package/src/hooks/useTimeAgo/useTimeAgo.js +0 -39
  282. package/src/hooks/useTokenCards/index.js +0 -41
  283. package/src/hooks/useTopProductsMovements/index.js +0 -27
  284. package/src/hooks/useTotalAllSales/index.js +0 -25
  285. package/src/hooks/useTotalProductsInStock/index.js +0 -23
  286. package/src/hooks/useTotalProductsSold/index.js +0 -23
  287. package/src/hooks/useTotalProductsSolded/index.js +0 -20
  288. package/src/hooks/useUpdateCart/index.js +0 -130
  289. package/src/hooks/useUpdateCartCookie/index.js +0 -43
  290. package/src/hooks/useUpdateDashboardComponent/index.ts +0 -91
  291. package/src/hooks/useUpdateExistingOrders/index.js +0 -85
  292. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -60
  293. package/src/hooks/useUpdateModuleOrder/index.js +0 -37
  294. package/src/hooks/useUpdateMultipleExtProduct/index.js +0 -33
  295. package/src/hooks/useUpdateMultipleExtProduct/queries.js +0 -33
  296. package/src/hooks/useUpdateMultipleProducts/index.js +0 -80
  297. package/src/hooks/useUpdateMultipleProducts/queries.js +0 -51
  298. package/src/hooks/useUploadProducts/helpers/index.js +0 -1
  299. package/src/hooks/useUploadProducts/helpers/parseNumber.js +0 -37
  300. package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +0 -73
  301. package/src/hooks/useUploadProducts/index.js +0 -422
  302. package/src/hooks/useUpsertGoal/index.js +0 -68
  303. package/src/hooks/useUser/index.js +0 -23
  304. package/src/hooks/useUser/queries.js +0 -131
  305. package/src/hooks/useWeeklyStockMovement/helpers/index.js +0 -32
  306. package/src/hooks/useWeeklyStockMovement/index.js +0 -51
  307. package/src/hooks/useWindowSize/index.js +0 -38
  308. package/src/index.jsx +0 -9
  309. package/src/mock/dessert/index.js +0 -16
  310. package/src/mock/index.js +0 -1
  311. package/src/security/index.js +0 -1
  312. package/src/services/index.js +0 -0
  313. package/src/utils/UtilDateRange.js +0 -31
  314. package/src/utils/index.js +0 -306
  315. package/tsconfig.json +0 -5
@@ -1,525 +0,0 @@
1
- import {
2
- useState,
3
- useEffect
4
- } from 'react'
5
- import { MockData } from '../../mock'
6
- import { RandomCode, updateCacheMod } from '../../utils'
7
- import { useUpdateExtProductFoodsOptional } from '../updateExtProductFoodsOptional'
8
- import { useUpdateExtProductFoodsSubOptional } from '../useUpdateExtProductFoodsSubOptional'
9
- import { useRemoveExtraProductFoodsOptional } from '../useRemoveExtraProductFoodsOptional'
10
- import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
11
- import { transformDataToDessert } from './helpers'
12
- import { useDeleteSubProductOptional } from '../useDeleteSubProductOptional'
13
- import { useEditSubProductOptional } from '../useEditSubProductOptional'
14
-
15
- export const useDessert = ({
16
- pId = null,
17
- initialData = null,
18
- sendNotification = (args) => { return args }
19
- }) => {
20
- const [selectedExtra, setSelectedExtra] = useState({})
21
- const [openModalEditExtra, setOpenModalEditExtra] = useState(false)
22
- const [selectedItem, setSelectedItem] = useState({})
23
-
24
- // Initialize state variables using the useState hook
25
- const [setCheck, setChecker] = useState({
26
- exState: false
27
- }) // State for checkboxes
28
- const [valueItems, setValueItems] = useState('') // State for input values
29
- const [title, setTitle] = useState('') // State for title input value
30
- // Initialize the data state with the transformedData or MockData
31
- const [data, setData] = useState(MockData)
32
- const handleCleanData = () => {
33
- setData(MockData)
34
- }
35
- const dataListIds = data?.listIds?.filter(x => x !== '01list')
36
-
37
- /**
38
- * Checks if all required lists have the maximum number of cards.
39
- *
40
- * @return {boolean} Returns true if all required lists have the maximum number of cards, otherwise false.
41
- */
42
- const isCompleteRequired = dataListIds?.every(listID => {
43
- try {
44
- if (!Array.isArray(dataListIds) || data === null) {
45
- throw new Error('Invalid arguments. dataListIds must be an array and data must be a non-null object.')
46
- }
47
- const list = data.lists[listID]
48
- // If list or list.cards is missing, assume the list is not complete
49
- const verifiEmpyRequireCard = list?.cards?.length
50
- if (list && list?.cards) {
51
- return Number(verifiEmpyRequireCard) === Number(list.numberLimit)
52
- }
53
-
54
- // If list or list.cards is missing, assume the list is not complete
55
- return false
56
- } catch (e) {
57
- return false
58
- }
59
- })
60
-
61
- // Use useEffect to update the data state when the initialData prop changes
62
- useEffect(() => {
63
- if (initialData) {
64
- // Only update the data state if it's different from initialData
65
- if (JSON.stringify(data) !== JSON.stringify(transformDataToDessert(initialData))) {
66
- const transformedInitialData = transformDataToDessert(initialData)
67
- setData(transformedInitialData)
68
- }
69
- }
70
- }, [initialData]) // Include data as a dependency
71
-
72
- // Filter the 'listIds' from 'data' and store the filtered result in 'dataListIds'
73
- // Here, it seems to exclude a specific list ID ('01list') from the listIds.
74
-
75
- // HOOKS
76
- const { handleMutateExtProductFoodsSubOptional } = useUpdateExtProductFoodsSubOptional({
77
- sendNotification
78
- })
79
- const { handleUpdateExtProduct } = useUpdateExtProductFoodsOptional()
80
- const { DeleteExtProductFoodsOptional } = useRemoveExtraProductFoodsOptional()
81
- const [DeleteExtFoodSubsOptional] = useDeleteSubProductOptional()
82
- const [editExtFoodSubsOptional, { loading: loadingEditSubOptional }] = useEditSubProductOptional()
83
-
84
- // HANDLESS
85
- /**
86
- * Handles checkbox changes and updates the setCheck state accordingly.
87
- * @param {Event} e - The checkbox change event object.
88
- */
89
- const handleCheck = (e) => {
90
- // Extract the 'name' and 'checked' properties from the event target (checkbox)
91
- const { name, checked } = e.target
92
-
93
- // Update the setCheck state with the new value for the checkbox identified by the 'name' property
94
- setChecker({ ...setCheck, [name]: checked })
95
- }
96
-
97
- /**
98
- * Handles the removal of a list from the data state and performs additional operations if needed.
99
- * @param {number} i - The index of the list to be removed.
100
- * @param {string} listID - The ID of the list to be removed (optional).
101
- * @throws {Error} Will throw an error if the provided index (i) is not a non-negative number.
102
- * @throws {Error} Will throw an error if the provided index (i) is out of range.
103
- * @throws {Error} Will throw an error if the provided listID is invalid (optional validation).
104
- */
105
- const handleRemoveList = (i, listID) => {
106
- // Validate that the provided index (i) is a non-negative number
107
- if (typeof i !== 'number' || i < 0) {
108
- throw new Error('Invalid index provided. The index must be a non-negative number.')
109
- }
110
-
111
- // Make a copy of the listIds array from the data state
112
- const listIdsCopy = [...data.listIds]
113
-
114
- // Validate that the provided index (i) is within the range of the listIds array
115
- if (i >= listIdsCopy.length) {
116
- throw new Error('Invalid index provided. The index is out of range.')
117
- }
118
-
119
- // Remove the list with the specified index from the listIdsCopy array
120
- const Lines = data?.listIds.filter((_, index) => index !== i)?.filter(x => x !== '01list')
121
- // Update the data state with the modified listIdsCopy array
122
- setData({
123
- listIds: listID ? Lines.filter((subItem) => { return subItem !== listID }) : Lines,
124
- lists: {
125
- ...data.lists
126
- }
127
- })
128
-
129
- // Perform additional operations if a valid listID is provided
130
- if (listID) {
131
- try {
132
- // Assuming DeleteExtProductFoodsOptional is a function that deletes an external product
133
- // Call the function to delete the external product using the provided listID
134
- DeleteExtProductFoodsOptional({
135
- variables: {
136
- state: 1,
137
- opExPid: listID,
138
- isCustomOpExPid: true
139
- },
140
- update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
141
- return updateCacheMod({
142
- cache,
143
- query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
144
- nameFun: 'ExtProductFoodsOptionalAll',
145
- dataNew: ExtProductFoodsOptionalAll
146
- })
147
- }
148
- })
149
- } catch (error) {
150
- // Handle any errors that may occur during the deletion process
151
- throw new Error('An error occurred while deleting the external product.')
152
- }
153
- }
154
- }
155
-
156
- /**
157
- * Removes a specific item from a list within the data state.
158
- * @param {Object} params - The parameters for removing the item.
159
- * @param {string} params.listID - The ID of the list from which the item will be removed.
160
- * @param {string} params.id - The ID of the item to be removed.
161
- * @throws {Error} Will throw an error if the provided listID does not exist in the data state.
162
- * @throws {Error} Will throw an error if the provided listID exists but the corresponding list does not have a cards array.
163
- */
164
- const removeOneItem = ({
165
- listID = '',
166
- id = '',
167
- isCustomSubOpExPid = false
168
- }) => {
169
- try {
170
- const forRemove = Boolean(listID && id)
171
- if (forRemove) {
172
- DeleteExtFoodSubsOptional({
173
- variables: {
174
- isCustomSubOpExPid,
175
- opSubExPid: id,
176
- state: 1
177
- }
178
- })
179
- }
180
- // Ensure the provided listID exists in the data state
181
- if (!data.lists[listID]) {
182
- throw new Error(`List with ID "${listID}" does not exist.`)
183
- }
184
-
185
- // Ensure the list has a cards array
186
- if (!Array.isArray(data.lists[listID].cards)) {
187
- throw new Error(`List with ID "${listID}" does not have a valid cards array.`)
188
- }
189
-
190
- // Get the current list from the data state using the provided listID
191
- const currentList = data.lists[listID]
192
-
193
- // Filter out the item with the specified ID from the current list's cards array
194
- const filteredCart = currentList?.cards?.filter((cart) => cart.id !== id)
195
-
196
- // Update the current list's cards with the filtered array to remove the specified item
197
- setData({
198
- listIds: [...data.listIds],
199
- lists: {
200
- ...data.lists,
201
- [listID]: {
202
- ...currentList,
203
- cards: filteredCart
204
- }
205
- }
206
- })
207
- } catch (error) {
208
- console.error(error)
209
- }
210
- }
211
-
212
- /**
213
- * Edits a single item within a list.
214
- *
215
- * The `editOneItem` function is responsible for editing the title of a specific item in a list.
216
- * It first updates the state of the selected item, then searches for the item in the current list
217
- * using its ID, and compares the existing title with the new title provided. If the title is
218
- * different and not null, it makes an API call (`editExtFoodSubsOptional`) to update the
219
- * title in the database. If the update is successful, a success notification is sent, and
220
- * the local state is updated to reflect the changes in the item. The function handles errors
221
- * internally and logs them to the console.
222
- *
223
- * @param {Object} params - Parameters for editing an item.
224
- * @param {string} params.listID - The ID of the list containing the item to be edited.
225
- * @param {string} params.id - The ID of the specific item to be edited.
226
- * @param {string|null} [params.title=null] - The new title for the item. If null, no
227
- * update is performed.
228
- */
229
- const editOneItem = ({
230
- listID = '',
231
- id = '',
232
- title = null
233
- }) => {
234
- try {
235
- setSelectedItem(() => {
236
- return { listID, id }
237
- })
238
- const currentList = data.lists[listID]
239
- const findItem = currentList?.cards?.find(item => { return item.id === id })
240
- const checkDifferentText = findItem?.title !== title
241
- if (title && checkDifferentText) {
242
- editExtFoodSubsOptional({
243
- variables: {
244
- isCustomSubOpExPid: false,
245
- opSubExPid: id,
246
- OptionalSubProName: title
247
- }
248
- }).then(({ data: response }) => {
249
- const { editExtFoodSubsOptional } = response || {}
250
- const { success } = editExtFoodSubsOptional || { success: false }
251
- if (success) {
252
- sendNotification({
253
- description: 'El sub item actualizado con éxito',
254
- title: 'Actualizado',
255
- backgroundColor: 'success'
256
- })
257
- const currentList = data.lists[listID]
258
- const updatedCards = currentList?.cards?.map((card) => {
259
- if (card.id === id) {
260
- return {
261
- ...card,
262
- title
263
- }
264
- }
265
- return card
266
- })
267
- setData({
268
- listIds: [...data.listIds],
269
- lists: {
270
- ...data.lists,
271
- [listID]: {
272
- ...currentList,
273
- cards: updatedCards
274
- }
275
- }
276
- })
277
- }
278
- })
279
- }
280
- } catch (error) {
281
- console.error(error)
282
- }
283
- }
284
-
285
- const updateListById = (listId, updatedFields) => {
286
- setData((prevData) => {
287
- const updatedLists = {
288
- ...prevData.lists,
289
- [listId]: {
290
- ...prevData.lists[listId],
291
- ...updatedFields
292
- }
293
- }
294
-
295
- return {
296
- ...prevData,
297
- lists: updatedLists
298
- }
299
- })
300
- }
301
- /**
302
- * Edit a extra.
303
- * @async
304
- * @param {Object} options - Opciones para la edición del extra.
305
- * @param {string} options.id - ID del extra.
306
- * @param {number|null} options.numberLimit - Límite de número para el extra.
307
- * @param {string} options.title - Título del extra.
308
- * @param {boolean} options.required - Indica si el extra es requerido.
309
- * @throws {Error} Se lanza un error si no se proporciona un ID válido.
310
- * @returns {Promise<void>}
311
- */
312
- const editOneExtra = async ({
313
- id = '',
314
- numberLimit = null,
315
- title,
316
- required
317
- }) => {
318
- try {
319
- if (id) {
320
- const response = await handleUpdateExtProduct({
321
- opExPid: id,
322
- code: id,
323
- OptionalProName: title,
324
- required: required ? 1 : 0,
325
- numbersOptionalOnly: numberLimit
326
- })
327
- const { data } = response || {}
328
- if (!data?.updateExtProductOptional) {
329
- return sendNotification({
330
- description: 'Ocurrió un error, intenta de nuevo',
331
- title: 'Error',
332
- backgroundColor: 'warning'
333
- })
334
- }
335
- const { success, message } = data?.updateExtProductOptional || {}
336
- if (success) {
337
- setSelectedExtra({})
338
- setOpenModalEditExtra(false)
339
- sendNotification({
340
- description: message,
341
- title: 'Actualizado',
342
- backgroundColor: 'success'
343
- })
344
- return updateListById(id, {
345
- title,
346
- numberLimit,
347
- required: required ? 1 : 0
348
- })
349
- }
350
- }
351
-
352
- if (!id) {
353
- return sendNotification({
354
- description: 'Ocurrió un error, intenta de nuevo',
355
- title: 'Error',
356
- backgroundColor: 'warning'
357
- })
358
- }
359
- } catch (error) {
360
- setSelectedExtra({})
361
- setOpenModalEditExtra(false)
362
- sendNotification({
363
- description: 'Ocurrió un error, intenta de nuevo',
364
- title: 'Error',
365
- backgroundColor: 'warning'
366
- })
367
- }
368
- }
369
-
370
- const addCard = async (title, listId) => {
371
- const id = RandomCode(9)
372
- const newCard = {
373
- id,
374
- title,
375
- numberLimit: 5,
376
- value: '',
377
- required: setCheck.exState ? 1 : 0
378
- }
379
- const list = data.lists[listId]
380
- list.cards = [...list.cards, newCard]
381
- setData({
382
- ...data,
383
- lists: {
384
- ...data.lists,
385
- [listId]: list
386
- }
387
- })
388
- handleMutateExtProductFoodsSubOptional({
389
- pId,
390
- title,
391
- listId,
392
- id,
393
- state: 1
394
- })
395
- setTitle('')
396
- }
397
- const handleAdd = ({ listId }) => {
398
- if (valueItems !== '' && valueItems.trim() !== '') {
399
- addCard(valueItems, listId)
400
- }
401
- setValueItems('')
402
- // Reset the value of all lists in dataListIds to 0 in a single setData call
403
- setData(prevData => {
404
- const updatedLists = Object.fromEntries(
405
- Object.entries(prevData.lists).map(([listId, list]) => {
406
- if (dataListIds.includes(listId)) {
407
- return [listId, { ...list, value: '' }]
408
- }
409
- return [listId, list]
410
- })
411
- )
412
- return {
413
- ...prevData,
414
- lists: updatedLists
415
- }
416
- })
417
- }
418
-
419
- /**
420
- * Handles the addition of a new list with the given title and number limit.
421
- * @param {Object} params - The parameters for adding the new list.
422
- * @param {string} params.title - The title of the new list.
423
- * @param {number} params.numberLimit - The number limit for the new list.
424
- */
425
- const handleAddList = async ({ title, numberLimit }) => {
426
- // Check if the title is not empty
427
- if (title.trim() === '') {
428
- sendNotification({
429
- description: 'El titulo no debe estar vacío',
430
- title: 'Error',
431
- backgroundColor: 'warning'
432
- })
433
- return // Termina la función si el título está vacío
434
- }
435
-
436
- // Generate a new list ID using the RandomCode function (must be implemented elsewhere)
437
- const newListId = RandomCode(9)
438
-
439
- // Determine if the list is required based on the setCheck.exState state
440
- const required = setCheck.exState ? 1 : 0
441
-
442
- // Add the new list to the beginning of the data state
443
- setData(prevData => ({
444
- listIds: [newListId, ...prevData.listIds], // Agrega el nuevo ID al principio del array
445
- lists: {
446
- ...prevData.lists,
447
- [newListId]: {
448
- id: newListId,
449
- title,
450
- required,
451
- numberLimit,
452
- value: '',
453
- cards: []
454
- }
455
- }
456
- }))
457
-
458
- // Update the external product with the information of the new list
459
- handleUpdateExtProduct({
460
- pId,
461
- code: newListId,
462
- OptionalProName: title,
463
- required,
464
- numbersOptionalOnly: numberLimit
465
- })
466
-
467
- // Clear the title field after adding the list
468
- setTitle('')
469
- }
470
-
471
- /**
472
- * Handles the change of items in a specific list.
473
- * @param {Object} params - The parameters for handling the change.
474
- * @param {string} params.listID - The ID of the list where the change is happening.
475
- * @param {Object} params.value - The event object containing the new value for the list items.
476
- */
477
- const handleChangeItems = ({ listID, value: e }) => {
478
- const value = e.target.value
479
- setValueItems(value)
480
-
481
- // Get the current list from the data state using the provided listID
482
- const currentList = data.lists[listID]
483
-
484
- // Update the value of the current list with the new value
485
- setData({
486
- listIds: [...data.listIds],
487
- lists: {
488
- ...data.lists,
489
- [listID]: {
490
- ...currentList,
491
- value
492
- }
493
- }
494
- })
495
-
496
- // Note: The return statement seems to be unnecessary, and the map function doesn't serve a purpose here.
497
- // If you want to map through dataListIds for some other reason, you should use it separately from this function.
498
- }
499
-
500
- return {
501
- addCard,
502
- data,
503
- dataListIds,
504
- loadingEditSubOptional,
505
- isCompleteRequired,
506
- handleAdd,
507
- handleAddList,
508
- handleChangeItems,
509
- handleCheck,
510
- handleRemoveList,
511
- removeOneItem,
512
- editOneExtra,
513
- editOneItem,
514
- setCheck,
515
- selectedItem,
516
- setData,
517
- handleCleanData,
518
- setTitle,
519
- title,
520
- selectedExtra,
521
- openModalEditExtra,
522
- setSelectedExtra,
523
- setOpenModalEditExtra
524
- }
525
- }
@@ -1,76 +0,0 @@
1
- export const transformData = (dataExtra) => {
2
- const transformedData = dataExtra?.map(item => ({
3
- extraName: item.extraName || '',
4
- extraPrice: item?.extraPrice?.toString() || '',
5
- exState: !!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 => 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
- }