npm-pkg-hook 1.2.0 → 1.2.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/package.json +1 -1
- package/src/config/client/errors.js +11 -9
- package/src/hooks/useCart/useCart/index.js +1 -1
- package/src/hooks/useClients/queries.js +2 -2
- package/src/hooks/useSales/helpers/index.js +9 -0
- package/src/hooks/useSales/index.js +18 -6
- package/src/hooks/useSales/useGetSale.js +1 -1
- package/src/hooks/useSchedule/index.js +41 -2
- package/src/hooks/useSchedule/queries.js +9 -0
- package/src/hooks/useStore/index.js +5 -13
- package/src/hooks/useStore/queries.js +2 -1
- package/src/hooks/useUser/queries.js +0 -1
package/package.json
CHANGED
|
@@ -2,14 +2,16 @@ import { onError } from '@apollo/client/link/error'
|
|
|
2
2
|
|
|
3
3
|
export const errorHandler = (error) => {
|
|
4
4
|
let logout = null
|
|
5
|
-
if (error) {
|
|
6
|
-
error.errors?.length && error
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
if (error && Array.isArray(error?.errors)) {
|
|
6
|
+
error.errors?.length && error?.errors?.forEach(err => {
|
|
7
|
+
if (err?.extensions) {
|
|
8
|
+
const { code, message: { message } } = err?.extensions || {}
|
|
9
|
+
if (code === 'UNAUTHENTICATED' || code === 'FORBIDDEN') {
|
|
10
|
+
logout = true
|
|
11
|
+
return {
|
|
12
|
+
status: 'FORBIDDEN',
|
|
13
|
+
message
|
|
14
|
+
}
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
})
|
|
@@ -21,4 +23,4 @@ export const errorLink = onError(({ graphQLErrors, networkError }) => {
|
|
|
21
23
|
if (graphQLErrors)graphQLErrors.map(({ message, location, path }) => { return console.log(`[GraphQL error]: Message: ${message}, Location: ${location}, Path: ${path}`) })
|
|
22
24
|
|
|
23
25
|
if (networkError) console.log(`[Network error]: ${networkError}`)
|
|
24
|
-
})
|
|
26
|
+
})
|
|
@@ -98,7 +98,7 @@ mutation registerShoppingCard($input: IShoppingCard, $idSubArray: IID_SUB_ITEMS
|
|
|
98
98
|
}
|
|
99
99
|
`
|
|
100
100
|
export const CREATE_SHOPPING_CARD_TO_USER_STORE = gql`
|
|
101
|
-
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change:
|
|
101
|
+
mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pCodeRef: String, $change: Int, $valueDelivery: Float, $payMethodPState: Int, $pickUp: Int, $totalProductsPrice: Float, $idSubArray: IID_SUB_ITEMS){
|
|
102
102
|
registerSalesStore(input: $input, id: $id, idStore: $idStore, pCodeRef: $pCodeRef, change: $change, valueDelivery: $valueDelivery, payMethodPState: $payMethodPState, pickUp: $pickUp, totalProductsPrice: $totalProductsPrice, idSubArray: $idSubArray){
|
|
103
103
|
ShoppingCard {
|
|
104
104
|
ShoppingCard
|
|
@@ -124,4 +124,4 @@ mutation registerSalesStore($input: [IShoppingCard], $id: ID, $idStore: ID, $pC
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
`
|
|
127
|
+
`
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function convertToIntegerOrFloat(numberString) {
|
|
2
|
+
if (!numberString) return 0;
|
|
3
|
+
|
|
4
|
+
// Convierte a número (entero o flotante)
|
|
5
|
+
const numericValue = parseFloat(numberString);
|
|
6
|
+
|
|
7
|
+
return isNaN(numericValue) ? 0 : numericValue; // Maneja valores no numéricos como 0
|
|
8
|
+
}
|
|
9
|
+
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from './queries'
|
|
27
27
|
import { updateExistingOrders } from '../useUpdateExistingOrders'
|
|
28
28
|
import { useGetSale } from './useGetSale'
|
|
29
|
+
import { convertToIntegerOrFloat } from './helpers'
|
|
29
30
|
export * from './useGetAllSales'
|
|
30
31
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
31
32
|
|
|
@@ -72,7 +73,11 @@ export const useSales = ({
|
|
|
72
73
|
const [_, setFilteredList] = useState([])
|
|
73
74
|
const [delivery, setDelivery] = useState(false)
|
|
74
75
|
const [print, setPrint] = useState(false)
|
|
75
|
-
const [values, setValues] = useState({
|
|
76
|
+
const [values, setValues] = useState({
|
|
77
|
+
comment: '',
|
|
78
|
+
change: '',
|
|
79
|
+
valueDelivery: ''
|
|
80
|
+
})
|
|
76
81
|
const [dataStore] = useStore()
|
|
77
82
|
const { createdAt } = dataStore || {}
|
|
78
83
|
const [code, setCode] = useState(null)
|
|
@@ -261,7 +266,11 @@ export const useSales = ({
|
|
|
261
266
|
return handleChangeNumber(state, action)
|
|
262
267
|
}
|
|
263
268
|
case 'REMOVE_ALL_PRODUCTS':
|
|
264
|
-
setValues({
|
|
269
|
+
setValues({
|
|
270
|
+
comment: '',
|
|
271
|
+
change: '',
|
|
272
|
+
valueDelivery: ''
|
|
273
|
+
})
|
|
265
274
|
return {
|
|
266
275
|
...state,
|
|
267
276
|
PRODUCT: [],
|
|
@@ -362,7 +371,7 @@ export const useSales = ({
|
|
|
362
371
|
const newData = dataOptional.map((el) =>
|
|
363
372
|
el.code === codeCategory ? updatedItem : el
|
|
364
373
|
)
|
|
365
|
-
setDataOptional((
|
|
374
|
+
setDataOptional(() => [...newData])
|
|
366
375
|
}
|
|
367
376
|
}
|
|
368
377
|
|
|
@@ -739,6 +748,7 @@ export const useSales = ({
|
|
|
739
748
|
price: totalProductPrice || 0,
|
|
740
749
|
discount: 0
|
|
741
750
|
})
|
|
751
|
+
|
|
742
752
|
function applyDiscount (percentage) {
|
|
743
753
|
const validateCondition =
|
|
744
754
|
isNaN(percentage) || percentage < 0 || percentage > 100
|
|
@@ -770,17 +780,19 @@ export const useSales = ({
|
|
|
770
780
|
setLoadingSale(true)
|
|
771
781
|
const code = RandomCode(10)
|
|
772
782
|
setCode(code)
|
|
783
|
+
const changeValue = values.change ? convertToIntegerOrFloat(values.change) : null;
|
|
784
|
+
|
|
773
785
|
return registerSalesStore({
|
|
774
786
|
variables: {
|
|
775
787
|
input: finalArrayProduct || [],
|
|
776
788
|
id: values?.cliId,
|
|
777
789
|
pCodeRef: code,
|
|
778
|
-
change:
|
|
779
|
-
valueDelivery:
|
|
790
|
+
change: changeValue,
|
|
791
|
+
valueDelivery: convertToIntegerOrFloat(values.valueDelivery),
|
|
780
792
|
payMethodPState: data.payMethodPState,
|
|
781
793
|
pickUp: 1,
|
|
782
794
|
discount: discount.discount || 0,
|
|
783
|
-
totalProductsPrice: totalProductsPrice || 0
|
|
795
|
+
totalProductsPrice: convertToIntegerOrFloat(totalProductsPrice) || 0
|
|
784
796
|
}
|
|
785
797
|
})
|
|
786
798
|
.then((responseRegisterR) => {
|
|
@@ -4,7 +4,7 @@ import { GET_ONE_SALE } from './queries'
|
|
|
4
4
|
export const useGetSale = () => {
|
|
5
5
|
const [getOnePedidoStore, { loading, data, called, error }] = useLazyQuery(GET_ONE_SALE)
|
|
6
6
|
return {
|
|
7
|
-
data: data?.getOnePedidoStore,
|
|
7
|
+
data: data?.getOnePedidoStore,
|
|
8
8
|
loading,
|
|
9
9
|
error,
|
|
10
10
|
called,
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { useQuery, useMutation } from '@apollo/client'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
GET_ONE_SCHEDULE_STORE,
|
|
4
|
+
GET_SCHEDULE_STORE,
|
|
5
|
+
CREATE_STORE_CALENDAR,
|
|
6
|
+
SET_STATUS_ALL_SCHEDULE_STORE
|
|
7
|
+
} from './queries'
|
|
4
8
|
|
|
5
9
|
export const useSchedule = ({ day = null, idStore = '' }) => {
|
|
6
10
|
const {
|
|
@@ -12,6 +16,41 @@ export const useSchedule = ({ day = null, idStore = '' }) => {
|
|
|
12
16
|
return [data?.getOneStoreSchedules, { loading, error }]
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
export const useSetScheduleOpenAll = () => {
|
|
20
|
+
const [setStoreSchedule, { loading, error }] = useMutation(SET_STATUS_ALL_SCHEDULE_STORE, {
|
|
21
|
+
onError: (e) => {
|
|
22
|
+
console.error(e);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const handleSetStoreSchedule = (scheduleOpenAll) => {
|
|
27
|
+
setStoreSchedule({
|
|
28
|
+
variables: {
|
|
29
|
+
scheduleOpenAll: scheduleOpenAll
|
|
30
|
+
}, update: (cache, { data }) => {
|
|
31
|
+
const success = data?.setScheduleOpenAll?.success
|
|
32
|
+
if (success) {
|
|
33
|
+
cache.modify({
|
|
34
|
+
fields: {
|
|
35
|
+
getStore (_, { readField }) {
|
|
36
|
+
const store = readField('getStore')
|
|
37
|
+
const updatedCart = {
|
|
38
|
+
...store,
|
|
39
|
+
scheduleOpenAll: scheduleOpenAll
|
|
40
|
+
}
|
|
41
|
+
return updatedCart
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
return [handleSetStoreSchedule, { loading, error }];
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
|
|
15
54
|
export const useSchedules = ({ schDay = 1, idStore = '' }) => {
|
|
16
55
|
const {
|
|
17
56
|
data,
|
|
@@ -32,3 +32,12 @@ export const GET_ONE_SCHEDULE_STORE = gql`
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
`
|
|
35
|
+
|
|
36
|
+
export const SET_STATUS_ALL_SCHEDULE_STORE = gql`
|
|
37
|
+
mutation setScheduleOpenAll($scheduleOpenAll: Boolean!) {
|
|
38
|
+
setScheduleOpenAll(scheduleOpenAll: $scheduleOpenAll) {
|
|
39
|
+
success
|
|
40
|
+
message
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`
|
|
@@ -4,6 +4,7 @@ import { GET_ONE_STORE, GET_ONE_STORE_BY_ID } from './queries' // Reemplaza con
|
|
|
4
4
|
import { errorHandler } from '../../config/client'
|
|
5
5
|
import { useLogout } from '../useLogout'
|
|
6
6
|
export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
7
|
+
|
|
7
8
|
const client = useApolloClient();
|
|
8
9
|
const [onClickLogout, { loading: load }] = useLogout();
|
|
9
10
|
|
|
@@ -17,8 +18,9 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
17
18
|
|
|
18
19
|
useEffect(() => {
|
|
19
20
|
if (cachedData) {
|
|
21
|
+
const array = store ? Object.keys(store) : []
|
|
20
22
|
// Comprobar si los datos de la caché ya están establecidos en el estado
|
|
21
|
-
if (!store ||
|
|
23
|
+
if (!store || Array.isArray(array) && array?.length === 0) {
|
|
22
24
|
setStore(cachedData.getStore);
|
|
23
25
|
}
|
|
24
26
|
}
|
|
@@ -40,7 +42,7 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
40
42
|
error: errorStoreClient
|
|
41
43
|
}];
|
|
42
44
|
} else {
|
|
43
|
-
const {
|
|
45
|
+
const { loading: loadingServer, error: errorServer } = useQuery(GET_ONE_STORE, {
|
|
44
46
|
skip: isClient && !idStore,
|
|
45
47
|
variables: {
|
|
46
48
|
idStore
|
|
@@ -63,16 +65,6 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
63
65
|
}
|
|
64
66
|
});
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
if (!loadingServer && !errorServer && !cachedData) {
|
|
69
|
-
client.writeQuery({
|
|
70
|
-
query: GET_ONE_STORE,
|
|
71
|
-
data: { getStore: store }
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}, [loadingServer, errorServer, cachedData, client, store]);
|
|
75
|
-
|
|
76
|
-
return [store, { loading: load || loadingServer, error }];
|
|
68
|
+
return [store, { loading: load || loadingServer || loading, error }];
|
|
77
69
|
}
|
|
78
70
|
};
|
|
@@ -15,6 +15,7 @@ query getStore($id: ID, $idStore: ID){
|
|
|
15
15
|
getStore(id: $id, idStore: $idStore){
|
|
16
16
|
cId
|
|
17
17
|
id
|
|
18
|
+
scheduleOpenAll
|
|
18
19
|
dId
|
|
19
20
|
idStore
|
|
20
21
|
ctId
|
|
@@ -100,7 +101,7 @@ query getOneStore($StoreName: String, $idStore: ID){
|
|
|
100
101
|
dId
|
|
101
102
|
ctId
|
|
102
103
|
catStore
|
|
103
|
-
neighborhoodStore
|
|
104
|
+
neighborhoodStore
|
|
104
105
|
Viaprincipal
|
|
105
106
|
storeOwner
|
|
106
107
|
storeName
|