npm-pkg-hook 1.8.3 → 1.8.5
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/package.json +5 -4
- package/src/hooks/getTotalHours/index.js +2 -2
- package/src/hooks/index.js +1 -0
- package/src/hooks/statusOpenStores/index.js +2 -1
- package/src/hooks/useMobile/index.js +9 -40
- package/src/hooks/useSales/helpers/index.js +29 -0
- package/src/hooks/useSales/index.js +6 -35
- package/src/hooks/useSetupSchedule/index.js +53 -11
- package/src/hooks/useStatusOpenStore/index.js +8 -3
- package/src/hooks/useUpdateCartCookie/index.js +43 -0
package/package.json
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
"js-cookie": "3.0.1",
|
|
7
7
|
"lodash": "^4.17.21",
|
|
8
8
|
"md5": "2.3.0",
|
|
9
|
-
"moment": "^2.29.4",
|
|
9
|
+
"moment": "^2.29.4",
|
|
10
10
|
"react": "18.1.0",
|
|
11
11
|
"react-dom": "18.1.0",
|
|
12
|
-
"react-query": "^3.39.2"
|
|
12
|
+
"react-query": "^3.39.2",
|
|
13
|
+
"react-responsive": "^10.0.0"
|
|
13
14
|
},
|
|
14
15
|
"description": "description-pkg-hook",
|
|
15
16
|
"devDependencies": {
|
|
@@ -30,7 +31,7 @@
|
|
|
30
31
|
},
|
|
31
32
|
"license": "ISC",
|
|
32
33
|
"main": "/src/index.jsx",
|
|
33
|
-
"name": "npm-pkg-hook",
|
|
34
|
+
"name": "npm-pkg-hook",
|
|
34
35
|
"publishConfig": {
|
|
35
36
|
"registry": "https://registry.npmjs.org/"
|
|
36
37
|
},
|
|
@@ -44,5 +45,5 @@
|
|
|
44
45
|
"rm": "rm -rf node_modules package-lock.json && npm i",
|
|
45
46
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
46
47
|
},
|
|
47
|
-
"version": "1.8.
|
|
48
|
+
"version": "1.8.5"
|
|
48
49
|
}
|
package/src/hooks/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from './useGetCookies'
|
|
|
20
20
|
export * from './isTokenExpired'
|
|
21
21
|
export * from './useCreateDeliveryTime'
|
|
22
22
|
export * from './addTenMinutes'
|
|
23
|
+
export * from './useUpdateCartCookie'
|
|
23
24
|
export * from './useCategoriesProduct'
|
|
24
25
|
export * from './useLogout'
|
|
25
26
|
export * from './useSetupSchedule'
|
|
@@ -22,6 +22,7 @@ export const statusOpenStores = ({
|
|
|
22
22
|
open
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
|
|
25
26
|
function getNextDaySchedule (dataSchedules, currentDayOfWeek) {
|
|
26
27
|
const today = new Date()
|
|
27
28
|
const tomorrow = new Date(today)
|
|
@@ -93,7 +94,7 @@ export const statusOpenStores = ({
|
|
|
93
94
|
const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow]
|
|
94
95
|
return handleState(
|
|
95
96
|
`Cerrado abre - Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
|
|
96
|
-
findDataNextDay?.schHoSta
|
|
97
|
+
findDataNextDay?.schHoSta ?? ''
|
|
97
98
|
}`,
|
|
98
99
|
false
|
|
99
100
|
)
|
|
@@ -1,47 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMediaQuery } from 'react-responsive'
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const [innerHeight, setInnerHeight] = useState(0)
|
|
8
|
-
const [innerWidth, setInnerWidth] = useState(0)
|
|
9
|
-
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
const handleResize = () => {
|
|
12
|
-
// Verificar si window está disponible (es decir, estamos en el lado del cliente)
|
|
13
|
-
if (typeof window !== 'undefined') {
|
|
14
|
-
const width = window.innerWidth
|
|
15
|
-
const height = window.innerHeight
|
|
16
|
-
setInnerWidth(width)
|
|
17
|
-
setInnerHeight(height)
|
|
18
|
-
callBack()
|
|
19
|
-
|
|
20
|
-
// Determinar el tipo de dispositivo
|
|
21
|
-
if (width <= 768) {
|
|
22
|
-
setIsTablet(true)
|
|
23
|
-
} else if (width <= 960) {
|
|
24
|
-
setIsMobile(true)
|
|
25
|
-
} else {
|
|
26
|
-
setIsMobile(false)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Ejecutar handleResize al cargar y al cambiar el tamaño de la pantalla
|
|
32
|
-
handleResize()
|
|
33
|
-
window.addEventListener('resize', handleResize)
|
|
3
|
+
export const MEDIA_QUERY = {
|
|
4
|
+
MOBILE: '768px',
|
|
5
|
+
TABLED: '960px'
|
|
6
|
+
}
|
|
34
7
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}, [callBack])
|
|
8
|
+
export const useMobile = () => {
|
|
9
|
+
const isMobile = useMediaQuery({ query: `(max-width: ${MEDIA_QUERY.MOBILE})` })
|
|
10
|
+
const isTablet = useMediaQuery({ query: `(max-width: ${MEDIA_QUERY.TABLED}})` })
|
|
40
11
|
|
|
41
12
|
return {
|
|
42
13
|
isMobile,
|
|
43
|
-
isTablet
|
|
44
|
-
innerHeight,
|
|
45
|
-
innerWidth
|
|
14
|
+
isTablet
|
|
46
15
|
}
|
|
47
16
|
}
|
|
@@ -24,3 +24,32 @@ export function filterProductsByCarProId (products, carProIds) {
|
|
|
24
24
|
|
|
25
25
|
return products.filter(product => carProIds.includes(product.carProId))
|
|
26
26
|
}
|
|
27
|
+
|
|
28
|
+
export function removeFunc (state, action, productsFood) {
|
|
29
|
+
const productExist = state?.PRODUCT.find((items) => {
|
|
30
|
+
return items.pId === action.payload.pId
|
|
31
|
+
})
|
|
32
|
+
const OurProduct = productsFood.find((items) => {
|
|
33
|
+
return items.pId === action.payload.pId
|
|
34
|
+
})
|
|
35
|
+
return {
|
|
36
|
+
...state,
|
|
37
|
+
counter: state.counter - 1,
|
|
38
|
+
totalAmount: state.totalAmount - action.payload.ProPrice,
|
|
39
|
+
PRODUCT:
|
|
40
|
+
action.payload.ProQuantity > 1
|
|
41
|
+
? state.PRODUCT.map((items) => {
|
|
42
|
+
return items.pId === action.payload.pId
|
|
43
|
+
? {
|
|
44
|
+
...items,
|
|
45
|
+
pId: action.payload.pId,
|
|
46
|
+
ProQuantity: items.ProQuantity - 1,
|
|
47
|
+
ProPrice: productExist.ProPrice - OurProduct?.ProPrice
|
|
48
|
+
}
|
|
49
|
+
: items
|
|
50
|
+
})
|
|
51
|
+
: state.PRODUCT.filter((items) => {
|
|
52
|
+
return items.pId !== action.payload.pId
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -28,13 +28,13 @@ import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
|
28
28
|
import { useGetSale } from './useGetSale'
|
|
29
29
|
import { useCatWithProduct } from './../useCatWithProduct/index'
|
|
30
30
|
import { useLogout } from '../useLogout'
|
|
31
|
-
import { filterProductsByCarProId } from './helpers'
|
|
31
|
+
import { filterProductsByCarProId, removeFunc } from './helpers'
|
|
32
32
|
export * from './useGetAllSales'
|
|
33
33
|
export * from './helpers'
|
|
34
34
|
|
|
35
35
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
36
36
|
|
|
37
|
-
const initialState = {
|
|
37
|
+
export const initialState = {
|
|
38
38
|
PRODUCT: [],
|
|
39
39
|
totalPrice: 0,
|
|
40
40
|
sortBy: null,
|
|
@@ -47,7 +47,7 @@ const initialState = {
|
|
|
47
47
|
payMethodPState: 0
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
const initializer = (initialValue = initialState) => {
|
|
50
|
+
export const initializer = (initialValue = initialState) => {
|
|
51
51
|
return (
|
|
52
52
|
JSON.parse(
|
|
53
53
|
// @ts-ignore
|
|
@@ -128,7 +128,7 @@ export const useSales = ({
|
|
|
128
128
|
onError: (error) => {
|
|
129
129
|
sendNotification({
|
|
130
130
|
backgroundColor: 'error',
|
|
131
|
-
title: error || 'Lo
|
|
131
|
+
title: error || 'Lo sentimos',
|
|
132
132
|
description: 'ha ocurrido un error'
|
|
133
133
|
})
|
|
134
134
|
}
|
|
@@ -282,7 +282,7 @@ export const useSales = ({
|
|
|
282
282
|
|
|
283
283
|
switch (action.type) {
|
|
284
284
|
case 'ADD_TO_CART':
|
|
285
|
-
return addToCartFunc(state, action)
|
|
285
|
+
return addToCartFunc(state, action) // https://www.npmjs.com/package/@sourcetoad/vision-camera-plugin-barcode-scanner
|
|
286
286
|
case 'ADD_PRODUCT':
|
|
287
287
|
return {
|
|
288
288
|
...state,
|
|
@@ -290,7 +290,7 @@ export const useSales = ({
|
|
|
290
290
|
PRODUCT: [...state?.PRODUCT, action?.payload],
|
|
291
291
|
}
|
|
292
292
|
case 'REMOVE_PRODUCT':
|
|
293
|
-
return removeFunc(state, action)
|
|
293
|
+
return removeFunc(state, action, productsFood)
|
|
294
294
|
case 'REMOVE_PRODUCT_TO_CART':
|
|
295
295
|
return {
|
|
296
296
|
...state,
|
|
@@ -649,35 +649,6 @@ export const useSales = ({
|
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
651
|
|
|
652
|
-
function removeFunc (state, action) {
|
|
653
|
-
const productExist = state?.PRODUCT.find((items) => {
|
|
654
|
-
return items.pId === action.payload.pId
|
|
655
|
-
})
|
|
656
|
-
const OurProduct = productsFood.find((items) => {
|
|
657
|
-
return items.pId === action.payload.pId
|
|
658
|
-
})
|
|
659
|
-
return {
|
|
660
|
-
...state,
|
|
661
|
-
counter: state.counter - 1,
|
|
662
|
-
totalAmount: state.totalAmount - action.payload.ProPrice,
|
|
663
|
-
PRODUCT:
|
|
664
|
-
action.payload.ProQuantity > 1
|
|
665
|
-
? state.PRODUCT.map((items) => {
|
|
666
|
-
return items.pId === action.payload.pId
|
|
667
|
-
? {
|
|
668
|
-
...items,
|
|
669
|
-
pId: action.payload.pId,
|
|
670
|
-
ProQuantity: items.ProQuantity - 1,
|
|
671
|
-
ProPrice: productExist.ProPrice - OurProduct?.ProPrice
|
|
672
|
-
}
|
|
673
|
-
: items
|
|
674
|
-
})
|
|
675
|
-
: state.PRODUCT.filter((items) => {
|
|
676
|
-
return items.pId !== action.payload.pId
|
|
677
|
-
})
|
|
678
|
-
}
|
|
679
|
-
}
|
|
680
|
-
|
|
681
652
|
// TOGGLE_FREE_PRODUCT
|
|
682
653
|
function toggleFreeProducts (state, action) {
|
|
683
654
|
const productExist = productsFood.find((items) => {
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
dateEnum,
|
|
4
|
+
initialDays,
|
|
5
|
+
timeSuggestions
|
|
6
|
+
} from './helpers'
|
|
3
7
|
import { useCreateSchedules, useSchedules } from '../useSchedule'
|
|
4
8
|
import { days as NameDays } from '../../utils'
|
|
5
9
|
import { convertToMilitaryTime } from '../convertToMilitaryTime'
|
|
@@ -11,13 +15,13 @@ export const useSetupSchedule = ({
|
|
|
11
15
|
return args
|
|
12
16
|
}
|
|
13
17
|
} = {}) => {
|
|
14
|
-
const [days, setDays] = useState(initialDays)
|
|
18
|
+
const [days, setDays] = useState(initialDays === null ? [] : initialDays)
|
|
15
19
|
const [alertModal, setAlertModal] = useState(false)
|
|
16
20
|
const [selectedDay, setSelectedDay] = useState({})
|
|
17
21
|
const [setStoreSchedule, { loading }] = useCreateSchedules()
|
|
18
22
|
|
|
19
23
|
const onCompleted = (data) => {
|
|
20
|
-
if (Array.isArray(data) && data
|
|
24
|
+
if (Array.isArray(data) && data?.length > 0) {
|
|
21
25
|
// Mapeamos los datos recibidos y los convertimos en un objeto con la estructura deseada
|
|
22
26
|
const newSchedules = data.map((day) => ({
|
|
23
27
|
day: day.schDay,
|
|
@@ -29,7 +33,7 @@ export const useSetupSchedule = ({
|
|
|
29
33
|
// Actualizamos el estado days
|
|
30
34
|
setDays(prevDays => {
|
|
31
35
|
// Creamos un nuevo array combinando los elementos existentes en days con los nuevos datos
|
|
32
|
-
const updatedDays = prevDays
|
|
36
|
+
const updatedDays = prevDays?.map(existingDay => {
|
|
33
37
|
// Buscamos si hay un elemento con el mismo día en los nuevos datos
|
|
34
38
|
const newData = newSchedules.find(newDay => newDay.day === existingDay.day)
|
|
35
39
|
// Si encontramos el día en los nuevos datos, lo fusionamos con el día existente
|
|
@@ -81,7 +85,7 @@ export const useSetupSchedule = ({
|
|
|
81
85
|
setSelectedDay(isSaved)
|
|
82
86
|
return setAlertModal(true)
|
|
83
87
|
}
|
|
84
|
-
const updatedDays = days
|
|
88
|
+
const updatedDays = days?.map((d) => {
|
|
85
89
|
if (d.day === day) {
|
|
86
90
|
return { ...d, selected: !d.selected }
|
|
87
91
|
} else {
|
|
@@ -93,10 +97,38 @@ export const useSetupSchedule = ({
|
|
|
93
97
|
const selectedDays = days?.filter((day) => Boolean(day.selected)).map((day) => {
|
|
94
98
|
return day.day
|
|
95
99
|
})
|
|
100
|
+
function sumHours (hora1, hora2) {
|
|
101
|
+
const [hora1Horas, hora1Minutos] = hora1.split(':').map(Number)
|
|
102
|
+
const [hora2Horas, hora2Minutos] = hora2.split(':').map(Number)
|
|
96
103
|
|
|
104
|
+
let sumaHour = hora1Horas + hora2Horas
|
|
105
|
+
let sumMinutes = hora1Minutos + hora2Minutos
|
|
106
|
+
|
|
107
|
+
if (sumMinutes >= 60) {
|
|
108
|
+
sumMinutes -= 60
|
|
109
|
+
sumaHour++
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (sumaHour >= 24) {
|
|
113
|
+
sumaHour -= 24
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const horaSumada = `${String(sumaHour).padStart(2, '0')}:${String(sumMinutes).padStart(2, '0')}`
|
|
117
|
+
return horaSumada
|
|
118
|
+
}
|
|
119
|
+
function isLessThanOneHour (hora1, hora2) {
|
|
120
|
+
const suma = sumHours(hora1, hora2)
|
|
121
|
+
const [sumaHour, sumMinutes] = suma.split(':').map(Number)
|
|
122
|
+
const totalMinutos = (sumaHour * 60) + sumMinutes
|
|
123
|
+
|
|
124
|
+
if (totalMinutos < 60) {
|
|
125
|
+
return true // La suma de las horas es menor a una hora
|
|
126
|
+
}
|
|
127
|
+
return false // La suma de las horas es igual o mayor a una hora
|
|
128
|
+
}
|
|
97
129
|
const onChangeSaveHour = async ({ time, name, day }) => {
|
|
98
130
|
setDays(prevDays => {
|
|
99
|
-
const updatedDays = prevDays
|
|
131
|
+
const updatedDays = prevDays?.map((d) => {
|
|
100
132
|
if (d.day === day) {
|
|
101
133
|
return { ...d, [name]: time, loading: Boolean(name === dateEnum.schHoEnd) }
|
|
102
134
|
} else {
|
|
@@ -112,6 +144,14 @@ export const useSetupSchedule = ({
|
|
|
112
144
|
const schHoEnd = findHour?.schHoEnd
|
|
113
145
|
const startHour = convertToMilitaryTime(schHoSta)
|
|
114
146
|
const endHour = convertToMilitaryTime(schHoEnd)
|
|
147
|
+
if (isLessThanOneHour(startHour, endHour)) {
|
|
148
|
+
// eslint-disable-next-line consistent-return
|
|
149
|
+
sendNotification({
|
|
150
|
+
description: 'Error, el horario debe ser mayor a una hora',
|
|
151
|
+
title: 'Error',
|
|
152
|
+
backgroundColor: 'error'
|
|
153
|
+
})
|
|
154
|
+
}
|
|
115
155
|
// Comparar solo las horas y minutos
|
|
116
156
|
if (startHour === endHour) {
|
|
117
157
|
// eslint-disable-next-line consistent-return
|
|
@@ -129,7 +169,8 @@ export const useSetupSchedule = ({
|
|
|
129
169
|
backgroundColor: 'error'
|
|
130
170
|
})
|
|
131
171
|
}
|
|
132
|
-
|
|
172
|
+
|
|
173
|
+
if (startHour !== endHour && startHour < endHour && !isLessThanOneHour(startHour, endHour)) {
|
|
133
174
|
setStoreSchedule({
|
|
134
175
|
variables: {
|
|
135
176
|
input: {
|
|
@@ -193,12 +234,13 @@ export const useSetupSchedule = ({
|
|
|
193
234
|
}
|
|
194
235
|
})
|
|
195
236
|
setDays(prevDays => {
|
|
196
|
-
|
|
237
|
+
if (!prevDays) return []
|
|
238
|
+
const updatedDays = prevDays?.map((d) => {
|
|
197
239
|
if (d.day === day) {
|
|
198
240
|
return {
|
|
199
241
|
...d,
|
|
200
|
-
[dateEnum.schHoEnd]: dateEnum
|
|
201
|
-
[dateEnum.schHoSta]: dateEnum
|
|
242
|
+
[dateEnum.schHoEnd]: dateEnum?.schHoEnd,
|
|
243
|
+
[dateEnum.schHoSta]: dateEnum?.schHoSta,
|
|
202
244
|
selected: false
|
|
203
245
|
}
|
|
204
246
|
} else {
|
|
@@ -215,7 +257,6 @@ export const useSetupSchedule = ({
|
|
|
215
257
|
|
|
216
258
|
return {
|
|
217
259
|
duplicateDay,
|
|
218
|
-
alertModal,
|
|
219
260
|
toggleCheck,
|
|
220
261
|
handleSelectedDay,
|
|
221
262
|
onChangeSaveHour,
|
|
@@ -224,6 +265,7 @@ export const useSetupSchedule = ({
|
|
|
224
265
|
days,
|
|
225
266
|
selectedDays,
|
|
226
267
|
selectedDay,
|
|
268
|
+
alertModal,
|
|
227
269
|
loading: lsc || loading,
|
|
228
270
|
times: timeSuggestions
|
|
229
271
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
getTimeObject
|
|
12
12
|
} from './helpers'
|
|
13
13
|
import { useFormatDate } from '../useFormatDate'
|
|
14
|
+
import { convertToMilitaryTime } from '../convertToMilitaryTime'
|
|
14
15
|
|
|
15
16
|
export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
|
|
16
17
|
const [open, setOpen] = useState('')
|
|
@@ -86,7 +87,11 @@ export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
|
|
|
86
87
|
)
|
|
87
88
|
}
|
|
88
89
|
|
|
89
|
-
const {
|
|
90
|
+
const {
|
|
91
|
+
findNextDay,
|
|
92
|
+
findDataNextDay,
|
|
93
|
+
dayOfWeekTomorrow
|
|
94
|
+
} = getNextDaySchedule(
|
|
90
95
|
dataSchedules,
|
|
91
96
|
currentDayOfWeek
|
|
92
97
|
)
|
|
@@ -95,14 +100,14 @@ export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
|
|
|
95
100
|
const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow]
|
|
96
101
|
return handleMessageHour(
|
|
97
102
|
`Cerrado abre Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
|
|
98
|
-
findDataNextDay?.schHoSta
|
|
103
|
+
handleHourPmAM(findDataNextDay?.schHoSta) ?? ''
|
|
99
104
|
}`,
|
|
100
105
|
false
|
|
101
106
|
)
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
const nextDayName = weekDayLookup[(dayOfWeek + 1) % 7]
|
|
105
|
-
const nextOpening = openings
|
|
110
|
+
const nextOpening = openings?.['opening' + nextDayName.substring(0, 3)]
|
|
106
111
|
const nextHours = nextOpening?.split(';')?.map((item) => item?.trim())
|
|
107
112
|
|
|
108
113
|
if (nextHours[0] !== ceroHours) {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useReducer } from 'react'
|
|
2
|
+
import { initializer } from '../useSales'
|
|
3
|
+
import { Cookies } from '../../cookies'
|
|
4
|
+
import { getCurrentDomain } from '../../utils'
|
|
5
|
+
|
|
6
|
+
export const useUpdateCartCookie = () => {
|
|
7
|
+
const keyToSaveData = process.env.LOCAL_SALES_STORE
|
|
8
|
+
const domain = getCurrentDomain()
|
|
9
|
+
|
|
10
|
+
const PRODUCT = (state, action) => {
|
|
11
|
+
switch (action.type) {
|
|
12
|
+
case 'REMOVE_PRODUCT_TO_CART':
|
|
13
|
+
return {
|
|
14
|
+
...state,
|
|
15
|
+
PRODUCT: state?.PRODUCT?.filter((t) => {
|
|
16
|
+
return t.pId !== action?.payload.pId
|
|
17
|
+
}),
|
|
18
|
+
counter: state.counter - action.payload.ProQuantity
|
|
19
|
+
}
|
|
20
|
+
case 'ADD_PRODUCT_TO_CART':
|
|
21
|
+
// Add code for 'ADD_PRODUCT_TO_CART' case
|
|
22
|
+
return state
|
|
23
|
+
case 'UPDATE_PRODUCT_IN_CART':
|
|
24
|
+
// Add code for 'UPDATE_PRODUCT_IN_CART' case
|
|
25
|
+
return state
|
|
26
|
+
default:
|
|
27
|
+
return state
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const [data, dispatch] = useReducer(PRODUCT, { PRODUCT: [], counter: 0 }, initializer)
|
|
31
|
+
|
|
32
|
+
const handleRemoveProductToCookieCart = (product) => {
|
|
33
|
+
dispatch({ type: 'REMOVE_PRODUCT_TO_CART', payload: product })
|
|
34
|
+
}
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
Cookies.set(keyToSaveData, JSON.stringify(data), { domain, path: '/' })
|
|
38
|
+
}, [data, domain])
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
handleRemoveProductToCookieCart
|
|
42
|
+
}
|
|
43
|
+
}
|