npm-pkg-hook 1.12.4 → 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 -147
- 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/usePrintSaleTicket/index.ts +0 -64
- 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,19 +0,0 @@
|
|
|
1
|
-
import { useQuery } from '@apollo/client'
|
|
2
|
-
import { GET_ONE_BANNER_STORE } from '../useProductsFood/queriesStore'
|
|
3
|
-
import { useStore } from '../useStore'
|
|
4
|
-
|
|
5
|
-
export const useBanner = () => {
|
|
6
|
-
const [store, { loading: loaStore }] = useStore()
|
|
7
|
-
|
|
8
|
-
const {
|
|
9
|
-
data,
|
|
10
|
-
loading,
|
|
11
|
-
error
|
|
12
|
-
} = useQuery(GET_ONE_BANNER_STORE, {
|
|
13
|
-
context: { clientName: 'admin-server' },
|
|
14
|
-
variables: {
|
|
15
|
-
idStore: !loaStore && store?.idStore
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
return [data?.getOneBanners, { loading, error }]
|
|
19
|
-
}
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
import { gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
export const CREATE_SHOPPING_CARD = gql`
|
|
4
|
-
mutation registerShoppingCard(
|
|
5
|
-
$input: IShoppingCard
|
|
6
|
-
$idSubArray: IID_SUB_ITEMS
|
|
7
|
-
) {
|
|
8
|
-
registerShoppingCard(input: $input, idSubArray: $idSubArray) {
|
|
9
|
-
ShoppingCard
|
|
10
|
-
id
|
|
11
|
-
pId
|
|
12
|
-
subProductsId
|
|
13
|
-
ShoppingCardRefCode
|
|
14
|
-
uuid
|
|
15
|
-
discountCardProduct
|
|
16
|
-
idUser
|
|
17
|
-
cName
|
|
18
|
-
idStore
|
|
19
|
-
cState
|
|
20
|
-
cDatCre
|
|
21
|
-
cDatMod
|
|
22
|
-
csDescription
|
|
23
|
-
cantProducts
|
|
24
|
-
comments
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
`
|
|
28
|
-
|
|
29
|
-
export const GET_ALL_SHOPPING_CARD = gql`
|
|
30
|
-
query getAllShoppingCard {
|
|
31
|
-
getAllShoppingCard {
|
|
32
|
-
ShoppingCard
|
|
33
|
-
cState
|
|
34
|
-
idStore
|
|
35
|
-
refCodePid
|
|
36
|
-
pId
|
|
37
|
-
comments
|
|
38
|
-
salesExtProductFoodOptional {
|
|
39
|
-
pId
|
|
40
|
-
opExPid
|
|
41
|
-
OptionalProName
|
|
42
|
-
state
|
|
43
|
-
code
|
|
44
|
-
required
|
|
45
|
-
numbersOptionalOnly
|
|
46
|
-
pDatCre
|
|
47
|
-
pDatMod
|
|
48
|
-
saleExtProductFoodsSubOptionalAll {
|
|
49
|
-
pId
|
|
50
|
-
opExPid
|
|
51
|
-
idStore
|
|
52
|
-
opSubExPid
|
|
53
|
-
OptionalSubProName
|
|
54
|
-
exCodeOptionExtra
|
|
55
|
-
exCode
|
|
56
|
-
state
|
|
57
|
-
pDatCre
|
|
58
|
-
pDatMod
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
ExtProductFoodsAll {
|
|
62
|
-
pId
|
|
63
|
-
exPid
|
|
64
|
-
exState
|
|
65
|
-
extraName
|
|
66
|
-
extraPrice
|
|
67
|
-
quantity
|
|
68
|
-
newExtraPrice
|
|
69
|
-
state
|
|
70
|
-
pDatCre
|
|
71
|
-
pDatMod
|
|
72
|
-
}
|
|
73
|
-
productFood {
|
|
74
|
-
pId
|
|
75
|
-
carProId
|
|
76
|
-
sizeId
|
|
77
|
-
colorId
|
|
78
|
-
idStore
|
|
79
|
-
cId
|
|
80
|
-
caId
|
|
81
|
-
dId
|
|
82
|
-
ctId
|
|
83
|
-
tpId
|
|
84
|
-
fId
|
|
85
|
-
pName
|
|
86
|
-
ProPrice
|
|
87
|
-
ProDescuento
|
|
88
|
-
ProUniDisponibles
|
|
89
|
-
ProDescription
|
|
90
|
-
ValueDelivery
|
|
91
|
-
ProProtegido
|
|
92
|
-
ProAssurance
|
|
93
|
-
ProImage
|
|
94
|
-
ProStar
|
|
95
|
-
ProWidth
|
|
96
|
-
ProHeight
|
|
97
|
-
ProLength
|
|
98
|
-
ProWeight
|
|
99
|
-
ProQuantity
|
|
100
|
-
ProOutstanding
|
|
101
|
-
ProDelivery
|
|
102
|
-
ProVoltaje
|
|
103
|
-
pState
|
|
104
|
-
sTateLogistic
|
|
105
|
-
pDatCre
|
|
106
|
-
pDatMod
|
|
107
|
-
}
|
|
108
|
-
cantProducts
|
|
109
|
-
getStore {
|
|
110
|
-
idStore
|
|
111
|
-
cId
|
|
112
|
-
scheduleOpenAll
|
|
113
|
-
getStoreSchedules {
|
|
114
|
-
schId
|
|
115
|
-
idStore
|
|
116
|
-
schDay
|
|
117
|
-
schHoSta
|
|
118
|
-
schHoEnd
|
|
119
|
-
schState
|
|
120
|
-
}
|
|
121
|
-
id
|
|
122
|
-
dId
|
|
123
|
-
ctId
|
|
124
|
-
scheduleOpenAll
|
|
125
|
-
catStore
|
|
126
|
-
neighborhoodStore
|
|
127
|
-
Viaprincipal
|
|
128
|
-
storeOwner
|
|
129
|
-
storeName
|
|
130
|
-
emailStore
|
|
131
|
-
storePhone
|
|
132
|
-
socialRaz
|
|
133
|
-
Image
|
|
134
|
-
banner
|
|
135
|
-
documentIdentifier
|
|
136
|
-
uPhoNum
|
|
137
|
-
ULocation
|
|
138
|
-
upLat
|
|
139
|
-
upLon
|
|
140
|
-
uState
|
|
141
|
-
siteWeb
|
|
142
|
-
description
|
|
143
|
-
NitStore
|
|
144
|
-
typeRegiments
|
|
145
|
-
typeContribute
|
|
146
|
-
secVia
|
|
147
|
-
addressStore
|
|
148
|
-
createdAt
|
|
149
|
-
pais {
|
|
150
|
-
cId
|
|
151
|
-
cName
|
|
152
|
-
cCalCod
|
|
153
|
-
cState
|
|
154
|
-
cDatCre
|
|
155
|
-
cDatMod
|
|
156
|
-
}
|
|
157
|
-
city {
|
|
158
|
-
ctId
|
|
159
|
-
dId
|
|
160
|
-
cName
|
|
161
|
-
cState
|
|
162
|
-
}
|
|
163
|
-
department {
|
|
164
|
-
dId
|
|
165
|
-
cId
|
|
166
|
-
dName
|
|
167
|
-
dState
|
|
168
|
-
dDatCre
|
|
169
|
-
dDatMod
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
`
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { filterKeyObject } from '../../../../utils'
|
|
2
|
-
|
|
3
|
-
const filters = ['__typename']
|
|
4
|
-
|
|
5
|
-
export const filterDataOptional = (dataOptional) => {
|
|
6
|
-
if (!Array.isArray(dataOptional)) {
|
|
7
|
-
throw new Error('Input data is not an array')
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
try {
|
|
11
|
-
const filteredDataOptional = dataOptional.map(item => {
|
|
12
|
-
const checkedSubOptions = item?.ExtProductFoodsSubOptionalAll?.filter(subItem => subItem.check === true)
|
|
13
|
-
const ExtProductFoodsSubOptionalAll = checkedSubOptions?.map(subItemsOptional => {
|
|
14
|
-
return {
|
|
15
|
-
...filterKeyObject(subItemsOptional, filters)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
return {
|
|
19
|
-
...filterKeyObject(item, filters),
|
|
20
|
-
ExtProductFoodsSubOptionalAll
|
|
21
|
-
}
|
|
22
|
-
}).filter(item => item?.ExtProductFoodsSubOptionalAll.length > 0)
|
|
23
|
-
return filteredDataOptional
|
|
24
|
-
} catch (error) {
|
|
25
|
-
console.error('An error occurred while filtering data:', error.message)
|
|
26
|
-
return []
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Valida los requerimientos de elementos opcionales.
|
|
32
|
-
* @param {Array} filteredDataOptional - El array de datos a validar.
|
|
33
|
-
* @returns {boolean} Devuelve true si se cumplen los requerimientos, de lo contrario, false.
|
|
34
|
-
*/
|
|
35
|
-
export function validateRequirements (filteredDataOptional) {
|
|
36
|
-
if (Array.isArray(filteredDataOptional)) {
|
|
37
|
-
for (const item of filteredDataOptional) {
|
|
38
|
-
if (item.required === 1) {
|
|
39
|
-
const checkedSubOptions = item?.ExtProductFoodsSubOptionalAll.filter(subItem => subItem.check === true)
|
|
40
|
-
if (checkedSubOptions.length !== item.numbersOptionalOnly) {
|
|
41
|
-
return true
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return false
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function validateExtraProducts (dataExtra) {
|
|
50
|
-
const requiredItems = dataExtra.filter(item => item.exState === 1)
|
|
51
|
-
|
|
52
|
-
if (requiredItems.length > 0) {
|
|
53
|
-
const hasSelectedRequiredProduct = requiredItems.some(item => item.quantity > 0)
|
|
54
|
-
return hasSelectedRequiredProduct
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return true
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export const filterExtra = (dataExtra) => {
|
|
61
|
-
if (!Array.isArray(dataExtra)) {
|
|
62
|
-
throw new Error('Input data is not an array')
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const dataExtraFiltered = dataExtra.filter(extra => extra.quantity !== 0)
|
|
66
|
-
.map(extra => {
|
|
67
|
-
return {
|
|
68
|
-
...filterKeyObject(extra, filters)
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
return dataExtraFiltered
|
|
72
|
-
} catch (error) {
|
|
73
|
-
return []
|
|
74
|
-
}
|
|
75
|
-
}
|
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect } from 'react'
|
|
2
|
-
import { useMutation } from '@apollo/client'
|
|
3
|
-
import { CREATE_SHOPPING_CARD, GET_ALL_SHOPPING_CARD } from '../queries'
|
|
4
|
-
import { RandomCode, updateCacheMod, numberFormat } from '../../../utils'
|
|
5
|
-
import { useExtProductFoodsAll, useGetOneProductsFood } from '../../useProductsFood'
|
|
6
|
-
import { useGetExtProductFoodsSubOptionalAll } from '../../useGetExtProductFoodsSubOptionalAll'
|
|
7
|
-
import { useGetCart } from '../useGetCart'
|
|
8
|
-
import {
|
|
9
|
-
filterDataOptional,
|
|
10
|
-
filterExtra,
|
|
11
|
-
validateExtraProducts,
|
|
12
|
-
validateRequirements
|
|
13
|
-
} from './helpers'
|
|
14
|
-
import { useManageQueryParams } from '../../useManageQueryParams'
|
|
15
|
-
|
|
16
|
-
export const useCart = ({
|
|
17
|
-
location = {
|
|
18
|
-
push: (props, state, { shallow }) => {
|
|
19
|
-
return { ...props, state, shallow }
|
|
20
|
-
},
|
|
21
|
-
query: {
|
|
22
|
-
plato: ''
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
openModalProduct = false,
|
|
26
|
-
handleMenu = (number) => { return number },
|
|
27
|
-
setOpenModalProduct = (boolean) => { return boolean },
|
|
28
|
-
setAlertBox = (args) => { return args }
|
|
29
|
-
} = {}) => {
|
|
30
|
-
// sub products
|
|
31
|
-
const { handleCleanQuery } = useManageQueryParams({
|
|
32
|
-
location
|
|
33
|
-
})
|
|
34
|
-
const [loadingButton, setLoadingButton] = useState(false)
|
|
35
|
-
const [dataOptional, setDataOptional] = useState([])
|
|
36
|
-
const [dataExtra, setDataExtra] = useState([])
|
|
37
|
-
const [quantity, setQuantity] = useState(1)
|
|
38
|
-
const [comments, setComments] = useState('')
|
|
39
|
-
const queryParamProduct = location.query.plato
|
|
40
|
-
const [registerShoppingCard] = useMutation(CREATE_SHOPPING_CARD, {
|
|
41
|
-
onError: (error) => {
|
|
42
|
-
console.error('Error registering shopping card:', error)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
// CUSTOM HOOKS
|
|
46
|
-
const [dataShoppingCard, { loading }] = useGetCart()
|
|
47
|
-
const [handleExtProductFoodsAll] = useExtProductFoodsAll()
|
|
48
|
-
|
|
49
|
-
const [ExtProductFoodsSubOptionalAll] = useGetExtProductFoodsSubOptionalAll()
|
|
50
|
-
const [dataOneProduct, setDataOneProduct] = useState({})
|
|
51
|
-
const [handleGetOneProduct,
|
|
52
|
-
{
|
|
53
|
-
loading: loadingProduct
|
|
54
|
-
}
|
|
55
|
-
] = useGetOneProductsFood({ fetchOnlyProduct: true })
|
|
56
|
-
|
|
57
|
-
const getOneProduct = async food => {
|
|
58
|
-
const { pId } = food || {}
|
|
59
|
-
|
|
60
|
-
if (!pId) return {}
|
|
61
|
-
setOpenModalProduct(true)
|
|
62
|
-
const product = await handleGetOneProduct({ variables: { pId } })
|
|
63
|
-
const productFoodsOne = product?.data?.productFoodsOne || {}
|
|
64
|
-
setDataOneProduct(productFoodsOne)
|
|
65
|
-
|
|
66
|
-
const matchingItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
67
|
-
return item?.productFood && item?.productFood?.pId === pId
|
|
68
|
-
})
|
|
69
|
-
const matchingItemInShoppingCartOptional = matchingItemInShoppingCart?.salesExtProductFoodOptional || []
|
|
70
|
-
if (matchingItemInShoppingCart && queryParamProduct) {
|
|
71
|
-
setDataOneProduct({
|
|
72
|
-
...productFoodsOne,
|
|
73
|
-
intoCart: true
|
|
74
|
-
})
|
|
75
|
-
const comments = matchingItemInShoppingCart?.comments
|
|
76
|
-
if (comments) {
|
|
77
|
-
setComments(comments)
|
|
78
|
-
}
|
|
79
|
-
const quantityProduct = matchingItemInShoppingCart?.cantProducts
|
|
80
|
-
if (quantityProduct) {
|
|
81
|
-
setQuantity(quantityProduct || 1)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
const optionalAll = await ExtProductFoodsSubOptionalAll({
|
|
85
|
-
variables: { pId }
|
|
86
|
-
})
|
|
87
|
-
const optionalFetch = optionalAll?.data?.ExtProductFoodsOptionalAll
|
|
88
|
-
const shoppingCartOptionalAll = matchingItemInShoppingCart?.ExtProductFoodsAll || []
|
|
89
|
-
if (Array.isArray(optionalFetch)) {
|
|
90
|
-
// Filtra y procesa los objetos de optionalFetch
|
|
91
|
-
const filteredDataOptional = optionalFetch
|
|
92
|
-
.map((obj) => {
|
|
93
|
-
const filteredSubOptions = (obj.ExtProductFoodsSubOptionalAll || []).filter(
|
|
94
|
-
(subObj) => subObj.check !== false
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
if (filteredSubOptions.length === 0) {
|
|
98
|
-
return null
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
...obj,
|
|
103
|
-
ExtProductFoodsSubOptionalAll: filteredSubOptions
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
.filter((obj) => obj !== null)
|
|
107
|
-
|
|
108
|
-
if (matchingItemInShoppingCartOptional?.length === 0) {
|
|
109
|
-
setDataOptional(filteredDataOptional || [])
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (matchingItemInShoppingCartOptional?.length) {
|
|
113
|
-
// Actualiza los objetos de filteredDataOptional con información de matchingItemInShoppingCartOptional
|
|
114
|
-
const updateOption = filteredDataOptional?.map((obj) => {
|
|
115
|
-
const matchingArray = matchingItemInShoppingCartOptional?.find(
|
|
116
|
-
(o) => o && o.opExPid === obj.opExPid
|
|
117
|
-
)
|
|
118
|
-
|
|
119
|
-
if (!matchingArray) {
|
|
120
|
-
return obj
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Actualiza las propiedades específicas
|
|
124
|
-
const updatedExtProductFoodsSubOptionalAll = (obj.ExtProductFoodsSubOptionalAll || []).map((subObj) => {
|
|
125
|
-
const newItem = matchingArray.saleExtProductFoodsSubOptionalAll?.find((newItem) => newItem && newItem.opSubExPid === subObj.opSubExPid)
|
|
126
|
-
|
|
127
|
-
if (newItem) {
|
|
128
|
-
return {
|
|
129
|
-
...subObj,
|
|
130
|
-
check: true
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return subObj
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
...obj,
|
|
139
|
-
ExtProductFoodsSubOptionalAll: updatedExtProductFoodsSubOptionalAll
|
|
140
|
-
}
|
|
141
|
-
}).filter((obj) => obj)
|
|
142
|
-
|
|
143
|
-
setDataOptional(updateOption || [])
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (!pId || pId === '') return
|
|
147
|
-
const resultExtra = await handleExtProductFoodsAll(pId)
|
|
148
|
-
const originalArray = resultExtra?.data?.ExtProductFoodsAll
|
|
149
|
-
|
|
150
|
-
if (Array.isArray(originalArray) && originalArray?.length) {
|
|
151
|
-
const fetchedDataExtra = originalArray?.map(extra => {
|
|
152
|
-
const updatedExtra = shoppingCartOptionalAll?.find(updatedItem => updatedItem.exPid === extra.exPid)
|
|
153
|
-
if (updatedExtra) {
|
|
154
|
-
return {
|
|
155
|
-
...extra,
|
|
156
|
-
quantity: updatedExtra?.quantity || 0,
|
|
157
|
-
newExtraPrice: updatedExtra?.newExtraPrice || 0
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
...extra,
|
|
162
|
-
quantity: 0
|
|
163
|
-
}
|
|
164
|
-
})
|
|
165
|
-
|
|
166
|
-
setDataExtra(fetchedDataExtra)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* The function `handleIncrementExtra` updates the quantity and price of a specific extra product in
|
|
172
|
-
* an array based on the provided index and product ID.
|
|
173
|
-
*/
|
|
174
|
-
function handleIncrementExtra ({ extra, index }) {
|
|
175
|
-
// Desestructura las propiedades necesarias de dataOneProduct
|
|
176
|
-
const { pId } = dataOneProduct || {}
|
|
177
|
-
|
|
178
|
-
// Desestructura exPid de extra o establece un valor predeterminado si no existe
|
|
179
|
-
const { exPid = null } = extra
|
|
180
|
-
|
|
181
|
-
if (exPid && pId) {
|
|
182
|
-
const newExtra = dataExtra.map((producto) => {
|
|
183
|
-
if (exPid === producto.exPid) {
|
|
184
|
-
// Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
|
|
185
|
-
const { quantity = 0, extraPrice = 0 } = producto
|
|
186
|
-
|
|
187
|
-
// Calcula la nueva cantidad y el nuevo precio extra
|
|
188
|
-
const newQuantity = quantity + 1
|
|
189
|
-
const newExtraPrice = extraPrice * newQuantity
|
|
190
|
-
|
|
191
|
-
return {
|
|
192
|
-
...producto,
|
|
193
|
-
quantity: newQuantity,
|
|
194
|
-
newExtraPrice
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return producto
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
// Actualiza el estado de dataExtra con el nuevo array
|
|
201
|
-
setDataExtra(newExtra)
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function handleDecrementExtra ({ extra, index }) {
|
|
206
|
-
// Desestructura las propiedades necesarias de dataOneProduct
|
|
207
|
-
const { pId } = dataOneProduct || {}
|
|
208
|
-
|
|
209
|
-
// Desestructura exPid de extra o establece un valor predeterminado si no existe
|
|
210
|
-
const { exPid = null } = extra
|
|
211
|
-
|
|
212
|
-
// Encuentra el índice del objeto extra en dataExtra
|
|
213
|
-
const extraIndex = dataExtra.findIndex((item) => item.exPid === exPid)
|
|
214
|
-
|
|
215
|
-
if (pId && exPid && extraIndex !== -1) {
|
|
216
|
-
const newExtra = dataExtra.map((producto, i) => {
|
|
217
|
-
if (exPid === producto.exPid) {
|
|
218
|
-
// Desestructura la cantidad y el precio extra del producto o establece valores predeterminados
|
|
219
|
-
const { quantity = 0, extraPrice = 0 } = producto
|
|
220
|
-
|
|
221
|
-
// Calcula la nueva cantidad, evitando que sea negativa
|
|
222
|
-
const newQuantity = Math.max(quantity - 1, 0)
|
|
223
|
-
|
|
224
|
-
// Calcula el nuevo precio extra
|
|
225
|
-
const newExtraPrice = newQuantity === 0 ? extraPrice : extraPrice * newQuantity
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
...producto,
|
|
229
|
-
quantity: newQuantity,
|
|
230
|
-
newExtraPrice
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
return producto
|
|
234
|
-
})
|
|
235
|
-
|
|
236
|
-
// Actualiza el estado de dataExtra con el nuevo array
|
|
237
|
-
setDataExtra(newExtra)
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const handleIncrease = () => {
|
|
242
|
-
return setQuantity((prev) => { return prev + 1 })
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const handleDecrease = () => {
|
|
246
|
-
return setQuantity((prev) => { return prev - 1 })
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const handleCountProducts = useCallback((ProPrice, quantity) => {
|
|
250
|
-
if (!ProPrice || !quantity) {
|
|
251
|
-
return 0 // Manejo de valores nulos o no numéricos
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
const price = parseFloat(ProPrice)
|
|
255
|
-
const numericQuantity = parseInt(quantity, 10)
|
|
256
|
-
|
|
257
|
-
if (isNaN(price) || isNaN(numericQuantity)) {
|
|
258
|
-
return 0 // Manejo de valores no numéricos
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (numericQuantity <= 0 || price <= 0) {
|
|
262
|
-
return price // Manejo de cantidades o precios no positivos
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const totalPrice = Math.abs(numericQuantity * price)
|
|
266
|
-
return numberFormat(totalPrice) // Si es necesario, aplicar formateo aquí
|
|
267
|
-
}, [dataOneProduct])
|
|
268
|
-
|
|
269
|
-
const handleAddOptional = ({ exOptional = null, codeCategory = null }) => {
|
|
270
|
-
if (!exOptional || !codeCategory) return
|
|
271
|
-
const item = dataOptional.find((item) => item.code === codeCategory)
|
|
272
|
-
if (!item) return
|
|
273
|
-
const idx = item.ExtProductFoodsSubOptionalAll.findIndex(
|
|
274
|
-
(el) => el.opSubExPid === exOptional
|
|
275
|
-
)
|
|
276
|
-
if (item && idx !== -1) {
|
|
277
|
-
const updatedItem = {
|
|
278
|
-
...item,
|
|
279
|
-
ExtProductFoodsSubOptionalAll: [
|
|
280
|
-
...item.ExtProductFoodsSubOptionalAll.slice(0, idx),
|
|
281
|
-
{
|
|
282
|
-
...item.ExtProductFoodsSubOptionalAll[idx],
|
|
283
|
-
check: !item.ExtProductFoodsSubOptionalAll[idx].check
|
|
284
|
-
},
|
|
285
|
-
...item.ExtProductFoodsSubOptionalAll.slice(idx + 1)
|
|
286
|
-
]
|
|
287
|
-
}
|
|
288
|
-
const newData = dataOptional.map((el) =>
|
|
289
|
-
el.code === codeCategory ? updatedItem : el
|
|
290
|
-
)
|
|
291
|
-
setDataOptional((prevData) => [...newData])
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
const isValidDataExtra = (!dataExtra.length && !dataOneProduct?.pId) ? false : !validateExtraProducts(dataExtra)
|
|
296
|
-
|
|
297
|
-
const isValid = (!dataOptional.length && !dataOneProduct?.pId) ? false : validateRequirements(dataOptional)
|
|
298
|
-
|
|
299
|
-
const disabled = isValid || isValidDataExtra
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Handles the addition of products to the cart.
|
|
303
|
-
*
|
|
304
|
-
* @param {Object} food - The selected food item.
|
|
305
|
-
*/
|
|
306
|
-
const handleAddProducts = async (food) => {
|
|
307
|
-
if (!food) return
|
|
308
|
-
const idStore = food?.getStore?.idStore
|
|
309
|
-
if (!idStore) {
|
|
310
|
-
return
|
|
311
|
-
}
|
|
312
|
-
setLoadingButton(true)
|
|
313
|
-
const isExistItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
314
|
-
return item?.productFood && item?.productFood?.pId === food.pId
|
|
315
|
-
}) ?? null
|
|
316
|
-
if (!isExistItemInShoppingCart) handleMenu(1)
|
|
317
|
-
const filteredDataOptional = filterDataOptional(dataOptional)
|
|
318
|
-
|
|
319
|
-
const dataExtraFiltered = filterExtra(dataExtra)
|
|
320
|
-
|
|
321
|
-
const refCodePid = RandomCode(20)
|
|
322
|
-
|
|
323
|
-
const idShoppingCart = isExistItemInShoppingCart?.ShoppingCard
|
|
324
|
-
try {
|
|
325
|
-
const idStore = food?.getStore?.idStore
|
|
326
|
-
const response = await registerShoppingCard({
|
|
327
|
-
variables: {
|
|
328
|
-
input: {
|
|
329
|
-
ShoppingCard: idShoppingCart ?? null,
|
|
330
|
-
cState: 1,
|
|
331
|
-
pId: food.pId,
|
|
332
|
-
idStore,
|
|
333
|
-
refCodePid: idShoppingCart ? null : refCodePid,
|
|
334
|
-
comments,
|
|
335
|
-
cName: '',
|
|
336
|
-
cantProducts: quantity,
|
|
337
|
-
csDescription: '',
|
|
338
|
-
dataExtra: dataExtraFiltered || [],
|
|
339
|
-
dataOptional: filteredDataOptional || []
|
|
340
|
-
},
|
|
341
|
-
idSubArray: {
|
|
342
|
-
setID: []
|
|
343
|
-
}
|
|
344
|
-
},
|
|
345
|
-
update: (cache, { data: { getAllShoppingCard } }) => {
|
|
346
|
-
return updateCacheMod({
|
|
347
|
-
cache,
|
|
348
|
-
query: GET_ALL_SHOPPING_CARD,
|
|
349
|
-
nameFun: 'getAllShoppingCard',
|
|
350
|
-
dataNew: getAllShoppingCard
|
|
351
|
-
})
|
|
352
|
-
}
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
if (response?.data) {
|
|
356
|
-
if (!idShoppingCart) {
|
|
357
|
-
setAlertBox({ message: 'producto agregado al carrito' })
|
|
358
|
-
}
|
|
359
|
-
if (idShoppingCart) {
|
|
360
|
-
setAlertBox({ message: 'producto actualizado' })
|
|
361
|
-
}
|
|
362
|
-
// Perform actions after adding products to cart
|
|
363
|
-
}
|
|
364
|
-
} catch (error) {
|
|
365
|
-
setAlertBox({ message: 'Ocurrió un error al añadir el producto al carrito' })
|
|
366
|
-
}
|
|
367
|
-
setLoadingButton(false)
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
const handleShowModalProduct = () => {
|
|
371
|
-
if (openModalProduct) {
|
|
372
|
-
setDataExtra([])
|
|
373
|
-
setDataOneProduct({})
|
|
374
|
-
setQuantity(1)
|
|
375
|
-
setComments('')
|
|
376
|
-
setDataOptional([])
|
|
377
|
-
}
|
|
378
|
-
if (queryParamProduct && openModalProduct) {
|
|
379
|
-
handleCleanQuery('plato')
|
|
380
|
-
}
|
|
381
|
-
return setOpenModalProduct(!openModalProduct)
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
useEffect(() => {
|
|
385
|
-
if (queryParamProduct) {
|
|
386
|
-
const product = { pId: queryParamProduct }
|
|
387
|
-
getOneProduct(product)
|
|
388
|
-
}
|
|
389
|
-
}, [queryParamProduct])
|
|
390
|
-
|
|
391
|
-
return {
|
|
392
|
-
quantity,
|
|
393
|
-
disabled,
|
|
394
|
-
comments,
|
|
395
|
-
loading: loadingProduct || loading,
|
|
396
|
-
dataOneProduct,
|
|
397
|
-
loadingButton,
|
|
398
|
-
dataExtra,
|
|
399
|
-
dataOptional,
|
|
400
|
-
setQuantity,
|
|
401
|
-
handleShowModalProduct,
|
|
402
|
-
handleDecrease,
|
|
403
|
-
handleIncrease,
|
|
404
|
-
getOneProduct,
|
|
405
|
-
handleIncrementExtra,
|
|
406
|
-
handleDecrementExtra,
|
|
407
|
-
handleAddOptional,
|
|
408
|
-
setComments,
|
|
409
|
-
handleCountProducts,
|
|
410
|
-
handleAddProducts
|
|
411
|
-
}
|
|
412
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GET_ALL_SHOPPING_CARD } from '../queries'
|
|
2
|
-
import { useQuery } from '@apollo/client'
|
|
3
|
-
|
|
4
|
-
export const useGetCart = ({
|
|
5
|
-
setAlertBox = ({
|
|
6
|
-
message
|
|
7
|
-
}) => { return { message } },
|
|
8
|
-
setCountItemProduct = (number) => { return number }
|
|
9
|
-
} = {}) => {
|
|
10
|
-
const {
|
|
11
|
-
data,
|
|
12
|
-
loading,
|
|
13
|
-
error,
|
|
14
|
-
called
|
|
15
|
-
} = useQuery(GET_ALL_SHOPPING_CARD, {
|
|
16
|
-
onCompleted: data => {
|
|
17
|
-
if (Array.isArray(data?.getAllShoppingCard) && Number(data?.getAllShoppingCard?.length)) {
|
|
18
|
-
setCountItemProduct(data?.getAllShoppingCard?.length)
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
fetchPolicy: 'cache-and-network',
|
|
22
|
-
onError: () => {
|
|
23
|
-
setAlertBox({ message: 'No pudimos cargar el carrito...' })
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
const cart = data?.getAllShoppingCard || []
|
|
27
|
-
return [cart, {
|
|
28
|
-
data,
|
|
29
|
-
called,
|
|
30
|
-
loading,
|
|
31
|
-
error
|
|
32
|
-
}]
|
|
33
|
-
}
|