npm-pkg-hook 1.13.1 → 1.13.2
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/.github/pull_request_template.md +18 -0
- package/.github/workflows/pepeline.yaml +30 -0
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -6
- package/dist/index.mjs.map +1 -1
- package/eslint.config.mts +153 -0
- package/expire.json +1 -0
- package/jsconfig.json +28 -0
- package/package.json +1 -6
- 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 +154 -0
- package/src/hooks/isTokenExpired/index.ts +17 -0
- package/src/hooks/newMessageSubscription/index.ts +28 -0
- package/src/hooks/newStoreOrderSubscription/index.ts +26 -0
- package/src/hooks/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 +24 -0
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.ts +118 -0
- package/src/hooks/useColorByLetters/index.ts +24 -0
- package/src/hooks/useConnection/index.ts +24 -0
- package/src/hooks/useCountries/index.ts +20 -0
- package/src/hooks/useCountries/queries.ts +12 -0
- package/src/hooks/useCreateDeliveryTime/index.ts +51 -0
- package/src/hooks/useCreateOrderStatusType/index.ts +134 -0
- package/src/hooks/useCreateProduct/helpers/index.ts +23 -0
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.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 +43 -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 +77 -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.ts +4 -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 +11 -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
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Cookies } from '../../cookies'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Decodes a JWT safely without verifying signature.
|
|
5
|
+
* Use ONLY for reading payload data.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} token - JWT string
|
|
8
|
+
* @returns {Record<string, any> | null}
|
|
9
|
+
*/
|
|
10
|
+
const decodeJwtPayload = (token: string): Record<string, any> | null => {
|
|
11
|
+
try {
|
|
12
|
+
const [, payload] = token.split('.')
|
|
13
|
+
if (!payload) return null
|
|
14
|
+
|
|
15
|
+
const decoded = Buffer.from(payload, 'base64').toString('utf-8')
|
|
16
|
+
return JSON.parse(decoded)
|
|
17
|
+
} catch {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Gets session data from cookie "session".
|
|
24
|
+
* Designed for Next.js 15 App Router (server-side).
|
|
25
|
+
*
|
|
26
|
+
* @returns {Promise<{
|
|
27
|
+
* isSession: boolean
|
|
28
|
+
* token?: string
|
|
29
|
+
* user?: Record<string, any>
|
|
30
|
+
* deviceid?: string
|
|
31
|
+
* error?: string
|
|
32
|
+
* }>}
|
|
33
|
+
*/
|
|
34
|
+
export const getSession = async () => {
|
|
35
|
+
try {
|
|
36
|
+
const token = Cookies.get('session')
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
if (!token) {
|
|
39
|
+
resolve({ isSession: false })
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
const payload = decodeJwtPayload(token)
|
|
43
|
+
if (!payload) {
|
|
44
|
+
resolve({ isSession: false })
|
|
45
|
+
return
|
|
46
|
+
}
|
|
47
|
+
const { user, deviceid, exp } = payload
|
|
48
|
+
const currentTime = Math.floor(Date.now() / 1000)
|
|
49
|
+
if (exp && currentTime >= exp) {
|
|
50
|
+
resolve({ isSession: false })
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
resolve({
|
|
54
|
+
isSession: true,
|
|
55
|
+
token,
|
|
56
|
+
user,
|
|
57
|
+
deviceid
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (error instanceof Error) {
|
|
62
|
+
return {
|
|
63
|
+
isSession: false,
|
|
64
|
+
error: String(error.message)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
isSession: false,
|
|
69
|
+
error: 'Unexpected session error'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the start timestamp for the current day.
|
|
3
|
+
* @returns {string} The start timestamp for the current day.
|
|
4
|
+
*/
|
|
5
|
+
export const getStartOfDayTimestamp = () => {
|
|
6
|
+
const start = new Date()
|
|
7
|
+
start.setHours(0, 0, 0, 0)
|
|
8
|
+
return start.toISOString()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the end timestamp for the current day.
|
|
13
|
+
* @returns {string} The end timestamp for the current day.
|
|
14
|
+
*/
|
|
15
|
+
export const getEndOfDayTimestamp = () => {
|
|
16
|
+
const end = new Date()
|
|
17
|
+
end.setHours(23, 59, 59, 999)
|
|
18
|
+
return end.toISOString()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Get start and end timestamps for the current day.
|
|
23
|
+
* @returns {Object} An object containing start and end timestamps.
|
|
24
|
+
*/
|
|
25
|
+
export const getTodayTimestamps = () => {
|
|
26
|
+
return {
|
|
27
|
+
startTimestamp: getStartOfDayTimestamp(),
|
|
28
|
+
endTimestamp: getEndOfDayTimestamp()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get start timestamp for a specific number of days ago.
|
|
34
|
+
* @param {number} daysAgo - The number of days ago.
|
|
35
|
+
* @returns {string} The start timestamp for the specified number of days ago.
|
|
36
|
+
*/
|
|
37
|
+
export const getStartTimestampDaysAgo = (daysAgo) => {
|
|
38
|
+
if (isNaN(daysAgo) || daysAgo < 0) {
|
|
39
|
+
throw new Error('Invalid input. Provide a valid number of days.')
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const start = new Date()
|
|
43
|
+
start.setDate(start.getDate() - daysAgo)
|
|
44
|
+
start.setHours(0, 0, 0, 0)
|
|
45
|
+
|
|
46
|
+
return start.toISOString()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param root0
|
|
52
|
+
* @param root0.dateString
|
|
53
|
+
* @param root0.start
|
|
54
|
+
*/
|
|
55
|
+
export function convertDateFormat ({ dateString, start }) {
|
|
56
|
+
const parsedDate = dateString ? new Date(dateString) : new Date()
|
|
57
|
+
const year = parsedDate.getFullYear()
|
|
58
|
+
const month = `0${parsedDate.getMonth() + 1}`.slice(-2)
|
|
59
|
+
const day = `0${parsedDate.getDate()}`.slice(-2)
|
|
60
|
+
|
|
61
|
+
if (start) {
|
|
62
|
+
// Inicio del día (00:00:00)
|
|
63
|
+
return `${year}-${month}-${day}T00:00:00.000Z`
|
|
64
|
+
}
|
|
65
|
+
// Final del día (23:59:59.999)
|
|
66
|
+
const endOfDay = new Date(parsedDate)
|
|
67
|
+
endOfDay.setHours(23, 59, 59, 999)
|
|
68
|
+
return endOfDay.toISOString()
|
|
69
|
+
|
|
70
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schedule day structure
|
|
3
|
+
*/
|
|
4
|
+
export interface ScheduleDay {
|
|
5
|
+
schHoSta?: string
|
|
6
|
+
schHoEnd?: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculate total worked hours from a list of days.
|
|
11
|
+
* Keeps original behavior and edge cases intact.
|
|
12
|
+
*
|
|
13
|
+
* @param {ScheduleDay[]} days - Array of days with start and end times
|
|
14
|
+
* @returns {string} Total time formatted as HH:MM
|
|
15
|
+
*/
|
|
16
|
+
export const getTotalHours = (days: ScheduleDay[] = []): string => {
|
|
17
|
+
const totalMinutesArray: number[] = days.map((day) => {
|
|
18
|
+
const { schHoSta, schHoEnd } = day
|
|
19
|
+
|
|
20
|
+
// Handle potential invalid time strings
|
|
21
|
+
if (!isValidTimeString(schHoSta) || !isValidTimeString(schHoEnd)) {
|
|
22
|
+
return 0
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const [startHours, startMinutes] = schHoSta.split(':')
|
|
26
|
+
const [endHours, endMinutes] = schHoEnd.split(':')
|
|
27
|
+
|
|
28
|
+
// Convert hours and minutes to integers for calculations
|
|
29
|
+
let totalHoursInt =
|
|
30
|
+
parseInt(endHours, 10) - parseInt(startHours, 10)
|
|
31
|
+
|
|
32
|
+
const totalMinutesInt =
|
|
33
|
+
parseInt(endMinutes, 10) - parseInt(startMinutes, 10)
|
|
34
|
+
|
|
35
|
+
// Handle negative total minutes
|
|
36
|
+
let totalMinutes = totalMinutesInt
|
|
37
|
+
if (totalMinutes < 0) {
|
|
38
|
+
totalHoursInt--
|
|
39
|
+
totalMinutes += 60
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Calculate total time in minutes
|
|
43
|
+
return totalHoursInt * 60 + totalMinutes
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Sum all minutes
|
|
47
|
+
const totalMinutes: number = totalMinutesArray.reduce(
|
|
48
|
+
(acc, curr) => {return acc + curr},
|
|
49
|
+
0
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
// Convert to hours and minutes
|
|
53
|
+
const totalHours: number = Math.floor(totalMinutes / 60)
|
|
54
|
+
const remainingMinutes: number = totalMinutes % 60
|
|
55
|
+
|
|
56
|
+
// Format HH:MM
|
|
57
|
+
const formattedHours = totalHours.toString().padStart(2, '0')
|
|
58
|
+
const formattedMinutes = remainingMinutes.toString().padStart(2, '0')
|
|
59
|
+
|
|
60
|
+
return `${formattedHours}:${formattedMinutes}`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validate time string format (HH:MM)
|
|
65
|
+
*
|
|
66
|
+
* @param {string | undefined} timeString
|
|
67
|
+
* @returns {boolean}
|
|
68
|
+
*/
|
|
69
|
+
export const isValidTimeString = (
|
|
70
|
+
timeString?: string
|
|
71
|
+
): timeString is string => {
|
|
72
|
+
if (!timeString) return false
|
|
73
|
+
|
|
74
|
+
const timeRegex = /^([0-1][0-9]|2[0-3]):([0-5][0-9])$/
|
|
75
|
+
return timeRegex.test(timeString)
|
|
76
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param body
|
|
4
|
+
*/
|
|
5
|
+
export async function handleLogin (body) {
|
|
6
|
+
const response = await fetch(`${process.env.URL_BASE}/api/auth/login`, {
|
|
7
|
+
method: 'POST',
|
|
8
|
+
headers: { 'Content-Type': 'application/json' },
|
|
9
|
+
body: JSON.stringify(body),
|
|
10
|
+
credentials: 'include'
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
return response.json()
|
|
14
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export * from './updateExtProductFoodsOptional'
|
|
2
|
+
export * from './useAcumulateDate'
|
|
3
|
+
export * from './useBanner'
|
|
4
|
+
export * from './useCategoryInStore'
|
|
5
|
+
export * from './useCategoryStore'
|
|
6
|
+
export * from './useCatWithProduct'
|
|
7
|
+
export * from './useManageQueryParams'
|
|
8
|
+
export * from './useDeliveryTime'
|
|
9
|
+
export * from './useModules'
|
|
10
|
+
export * from './getTotalHours'
|
|
11
|
+
export * from './useUpdateMultipleProducts'
|
|
12
|
+
export * from './useTokenCards'
|
|
13
|
+
export * from './useStoreTable/index'
|
|
14
|
+
export * from './useSubscriptionValidation'
|
|
15
|
+
export * from './convertToMilitaryTime'
|
|
16
|
+
export * from './useRoles'
|
|
17
|
+
export * from './useLocalBackendIp'
|
|
18
|
+
export * from './statusOpenStores'
|
|
19
|
+
export * from './completeSchedules'
|
|
20
|
+
export * from './useLogout/helpers/BroadcastChannel'
|
|
21
|
+
export * from './useLogout/helpers/index'
|
|
22
|
+
export * from './getCardType'
|
|
23
|
+
export * from './useLoginEmployeeInStore'
|
|
24
|
+
export * from './useUploadProducts'
|
|
25
|
+
export * from './useAmountInput'
|
|
26
|
+
export * from './useColorByLetters'
|
|
27
|
+
export * from './newMessageSubscription'
|
|
28
|
+
export * from './usePWAInstall'
|
|
29
|
+
export * from './useGetCookies'
|
|
30
|
+
export * from './generateTemplate'
|
|
31
|
+
export * from './isTokenExpired'
|
|
32
|
+
export * from './useCreateDeliveryTime'
|
|
33
|
+
export * from './addTenMinutes'
|
|
34
|
+
export * from './useUpdateCartCookie'
|
|
35
|
+
export * from './useCategoriesProduct'
|
|
36
|
+
export * from './useLogout'
|
|
37
|
+
export * from './useSetupSchedule'
|
|
38
|
+
export * from './useMouse'
|
|
39
|
+
export * from './useStatusOpenStore'
|
|
40
|
+
export * from './usePushNotificationOrder'
|
|
41
|
+
export * from './newStoreOrderSubscription'
|
|
42
|
+
export * from './useChatRoomSubscription'
|
|
43
|
+
export * from './useScheduleData'
|
|
44
|
+
export * from './useGetMessagesToRoom'
|
|
45
|
+
export * from './useOrders'
|
|
46
|
+
export * from './usePushNotifications'
|
|
47
|
+
export * from './useLocationManager'
|
|
48
|
+
export * from './useQueryLocationsMap'
|
|
49
|
+
export * from './useGetAllLocationUser'
|
|
50
|
+
export * from './useFingerprintjs'
|
|
51
|
+
export * from './useCountries'
|
|
52
|
+
export * from './useDessertWithPrice'
|
|
53
|
+
export * from './generateStoreURL'
|
|
54
|
+
export * from './useCreateStorePendingToRegister'
|
|
55
|
+
export * from './useDepartments'
|
|
56
|
+
export * from './useSaveLocation'
|
|
57
|
+
export * from './useRoads'
|
|
58
|
+
export * from './useCities'
|
|
59
|
+
export * from './useEditCategory'
|
|
60
|
+
export * from './useEmployee'
|
|
61
|
+
export * from './useEmployee/useCreateEmployee'
|
|
62
|
+
export * from './useCheckbox'
|
|
63
|
+
export * from './useRemoveExtraProductFoodsOptional'
|
|
64
|
+
export * from './useDeleteSubProductOptional'
|
|
65
|
+
export * from './useGetOneStoreRating'
|
|
66
|
+
export * from './useFavoriteStores'
|
|
67
|
+
export * from './useAsideCart'
|
|
68
|
+
export * from './useRatingArrayData'
|
|
69
|
+
export * from './useChartData'
|
|
70
|
+
export * from './useDevices'
|
|
71
|
+
export * from './useClients'
|
|
72
|
+
export * from './useScroll'
|
|
73
|
+
export * from './useStatusOrdersClient'
|
|
74
|
+
export * from './useUpdateExistingOrders'
|
|
75
|
+
export * from './useConnection'
|
|
76
|
+
export * from './useManageNewOrder'
|
|
77
|
+
export * from './useCreateProduct'
|
|
78
|
+
export * from './useCreateProduct/helpers/useEditImageProduct'
|
|
79
|
+
export * from './useDessert'
|
|
80
|
+
export * from './useDrag'
|
|
81
|
+
export * from './useEvent'
|
|
82
|
+
export * from './useFetchJson'
|
|
83
|
+
export * from './useFormatDate'
|
|
84
|
+
export * from './getTodayTimestamps'
|
|
85
|
+
export * from './useFormatNumberPhone'
|
|
86
|
+
export * from './useFormTools/index'
|
|
87
|
+
export * from './useHover'
|
|
88
|
+
export * from './useImageOptimization'
|
|
89
|
+
export * from './useImagesStore'
|
|
90
|
+
export * from './useImageWeight'
|
|
91
|
+
export * from './useIntersection'
|
|
92
|
+
export * from './useKeypress'
|
|
93
|
+
export * from './useLazyScript'
|
|
94
|
+
export * from './useLocalSorage'
|
|
95
|
+
export * from './useLocationNavigate'
|
|
96
|
+
export * from './useSetSession'
|
|
97
|
+
export * from './useMobile'
|
|
98
|
+
export * from './useMutateHeight'
|
|
99
|
+
export * from './useProductsFood'
|
|
100
|
+
export * from './useProductsFood/usetagsProducts'
|
|
101
|
+
// export * from './useReactToPrint'
|
|
102
|
+
export * from './useReport'
|
|
103
|
+
export * from './useSales/useTotalSales'
|
|
104
|
+
export * from './useOrderClient'
|
|
105
|
+
export * from './useStoreContacts'
|
|
106
|
+
export * from './useRestaurant'
|
|
107
|
+
export * from './useSales/index'
|
|
108
|
+
export * from './useSales/useGetSale'
|
|
109
|
+
export * from './useGetMinPrice'
|
|
110
|
+
export * from './useCatWithProductClient'
|
|
111
|
+
export * from './useGetFoodRecomended'
|
|
112
|
+
export * from './useSaveAvailableProduct'
|
|
113
|
+
export * from './useSchedule'
|
|
114
|
+
export * from './useSetState'
|
|
115
|
+
export * from './useStore'
|
|
116
|
+
export * from './useStoreCalendar'
|
|
117
|
+
export * from './getCategoriesWithProduct'
|
|
118
|
+
export * from './useIncomingOrders'
|
|
119
|
+
export * from './useTimeAgo/useTimeAgo'
|
|
120
|
+
export * from './useUpdateCart'
|
|
121
|
+
export * from './useUpdateExtProductFoodsSubOptional'
|
|
122
|
+
export * from './useUser'
|
|
123
|
+
export * from './useCart'
|
|
124
|
+
export * from './useGetStoreCookie'
|
|
125
|
+
export * from './getGlobalSession'
|
|
126
|
+
export * from './handleLogin'
|
|
127
|
+
export * from './useInventory'
|
|
128
|
+
export * from './useStockMovements'
|
|
129
|
+
export * from './useTopProductsMovements'
|
|
130
|
+
export * from './useTotalProductsSold'
|
|
131
|
+
export * from './useTotalProductsInStock/index'
|
|
132
|
+
export * from './useTotalAllSales/index'
|
|
133
|
+
export * from './useTotalProductsSolded'
|
|
134
|
+
export * from './useWeeklyStockMovement'
|
|
135
|
+
export * from './useSetImageProducts'
|
|
136
|
+
export * from './useGetSalesAmountToday'
|
|
137
|
+
export * from './useUpsertGoal'
|
|
138
|
+
export * from './useDashboardComponents'
|
|
139
|
+
export * from './useUpdateDashboardComponent'
|
|
140
|
+
export * from './useUpdateModuleOrder'
|
|
141
|
+
export * from './useDownloadReports'
|
|
142
|
+
export * from './usePortFetcher'
|
|
143
|
+
export * from './useImageUploaderProduct'
|
|
144
|
+
export * from './useTagProducts'
|
|
145
|
+
export * from './useOrderStatusTypes'
|
|
146
|
+
export * from './useCreateOrderStatusType'
|
|
147
|
+
export * from './useDevWS'
|
|
148
|
+
export * from './usePrintSaleTicket'
|
|
149
|
+
export * from './usePaymentMethod'
|
|
150
|
+
export * from './useGetAllSales'
|
|
151
|
+
export * from './useTheme'
|
|
152
|
+
export * from './useFilterConfigs'
|
|
153
|
+
export * from './useStock'
|
|
154
|
+
export * from './getSession'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verifica si un token JWT ha expirado.
|
|
3
|
+
* @param {string} token El token JWT a verificar.
|
|
4
|
+
* @param {string} [expField='exp'] El nombre del campo que contiene la fecha de expiración en el token.
|
|
5
|
+
* @returns {boolean} True si el token ha expirado, false de lo contrario.
|
|
6
|
+
*/
|
|
7
|
+
export const isTokenExpired = (token, expField = 'exp') => {
|
|
8
|
+
try {
|
|
9
|
+
const [, payloadBase64] = token.split('.')
|
|
10
|
+
const decodedJson = Buffer.from(payloadBase64, 'base64').toString()
|
|
11
|
+
const decoded = JSON.parse(decodedJson)
|
|
12
|
+
const exp = decoded[expField] * 1000 // Convertir segundos a milisegundos
|
|
13
|
+
return Date.now() >= exp
|
|
14
|
+
} catch (error) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSubscription, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const NEW_MESSAGE_SUBSCRIPTION = gql`
|
|
4
|
+
subscription NewMessage($idStore: String!) {
|
|
5
|
+
newMessage(idStore: $idStore) {
|
|
6
|
+
uuid
|
|
7
|
+
content
|
|
8
|
+
aDatCre
|
|
9
|
+
from
|
|
10
|
+
to
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
export const newMessageSubscription = (idStore, onMessageReceived) => {
|
|
16
|
+
const subscription = useSubscription(NEW_MESSAGE_SUBSCRIPTION, {
|
|
17
|
+
variables: { idStore },
|
|
18
|
+
onSubscriptionData: ({ client, subscriptionData }) => {
|
|
19
|
+
if (subscriptionData.data && subscriptionData.data.newMessage) {
|
|
20
|
+
// Llama a la función proporcionada cuando se recibe un nuevo mensaje
|
|
21
|
+
onMessageReceived(subscriptionData.data.newMessage)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Puedes ajustar lo que devuelve el hook según tus necesidades
|
|
27
|
+
return subscription
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useSubscription, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const NEW_STORE_ORDER_SUBSCRIPTION = gql`
|
|
4
|
+
subscription NewStoreOrder($idStore: String!) {
|
|
5
|
+
newStoreOrder(idStore: $idStore) {
|
|
6
|
+
id
|
|
7
|
+
idStore
|
|
8
|
+
pCodeRef
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
export const newStoreOrderSubscription = (idStore, onOrderReceived) => {
|
|
14
|
+
const subscription = useSubscription(NEW_STORE_ORDER_SUBSCRIPTION, {
|
|
15
|
+
variables: { idStore },
|
|
16
|
+
onSubscriptionData: ({ client, subscriptionData }) => {
|
|
17
|
+
if (subscriptionData.data && subscriptionData.data.newStoreOrder) {
|
|
18
|
+
// Llama a la función proporcionada cuando se recibe una nueva orden
|
|
19
|
+
onOrderReceived(subscriptionData.data.newStoreOrder)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
// Puedes ajustar lo que devuelve el hook según tus necesidades
|
|
25
|
+
return subscription
|
|
26
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const getDayFromOpeningKey = (key) => {
|
|
2
|
+
const days = {
|
|
3
|
+
openingSun: 0,
|
|
4
|
+
openingMon: 1,
|
|
5
|
+
openingTue: 2,
|
|
6
|
+
openingWed: 3,
|
|
7
|
+
openingThu: 4,
|
|
8
|
+
openingFri: 5,
|
|
9
|
+
openingSat: 6
|
|
10
|
+
}
|
|
11
|
+
return days[key] !== undefined ? days[key] : -1
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Función para convertir el objeto de tiempo en una cadena de tiempo
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param timeStr
|
|
18
|
+
*/
|
|
19
|
+
export function getTimeString (timeStr) {
|
|
20
|
+
return timeStr || '00:00' // Return '00:00' for empty time strings
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
export function getCurrentDayAndTime () {
|
|
27
|
+
try {
|
|
28
|
+
const date = new Date()
|
|
29
|
+
const currentTime = date.getHours() * 60 + date.getMinutes()
|
|
30
|
+
const currentDayOfWeek = date.getDay()
|
|
31
|
+
return { currentTime, currentDayOfWeek }
|
|
32
|
+
} catch (error) {
|
|
33
|
+
return {
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param timeStr
|
|
42
|
+
*/
|
|
43
|
+
export function getTimeObject (timeStr) {
|
|
44
|
+
try {
|
|
45
|
+
if (!timeStr || !/\d{2}:\d{2}/.test(timeStr)) {
|
|
46
|
+
return { hours: 0, minutes: 0 } // Return default values for invalid input
|
|
47
|
+
}
|
|
48
|
+
const [hours, minutes] = timeStr.split(':').map(str => {return parseInt(str)})
|
|
49
|
+
return { hours, minutes }
|
|
50
|
+
} catch (e) {
|
|
51
|
+
return { hours: 0, minutes: 0 } // Return default values on error
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param openings
|
|
58
|
+
*/
|
|
59
|
+
export function sortOpeningsByDay (openings) {
|
|
60
|
+
const days = [
|
|
61
|
+
'openingSun',
|
|
62
|
+
'openingMon',
|
|
63
|
+
'openingTue',
|
|
64
|
+
'openingWed',
|
|
65
|
+
'openingThu',
|
|
66
|
+
'openingFri',
|
|
67
|
+
'openingSat'
|
|
68
|
+
]
|
|
69
|
+
const sortedOpenings = {}
|
|
70
|
+
|
|
71
|
+
days.forEach((day) => {
|
|
72
|
+
sortedOpenings[day] = openings[day] || '00:00 - 00:00' // Agregar horario vacío para los días faltantes
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return sortedOpenings
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Función para obtener la clave de openings a partir del día de la semana
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param day
|
|
82
|
+
*/
|
|
83
|
+
export function getOpeningKeyFromDay (day) {
|
|
84
|
+
const days = {
|
|
85
|
+
0: 'openingSun',
|
|
86
|
+
1: 'openingMon',
|
|
87
|
+
2: 'openingTue',
|
|
88
|
+
3: 'openingWed',
|
|
89
|
+
4: 'openingThu',
|
|
90
|
+
5: 'openingFri',
|
|
91
|
+
6: 'openingSat'
|
|
92
|
+
}
|
|
93
|
+
return days[day]
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const weekDays = [
|
|
97
|
+
'Domingo',
|
|
98
|
+
'Lunes',
|
|
99
|
+
'Martes',
|
|
100
|
+
'Miércoles',
|
|
101
|
+
'Jueves',
|
|
102
|
+
'Viernes',
|
|
103
|
+
'Sábado'
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @param text
|
|
109
|
+
*/
|
|
110
|
+
export function timeToInt (text) {
|
|
111
|
+
const hour = parseInt(text.substring(0, 2))
|
|
112
|
+
const minute = parseInt(text.substring(3))
|
|
113
|
+
return hour * 60 + minute
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export const days = {
|
|
117
|
+
Monday: 'Lunes',
|
|
118
|
+
Tuesday: 'Martes',
|
|
119
|
+
Wednesday: 'Miércoles',
|
|
120
|
+
Thursday: 'Jueves',
|
|
121
|
+
Friday: 'Viernes',
|
|
122
|
+
Saturday: 'Sábado',
|
|
123
|
+
Sunday: 'Domingo'
|
|
124
|
+
}
|