npm-pkg-hook 1.10.4 → 1.10.6

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 CHANGED
@@ -47,5 +47,5 @@
47
47
  "rm": "rm -rf node_modules package-lock.json && npm i",
48
48
  "test": "echo \"Error: no test specified\" && exit 1"
49
49
  },
50
- "version": "1.10.4"
50
+ "version": "1.10.6"
51
51
  }
@@ -123,3 +123,9 @@ export * from './useGetStoreCookie'
123
123
  export * from './getGlobalSession'
124
124
  export * from './handleLogin'
125
125
  export * from './useInventory'
126
+ export * from './useStockMovements'
127
+ export * from './useTopProductsMovements'
128
+ export * from './useTotalProductsSold'
129
+ export * from './useTotalProductsInStock/index'
130
+ export * from './useTotalAllSales/index'
131
+ export * from './useTotalProductsSolded'
@@ -74,73 +74,7 @@ export const GET_ALL_EMPLOYEE_STORE = gql`
74
74
  }
75
75
  }
76
76
  `
77
- export const GET_ALL_PRODUCT_STORE = gql`
78
- query productFoodsAll(
79
- $search: String
80
- $min: Int
81
- $max: Int
82
- $gender: [String]
83
- $pState: Int
84
- $desc: [String]
85
- $categories: [ID]
86
- $fromDate: DateTime
87
- $toDate: DateTime
88
- ) {
89
- productFoodsAll(
90
- search: $search
91
- min: $min
92
- max: $max
93
- gender: $gender
94
- desc: $desc
95
- pState: $pState
96
- categories: $categories
97
- toDate: $toDate
98
- fromDate: $fromDate
99
- ) {
100
- pId
101
- sizeId #Talla
102
- colorId #Color
103
- cId #Country
104
- dId #Department
105
- ctId #Cuidad
106
- fId #Características
107
- pName
108
- ProPrice
109
- ProDescuento
110
- free
111
- manageStock
112
- ProUniDisponibles
113
- ProDescription
114
- ProProtegido
115
- ProAssurance
116
- ValueDelivery
117
- ProStar
118
- sTateLogistic
119
- ProImage
120
- ProWidth
121
- ProHeight
122
- ProLength
123
- ProWeight
124
- ProQuantity
125
- ProOutstanding
126
- pDatCre
127
- pDatMod
128
- ProDelivery
129
- ProVoltaje
130
- stock
131
- pState
132
- feat {
133
- fId
134
- thpId
135
- hpqrQuestion
136
- }
137
- area {
138
- aId
139
- aName
140
- }
141
- }
142
- }
143
- `
77
+
144
78
  export const GET_ALL_RATING_START_STORE = gql`
145
79
  query getAllRatingStar($idStore: ID) {
146
80
  getAllRatingStar(idStore: $idStore) {
@@ -25,12 +25,12 @@ export const useProductsFood = ({
25
25
  search = null,
26
26
  toDate
27
27
  }) => {
28
- // const [productsFood, setProductsFood] = useState([])
29
28
  const [showMore, setShowMore] = useState(500)
30
29
  const {
31
30
  data,
32
31
  loading,
33
32
  fetchMore,
33
+ refetch,
34
34
  error,
35
35
  called
36
36
  } = useQuery(GET_ALL_PRODUCT_STORE, {
@@ -51,14 +51,15 @@ export const useProductsFood = ({
51
51
  toDate: toDate || null
52
52
  }
53
53
  })
54
-
55
- const productsFood = data?.productFoodsAll
54
+ const productsFood = data?.productFoodsAll.data ?? []
56
55
  return [
57
56
  productsFood, {
58
- error,
57
+ pagination: data?.productFoodsAll.pagination || {},
59
58
  loading: called ? false : loading,
59
+ error,
60
60
  showMore,
61
61
  fetchMore,
62
+ refetch,
62
63
  setShowMore
63
64
  }
64
65
  ]
@@ -76,7 +76,7 @@ export const GET_ALL_EMPLOYEE_STORE = gql`
76
76
  `
77
77
 
78
78
  export const GET_ALL_PRODUCT_STORE = gql`
79
- query productFoodsAll(
79
+ query productFoodsAll(
80
80
  $search: String
81
81
  $min: Int
82
82
  $max: Int
@@ -86,6 +86,7 @@ export const GET_ALL_PRODUCT_STORE = gql`
86
86
  $categories: [ID]
87
87
  $fromDate: DateTime
88
88
  $toDate: DateTime
89
+ $page: Int
89
90
  ) {
90
91
  productFoodsAll(
91
92
  search: $search
@@ -97,7 +98,17 @@ export const GET_ALL_PRODUCT_STORE = gql`
97
98
  categories: $categories
98
99
  toDate: $toDate
99
100
  fromDate: $fromDate
101
+ page: $page
100
102
  ) {
103
+ success
104
+ message
105
+ pagination {
106
+ totalRecords
107
+ totalPages
108
+ currentPage
109
+ __typename
110
+ }
111
+ data {
101
112
  pId
102
113
  sizeId #Talla
103
114
  colorId #Color
@@ -149,6 +160,7 @@ export const GET_ALL_PRODUCT_STORE = gql`
149
160
  aName
150
161
  }
151
162
  }
163
+ }
152
164
  }
153
165
  `
154
166
  export const GET_ALL_RATING_START_STORE = gql`
@@ -34,7 +34,7 @@ export const useReport = ({
34
34
  })
35
35
 
36
36
  const totalSales = totalSalesData?.getAllSalesStoreTotal ?? {}
37
-
37
+ console.log(totalSales)
38
38
  return {
39
39
  getAllSalesStore: lazyQuery ? getAllSalesStore : () => { }, // Return function only if in lazy mode
40
40
  data: lazyQuery ? lazyDataSales : data, // Use data from lazy query if available
@@ -153,7 +153,13 @@ export const useSales = ({
153
153
  setDataExtra([])
154
154
  }
155
155
  })
156
- const [productsFood, { loading, fetchMore }] = useProductsFood({
156
+
157
+ const [productsFood, {
158
+ loading,
159
+ fetchMore,
160
+ pagination,
161
+ refetch
162
+ }] = useProductsFood({
157
163
  // @ts-ignore
158
164
  search: search?.length >= 4 ? search : '',
159
165
  gender: [],
@@ -164,6 +170,13 @@ export const useSales = ({
164
170
  max: showMore,
165
171
  min: 0
166
172
  })
173
+ const [currentPage, setCurrentPage] = useState(1)
174
+
175
+ const handlePageChange = (pageNumber) => {
176
+ setCurrentPage(pageNumber)
177
+ refetch({ page: pageNumber })
178
+ }
179
+
167
180
  const handleChangeCheck = (caId) => {
168
181
  // @ts-ignore
169
182
  setCategories((prev) => {
@@ -176,7 +189,6 @@ export const useSales = ({
176
189
  })
177
190
  })
178
191
  }
179
-
180
192
  const max = productsFood?.reduce(function (a, b) {
181
193
  return Math.max(a, b?.ProPrice || 0)
182
194
  }, 0)
@@ -776,7 +788,6 @@ export const useSales = ({
776
788
  const OurProduct = productsFood?.find((item) => item.pId === pId)
777
789
  const isFree = productExist?.free
778
790
  const currentQuantity = productExist?.ProQuantity || 0
779
- console.log('currentQuantity', productExist)
780
791
  if (productExist?.manageStock && isStockInsufficient(currentQuantity, stock)) {
781
792
  sendAlertStock(stock)
782
793
  return state
@@ -1062,7 +1073,6 @@ export const useSales = ({
1062
1073
  cache.modify({
1063
1074
  fields: {
1064
1075
  productFoodsAll (existingProductFoodsAll = []) {
1065
- console.log('existingProductFoodsAll', existingProductFoodsAll)
1066
1076
  return existingProductFoodsAll
1067
1077
  }
1068
1078
  }
@@ -1308,13 +1318,16 @@ export const useSales = ({
1308
1318
  dataOptional: dataOptional || [],
1309
1319
  dataExtra: dataExtra || [],
1310
1320
  fetchMore,
1321
+ pagination,
1311
1322
  discount,
1312
1323
  datCat: categories,
1324
+ currentPage,
1313
1325
  loadingProduct: loading,
1314
1326
  handleChangeCheck,
1315
1327
  errors,
1316
1328
  handleUpdateAllExtra,
1317
1329
  dispatch,
1330
+ handlePageChange,
1318
1331
  handleComment,
1319
1332
  setModalItem,
1320
1333
  handleChangeFilter,
@@ -0,0 +1,16 @@
1
+ export const fillMissingDates = (data, days = 7) => {
2
+ const today = new Date()
3
+ const filledData = []
4
+
5
+ for (let i = days - 1; i >= 0; i--) {
6
+ const date = new Date()
7
+ date.setDate(today.getDate() - i)
8
+
9
+ const formattedDate = date.toLocaleDateString('es-ES') // "dd/mm/yyyy"
10
+ const existingData = data.find(item => item.date === formattedDate)
11
+
12
+ filledData.push(existingData || { date: formattedDate, TotalIn: 0, TotalOut: 0 })
13
+ }
14
+
15
+ return filledData
16
+ }
@@ -0,0 +1,36 @@
1
+ import { useState, useEffect } from 'react'
2
+ import { useQuery, gql } from '@apollo/client'
3
+ import { fillMissingDates } from './helpers'
4
+
5
+ const GET_STOCK_MOVEMENTS = gql`
6
+ query {
7
+ getStockMovementsByDay {
8
+ date
9
+ total_in
10
+ total_out
11
+ }
12
+ }
13
+ `
14
+
15
+ /**
16
+ * Custom hook to fetch stock movements data for visualization.
17
+ * @returns {Object} { data, loading, error }
18
+ */
19
+ export const useStockMovements = () => {
20
+ const { data, loading, error } = useQuery(GET_STOCK_MOVEMENTS)
21
+ const [chartData, setChartData] = useState([])
22
+
23
+ useEffect(() => {
24
+ if (data && data.getStockMovementsByDay) {
25
+ // Transform data to be compatible with Recharts
26
+ const formattedData = data.getStockMovementsByDay.map(entry => ({
27
+ date: new Date(entry.date).toLocaleDateString(),
28
+ TotalIn: entry.total_in,
29
+ TotalOut: entry.total_out
30
+ }))
31
+ setChartData(formattedData)
32
+ }
33
+ }, [data])
34
+
35
+ return [fillMissingDates(chartData), { loading, error }]
36
+ }
@@ -0,0 +1,27 @@
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
+ }
@@ -0,0 +1,25 @@
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
+ }
@@ -0,0 +1,23 @@
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
+ }
@@ -0,0 +1,23 @@
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
+ }
@@ -0,0 +1,20 @@
1
+ import { useQuery, gql } from '@apollo/client'
2
+
3
+ const GET_TOTAL_PRODUCTS_SOLD = gql`
4
+ query {
5
+ getTotalProductsSold
6
+ }
7
+ `
8
+
9
+ /**
10
+ * Custom hook to fetch the total number of products sold.
11
+ * @returns {{ totalSold: number, loading: boolean, error: any }}
12
+ */
13
+ export const useTotalProductsSolded = () => {
14
+ const { data, loading, error } = useQuery(GET_TOTAL_PRODUCTS_SOLD)
15
+
16
+ return [data?.getTotalProductsSold, {
17
+ loading,
18
+ error
19
+ }]
20
+ }
@@ -38,7 +38,7 @@ export const useUpdateMultipleProducts = ({
38
38
  sTateLogistic: 1,
39
39
  ProStar: 0,
40
40
  stock,
41
- ProImage: null,
41
+ ProImage: '/images/placeholder-image.webp',
42
42
  vat,
43
43
  ProBarCode: String(ProBarCode) || '',
44
44
  ProHeight: null,
@@ -59,7 +59,9 @@ export const useUploadProducts = ({
59
59
  pCode: code,
60
60
  editing: false,
61
61
  PRECIO_AL_PUBLICO,
62
+ ProImage: '/images/placeholder-image.webp',
62
63
  VALOR_DE_COMPRA,
64
+ manageStock: true,
63
65
  errors: validationErrors.length > 0 ? validationErrors : null
64
66
  }
65
67
  })