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.
- package/dist/index.cjs +20089 -0
- package/dist/index.js +19854 -0
- package/dist/index.mjs +19854 -0
- package/package.json +28 -6
- package/.babelrc +0 -0
- package/.env +0 -5
- package/.eslintrc.js +0 -38
- package/.eslintrc.json +0 -127
- package/.github/pull_request_template.md +0 -18
- package/.github/workflows/pepeline.yaml +0 -30
- package/expire.json +0 -1
- package/jsconfig.json +0 -28
- package/script.txt +0 -7
- package/src/config/client/errors.js +0 -26
- package/src/config/client/index.js +0 -1
- package/src/config/content/en.json +0 -5
- package/src/config/content/es.json +0 -5
- package/src/config/content/index.js +0 -16
- package/src/cookies/index.js +0 -3
- package/src/hooks/addTenMinutes/index.js +0 -14
- package/src/hooks/calculateLogLatHaversine/index.js +0 -30
- package/src/hooks/completeSchedules/index.js +0 -22
- package/src/hooks/convertToMilitaryTime/index.js +0 -14
- package/src/hooks/generateStoreURL/index.js +0 -38
- package/src/hooks/generateTemplate/index.js +0 -62
- package/src/hooks/getCardType/index.js +0 -24
- package/src/hooks/getCategoriesWithProduct/helpers/index.js +0 -7
- package/src/hooks/getCategoriesWithProduct/index.js +0 -62
- package/src/hooks/getGlobalSession/index.js +0 -49
- package/src/hooks/getSession/index.js +0 -18
- package/src/hooks/getTodayTimestamps/index.js +0 -64
- package/src/hooks/getTotalHours/index.js +0 -48
- package/src/hooks/handleLogin/index.js +0 -10
- package/src/hooks/index.ts +0 -146
- package/src/hooks/isTokenExpired/index.js +0 -17
- package/src/hooks/newMessageSubscription/index.js +0 -28
- package/src/hooks/newStoreOrderSubscription/index.js +0 -26
- package/src/hooks/statusOpenStores/helpers/index.js +0 -101
- package/src/hooks/statusOpenStores/index.js +0 -156
- package/src/hooks/updateExtProductFoodsOptional/index.js +0 -40
- package/src/hooks/useAcumulateDate/index.js +0 -16
- package/src/hooks/useAllStoresPendingToRegister/index.js +0 -34
- package/src/hooks/useAmountInput/index.ts +0 -117
- package/src/hooks/useAnimationFrame/index.js +0 -45
- package/src/hooks/useAnimationText/index.jsx +0 -31
- package/src/hooks/useAsideCart/helpers/index.js +0 -22
- package/src/hooks/useAsideCart/index.js +0 -214
- package/src/hooks/useAsideCart/queries.js +0 -10
- package/src/hooks/useBanner/index.js +0 -19
- package/src/hooks/useCart/index.js +0 -2
- package/src/hooks/useCart/queries.js +0 -174
- package/src/hooks/useCart/useCart/helpers/index.js +0 -75
- package/src/hooks/useCart/useCart/index.js +0 -412
- package/src/hooks/useCart/useGetCart/index.js +0 -33
- package/src/hooks/useCatWithProduct/index.js +0 -48
- package/src/hooks/useCatWithProduct/queries.js +0 -200
- package/src/hooks/useCatWithProductClient/index.js +0 -56
- package/src/hooks/useCatWithProductClient/queries.js +0 -56
- package/src/hooks/useCategoriesProduct/index.js +0 -13
- package/src/hooks/useCategoriesProduct/queries.js +0 -16
- package/src/hooks/useCategoryInStore/index.js +0 -100
- package/src/hooks/useCategoryInStore/queries.js +0 -78
- package/src/hooks/useCategoryStore/index.js +0 -7
- package/src/hooks/useCategoryStore/queries.js +0 -16
- package/src/hooks/useChartData/index.js +0 -170
- package/src/hooks/useChartData/useChartData/index.js +0 -199
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +0 -94
- package/src/hooks/useChatRoomSubscription/index.js +0 -28
- package/src/hooks/useCheckbox/index.js +0 -115
- package/src/hooks/useCities/index.js +0 -13
- package/src/hooks/useCities/queries.js +0 -12
- package/src/hooks/useClients/index.js +0 -96
- package/src/hooks/useClients/queries.js +0 -212
- package/src/hooks/useColorByLetters/helpers/alea.js +0 -54
- package/src/hooks/useColorByLetters/helpers/colors.js +0 -45
- package/src/hooks/useColorByLetters/helpers/index.js +0 -18
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.js +0 -118
- package/src/hooks/useColorByLetters/index.js +0 -27
- package/src/hooks/useConnection/index.js +0 -24
- package/src/hooks/useCountries/index.js +0 -19
- package/src/hooks/useCountries/queries.js +0 -12
- package/src/hooks/useCreateDeliveryTime/index.js +0 -51
- package/src/hooks/useCreateOrderStatusType/index.ts +0 -132
- package/src/hooks/useCreateProduct/helpers/index.js +0 -23
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +0 -52
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +0 -176
- package/src/hooks/useCreateProduct/index.js +0 -334
- package/src/hooks/useCreateStorePendingToRegister/index.js +0 -13
- package/src/hooks/useCreateStorePendingToRegister/queries.js +0 -10
- package/src/hooks/useDashboardComponents/index.js +0 -50
- package/src/hooks/useDeleteExtraProductFoods/index.js +0 -12
- package/src/hooks/useDeleteSubProductOptional/index.js +0 -30
- package/src/hooks/useDeleteSubProductOptional/queries.js +0 -10
- package/src/hooks/useDeliveryTime/index.js +0 -27
- package/src/hooks/useDepartments/index.js +0 -13
- package/src/hooks/useDepartments/queries.js +0 -13
- package/src/hooks/useDessert/helpers/index.js +0 -51
- package/src/hooks/useDessert/index.js +0 -525
- package/src/hooks/useDessertWithPrice/helpers/index.js +0 -76
- package/src/hooks/useDessertWithPrice/index.js +0 -373
- package/src/hooks/useDessertWithPrice/queries.js +0 -18
- package/src/hooks/useDevWS/index.ts +0 -53
- package/src/hooks/useDevices/index.js +0 -2
- package/src/hooks/useDevices/queries.js +0 -28
- package/src/hooks/useDevices/useGetDevices.js +0 -28
- package/src/hooks/useDevices/useRegisterDevices.js +0 -75
- package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +0 -21
- package/src/hooks/useDownloadReports/index.ts +0 -2
- package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +0 -103
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +0 -115
- package/src/hooks/useDrag/index.js +0 -63
- package/src/hooks/useDropzone/index.js +0 -94
- package/src/hooks/useDynamicAuth/index.js +0 -13
- package/src/hooks/useDynamicAuth/queries.js +0 -24
- package/src/hooks/useEditCategory/index.js +0 -41
- package/src/hooks/useEditOneExtProductFoodOptional/index.js +0 -28
- package/src/hooks/useEditOneExtProductFoodOptional/queries.js +0 -16
- package/src/hooks/useEditSubProductOptional/index.js +0 -11
- package/src/hooks/useEditSubProductOptional/queries.js +0 -10
- package/src/hooks/useEmployee/index.js +0 -17
- package/src/hooks/useEmployee/queries.js +0 -85
- package/src/hooks/useEmployee/useCreateEmployee.js +0 -86
- package/src/hooks/useEvent/index.js +0 -34
- package/src/hooks/useFavoriteStores/index.js +0 -29
- package/src/hooks/useFavoriteStores/queries.js +0 -54
- package/src/hooks/useFetchJson/index.js +0 -25
- package/src/hooks/useFetchMoreInteractions/index.jsx +0 -39
- package/src/hooks/useFingerprintjs/index.js +0 -172
- package/src/hooks/useFormTools/index.js +0 -116
- package/src/hooks/useFormatDate/index.js +0 -86
- package/src/hooks/useFormatNumberPhone/index.js +0 -23
- package/src/hooks/useFullScreenMode/index.js +0 -65
- package/src/hooks/useGenerateNumberArray/index.js +0 -17
- package/src/hooks/useGetAllLocationUser/index.js +0 -12
- package/src/hooks/useGetAllLocationUser/queries.js +0 -44
- package/src/hooks/useGetCookies/index.js +0 -43
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +0 -14
- package/src/hooks/useGetFoodRecomended/index.js +0 -32
- package/src/hooks/useGetFoodRecomended/queries.js +0 -47
- package/src/hooks/useGetMessagesToRoom/index.js +0 -23
- package/src/hooks/useGetMinPrice/index.js +0 -12
- package/src/hooks/useGetMinPrice/queries.js +0 -7
- package/src/hooks/useGetOneStoreRating/index.js +0 -40
- package/src/hooks/useGetOneStoreRating/queries.js +0 -18
- package/src/hooks/useGetSalesAmountToday/index.js +0 -31
- package/src/hooks/useGetStoreCookie/index.js +0 -21
- package/src/hooks/useGoogleLogin/index.js +0 -160
- package/src/hooks/useGoogleLogin/loadScript.js +0 -15
- package/src/hooks/useGoogleLogin/removeScript.js +0 -7
- package/src/hooks/useHover/index.js +0 -29
- package/src/hooks/useImageOptimization/index.js +0 -28
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +0 -130
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +0 -53
- package/src/hooks/useImageUploaderProduct/helper/index.ts +0 -5
- package/src/hooks/useImageUploaderProduct/index.ts +0 -292
- package/src/hooks/useImageWeight/index.js +0 -51
- package/src/hooks/useImagesStore/index.js +0 -225
- package/src/hooks/useImagesStore/queries.js +0 -193
- package/src/hooks/useImagesStore/utils/index.js +0 -4
- package/src/hooks/useIncomingOrders/index.js +0 -10
- package/src/hooks/useIncomingOrders/queries.js +0 -87
- package/src/hooks/useInnerHtml/index.js +0 -39
- package/src/hooks/useIntersection/index.js +0 -84
- package/src/hooks/useInventory/index.js +0 -2
- package/src/hooks/useInventory/queries.js +0 -58
- package/src/hooks/useInventory/useGetProductsInStock.js +0 -15
- package/src/hooks/useInventory/useUpdateManageStock.js +0 -41
- package/src/hooks/useKeypress/index.js +0 -28
- package/src/hooks/useLazyScript/index.js +0 -71
- package/src/hooks/useLocalBackendIp/index.js +0 -34
- package/src/hooks/useLocalSorage/index.js +0 -36
- package/src/hooks/useLocationManager/index.js +0 -63
- package/src/hooks/useLocationNavigate/index.js +0 -54
- package/src/hooks/useLoginEmployeeInStore/index.js +0 -38
- package/src/hooks/useLogout/helpers/BroadcastChannel.js +0 -31
- package/src/hooks/useLogout/helpers/apiBaseUrl.js +0 -8
- package/src/hooks/useLogout/helpers/fetchData.js +0 -28
- package/src/hooks/useLogout/helpers/getCsrfToken.js +0 -30
- package/src/hooks/useLogout/helpers/index.js +0 -57
- package/src/hooks/useLogout/helpers/logger.js +0 -70
- package/src/hooks/useLogout/helpers/parseUrl.js +0 -36
- package/src/hooks/useLogout/index.js +0 -96
- package/src/hooks/useManageNewOrder/helpers/index.js +0 -45
- package/src/hooks/useManageNewOrder/helpers/mock.js +0 -0
- package/src/hooks/useManageNewOrder/index.js +0 -102
- package/src/hooks/useManageQueryParams/index.js +0 -40
- package/src/hooks/useMobile/index.js +0 -65
- package/src/hooks/useModules/helpers/index.js +0 -1
- package/src/hooks/useModules/helpers/validateModules.js +0 -29
- package/src/hooks/useModules/index.js +0 -58
- package/src/hooks/useMouse/index.ts +0 -50
- package/src/hooks/useMutateHeight/index.js +0 -36
- package/src/hooks/useOrderClient/index.js +0 -5
- package/src/hooks/useOrderStatusTypes/index.ts +0 -2
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +0 -133
- package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +0 -97
- package/src/hooks/useOrders/index.js +0 -3
- package/src/hooks/useOrders/queries.js +0 -89
- package/src/hooks/useOrders/useChangeOrderState/index.ts +0 -125
- package/src/hooks/useOrders/useOrdersFromStore/index.ts +0 -77
- package/src/hooks/usePWAInstall/index.js +0 -38
- package/src/hooks/usePortFetcher/index.ts +0 -33
- package/src/hooks/useProductsFood/index.js +0 -253
- package/src/hooks/useProductsFood/queriesStore.js +0 -964
- package/src/hooks/useProductsFood/useEditProduct.js +0 -48
- package/src/hooks/useProductsFood/usetagsProducts.js +0 -98
- package/src/hooks/useProviders/index.js +0 -3
- package/src/hooks/useProviders/queries.js +0 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +0 -12
- package/src/hooks/useProviders/useProvidersDataStore/index.js +0 -24
- package/src/hooks/useProvidersStore/index.js +0 -24
- package/src/hooks/useProvidersStore/queries.js +0 -31
- package/src/hooks/usePushNotificationOrder/index.js +0 -52
- package/src/hooks/usePushNotifications/helpers/index.js +0 -114
- package/src/hooks/usePushNotifications/index.js +0 -149
- package/src/hooks/useQueryLocationsMap/index.js +0 -19
- package/src/hooks/useQueryLocationsMap/queries.js +0 -40
- package/src/hooks/useRatingArrayData/index.js +0 -54
- package/src/hooks/useRatingArrayData/queries.js +0 -19
- package/src/hooks/useReactToPrint/index.js +0 -1223
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +0 -23
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +0 -48
- package/src/hooks/useReport/index.js +0 -47
- package/src/hooks/useReport/queries.js +0 -123
- package/src/hooks/useRestaurant/helpers/index.js +0 -24
- package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +0 -26
- package/src/hooks/useRestaurant/index.js +0 -69
- package/src/hooks/useRestaurant/queries.js +0 -81
- package/src/hooks/useRoads/index.js +0 -19
- package/src/hooks/useRoads/queries.js +0 -13
- package/src/hooks/useRoles/index.js +0 -4
- package/src/hooks/useRoles/queries.js +0 -70
- package/src/hooks/useRoles/useCreateRole.js +0 -37
- package/src/hooks/useRoles/useGetRoles.js +0 -36
- package/src/hooks/useRoles/useRemoveRoles.js +0 -40
- package/src/hooks/useRoles/useUpdateRolesPriority.js +0 -44
- package/src/hooks/useSales/helpers/index.js +0 -55
- package/src/hooks/useSales/index.js +0 -1381
- package/src/hooks/useSales/queries.js +0 -424
- package/src/hooks/useSales/useGetAllSales/index.js +0 -25
- package/src/hooks/useSales/useGetSale.js +0 -13
- package/src/hooks/useSales/useTotalSales.js +0 -23
- package/src/hooks/useSaveAvailableProduct/helpers/index.js +0 -38
- package/src/hooks/useSaveAvailableProduct/index.js +0 -31
- package/src/hooks/useSaveAvailableProduct/queries.js +0 -10
- package/src/hooks/useSaveLocation/index.js +0 -16
- package/src/hooks/useSaveLocation/queries.js +0 -19
- package/src/hooks/useSchedule/index.js +0 -78
- package/src/hooks/useSchedule/index.jsx +0 -22
- package/src/hooks/useSchedule/queries.js +0 -43
- package/src/hooks/useScheduleData/index.js +0 -123
- package/src/hooks/useScroll/index.js +0 -56
- package/src/hooks/useScrollRotate/index.js +0 -16
- package/src/hooks/useSetImageProducts/index.js +0 -57
- package/src/hooks/useSetImageProducts/queries.js +0 -18
- package/src/hooks/useSetSession/index.js +0 -44
- package/src/hooks/useSetState/index.js +0 -24
- package/src/hooks/useSetupSchedule/helpers/index.js +0 -85
- package/src/hooks/useSetupSchedule/index.js +0 -272
- package/src/hooks/useStatusOpenStore/helpers/index.js +0 -101
- package/src/hooks/useStatusOpenStore/index.js +0 -179
- package/src/hooks/useStatusOrdersClient/helpers/index.js +0 -14
- package/src/hooks/useStatusOrdersClient/index.js +0 -17
- package/src/hooks/useStatusOrdersClient/queries.js +0 -80
- package/src/hooks/useStockMovements/helpers/index.js +0 -16
- package/src/hooks/useStockMovements/index.js +0 -38
- package/src/hooks/useStore/index.js +0 -80
- package/src/hooks/useStore/queries.js +0 -163
- package/src/hooks/useStoreCalendar/index.js +0 -5
- package/src/hooks/useStoreContacts/index.js +0 -47
- package/src/hooks/useStoreContacts/queries.js +0 -48
- package/src/hooks/useStoreTable/index.js +0 -2
- package/src/hooks/useStoreTable/queries.js +0 -47
- package/src/hooks/useStoreTable/useStoreTableCreate.js +0 -76
- package/src/hooks/useStoreTable/useStoreTables.js +0 -14
- package/src/hooks/useSubscriptionValidation/index.js +0 -41
- package/src/hooks/useTagProducts/index.ts +0 -3
- package/src/hooks/useTagProducts/useDeleteOneTag.ts +0 -106
- package/src/hooks/useTagProducts/useGetAllTags.ts +0 -68
- package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +0 -156
- package/src/hooks/useTimeAgo/useTimeAgo.js +0 -39
- package/src/hooks/useTokenCards/index.js +0 -41
- package/src/hooks/useTopProductsMovements/index.js +0 -27
- package/src/hooks/useTotalAllSales/index.js +0 -25
- package/src/hooks/useTotalProductsInStock/index.js +0 -23
- package/src/hooks/useTotalProductsSold/index.js +0 -23
- package/src/hooks/useTotalProductsSolded/index.js +0 -20
- package/src/hooks/useUpdateCart/index.js +0 -130
- package/src/hooks/useUpdateCartCookie/index.js +0 -43
- package/src/hooks/useUpdateDashboardComponent/index.ts +0 -91
- package/src/hooks/useUpdateExistingOrders/index.js +0 -85
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -60
- package/src/hooks/useUpdateModuleOrder/index.js +0 -37
- package/src/hooks/useUpdateMultipleExtProduct/index.js +0 -33
- package/src/hooks/useUpdateMultipleExtProduct/queries.js +0 -33
- package/src/hooks/useUpdateMultipleProducts/index.js +0 -80
- package/src/hooks/useUpdateMultipleProducts/queries.js +0 -51
- package/src/hooks/useUploadProducts/helpers/index.js +0 -1
- package/src/hooks/useUploadProducts/helpers/parseNumber.js +0 -37
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.js +0 -73
- package/src/hooks/useUploadProducts/index.js +0 -422
- package/src/hooks/useUpsertGoal/index.js +0 -68
- package/src/hooks/useUser/index.js +0 -23
- package/src/hooks/useUser/queries.js +0 -131
- package/src/hooks/useWeeklyStockMovement/helpers/index.js +0 -32
- package/src/hooks/useWeeklyStockMovement/index.js +0 -51
- package/src/hooks/useWindowSize/index.js +0 -38
- package/src/index.jsx +0 -9
- package/src/mock/dessert/index.js +0 -16
- package/src/mock/index.js +0 -1
- package/src/security/index.js +0 -1
- package/src/services/index.js +0 -0
- package/src/utils/UtilDateRange.js +0 -31
- package/src/utils/index.js +0 -306
- package/tsconfig.json +0 -5
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useLocalStorage = (key, initialValue) => {
|
|
4
|
-
// const { setAlertBox } = useContext(Context)
|
|
5
|
-
// State to store our value
|
|
6
|
-
// Pass initial state function to useState so logic is only executed once
|
|
7
|
-
const [storedValue, setStoredValue] = useState(() => {
|
|
8
|
-
try {
|
|
9
|
-
// Get from local storage by key
|
|
10
|
-
const item = window.localStorage.getItem(key)
|
|
11
|
-
// Parse stored json or if none return initialValue
|
|
12
|
-
return item ? JSON.parse(item) : initialValue
|
|
13
|
-
} catch (error) {
|
|
14
|
-
// If error also return initialValue
|
|
15
|
-
return initialValue
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
// Return a wrapped version of useState's setter function that ...
|
|
20
|
-
// ... persists the new value to localStorage.
|
|
21
|
-
const setValue = value => {
|
|
22
|
-
try {
|
|
23
|
-
// Allow value to be a function so we have same API as useState
|
|
24
|
-
const valueToStore =
|
|
25
|
-
value instanceof Function ? value(storedValue) : value
|
|
26
|
-
// Save state
|
|
27
|
-
setStoredValue(valueToStore)
|
|
28
|
-
// Save to local storage
|
|
29
|
-
window.localStorage.setItem(key, JSON.stringify(valueToStore))
|
|
30
|
-
} catch (error) {
|
|
31
|
-
// A more advanced implementation would handle the error case
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return [storedValue, setValue]
|
|
36
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Hook para gestionar la lógica de ubicaciones, valores y errores.
|
|
5
|
-
*
|
|
6
|
-
* @param {Function} getDepartments - Función para obtener los departamentos basado en el ID de país.
|
|
7
|
-
* @param {Function} getCities - Función para obtener las ciudades basado en el ID de departamento.
|
|
8
|
-
*
|
|
9
|
-
* @returns {Object} - Retorna los estados y funciones de manejo asociados.
|
|
10
|
-
*/
|
|
11
|
-
export function useLocationManager (getDepartments, getCities) {
|
|
12
|
-
const [values, setValues] = useState({})
|
|
13
|
-
console.log('🚀 ~ useLocationManager ~ values:', values)
|
|
14
|
-
const [errors, setErrors] = useState({})
|
|
15
|
-
const [showLocation, setShowLocation] = useState(true)
|
|
16
|
-
|
|
17
|
-
const handleUpdateValues = (name, value) => {
|
|
18
|
-
setValues(prevValues => ({ ...prevValues, [name]: value }))
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const handleUpdateErrors = (name, error) => {
|
|
22
|
-
setErrors(prevErrors => ({ ...prevErrors, [name]: error }))
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const handleCountrySearch = (value) => {
|
|
26
|
-
getDepartments({ variables: { cId: value } })
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const handleDepartmentSearch = (value) => {
|
|
30
|
-
setValues(prevValues => ({ ...prevValues, ctId: '' }))
|
|
31
|
-
getCities({ variables: { dId: value } })
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const handleChangeLocation = (e, error) => {
|
|
35
|
-
const { name, value } = e.target
|
|
36
|
-
handleUpdateValues(name, value)
|
|
37
|
-
handleUpdateErrors(name, error)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const handleChangeSearch = (e) => {
|
|
41
|
-
const { name, value } = e.target
|
|
42
|
-
switch (name) {
|
|
43
|
-
case 'countryId':
|
|
44
|
-
handleCountrySearch(value)
|
|
45
|
-
break
|
|
46
|
-
case 'code_dId':
|
|
47
|
-
handleDepartmentSearch(value)
|
|
48
|
-
break
|
|
49
|
-
default:
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
handleChangeLocation(e)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {
|
|
56
|
-
values,
|
|
57
|
-
errors,
|
|
58
|
-
showLocation,
|
|
59
|
-
setShowLocation,
|
|
60
|
-
handleChangeSearch,
|
|
61
|
-
setValues
|
|
62
|
-
}
|
|
63
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const defaultSettings = {
|
|
4
|
-
enableHighAccuracy: false,
|
|
5
|
-
timeout: Infinity,
|
|
6
|
-
maximumAge: 0
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const usePosition = (watch = false, settings = defaultSettings) => {
|
|
10
|
-
const [position, setPosition] = useState({})
|
|
11
|
-
const [error, setError] = useState(null)
|
|
12
|
-
|
|
13
|
-
const onChange = ({ coords, timestamp }) => {
|
|
14
|
-
setPosition({
|
|
15
|
-
latitude: coords.latitude,
|
|
16
|
-
longitude: coords.longitude,
|
|
17
|
-
accuracy: coords.accuracy,
|
|
18
|
-
speed: coords.speed,
|
|
19
|
-
timestamp
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const onError = () => {
|
|
24
|
-
setError(error?.message)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (!navigator || !navigator.geolocation) {
|
|
29
|
-
setError('Geolocation is not supported')
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let watcher = null
|
|
34
|
-
if (watch) {
|
|
35
|
-
watcher = navigator.geolocation.watchPosition(
|
|
36
|
-
onChange,
|
|
37
|
-
onError,
|
|
38
|
-
settings
|
|
39
|
-
)
|
|
40
|
-
} else {
|
|
41
|
-
navigator.geolocation.getCurrentPosition(onChange, onError, settings)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return () => { return watcher && navigator.geolocation.clearWatch(watcher) }
|
|
45
|
-
}, [
|
|
46
|
-
settings,
|
|
47
|
-
settings.enableHighAccuracy,
|
|
48
|
-
settings.timeout,
|
|
49
|
-
settings.maximumAge,
|
|
50
|
-
watch
|
|
51
|
-
])
|
|
52
|
-
|
|
53
|
-
return { ...position, error }
|
|
54
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { gql, useMutation } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
const LOGIN_EMPLOYEE_IN_STORE = gql`
|
|
4
|
-
mutation loginEmployeeInStore($eId: ID, $tenantId: String, $idStore: ID, $idUser: ID, $eEmail: String) {
|
|
5
|
-
loginEmployeeInStore(eId: $eId, tenantId: $tenantId, idStore: $idStore, idUser: $idUser, eEmail: $eEmail) {
|
|
6
|
-
success
|
|
7
|
-
message
|
|
8
|
-
token
|
|
9
|
-
idStore
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
`
|
|
13
|
-
|
|
14
|
-
export const useLoginEmployeeInStore = () => {
|
|
15
|
-
const [loginEmployeeInStore, { data, loading, error }] = useMutation(LOGIN_EMPLOYEE_IN_STORE)
|
|
16
|
-
|
|
17
|
-
const loginEmployee = async (idStore, eEmail) => {
|
|
18
|
-
try {
|
|
19
|
-
const response = await loginEmployeeInStore({
|
|
20
|
-
variables: {
|
|
21
|
-
idStore,
|
|
22
|
-
eEmail
|
|
23
|
-
}
|
|
24
|
-
})
|
|
25
|
-
return response.data.loginEmployeeInStore
|
|
26
|
-
} catch (err) {
|
|
27
|
-
console.error('Error during loginEmployeeInStore mutation:', err)
|
|
28
|
-
throw err
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
loginEmployee,
|
|
34
|
-
data,
|
|
35
|
-
loading,
|
|
36
|
-
error
|
|
37
|
-
}
|
|
38
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function BroadcastChannel (name = 'nextauth.message') {
|
|
2
|
-
return {
|
|
3
|
-
receive: function (onReceive) {
|
|
4
|
-
const handler = function (event) {
|
|
5
|
-
if (event.key !== name) return
|
|
6
|
-
const message = JSON.parse(event.newValue ?? '{}')
|
|
7
|
-
if (message?.event !== 'session' || !message?.data) return
|
|
8
|
-
onReceive(message)
|
|
9
|
-
}
|
|
10
|
-
window.addEventListener('storage', handler)
|
|
11
|
-
return function () {
|
|
12
|
-
window.removeEventListener('storage', handler)
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
post: function (message) {
|
|
16
|
-
if (typeof window === 'undefined') return
|
|
17
|
-
try {
|
|
18
|
-
localStorage.setItem(
|
|
19
|
-
name,
|
|
20
|
-
JSON.stringify({ ...message, timestamp: Date.now() })
|
|
21
|
-
)
|
|
22
|
-
} catch {
|
|
23
|
-
// The localStorage API isn't always available.
|
|
24
|
-
// It won't work in private mode prior to Safari 11 for example.
|
|
25
|
-
// Notifications are simply dropped if an error is encountered.
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { BroadcastChannel }
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function apiBaseUrl (__NEXTAUTH) {
|
|
2
|
-
if (typeof window === 'undefined') {
|
|
3
|
-
// Return absolute path when called server side
|
|
4
|
-
return `${__NEXTAUTH.baseUrlServer}${__NEXTAUTH.basePathServer}`
|
|
5
|
-
}
|
|
6
|
-
// Return relative path when called client side
|
|
7
|
-
return __NEXTAUTH.basePath
|
|
8
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { apiBaseUrl } from './apiBaseUrl'
|
|
2
|
-
|
|
3
|
-
async function fetchData(path, __NEXTAUTH, logger, { ctx, req } = {}) {
|
|
4
|
-
const url = `${apiBaseUrl(__NEXTAUTH)}/${path}`
|
|
5
|
-
try {
|
|
6
|
-
const options = {
|
|
7
|
-
headers: {
|
|
8
|
-
'Content-Type': 'application/json',
|
|
9
|
-
...(req?.headers?.cookie ? { cookie: req.headers.cookie } : {})
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (req?.body) {
|
|
14
|
-
options.body = JSON.stringify(req.body)
|
|
15
|
-
options.method = 'POST'
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const res = await fetch(url, options)
|
|
19
|
-
const data = await res.json()
|
|
20
|
-
if (!res.ok) throw data
|
|
21
|
-
return Object.keys(data).length > 0 ? data : null // Return null if data is empty
|
|
22
|
-
} catch (error) {
|
|
23
|
-
logger.error('CLIENT_FETCH_ERROR', { error, url })
|
|
24
|
-
return null
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { fetchData }
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { fetchData } from './fetchData'
|
|
2
|
-
import _logger, { proxyLogger } from './logger'
|
|
3
|
-
import { parseUrl } from './parseUrl'
|
|
4
|
-
|
|
5
|
-
const __NEXTAUTH = {
|
|
6
|
-
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
7
|
-
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
8
|
-
baseUrlServer: parseUrl(
|
|
9
|
-
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
10
|
-
process.env.NEXTAUTH_URL ||
|
|
11
|
-
process.env.VERCEL_URL
|
|
12
|
-
).origin,
|
|
13
|
-
basePathServer: parseUrl(
|
|
14
|
-
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
15
|
-
).path,
|
|
16
|
-
_lastSync: 0,
|
|
17
|
-
_session: undefined,
|
|
18
|
-
_getSession: () => {}
|
|
19
|
-
}
|
|
20
|
-
const logger = proxyLogger(_logger, __NEXTAUTH.basePath)
|
|
21
|
-
|
|
22
|
-
export async function getCsrfToken (params) {
|
|
23
|
-
const response = await fetchData(
|
|
24
|
-
'csrf',
|
|
25
|
-
__NEXTAUTH,
|
|
26
|
-
logger,
|
|
27
|
-
params
|
|
28
|
-
)
|
|
29
|
-
return response?.csrfToken
|
|
30
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { apiBaseUrl } from './apiBaseUrl'
|
|
2
|
-
import { getCsrfToken } from './getCsrfToken'
|
|
3
|
-
import { parseUrl } from './parseUrl'
|
|
4
|
-
import { BroadcastChannel } from './BroadcastChannel'
|
|
5
|
-
|
|
6
|
-
const broadcast = BroadcastChannel()
|
|
7
|
-
|
|
8
|
-
export const __NEXTAUTH = {
|
|
9
|
-
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
10
|
-
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
11
|
-
baseUrlServer: parseUrl(
|
|
12
|
-
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
13
|
-
process.env.NEXTAUTH_URL ||
|
|
14
|
-
process.env.VERCEL_URL
|
|
15
|
-
).origin,
|
|
16
|
-
basePathServer: parseUrl(
|
|
17
|
-
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
18
|
-
).path,
|
|
19
|
-
_lastSync: 0,
|
|
20
|
-
_session: undefined,
|
|
21
|
-
_getSession: () => {}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export async function signOutAuth (options) {
|
|
25
|
-
const { callbackUrl = window.location.href, reload = true } = options ?? {}
|
|
26
|
-
const baseUrl = apiBaseUrl(__NEXTAUTH)
|
|
27
|
-
const fetchOptions = {
|
|
28
|
-
method: 'post',
|
|
29
|
-
headers: {
|
|
30
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
31
|
-
},
|
|
32
|
-
// @ts-expect-error
|
|
33
|
-
body: new URLSearchParams({
|
|
34
|
-
csrfToken: await getCsrfToken(),
|
|
35
|
-
callbackUrl,
|
|
36
|
-
json: true
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
const res = await fetch(`${baseUrl}/signout`, fetchOptions)
|
|
40
|
-
const data = await res.json()
|
|
41
|
-
|
|
42
|
-
broadcast.post({ event: 'session', data: { trigger: 'signout' } })
|
|
43
|
-
if (!reload) {
|
|
44
|
-
await __NEXTAUTH._getSession({ event: 'storage' })
|
|
45
|
-
return data
|
|
46
|
-
}
|
|
47
|
-
if (options?.redirect ?? true) {
|
|
48
|
-
const url = data.url ?? callbackUrl
|
|
49
|
-
window.location.href = url
|
|
50
|
-
// If url contains a hash, the browser does not reload the page. We reload manually
|
|
51
|
-
if (url.includes('#') && !reload) window.location.reload()
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
await __NEXTAUTH._getSession({ event: 'storage' })
|
|
56
|
-
return data
|
|
57
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
function formatError(o) {
|
|
2
|
-
if (hasErrorProperty(o)) {
|
|
3
|
-
o.error = formatError(o.error)
|
|
4
|
-
o.message = o.message ?? o.error.message
|
|
5
|
-
}
|
|
6
|
-
return o
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function hasErrorProperty(x) {
|
|
10
|
-
return !!(x?.error)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const _logger = {
|
|
14
|
-
error(code, metadata) {
|
|
15
|
-
metadata = formatError(metadata)
|
|
16
|
-
console.error(
|
|
17
|
-
`[next-auth][error][${code}]`,
|
|
18
|
-
`\nhttps://next-auth.js.org/errors#${code.toLowerCase()}`,
|
|
19
|
-
metadata.message,
|
|
20
|
-
metadata
|
|
21
|
-
)
|
|
22
|
-
},
|
|
23
|
-
warn(code) {
|
|
24
|
-
console.warn(
|
|
25
|
-
`[next-auth][warn][${code}]`,
|
|
26
|
-
`\nhttps://next-auth.js.org/warnings#${code.toLowerCase()}`
|
|
27
|
-
)
|
|
28
|
-
},
|
|
29
|
-
debug(code, metadata) {
|
|
30
|
-
console.log(`[next-auth][debug][${code}]`, metadata)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function setLogger(newLogger = {}, debug) {
|
|
35
|
-
if (!debug) _logger.debug = () => { }
|
|
36
|
-
|
|
37
|
-
if (newLogger.error) _logger.error = newLogger.error
|
|
38
|
-
if (newLogger.warn) _logger.warn = newLogger.warn
|
|
39
|
-
if (newLogger.debug) _logger.debug = newLogger.debug
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function proxyLogger(logger = _logger, basePath) {
|
|
43
|
-
try {
|
|
44
|
-
if (typeof window === 'undefined') {
|
|
45
|
-
return logger
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const clientLogger = {}
|
|
49
|
-
for (const level in logger) {
|
|
50
|
-
clientLogger[level] = (code, metadata) => {
|
|
51
|
-
_logger[level](code, metadata)
|
|
52
|
-
|
|
53
|
-
if (level === 'error') {
|
|
54
|
-
metadata = formatError(metadata)
|
|
55
|
-
}
|
|
56
|
-
metadata.client = true
|
|
57
|
-
const url = `${basePath}/_log`
|
|
58
|
-
const body = new URLSearchParams({ level, code, ...metadata })
|
|
59
|
-
if (navigator.sendBeacon) {
|
|
60
|
-
return navigator.sendBeacon(url, body)
|
|
61
|
-
}
|
|
62
|
-
return fetch(url, { method: 'POST', body, keepalive: true })
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return clientLogger
|
|
66
|
-
} catch {
|
|
67
|
-
return _logger
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export { _logger as default }
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/** Interface for the internal URL structure */
|
|
2
|
-
const InternalUrl = {
|
|
3
|
-
origin: 'http://localhost:3000',
|
|
4
|
-
host: 'localhost:3000',
|
|
5
|
-
path: '/api/auth',
|
|
6
|
-
base: 'http://localhost:3000/api/auth',
|
|
7
|
-
toString: function () {
|
|
8
|
-
return this.base
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Function to parse a URL-like object for server-side requests/redirects */
|
|
13
|
-
function parseUrl (url) {
|
|
14
|
-
const defaultUrl = new URL('http://localhost:3000/api/auth')
|
|
15
|
-
|
|
16
|
-
if (url && !url.startsWith('http')) {
|
|
17
|
-
url = `https://${url}`
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _url = new URL(url || defaultUrl)
|
|
21
|
-
const path = (_url.pathname === '/' ? defaultUrl.pathname : _url.pathname).replace(/\/$/, '')
|
|
22
|
-
|
|
23
|
-
const base = `${_url.origin}${path}`
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
origin: _url.origin,
|
|
27
|
-
host: _url.host,
|
|
28
|
-
path,
|
|
29
|
-
base,
|
|
30
|
-
toString: function () {
|
|
31
|
-
return base
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { InternalUrl, parseUrl }
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from '@apollo/client'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
import { Cookies } from '../../cookies/index'
|
|
4
|
-
import { signOutAuth } from './helpers'
|
|
5
|
-
import { getCurrentDomain } from '../../utils'
|
|
6
|
-
export { signOutAuth } from './helpers'
|
|
7
|
-
|
|
8
|
-
export const useLogout = ({
|
|
9
|
-
setAlertBox = ({
|
|
10
|
-
message
|
|
11
|
-
}) => { return { message } }
|
|
12
|
-
} = {}) => {
|
|
13
|
-
const [loading, setLoading] = useState(false)
|
|
14
|
-
const [error, setError] = useState(false)
|
|
15
|
-
const client = useApolloClient()
|
|
16
|
-
|
|
17
|
-
const eliminarCookie = async (nombreCookie) => {
|
|
18
|
-
try {
|
|
19
|
-
let domain = getCurrentDomain()
|
|
20
|
-
|
|
21
|
-
// Si estás en entorno local, usa 'localhost' como dominio
|
|
22
|
-
if (domain === 'localhost') {
|
|
23
|
-
domain = undefined // Esto permitirá la cookie en 'localhost'
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const expirationTime = new Date()
|
|
27
|
-
expirationTime.setTime(expirationTime.getTime() - 1000) // Establece una fecha de expiración en el pasado
|
|
28
|
-
|
|
29
|
-
const formattedDomain = domain || getCurrentDomain()
|
|
30
|
-
|
|
31
|
-
await Cookies.remove(nombreCookie, { domain: formattedDomain, path: '/', secure: process.env.NODE_ENV === 'production' })
|
|
32
|
-
|
|
33
|
-
console.log('Cookie eliminada correctamente.')
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('Error al eliminar la cookie:', error)
|
|
36
|
-
throw new Error('Error al eliminar la cookie. ')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const deleteCookie = async () => {
|
|
40
|
-
await eliminarCookie(process.env.NEXT_PUBLIC_SESSION_NAME)
|
|
41
|
-
await eliminarCookie(process.env.LOCAL_SALES_STORE)
|
|
42
|
-
await eliminarCookie('restaurant')
|
|
43
|
-
await eliminarCookie('usuario')
|
|
44
|
-
await eliminarCookie('session')
|
|
45
|
-
}
|
|
46
|
-
const onClickLogout = async ({ redirect = true } = { redirect: true }) => {
|
|
47
|
-
console.log(redirect)
|
|
48
|
-
try {
|
|
49
|
-
if (!redirect) return await deleteCookie()
|
|
50
|
-
setLoading(true)
|
|
51
|
-
await deleteCookie()
|
|
52
|
-
// Logout from the server
|
|
53
|
-
const port = window.location.port ? `:${window.location.port}` : ''
|
|
54
|
-
const baseUrl = `${window.location.protocol}//${window.location.hostname}${port}`
|
|
55
|
-
const logoutResponse = await fetch(`${baseUrl}/api/auth/signout/`, {
|
|
56
|
-
method: 'POST',
|
|
57
|
-
headers: {
|
|
58
|
-
'Content-Type': 'application/json'
|
|
59
|
-
},
|
|
60
|
-
credentials: 'include'
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
if (!logoutResponse.ok) {
|
|
64
|
-
setLoading(false)
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
await logoutResponse.json()
|
|
69
|
-
console.log('Intentando borrar cookies...')
|
|
70
|
-
|
|
71
|
-
// Eliminar la cookie process.env.NEXT_PUBLIC_SESSION_NAME
|
|
72
|
-
await eliminarCookie(process.env.NEXT_PUBLIC_SESSION_NAME)
|
|
73
|
-
Cookies.remove(process.env.LOCAL_SALES_STORE)
|
|
74
|
-
Cookies.remove('restaurant')
|
|
75
|
-
Cookies.remove('usuario')
|
|
76
|
-
Cookies.remove('session')
|
|
77
|
-
|
|
78
|
-
// Clear Apollo Client cache
|
|
79
|
-
client?.clearStore()
|
|
80
|
-
|
|
81
|
-
setLoading(false)
|
|
82
|
-
console.log('Cookies eliminadas y sesión cerrada con éxito')
|
|
83
|
-
signOutAuth({ redirect: true, callbackUrl: '/' })
|
|
84
|
-
.catch(() => {
|
|
85
|
-
setError(true)
|
|
86
|
-
setAlertBox({ message: 'Ocurrió un error al cerrar sesión' })
|
|
87
|
-
})
|
|
88
|
-
} catch (error) {
|
|
89
|
-
setLoading(false)
|
|
90
|
-
setError(true)
|
|
91
|
-
setAlertBox({ message: 'Ocurrió un error al cerrar sesión' })
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return [onClickLogout, { loading, error }]
|
|
96
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Busca un objeto dentro de un conjunto de columnas por su código de referencia.
|
|
3
|
-
* @param {Object} data - El objeto que contiene las columnas.
|
|
4
|
-
* @param {string} pCodeRef - El código de referencia a buscar.
|
|
5
|
-
* @returns {Object|null} - El objeto encontrado o null si no se encuentra.
|
|
6
|
-
*/
|
|
7
|
-
export function findOrderByCodeRef (data, pCodeRef) {
|
|
8
|
-
if (!data || typeof data !== 'object') {
|
|
9
|
-
throw new Error('El parámetro "data" debe ser un objeto no nulo.')
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (typeof pCodeRef !== 'string') {
|
|
13
|
-
throw new Error('El parámetro "pCodeRef" debe ser una cadena de texto.')
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Iterar sobre cada columna en el objeto data
|
|
17
|
-
for (const columnKey in data) {
|
|
18
|
-
if (Object.hasOwnProperty.call(data, columnKey)) {
|
|
19
|
-
const column = data[columnKey]
|
|
20
|
-
// Verificar si la columna es un array
|
|
21
|
-
if (Array.isArray(column)) {
|
|
22
|
-
// Buscar el objeto por pCodeRef dentro de la columna actual
|
|
23
|
-
const foundOrder = column.find(
|
|
24
|
-
(order) => order && order.pCodeRef === pCodeRef
|
|
25
|
-
)
|
|
26
|
-
// Si se encuentra el objeto, devolverlo
|
|
27
|
-
if (foundOrder) {
|
|
28
|
-
return foundOrder
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Si no se encuentra el objeto en ninguna columna, devolver null
|
|
34
|
-
return null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const isDateInRange = (dateString) => {
|
|
38
|
-
const currentDate = new Date()
|
|
39
|
-
const todayStart = new Date(currentDate.setHours(0, 0, 0, 0))
|
|
40
|
-
const tomorrowStart = new Date(todayStart)
|
|
41
|
-
tomorrowStart.setDate(tomorrowStart.getDate() + 1)
|
|
42
|
-
|
|
43
|
-
const date = new Date(dateString)
|
|
44
|
-
return date >= todayStart && date < tomorrowStart
|
|
45
|
-
}
|
|
File without changes
|