npm-pkg-hook 1.13.0 → 1.13.1
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.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -2
- package/.babelrc +0 -0
- package/.github/pull_request_template.md +0 -18
- package/.github/workflows/pepeline.yaml +0 -30
- package/eslint.config.mts +0 -153
- package/expire.json +0 -1
- package/jsconfig.json +0 -28
- package/script.txt +0 -7
- package/src/config/client/errors.ts +0 -39
- package/src/config/client/index.ts +0 -1
- package/src/config/content/en.json +0 -5
- package/src/config/content/es.json +0 -5
- package/src/config/content/index.ts +0 -16
- package/src/cookies/index.ts +0 -3
- package/src/hooks/addTenMinutes/index.ts +0 -14
- package/src/hooks/calculateLogLatHaversine/index.ts +0 -41
- package/src/hooks/completeSchedules/index.ts +0 -22
- package/src/hooks/convertToMilitaryTime/index.ts +0 -18
- package/src/hooks/generateStoreURL/index.ts +0 -41
- package/src/hooks/generateTemplate/index.ts +0 -66
- package/src/hooks/getCardType/index.ts +0 -24
- package/src/hooks/getCategoriesWithProduct/helpers/index.ts +0 -7
- package/src/hooks/getCategoriesWithProduct/index.ts +0 -62
- package/src/hooks/getGlobalSession/index.ts +0 -69
- package/src/hooks/getSession/index.ts +0 -72
- package/src/hooks/getTodayTimestamps/index.ts +0 -70
- package/src/hooks/getTotalHours/index.ts +0 -76
- package/src/hooks/handleLogin/index.ts +0 -14
- package/src/hooks/index.ts +0 -154
- package/src/hooks/isTokenExpired/index.ts +0 -17
- package/src/hooks/newMessageSubscription/index.ts +0 -28
- package/src/hooks/newStoreOrderSubscription/index.ts +0 -26
- package/src/hooks/statusOpenStores/helpers/index.ts +0 -124
- package/src/hooks/statusOpenStores/index.ts +0 -221
- package/src/hooks/updateExtProductFoodsOptional/index.ts +0 -49
- package/src/hooks/useAcumulateDate/index.ts +0 -18
- package/src/hooks/useAllStoresPendingToRegister/index.ts +0 -37
- package/src/hooks/useAmountInput/index.ts +0 -127
- package/src/hooks/useAnimationFrame/index.ts +0 -45
- package/src/hooks/useAnimationText/index.ts +0 -31
- package/src/hooks/useAsideCart/helpers/index.ts +0 -22
- package/src/hooks/useAsideCart/index.ts +0 -217
- package/src/hooks/useAsideCart/queries.ts +0 -10
- package/src/hooks/useBanner/index.ts +0 -20
- package/src/hooks/useCart/index.ts +0 -2
- package/src/hooks/useCart/queries.ts +0 -174
- package/src/hooks/useCart/useCart/helpers/index.ts +0 -79
- package/src/hooks/useCart/useCart/index.ts +0 -424
- package/src/hooks/useCart/useGetCart/index.ts +0 -34
- package/src/hooks/useCatWithProduct/index.ts +0 -54
- package/src/hooks/useCatWithProduct/queries.ts +0 -200
- package/src/hooks/useCatWithProduct/types/index.ts +0 -104
- package/src/hooks/useCatWithProductClient/index.ts +0 -57
- package/src/hooks/useCatWithProductClient/queries.ts +0 -56
- package/src/hooks/useCategoriesProduct/index.ts +0 -14
- package/src/hooks/useCategoriesProduct/queries.ts +0 -16
- package/src/hooks/useCategoryInStore/index.ts +0 -167
- package/src/hooks/useCategoryInStore/queries.ts +0 -78
- package/src/hooks/useCategoryStore/index.ts +0 -8
- package/src/hooks/useCategoryStore/queries.ts +0 -16
- package/src/hooks/useChartData/index.ts +0 -171
- package/src/hooks/useChartData/useChartData/index.ts +0 -200
- package/src/hooks/useChartData/useChartDataAllOrders/index.ts +0 -94
- package/src/hooks/useChatRoomSubscription/index.ts +0 -28
- package/src/hooks/useCheckbox/index.ts +0 -115
- package/src/hooks/useCities/index.ts +0 -14
- package/src/hooks/useCities/queries.ts +0 -12
- package/src/hooks/useClients/index.ts +0 -97
- package/src/hooks/useClients/queries.ts +0 -215
- package/src/hooks/useColorByLetters/helpers/alea.ts +0 -73
- package/src/hooks/useColorByLetters/helpers/colors.ts +0 -45
- package/src/hooks/useColorByLetters/helpers/index.ts +0 -24
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.ts +0 -118
- package/src/hooks/useColorByLetters/index.ts +0 -24
- package/src/hooks/useConnection/index.ts +0 -24
- package/src/hooks/useCountries/index.ts +0 -20
- package/src/hooks/useCountries/queries.ts +0 -12
- package/src/hooks/useCreateDeliveryTime/index.ts +0 -51
- package/src/hooks/useCreateOrderStatusType/index.ts +0 -134
- package/src/hooks/useCreateProduct/helpers/index.ts +0 -23
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.ts +0 -52
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.ts +0 -182
- package/src/hooks/useCreateProduct/index.ts +0 -337
- package/src/hooks/useCreateStorePendingToRegister/index.ts +0 -17
- package/src/hooks/useCreateStorePendingToRegister/queries.ts +0 -10
- package/src/hooks/useDashboardComponents/index.ts +0 -50
- package/src/hooks/useDeleteExtraProductFoods/index.ts +0 -13
- package/src/hooks/useDeleteSubProductOptional/index.ts +0 -32
- package/src/hooks/useDeleteSubProductOptional/queries.ts +0 -10
- package/src/hooks/useDeliveryTime/index.ts +0 -29
- package/src/hooks/useDepartments/index.ts +0 -14
- package/src/hooks/useDepartments/queries.ts +0 -13
- package/src/hooks/useDessert/helpers/index.ts +0 -51
- package/src/hooks/useDessert/index.ts +0 -529
- package/src/hooks/useDessertWithPrice/helpers/index.ts +0 -76
- package/src/hooks/useDessertWithPrice/index.ts +0 -381
- package/src/hooks/useDessertWithPrice/queries.ts +0 -18
- package/src/hooks/useDevWS/index.ts +0 -53
- package/src/hooks/useDevices/index.ts +0 -2
- package/src/hooks/useDevices/queries.ts +0 -28
- package/src/hooks/useDevices/useGetDevices.ts +0 -28
- package/src/hooks/useDevices/useRegisterDevices.ts +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 -105
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +0 -116
- package/src/hooks/useDrag/index.ts +0 -79
- package/src/hooks/useDropzone/index.ts +0 -94
- package/src/hooks/useDynamicAuth/index.ts +0 -14
- package/src/hooks/useDynamicAuth/queries.ts +0 -24
- package/src/hooks/useEditCategory/index.ts +0 -41
- package/src/hooks/useEditOneExtProductFoodOptional/index.ts +0 -28
- package/src/hooks/useEditOneExtProductFoodOptional/queries.ts +0 -16
- package/src/hooks/useEditSubProductOptional/index.ts +0 -12
- package/src/hooks/useEditSubProductOptional/queries.ts +0 -10
- package/src/hooks/useEmployee/index.ts +0 -18
- package/src/hooks/useEmployee/queries.ts +0 -85
- package/src/hooks/useEmployee/useCreateEmployee.ts +0 -90
- package/src/hooks/useEvent/index.ts +0 -34
- package/src/hooks/useFavoriteStores/index.ts +0 -31
- package/src/hooks/useFavoriteStores/queries.ts +0 -54
- package/src/hooks/useFetchJson/index.ts +0 -25
- package/src/hooks/useFetchMoreInteractions/index.jsx +0 -39
- package/src/hooks/useFilterConfigs/index.ts +0 -173
- package/src/hooks/useFingerprintjs/index.ts +0 -197
- package/src/hooks/useFormTools/index.ts +0 -143
- package/src/hooks/useFormatDate/index.ts +0 -91
- package/src/hooks/useFormatNumberPhone/index.ts +0 -23
- package/src/hooks/useFullScreenMode/index.ts +0 -61
- package/src/hooks/useGenerateNumberArray/index.ts +0 -17
- package/src/hooks/useGetAllLocationUser/index.ts +0 -13
- package/src/hooks/useGetAllLocationUser/queries.ts +0 -44
- package/src/hooks/useGetAllSales/index.ts +0 -26
- package/src/hooks/useGetCookies/index.ts +0 -43
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.ts +0 -15
- package/src/hooks/useGetFoodRecomended/index.ts +0 -33
- package/src/hooks/useGetFoodRecomended/queries.ts +0 -47
- package/src/hooks/useGetMessagesToRoom/index.ts +0 -23
- package/src/hooks/useGetMinPrice/index.ts +0 -13
- package/src/hooks/useGetMinPrice/queries.ts +0 -7
- package/src/hooks/useGetOneStoreRating/index.ts +0 -41
- package/src/hooks/useGetOneStoreRating/queries.ts +0 -18
- package/src/hooks/useGetSalesAmountToday/index.ts +0 -31
- package/src/hooks/useGetStoreCookie/index.ts +0 -21
- package/src/hooks/useGoogleLogin/index.ts +0 -169
- package/src/hooks/useGoogleLogin/loadScript.ts +0 -15
- package/src/hooks/useGoogleLogin/removeScript.ts +0 -7
- package/src/hooks/useHover/index.ts +0 -32
- package/src/hooks/useImageOptimization/index.ts +0 -32
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +0 -146
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +0 -54
- package/src/hooks/useImageUploaderProduct/helper/index.ts +0 -5
- package/src/hooks/useImageUploaderProduct/index.ts +0 -295
- package/src/hooks/useImageWeight/index.ts +0 -55
- package/src/hooks/useImagesStore/index.ts +0 -227
- package/src/hooks/useImagesStore/queries.ts +0 -193
- package/src/hooks/useImagesStore/utils/index.ts +0 -4
- package/src/hooks/useIncomingOrders/index.ts +0 -11
- package/src/hooks/useIncomingOrders/queries.ts +0 -87
- package/src/hooks/useInnerHtml/index.ts +0 -39
- package/src/hooks/useIntersection/index.ts +0 -84
- package/src/hooks/useInventory/index.ts +0 -2
- package/src/hooks/useInventory/queries.ts +0 -58
- package/src/hooks/useInventory/useGetProductsInStock.ts +0 -16
- package/src/hooks/useInventory/useUpdateManageStock.ts +0 -41
- package/src/hooks/useKeypress/index.ts +0 -28
- package/src/hooks/useLazyScript/index.ts +0 -74
- package/src/hooks/useLocalBackendIp/index.ts +0 -34
- package/src/hooks/useLocalSorage/index.ts +0 -36
- package/src/hooks/useLocationManager/index.ts +0 -63
- package/src/hooks/useLocationNavigate/index.ts +0 -54
- package/src/hooks/useLoginEmployeeInStore/index.ts +0 -38
- package/src/hooks/useLogout/helpers/BroadcastChannel.ts +0 -74
- package/src/hooks/useLogout/helpers/apiBaseUrl.ts +0 -12
- package/src/hooks/useLogout/helpers/fetchData.ts +0 -37
- package/src/hooks/useLogout/helpers/getCsrfToken.ts +0 -37
- package/src/hooks/useLogout/helpers/index.ts +0 -65
- package/src/hooks/useLogout/helpers/logger.ts +0 -88
- package/src/hooks/useLogout/helpers/parseUrl.ts +0 -39
- package/src/hooks/useLogout/index.ts +0 -105
- package/src/hooks/useManageNewOrder/helpers/index.ts +0 -45
- package/src/hooks/useManageNewOrder/helpers/mock.ts +0 -0
- package/src/hooks/useManageNewOrder/index.ts +0 -104
- package/src/hooks/useManageQueryParams/index.ts +0 -120
- package/src/hooks/useMobile/index.ts +0 -65
- package/src/hooks/useModules/helpers/index.ts +0 -1
- package/src/hooks/useModules/helpers/validateModules.ts +0 -43
- package/src/hooks/useModules/index.ts +0 -124
- package/src/hooks/useMouse/index.ts +0 -55
- package/src/hooks/useMutateHeight/index.ts +0 -36
- package/src/hooks/useOrderClient/index.ts +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 -99
- package/src/hooks/useOrders/index.ts +0 -3
- package/src/hooks/useOrders/queries.ts +0 -99
- package/src/hooks/useOrders/useChangeOrderState/index.ts +0 -128
- package/src/hooks/useOrders/useOrdersFromStore/index.ts +0 -77
- package/src/hooks/usePWAInstall/index.ts +0 -38
- package/src/hooks/usePaymentMethod/index.ts +0 -3
- package/src/hooks/usePaymentMethod/paymentMethod.gql.ts +0 -62
- package/src/hooks/usePaymentMethod/paymentMethod.types.ts +0 -28
- package/src/hooks/usePaymentMethod/useCreatePaymentMethod/index.ts +0 -25
- package/src/hooks/usePaymentMethod/useGetAllPaymentMethods/index.ts +0 -19
- package/src/hooks/usePaymentMethod/useGetPaymentMethod/index.ts +0 -26
- package/src/hooks/usePortFetcher/index.ts +0 -33
- package/src/hooks/usePrintSaleTicket/index.ts +0 -68
- package/src/hooks/useProductsFood/index.ts +0 -341
- package/src/hooks/useProductsFood/queriesStore.ts +0 -964
- package/src/hooks/useProductsFood/types/index.ts +0 -0
- package/src/hooks/useProductsFood/useEditProduct.ts +0 -49
- package/src/hooks/useProductsFood/usetagsProducts.ts +0 -101
- package/src/hooks/useProviders/index.ts +0 -3
- package/src/hooks/useProviders/queries.ts +0 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.ts +0 -13
- package/src/hooks/useProviders/useProvidersDataStore/index.ts +0 -25
- package/src/hooks/useProvidersStore/index.ts +0 -25
- package/src/hooks/useProvidersStore/queries.ts +0 -31
- package/src/hooks/usePushNotificationOrder/index.ts +0 -52
- package/src/hooks/usePushNotifications/helpers/index.ts +0 -123
- package/src/hooks/usePushNotifications/index.ts +0 -150
- package/src/hooks/useQueryLocationsMap/index.ts +0 -20
- package/src/hooks/useQueryLocationsMap/queries.ts +0 -40
- package/src/hooks/useRatingArrayData/index.ts +0 -54
- package/src/hooks/useRatingArrayData/queries.ts +0 -19
- package/src/hooks/useReactToPrint/index.ts +0 -4
- package/src/hooks/useReactToPrint/index.txt +0 -1223
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.ts +0 -24
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.ts +0 -48
- package/src/hooks/useReport/index.ts +0 -48
- package/src/hooks/useReport/queries.ts +0 -72
- package/src/hooks/useRestaurant/helpers/index.ts +0 -28
- package/src/hooks/useRestaurant/helpers/manageStatusOpen.ts +0 -26
- package/src/hooks/useRestaurant/index.ts +0 -71
- package/src/hooks/useRestaurant/queries.ts +0 -81
- package/src/hooks/useRoads/index.ts +0 -20
- package/src/hooks/useRoads/queries.ts +0 -13
- package/src/hooks/useRoles/index.ts +0 -4
- package/src/hooks/useRoles/queries.ts +0 -70
- package/src/hooks/useRoles/useCreateRole.ts +0 -40
- package/src/hooks/useRoles/useGetRoles.ts +0 -37
- package/src/hooks/useRoles/useRemoveRoles.ts +0 -40
- package/src/hooks/useRoles/useUpdateRolesPriority.ts +0 -44
- package/src/hooks/useSales/helpers/add-product.utils.ts +0 -120
- package/src/hooks/useSales/helpers/apply-discount-to-cart.utils.ts +0 -292
- package/src/hooks/useSales/helpers/comment-product.utils.ts +0 -41
- package/src/hooks/useSales/helpers/constants/index.ts +0 -38
- package/src/hooks/useSales/helpers/extras.utils.ts +0 -42
- package/src/hooks/useSales/helpers/filterProductsByCarProId.utils.ts +0 -17
- package/src/hooks/useSales/helpers/increment-product-quantity.utils.ts +0 -76
- package/src/hooks/useSales/helpers/index.ts +0 -3
- package/src/hooks/useSales/helpers/initializer.utils.ts +0 -22
- package/src/hooks/useSales/helpers/isStockInsufficient.ts +0 -3
- package/src/hooks/useSales/helpers/remove-product.utils.test.ts +0 -49
- package/src/hooks/useSales/helpers/remove-product.utils.ts +0 -34
- package/src/hooks/useSales/helpers/resolveProduct.ts +0 -29
- package/src/hooks/useSales/helpers/useAddToCart.ts +0 -64
- package/src/hooks/useSales/index.ts +0 -1418
- package/src/hooks/useSales/queries.ts +0 -532
- package/src/hooks/useSales/types/index.ts +0 -206
- package/src/hooks/useSales/types/use-sales.types.ts +0 -8
- package/src/hooks/useSales/useGetSale.ts +0 -21
- package/src/hooks/useSales/useTotalSales.ts +0 -24
- package/src/hooks/useSaveAvailableProduct/helpers/index.ts +0 -38
- package/src/hooks/useSaveAvailableProduct/index.ts +0 -32
- package/src/hooks/useSaveAvailableProduct/queries.ts +0 -10
- package/src/hooks/useSaveLocation/index.ts +0 -17
- package/src/hooks/useSaveLocation/queries.ts +0 -19
- package/src/hooks/useSchedule/index.ts +0 -35
- package/src/hooks/useSchedule/queries.ts +0 -43
- package/src/hooks/useSchedule/schedule.ts +0 -79
- package/src/hooks/useScheduleData/index.ts +0 -135
- package/src/hooks/useScroll/index.ts +0 -56
- package/src/hooks/useScrollRotate/index.ts +0 -16
- package/src/hooks/useSetImageProducts/index.ts +0 -59
- package/src/hooks/useSetImageProducts/queries.ts +0 -18
- package/src/hooks/useSetSession/index.ts +0 -44
- package/src/hooks/useSetState/index.ts +0 -24
- package/src/hooks/useSetupSchedule/helpers/index.ts +0 -85
- package/src/hooks/useSetupSchedule/index.ts +0 -284
- package/src/hooks/useStatusOpenStore/helpers/index.ts +0 -124
- package/src/hooks/useStatusOpenStore/index.ts +0 -195
- package/src/hooks/useStatusOrdersClient/helpers/index.ts +0 -14
- package/src/hooks/useStatusOrdersClient/index.ts +0 -18
- package/src/hooks/useStatusOrdersClient/queries.ts +0 -80
- package/src/hooks/useStock/index.ts +0 -1
- package/src/hooks/useStock/useStockUpdatedAllSubscription.ts +0 -40
- package/src/hooks/useStockMovements/helpers/index.ts +0 -16
- package/src/hooks/useStockMovements/index.ts +0 -39
- package/src/hooks/useStore/index.ts +0 -83
- package/src/hooks/useStore/queries.ts +0 -163
- package/src/hooks/useStoreCalendar/index.ts +0 -5
- package/src/hooks/useStoreContacts/index.ts +0 -53
- package/src/hooks/useStoreContacts/queries.ts +0 -48
- package/src/hooks/useStoreTable/index.ts +0 -2
- package/src/hooks/useStoreTable/queries.ts +0 -47
- package/src/hooks/useStoreTable/useStoreTableCreate.ts +0 -77
- package/src/hooks/useStoreTable/useStoreTables.ts +0 -15
- package/src/hooks/useSubscriptionValidation/index.ts +0 -112
- 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 -157
- package/src/hooks/useTheme/index.ts +0 -65
- package/src/hooks/useTimeAgo/useTimeAgo.ts +0 -39
- package/src/hooks/useTokenCards/index.ts +0 -45
- package/src/hooks/useTopProductsMovements/index.ts +0 -27
- package/src/hooks/useTotalAllSales/index.ts +0 -25
- package/src/hooks/useTotalProductsInStock/index.ts +0 -23
- package/src/hooks/useTotalProductsSold/index.ts +0 -23
- package/src/hooks/useTotalProductsSolded/index.ts +0 -20
- package/src/hooks/useUpdateCart/index.ts +0 -131
- package/src/hooks/useUpdateCartCookie/index.ts +0 -60
- package/src/hooks/useUpdateDashboardComponent/index.ts +0 -91
- package/src/hooks/useUpdateExistingOrders/index.ts +0 -85
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.ts +0 -61
- package/src/hooks/useUpdateModuleOrder/index.ts +0 -37
- package/src/hooks/useUpdateMultipleExtProduct/index.ts +0 -34
- package/src/hooks/useUpdateMultipleExtProduct/queries.ts +0 -33
- package/src/hooks/useUpdateMultipleProducts/index.ts +0 -117
- package/src/hooks/useUpdateMultipleProducts/queries.ts +0 -51
- package/src/hooks/useUploadProducts/helpers/index.ts +0 -1
- package/src/hooks/useUploadProducts/helpers/parseNumber.ts +0 -37
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.ts +0 -73
- package/src/hooks/useUploadProducts/index.ts +0 -442
- package/src/hooks/useUpsertGoal/index.ts +0 -68
- package/src/hooks/useUser/index.ts +0 -24
- package/src/hooks/useUser/queries.ts +0 -131
- package/src/hooks/useWeeklyStockMovement/helpers/index.ts +0 -32
- package/src/hooks/useWeeklyStockMovement/index.ts +0 -52
- package/src/hooks/useWindowSize/index.ts +0 -45
- package/src/index.ts +0 -11
- package/src/mock/dessert/index.ts +0 -16
- package/src/mock/index.ts +0 -1
- package/src/security/index.ts +0 -1
- package/src/services/index.ts +0 -1
- package/src/utils/UtilDateRange.ts +0 -56
- package/src/utils/generateCode.ts +0 -222
- package/src/utils/index.ts +0 -2
- package/src/utils/utils.ts +0 -344
- package/tsconfig.eslint.json +0 -16
- package/tsconfig.json +0 -21
- package/tsup.config.ts +0 -24
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
import { gql, useQuery } from '@apollo/client'
|
|
2
|
-
import { useEffect, useState } from 'react'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* GraphQL query to validate free subscription
|
|
6
|
-
*/
|
|
7
|
-
const VALIDATE_SUBSCRIPTION_QUERY = gql`
|
|
8
|
-
query validateFreeSubscription($idStore: ID) {
|
|
9
|
-
validateFreeSubscription(idStore: $idStore) {
|
|
10
|
-
subscriptionId
|
|
11
|
-
status
|
|
12
|
-
businessName
|
|
13
|
-
currentPeriodEnd
|
|
14
|
-
currentPeriodStart
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
`
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Subscription entity returned by the API
|
|
21
|
-
*/
|
|
22
|
-
export interface SubscriptionData {
|
|
23
|
-
subscriptionId: string
|
|
24
|
-
status: string
|
|
25
|
-
businessName: string
|
|
26
|
-
currentPeriodEnd: string
|
|
27
|
-
currentPeriodStart: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* GraphQL query response shape
|
|
32
|
-
*/
|
|
33
|
-
interface ValidateSubscriptionResponse {
|
|
34
|
-
validateFreeSubscription: SubscriptionData
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Hook return type
|
|
39
|
-
*/
|
|
40
|
-
export interface UseSubscriptionValidationResult {
|
|
41
|
-
loading: boolean
|
|
42
|
-
error?: Error
|
|
43
|
-
subscriptionData?: SubscriptionData
|
|
44
|
-
daysRemaining: number | null
|
|
45
|
-
daysElapsed: number | null
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Hook to validate store subscription and calculate elapsed/remaining days.
|
|
50
|
-
* Keeps original behavior and calculations intact.
|
|
51
|
-
*
|
|
52
|
-
* @param {string} idStore - Store identifier
|
|
53
|
-
* @returns {UseSubscriptionValidationResult}
|
|
54
|
-
*/
|
|
55
|
-
export const useSubscriptionValidation = (
|
|
56
|
-
idStore: string
|
|
57
|
-
): UseSubscriptionValidationResult => {
|
|
58
|
-
const { loading, error, data } = useQuery<ValidateSubscriptionResponse>(
|
|
59
|
-
VALIDATE_SUBSCRIPTION_QUERY,
|
|
60
|
-
{
|
|
61
|
-
variables: { idStore }
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
const [daysRemaining, setDaysRemaining] = useState<number | null>(null)
|
|
66
|
-
const [daysElapsed, setDaysElapsed] = useState<number | null>(null)
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
if (data?.validateFreeSubscription) {
|
|
70
|
-
const { currentPeriodEnd, currentPeriodStart } =
|
|
71
|
-
data.validateFreeSubscription
|
|
72
|
-
|
|
73
|
-
const currentDate = new Date()
|
|
74
|
-
const endOfPeriod = new Date(parseInt(currentPeriodEnd, 10))
|
|
75
|
-
const startOfPeriod = new Date(parseInt(currentPeriodStart, 10))
|
|
76
|
-
|
|
77
|
-
const differenceInTimeUntilEnd =
|
|
78
|
-
endOfPeriod.getTime() - currentDate.getTime()
|
|
79
|
-
|
|
80
|
-
const differenceInDaysUntilEnd = Math.ceil(
|
|
81
|
-
differenceInTimeUntilEnd / (1000 * 3600 * 24)
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
setDaysRemaining(
|
|
85
|
-
isNaN(differenceInDaysUntilEnd)
|
|
86
|
-
? 0
|
|
87
|
-
: differenceInDaysUntilEnd
|
|
88
|
-
)
|
|
89
|
-
|
|
90
|
-
const differenceInTimeSinceStart =
|
|
91
|
-
currentDate.getTime() - startOfPeriod.getTime()
|
|
92
|
-
|
|
93
|
-
const differenceInDaysSinceStart = Math.ceil(
|
|
94
|
-
differenceInTimeSinceStart / (1000 * 3600 * 24)
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
setDaysElapsed(
|
|
98
|
-
isNaN(differenceInDaysSinceStart)
|
|
99
|
-
? 0
|
|
100
|
-
: differenceInDaysSinceStart
|
|
101
|
-
)
|
|
102
|
-
}
|
|
103
|
-
}, [data])
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
loading,
|
|
107
|
-
error: error ?? undefined,
|
|
108
|
-
subscriptionData: data?.validateFreeSubscription,
|
|
109
|
-
daysRemaining,
|
|
110
|
-
daysElapsed
|
|
111
|
-
}
|
|
112
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { gql, useMutation } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GraphQL mutation to delete a tag by ID or name.
|
|
5
|
-
*/
|
|
6
|
-
const DELETE_ONE_TAG = gql`
|
|
7
|
-
mutation deleteOneTag($tgId: ID, $nameTag: String) {
|
|
8
|
-
deleteOneTag(tgId: $tgId, nameTag: $nameTag) {
|
|
9
|
-
success
|
|
10
|
-
message
|
|
11
|
-
data {
|
|
12
|
-
tgId
|
|
13
|
-
nameTag
|
|
14
|
-
state
|
|
15
|
-
}
|
|
16
|
-
errors {
|
|
17
|
-
path
|
|
18
|
-
message
|
|
19
|
-
type
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
`
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Custom hook to delete a tag by ID or name.
|
|
27
|
-
* @returns {Object} An object with the deleteTag function and mutation state.
|
|
28
|
-
*/
|
|
29
|
-
export const useDeleteOneTag = () => {
|
|
30
|
-
const [deleteOneTag, { data, loading, error }] = useMutation(DELETE_ONE_TAG, {
|
|
31
|
-
update(cache, { data }) {
|
|
32
|
-
const deleted = data?.deleteOneTag?.data
|
|
33
|
-
const success = data?.deleteOneTag?.success
|
|
34
|
-
|
|
35
|
-
if (!success || !deleted?.tgId) return
|
|
36
|
-
|
|
37
|
-
// Update cache for getAllTags
|
|
38
|
-
cache.modify({
|
|
39
|
-
fields: {
|
|
40
|
-
getAllTags(existing = {}) {
|
|
41
|
-
const filteredData = existing?.data?.filter(
|
|
42
|
-
(tag: any) => {return tag.tgId !== deleted.tgId}
|
|
43
|
-
) || []
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
...existing,
|
|
47
|
-
data: filteredData,
|
|
48
|
-
pagination: {
|
|
49
|
-
...existing.pagination,
|
|
50
|
-
totalRecords: Math.max((existing.pagination?.totalRecords || 1) - 1, 0)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
},
|
|
57
|
-
// optional, remove if you prefer default behavior
|
|
58
|
-
onError(err) {
|
|
59
|
-
console.error('❌ Apollo error in deleteOneTag:', err)
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
/**
|
|
63
|
-
* Deletes a tag by ID or name.
|
|
64
|
-
* @param {Object} variables - Mutation input.
|
|
65
|
-
* @param {string} [variables.tgId] - Tag ID (optional).
|
|
66
|
-
* @param {string} [variables.nameTag] - Tag name (optional).
|
|
67
|
-
* @returns {Promise<Object>} Response from server.
|
|
68
|
-
*/
|
|
69
|
-
const handleDeleteTag = async ({
|
|
70
|
-
tgId,
|
|
71
|
-
nameTag
|
|
72
|
-
}: {
|
|
73
|
-
tgId?: string
|
|
74
|
-
nameTag?: string
|
|
75
|
-
}) => {
|
|
76
|
-
try {
|
|
77
|
-
const { data } = await deleteOneTag({
|
|
78
|
-
variables: {
|
|
79
|
-
tgId,
|
|
80
|
-
nameTag
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
return data.deleteOneTag
|
|
85
|
-
} catch (err: any) {
|
|
86
|
-
return {
|
|
87
|
-
success: false,
|
|
88
|
-
message: 'An error occurred while deleting the tag.',
|
|
89
|
-
data: null,
|
|
90
|
-
errors: [
|
|
91
|
-
{
|
|
92
|
-
path: 'mutation',
|
|
93
|
-
message: err.message || 'Unknown error',
|
|
94
|
-
type: 'server'
|
|
95
|
-
}
|
|
96
|
-
]
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return [handleDeleteTag, {
|
|
102
|
-
data,
|
|
103
|
-
loading,
|
|
104
|
-
error
|
|
105
|
-
}]
|
|
106
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { useQuery, gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GraphQL query to fetch all tags
|
|
5
|
-
*/
|
|
6
|
-
export const GET_ALL_TAGS = gql`
|
|
7
|
-
query getAllTags {
|
|
8
|
-
getAllTags {
|
|
9
|
-
success
|
|
10
|
-
message
|
|
11
|
-
pagination {
|
|
12
|
-
totalRecords
|
|
13
|
-
totalPages
|
|
14
|
-
currentPage
|
|
15
|
-
}
|
|
16
|
-
data {
|
|
17
|
-
tgId
|
|
18
|
-
idUser
|
|
19
|
-
idStore
|
|
20
|
-
pId
|
|
21
|
-
nameTag
|
|
22
|
-
aName
|
|
23
|
-
}
|
|
24
|
-
errors {
|
|
25
|
-
path
|
|
26
|
-
message
|
|
27
|
-
type
|
|
28
|
-
context {
|
|
29
|
-
limit
|
|
30
|
-
value
|
|
31
|
-
label
|
|
32
|
-
key
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Custom hook to fetch all tags
|
|
41
|
-
*
|
|
42
|
-
* @returns {{
|
|
43
|
-
* tags: any[],
|
|
44
|
-
* loading: boolean,
|
|
45
|
-
* error: Error | null,
|
|
46
|
-
* message: string,
|
|
47
|
-
* success: boolean,
|
|
48
|
-
* pagination: { totalRecords: number, totalPages: number, currentPage: number } | null,
|
|
49
|
-
* errors: any[] | null
|
|
50
|
-
* }}
|
|
51
|
-
*/
|
|
52
|
-
export const useGetAllTags = () => {
|
|
53
|
-
const { data, loading, error } = useQuery(GET_ALL_TAGS, {
|
|
54
|
-
fetchPolicy: 'network-only'
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
const result = data?.getAllTags ?? {}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
tags: result?.data || [],
|
|
61
|
-
loading,
|
|
62
|
-
error,
|
|
63
|
-
message: result?.message ?? '',
|
|
64
|
-
success: result?.success ?? false,
|
|
65
|
-
pagination: result?.pagination ?? null,
|
|
66
|
-
errors: result?.errors ?? null
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { useMutation, gql, useApolloClient } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
import { GET_ALL_TAGS } from './useGetAllTags'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* GraphQL mutation to register multiple tags.
|
|
7
|
-
*/
|
|
8
|
-
const REGISTER_MULTIPLE_TAGS = gql`
|
|
9
|
-
mutation registerMultipleTags($input: [String!]!) {
|
|
10
|
-
registerMultipleTags(input: $input) {
|
|
11
|
-
success
|
|
12
|
-
message
|
|
13
|
-
errors {
|
|
14
|
-
path
|
|
15
|
-
message
|
|
16
|
-
}
|
|
17
|
-
data {
|
|
18
|
-
tgId
|
|
19
|
-
nameTag
|
|
20
|
-
idStore
|
|
21
|
-
idUser
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
`
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Response structure for tag registration errors.
|
|
29
|
-
*/
|
|
30
|
-
interface ITagError {
|
|
31
|
-
path: string
|
|
32
|
-
message: string
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Structure for a registered tag.
|
|
37
|
-
*/
|
|
38
|
-
interface ITag {
|
|
39
|
-
tgId: string
|
|
40
|
-
nameTag: string
|
|
41
|
-
idStore: string
|
|
42
|
-
idUser: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* General GraphQL response for registering tags.
|
|
47
|
-
*/
|
|
48
|
-
interface IResponseTag {
|
|
49
|
-
success: boolean
|
|
50
|
-
message: string
|
|
51
|
-
errors: ITagError[]
|
|
52
|
-
data: ITag[]
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Options for the useRegisterMultipleTags hook.
|
|
57
|
-
*/
|
|
58
|
-
interface UseRegisterMultipleTagsOptions {
|
|
59
|
-
callback?: (response: IResponseTag) => void
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Return type for the useRegisterMultipleTags hook.
|
|
64
|
-
*/
|
|
65
|
-
type UseRegisterMultipleTagsReturn = [
|
|
66
|
-
(tags: string[]) => Promise<IResponseTag>,
|
|
67
|
-
{
|
|
68
|
-
loading: boolean
|
|
69
|
-
error: any
|
|
70
|
-
data: IResponseTag | null
|
|
71
|
-
}
|
|
72
|
-
]
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* Hook to register multiple tags via GraphQL mutation.
|
|
76
|
-
*
|
|
77
|
-
* @param {UseRegisterMultipleTagsOptions} [options] - Optional callback for post-mutation handling.
|
|
78
|
-
* @returns {UseRegisterMultipleTagsReturn} - Mutation handler and state.
|
|
79
|
-
*/
|
|
80
|
-
export const useRegisterMultipleTags = (
|
|
81
|
-
{ callback = () => { } }: UseRegisterMultipleTagsOptions = {}
|
|
82
|
-
): UseRegisterMultipleTagsReturn => {
|
|
83
|
-
const client = useApolloClient()
|
|
84
|
-
const [registerMultipleTags, { loading, error, data }] = useMutation<
|
|
85
|
-
{ registerMultipleTags: IResponseTag },
|
|
86
|
-
{ input: string[] }
|
|
87
|
-
>(REGISTER_MULTIPLE_TAGS, {
|
|
88
|
-
onCompleted: (data) => {
|
|
89
|
-
if (typeof callback === 'function') {
|
|
90
|
-
callback(data.registerMultipleTags)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Register multiple tags with the provided names.
|
|
97
|
-
*
|
|
98
|
-
* @param {string[]} tags - Array of tag names.
|
|
99
|
-
* @returns {Promise<IResponseTag>} - Mutation response.
|
|
100
|
-
*/
|
|
101
|
-
const handleRegisterTags = async (tags: string[]): Promise<IResponseTag> => {
|
|
102
|
-
if (!Array.isArray(tags) || tags.length === 0 || tags.some(tag => {return typeof tag !== 'string'})) {
|
|
103
|
-
throw new Error('Tag list must be a non-empty array of strings.')
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const response = await registerMultipleTags({
|
|
107
|
-
variables: {
|
|
108
|
-
input: tags
|
|
109
|
-
},
|
|
110
|
-
update: (cache, { data }) => {
|
|
111
|
-
if (!data?.registerMultipleTags?.data?.length) return
|
|
112
|
-
|
|
113
|
-
const newTags = data.registerMultipleTags.data
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
const existing = client.readQuery({ query: GET_ALL_TAGS })
|
|
117
|
-
|
|
118
|
-
const updatedTags = [
|
|
119
|
-
...newTags,
|
|
120
|
-
...(existing?.getAllTags?.data || [])
|
|
121
|
-
]
|
|
122
|
-
|
|
123
|
-
cache.writeQuery({
|
|
124
|
-
query: GET_ALL_TAGS,
|
|
125
|
-
data: {
|
|
126
|
-
getAllTags: {
|
|
127
|
-
...existing.getAllTags,
|
|
128
|
-
data: updatedTags,
|
|
129
|
-
pagination: {
|
|
130
|
-
...existing.getAllTags.pagination,
|
|
131
|
-
totalRecords: updatedTags.length
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
})
|
|
136
|
-
} catch (error) {
|
|
137
|
-
console.warn('Failed to update cache for GET_ALL_TAGS:', error)
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
return response.data?.registerMultipleTags ?? {
|
|
142
|
-
success: false,
|
|
143
|
-
message: 'No response from server',
|
|
144
|
-
errors: [],
|
|
145
|
-
data: []
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return [
|
|
150
|
-
handleRegisterTags,
|
|
151
|
-
{
|
|
152
|
-
loading,
|
|
153
|
-
error,
|
|
154
|
-
data: data?.registerMultipleTags ?? null
|
|
155
|
-
}
|
|
156
|
-
]
|
|
157
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { Cookies } from '../../cookies'
|
|
4
|
-
|
|
5
|
-
enum Theme {
|
|
6
|
-
LIGHT = 'light',
|
|
7
|
-
DARK = 'dark',
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Handles light/dark theme switching using data-theme attribute.
|
|
12
|
-
* Cookie is used only for persistence, not as source of truth.
|
|
13
|
-
*/
|
|
14
|
-
export const useTheme = () => {
|
|
15
|
-
|
|
16
|
-
// STATES
|
|
17
|
-
const [theme, setTheme] = useState<Theme>(Theme.LIGHT)
|
|
18
|
-
/**
|
|
19
|
-
* Applies theme to DOM and persists it.
|
|
20
|
-
* @param theme
|
|
21
|
-
*/
|
|
22
|
-
const applyTheme = (theme: Theme): void => {
|
|
23
|
-
document.documentElement.setAttribute('data-theme', theme)
|
|
24
|
-
Cookies.set('theme', theme, { expires: 365 })
|
|
25
|
-
setTheme(theme)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Toggles between light and dark themes.
|
|
30
|
-
*/
|
|
31
|
-
const toggleTheme = (): void => {
|
|
32
|
-
if (typeof document === 'undefined') return
|
|
33
|
-
|
|
34
|
-
const current =
|
|
35
|
-
(document.documentElement.getAttribute('data-theme') as Theme) ??
|
|
36
|
-
Theme.LIGHT
|
|
37
|
-
|
|
38
|
-
applyTheme(current === Theme.DARK ? Theme.LIGHT : Theme.DARK)
|
|
39
|
-
setTheme(current === Theme.DARK ? Theme.LIGHT : Theme.DARK)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Initializes theme from cookie or system preference.
|
|
44
|
-
*/
|
|
45
|
-
const initTheme = (): void => {
|
|
46
|
-
if (typeof document === 'undefined') return
|
|
47
|
-
|
|
48
|
-
const cookieTheme = Cookies.get('theme') as Theme | undefined
|
|
49
|
-
|
|
50
|
-
const systemTheme =
|
|
51
|
-
window.matchMedia?.('(prefers-color-scheme: dark)').matches
|
|
52
|
-
? Theme.DARK
|
|
53
|
-
: Theme.LIGHT
|
|
54
|
-
|
|
55
|
-
applyTheme(cookieTheme ?? systemTheme)
|
|
56
|
-
setTheme(cookieTheme ?? systemTheme)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
setTheme: applyTheme,
|
|
61
|
-
toggleTheme,
|
|
62
|
-
initTheme,
|
|
63
|
-
theme
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
const DATE_UNITS: [unit: Intl.RelativeTimeFormatUnit, secondsInUnit: number][] = [
|
|
4
|
-
['day', 86400],
|
|
5
|
-
['hour', 3600],
|
|
6
|
-
['minute', 60],
|
|
7
|
-
['second', 1]
|
|
8
|
-
]
|
|
9
|
-
|
|
10
|
-
type DateDiff = { value: number; unit: Intl.RelativeTimeFormatUnit }
|
|
11
|
-
|
|
12
|
-
const getDateDiffs = (timestamp: number): DateDiff | undefined => {
|
|
13
|
-
const now = Date.now()
|
|
14
|
-
const elapsed = (timestamp - now) / 1000
|
|
15
|
-
|
|
16
|
-
for (const [unit, secondsInUnit] of DATE_UNITS) {
|
|
17
|
-
if (Math.abs(elapsed) > secondsInUnit || unit === 'second') {
|
|
18
|
-
const value = Math.round(elapsed / secondsInUnit)
|
|
19
|
-
return { value, unit }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export const useTimeAgo = (timestamp: number) => {
|
|
25
|
-
const [timeAgo, setTimeAgo] = useState<DateDiff | undefined>(() => getDateDiffs(timestamp))
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
const interval = setInterval(() => {
|
|
29
|
-
const newTimeAgo = getDateDiffs(timestamp)
|
|
30
|
-
setTimeAgo(newTimeAgo)
|
|
31
|
-
}, 5000)
|
|
32
|
-
|
|
33
|
-
return () => { return clearInterval(interval) }
|
|
34
|
-
}, [timestamp])
|
|
35
|
-
|
|
36
|
-
const rtf = new Intl.RelativeTimeFormat('es', { style: 'short' })
|
|
37
|
-
|
|
38
|
-
return rtf?.format(timeAgo?.value ?? 0, (timeAgo?.unit ?? 'second'))
|
|
39
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
|
|
3
|
-
export const useTokenCards = () => {
|
|
4
|
-
const [loading, setLoading] = useState(false)
|
|
5
|
-
const [error, setError] = useState<string | null>(null)
|
|
6
|
-
const [responseData, setResponseData] = useState(null)
|
|
7
|
-
|
|
8
|
-
const handleTokenCardsSubmit = async (postData: any) => {
|
|
9
|
-
setLoading(true)
|
|
10
|
-
setError(null)
|
|
11
|
-
try {
|
|
12
|
-
const headers = {
|
|
13
|
-
'Content-Type': 'application/json'
|
|
14
|
-
}
|
|
15
|
-
const url = 'http://localhost:3000/api/v1/wompi/transaction/tokens/cards'
|
|
16
|
-
|
|
17
|
-
const response = await fetch(url, {
|
|
18
|
-
method: 'POST',
|
|
19
|
-
headers,
|
|
20
|
-
body: JSON.stringify(postData)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const responseData = await response.json()
|
|
24
|
-
|
|
25
|
-
if (!response.ok) {
|
|
26
|
-
throw new Error(responseData.message || 'Something went wrong')
|
|
27
|
-
}
|
|
28
|
-
setResponseData(responseData)
|
|
29
|
-
return responseData
|
|
30
|
-
} catch (error) {
|
|
31
|
-
if (error instanceof Error) {
|
|
32
|
-
setError(String(error.message))
|
|
33
|
-
} else {
|
|
34
|
-
setError(String(error))
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
} finally {
|
|
40
|
-
setLoading(false)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { loading, error, responseData, handleTokenCardsSubmit }
|
|
45
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { useQuery, gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GraphQL query to fetch top-selling products movements
|
|
5
|
-
*/
|
|
6
|
-
const GET_TOP_PRODUCTS_MOVEMENTS = gql`
|
|
7
|
-
query {
|
|
8
|
-
getTopProductsMovements {
|
|
9
|
-
productName
|
|
10
|
-
idProduct
|
|
11
|
-
totalMovements
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
`
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Custom hook to fetch and return the top-selling products movements
|
|
18
|
-
* @returns {Object} - { data, loading, error }
|
|
19
|
-
*/
|
|
20
|
-
export const useTopProductsMovements = () => {
|
|
21
|
-
const { data, loading, error } = useQuery(GET_TOP_PRODUCTS_MOVEMENTS)
|
|
22
|
-
|
|
23
|
-
return [data?.getTopProductsMovements, {
|
|
24
|
-
loading,
|
|
25
|
-
error
|
|
26
|
-
}]
|
|
27
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { useQuery, gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
const GET_TOTAL_SALES = gql`
|
|
4
|
-
query totalSales {
|
|
5
|
-
totalSales {
|
|
6
|
-
success
|
|
7
|
-
message
|
|
8
|
-
totalSales
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
`
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Custom hook to fetch total sales from GraphQL API.
|
|
15
|
-
* @returns {Object} An object containing total sales, loading state, error, and refetch function.
|
|
16
|
-
*/
|
|
17
|
-
export const useTotalAllSales = () => {
|
|
18
|
-
const { data, loading, error, refetch } = useQuery(GET_TOTAL_SALES)
|
|
19
|
-
|
|
20
|
-
return [data?.totalSales?.totalSales, {
|
|
21
|
-
loading,
|
|
22
|
-
error,
|
|
23
|
-
refetch
|
|
24
|
-
}]
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useQuery, gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GraphQL query to fetch total products in stock.
|
|
5
|
-
*/
|
|
6
|
-
const GET_TOTAL_PRODUCTS_IN_STOCK = gql`
|
|
7
|
-
query getTotalProductsInStock {
|
|
8
|
-
getTotalProductsInStock
|
|
9
|
-
}
|
|
10
|
-
`
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Custom hook to fetch total products in stock.
|
|
14
|
-
* @returns {Object} - { totalProductsInStock, loading, error }
|
|
15
|
-
*/
|
|
16
|
-
export const useTotalProductsInStock = () => {
|
|
17
|
-
const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_IN_STOCK)
|
|
18
|
-
|
|
19
|
-
return [data?.getTotalProductsInStock ?? 0, {
|
|
20
|
-
loading,
|
|
21
|
-
error
|
|
22
|
-
}]
|
|
23
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useQuery, gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GraphQL query to fetch total products sold.
|
|
5
|
-
*/
|
|
6
|
-
const GET_TOTAL_PRODUCTS_SOLD = gql`
|
|
7
|
-
query getTotalSalesSold {
|
|
8
|
-
getTotalSalesSold
|
|
9
|
-
}
|
|
10
|
-
`
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Custom hook to fetch total products sold.
|
|
14
|
-
* @returns {Object} - { totalProductsSold, loading, error }
|
|
15
|
-
*/
|
|
16
|
-
export const useTotalProductsSold = () => {
|
|
17
|
-
const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
|
|
18
|
-
|
|
19
|
-
return [data?.getTotalSalesSold || 0, {
|
|
20
|
-
loading,
|
|
21
|
-
error
|
|
22
|
-
}]
|
|
23
|
-
}
|