npm-pkg-hook 1.0.9 → 1.1.2
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/.eslintrc.js +132 -132
- package/next.config.js +0 -1
- package/package.json +46 -43
- package/src/config/client/errors.js +2 -1
- package/src/hooks/getSession/index.js +18 -0
- package/src/hooks/index.js +27 -6
- package/src/hooks/useAnimationFrame/index.js +45 -0
- package/src/hooks/useAnimationText/index.jsx +11 -13
- package/src/hooks/useCatWithProduct/index.js +37 -4
- package/src/hooks/useCatWithProduct/queries.js +0 -16
- package/src/hooks/useCategoriesProduct/index.js +12 -0
- package/src/hooks/useCategoriesProduct/queries.js +16 -0
- package/src/hooks/useChartData/index.js +182 -154
- package/src/hooks/useCheckbox/index.js +5 -1
- package/src/hooks/useClients/index.js +17 -8
- package/src/hooks/useCreateProduct/index.js +96 -66
- package/src/hooks/useDeleteSubProductOptional/index.js +30 -0
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -0
- package/src/hooks/useDessert/helpers/index.js +51 -0
- package/src/hooks/useDessert/index.js +319 -121
- package/src/hooks/useDevices/index.js +36 -0
- package/src/hooks/useDevices/queries.js +19 -0
- package/src/hooks/useDrag/index.js +1 -1
- package/src/hooks/useDropzone/index.js +79 -0
- package/src/hooks/useDynamicAuth/index.js +13 -0
- package/src/hooks/useDynamicAuth/queries.js +24 -0
- package/src/hooks/useEmployee/index.js +11 -8
- package/src/hooks/useFingerprintjs/index.js +176 -0
- package/src/hooks/useFormTools/index.js +1 -1
- package/src/hooks/useFullScreenMode/index.js +8 -9
- package/src/hooks/useGenerateNumberArray/index.js +17 -0
- package/src/hooks/useImagesStore/index.js +176 -143
- package/src/hooks/useImagesStore/queries.js +1 -28
- package/src/hooks/useKeypress/index.js +7 -1
- package/src/hooks/useLocalSorage/index.js +1 -1
- package/src/hooks/useLogout/index.js +22 -25
- package/src/hooks/useManageQueryParams/index.js +37 -0
- package/src/hooks/useProductsFood/index.js +19 -4
- package/src/hooks/useProductsFood/queriesStore.js +3 -16
- package/src/hooks/useProductsFood/useEditProduct.js +10 -0
- package/src/hooks/useProductsFood/usetagsProducts.js +30 -5
- package/src/hooks/useProviders/index.js +3 -0
- package/src/hooks/useProviders/queries.js +31 -0
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +13 -0
- package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -0
- package/src/hooks/useProvidersStore/index.js +24 -0
- package/src/hooks/useProvidersStore/queries.js +31 -0
- package/src/hooks/useRatingData/index.js +53 -0
- package/src/hooks/useRatingData/queries.js +18 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -0
- package/src/hooks/useReport/index.js +16 -7
- package/src/hooks/useReport/queries.js +47 -32
- package/src/hooks/useSales/index.js +53 -22
- package/src/hooks/useSales/queries.js +48 -38
- package/src/hooks/useSales/useGetAllSales/index.js +25 -0
- package/src/hooks/useSales/useGetSale.js +16 -2
- package/src/hooks/useSchedule/index.js +36 -0
- package/src/hooks/useSchedule/queries.js +35 -0
- package/src/hooks/useScheduleData/index.js +171 -0
- package/src/hooks/useScroll/index.js +57 -0
- package/src/hooks/useScrollRotate/index.js +14 -0
- package/src/hooks/useStatusOpenStore/helpers/index.js +102 -0
- package/src/hooks/useStatusOpenStore/index.js +173 -0
- package/src/hooks/useStore/index.js +30 -16
- package/src/hooks/useUpdateExistingOrders/index.js +91 -0
- package/src/hooks/useUser/index.js +7 -2
- package/src/hooks/useUser/queries.js +40 -0
- package/src/index.jsx +3 -1
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -8
- package/src/hooks/useSchedule/index.jsx +0 -23
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS } from './queries'
|
|
3
|
+
import { updateCacheMod } from '../../utils'
|
|
4
|
+
import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
|
|
5
|
+
|
|
6
|
+
export const useDeleteSubProductOptional = ({ setAlertBox = () => { return } } = {}) => {
|
|
7
|
+
const [DeleteExtFoodSubsOptional, {
|
|
8
|
+
loading,
|
|
9
|
+
error,
|
|
10
|
+
called
|
|
11
|
+
}] = useMutation(DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS)
|
|
12
|
+
|
|
13
|
+
const handleRemoveSubProductOptional = ({ state, opSubExPid }) => {
|
|
14
|
+
console.log(state, opSubExPid )
|
|
15
|
+
DeleteExtFoodSubsOptional({
|
|
16
|
+
variables: {
|
|
17
|
+
state: state,
|
|
18
|
+
opSubExPid: opSubExPid
|
|
19
|
+
}, update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
|
|
20
|
+
return updateCacheMod({
|
|
21
|
+
cache,
|
|
22
|
+
query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
23
|
+
nameFun: 'ExtProductFoodsOptionalAll',
|
|
24
|
+
dataNew: ExtProductFoodsOptionalAll
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
}).then(res => { return setAlertBox({ message: res?.message?.DeleteExtFoodSubsOptional?.message }) })
|
|
28
|
+
}
|
|
29
|
+
return [DeleteExtFoodSubsOptional, handleRemoveSubProductOptional, { loading, error, called }]
|
|
30
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { gql } from "@apollo/client";
|
|
2
|
+
|
|
3
|
+
export const DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
|
|
4
|
+
mutation DeleteExtFoodSubsOptional($opSubExPid: ID, $state: Int, $isCustomSubOpExPid: Boolean){
|
|
5
|
+
DeleteExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state, isCustomSubOpExPid: $isCustomSubOpExPid){
|
|
6
|
+
success,
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MockData } from '../../../mock'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Transforms an array of objects into a specific data format suitable for desserts.
|
|
5
|
+
*
|
|
6
|
+
* @param {Array<Object>} dataArray - The array of objects to transform.
|
|
7
|
+
* @return {Object} The transformed data containing lists and listIds.
|
|
8
|
+
* @throws {Error} If dataArray is not an array or if the objects lack required properties.
|
|
9
|
+
*/
|
|
10
|
+
export const transformDataToDessert = (dataArray) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!dataArray) {
|
|
13
|
+
return MockData
|
|
14
|
+
}
|
|
15
|
+
if (!Array.isArray(dataArray)) {
|
|
16
|
+
throw new Error('dataArray must be an array.');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const transformedData = {
|
|
20
|
+
lists: {},
|
|
21
|
+
listIds: []
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
dataArray.forEach((item) => {
|
|
25
|
+
const listId = item.code;
|
|
26
|
+
transformedData.listIds.push(listId);
|
|
27
|
+
transformedData.lists[listId] = {
|
|
28
|
+
id: listId,
|
|
29
|
+
title: item?.OptionalProName,
|
|
30
|
+
numberLimit: item?.numbersOptionalOnly,
|
|
31
|
+
required: item?.required,
|
|
32
|
+
value: '',
|
|
33
|
+
cards: item?.ExtProductFoodsSubOptionalAll?.length > 0 ? item?.ExtProductFoodsSubOptionalAll?.map(subOptional => {
|
|
34
|
+
return {
|
|
35
|
+
id: subOptional?.exCode,
|
|
36
|
+
title: subOptional?.OptionalSubProName,
|
|
37
|
+
required: subOptional?.state,
|
|
38
|
+
value: ''
|
|
39
|
+
}
|
|
40
|
+
}) : []
|
|
41
|
+
};
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return transformedData;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(error.message)
|
|
47
|
+
return MockData
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
};
|
|
51
|
+
|
|
@@ -1,141 +1,339 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useState,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo
|
|
5
|
+
} from 'react'
|
|
2
6
|
import { MockData } from '../../mock'
|
|
3
|
-
import { RandomCode } from '../../utils'
|
|
7
|
+
import { RandomCode, updateCacheMod } from '../../utils'
|
|
4
8
|
import { useUpdateExtProductFoodsOptional } from '../updateExtProductFoodsOptional'
|
|
5
9
|
import { useUpdateExtProductFoodsSubOptional } from '../useUpdateExtProductFoodsSubOptional'
|
|
10
|
+
import { useRemoveExtraProductFoodsOptional } from '../useRemoveExtraProductFoodsOptional'
|
|
11
|
+
import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
|
|
12
|
+
import { transformDataToDessert } from './helpers'
|
|
13
|
+
import { useDeleteSubProductOptional } from '../useDeleteSubProductOptional'
|
|
6
14
|
|
|
7
|
-
export const useDessert = ({
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
export const useDessert = ({
|
|
16
|
+
pId = null,
|
|
17
|
+
initialData = null,
|
|
18
|
+
sendNotification = () => { return }
|
|
19
|
+
}) => {
|
|
20
|
+
|
|
21
|
+
// Initialize state variables using the useState hook
|
|
22
|
+
const [setCheck, setChecker] = useState({}); // State for checkboxes
|
|
23
|
+
const [valueItems, setValueItems] = useState(''); // State for input values
|
|
24
|
+
const [title, setTitle] = useState('') // State for title input value
|
|
25
|
+
|
|
26
|
+
// Initialize the data state with the transformedData or MockData
|
|
27
|
+
const [data, setData] = useState(MockData);
|
|
28
|
+
const dataListIds = data?.listIds?.filter(x => x !== '01list');
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Checks if all required lists have the maximum number of cards.
|
|
32
|
+
*
|
|
33
|
+
* @return {boolean} Returns true if all required lists have the maximum number of cards, otherwise false.
|
|
34
|
+
*/
|
|
35
|
+
const isCompleteRequired = dataListIds?.every(listID => {
|
|
36
|
+
try {
|
|
37
|
+
if (!Array.isArray(dataListIds) || data === null) {
|
|
38
|
+
throw new Error('Invalid arguments. dataListIds must be an array and data must be a non-null object.');
|
|
39
|
+
}
|
|
40
|
+
const list = data.lists[listID]
|
|
41
|
+
// If list or list.cards is missing, assume the list is not complete
|
|
42
|
+
const verifiEmpyRequireCard = list?.cards?.length
|
|
43
|
+
if (list && list?.cards) {
|
|
44
|
+
return verifiEmpyRequireCard === list.numberLimit;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// If list or list.cards is missing, assume the list is not complete
|
|
48
|
+
return false;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
// Transform initialData using useMemo to prevent unnecessary re-computation
|
|
55
|
+
const transformedData = useMemo(() => transformDataToDessert(initialData), [initialData]);
|
|
56
|
+
|
|
57
|
+
// Use useEffect to update the data state when the initialData prop changes
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (initialData) {
|
|
60
|
+
setData(transformedData);
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
// Filter the 'listIds' from 'data' and store the filtered result in 'dataListIds'
|
|
66
|
+
// Here, it seems to exclude a specific list ID ('01list') from the listIds.
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
// HOOKS
|
|
70
|
+
const { handleMutateExtProductFoodsSubOptional } = useUpdateExtProductFoodsSubOptional()
|
|
71
|
+
const { handleUpdateExtProduct } = useUpdateExtProductFoodsOptional()
|
|
72
|
+
const { DeleteExtProductFoodsOptional } = useRemoveExtraProductFoodsOptional()
|
|
73
|
+
const [DeleteExtFoodSubsOptional, { loading: loadingFoodSubOptional }] = useDeleteSubProductOptional()
|
|
74
|
+
|
|
75
|
+
// HANDLESS
|
|
76
|
+
/**
|
|
77
|
+
* Handles checkbox changes and updates the setCheck state accordingly.
|
|
78
|
+
* @param {Event} e - The checkbox change event object.
|
|
79
|
+
*/
|
|
80
|
+
const handleCheck = (e) => {
|
|
81
|
+
// Extract the 'name' and 'checked' properties from the event target (checkbox)
|
|
82
|
+
const { name, checked } = e.target;
|
|
83
|
+
|
|
84
|
+
// Update the setCheck state with the new value for the checkbox identified by the 'name' property
|
|
85
|
+
setChecker({ ...setCheck, [name]: checked });
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Handles the removal of a list from the data state and performs additional operations if needed.
|
|
91
|
+
* @param {number} i - The index of the list to be removed.
|
|
92
|
+
* @param {string} listID - The ID of the list to be removed (optional).
|
|
93
|
+
* @throws {Error} Will throw an error if the provided index (i) is not a non-negative number.
|
|
94
|
+
* @throws {Error} Will throw an error if the provided index (i) is out of range.
|
|
95
|
+
* @throws {Error} Will throw an error if the provided listID is invalid (optional validation).
|
|
96
|
+
*/
|
|
97
|
+
const handleRemoveList = (i, listID) => {
|
|
98
|
+
// Validate that the provided index (i) is a non-negative number
|
|
99
|
+
if (typeof i !== 'number' || i < 0) {
|
|
100
|
+
throw new Error('Invalid index provided. The index must be a non-negative number.');
|
|
22
101
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
102
|
+
|
|
103
|
+
// Make a copy of the listIds array from the data state
|
|
104
|
+
const listIdsCopy = [...data.listIds];
|
|
105
|
+
|
|
106
|
+
// Validate that the provided index (i) is within the range of the listIds array
|
|
107
|
+
if (i >= listIdsCopy.length) {
|
|
108
|
+
throw new Error('Invalid index provided. The index is out of range.');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Remove the list with the specified index from the listIdsCopy array
|
|
112
|
+
const Lines = data?.listIds.filter((_, index) => index !== i)?.filter(x => x !== '01list');;
|
|
113
|
+
// Update the data state with the modified listIdsCopy array
|
|
114
|
+
setData({
|
|
115
|
+
listIds: listID ? Lines.filter((subItem) => { return subItem !== listID }) : Lines,
|
|
116
|
+
lists: {
|
|
117
|
+
...data.lists,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// Perform additional operations if a valid listID is provided
|
|
122
|
+
if (listID) {
|
|
123
|
+
try {
|
|
124
|
+
// Assuming DeleteExtProductFoodsOptional is a function that deletes an external product
|
|
125
|
+
// Call the function to delete the external product using the provided listID
|
|
126
|
+
DeleteExtProductFoodsOptional({
|
|
127
|
+
variables: {
|
|
128
|
+
state: 1,
|
|
129
|
+
opExPid: listID,
|
|
130
|
+
isCustomOpExPid: true,
|
|
131
|
+
}, update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
|
|
132
|
+
return updateCacheMod({
|
|
133
|
+
cache,
|
|
134
|
+
query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
|
|
135
|
+
nameFun: 'ExtProductFoodsOptionalAll',
|
|
136
|
+
dataNew: ExtProductFoodsOptionalAll
|
|
137
|
+
})
|
|
29
138
|
}
|
|
30
139
|
})
|
|
140
|
+
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// Handle any errors that may occur during the deletion process
|
|
143
|
+
throw new Error('An error occurred while deleting the external product.');
|
|
31
144
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Removes a specific item from a list within the data state.
|
|
151
|
+
* @param {Object} params - The parameters for removing the item.
|
|
152
|
+
* @param {string} params.listID - The ID of the list from which the item will be removed.
|
|
153
|
+
* @param {string} params.id - The ID of the item to be removed.
|
|
154
|
+
* @throws {Error} Will throw an error if the provided listID does not exist in the data state.
|
|
155
|
+
* @throws {Error} Will throw an error if the provided listID exists but the corresponding list does not have a cards array.
|
|
156
|
+
*/
|
|
157
|
+
const removeOneItem = ({
|
|
158
|
+
listID = '',
|
|
159
|
+
id = '',
|
|
160
|
+
isCustomSubOpExPid = false
|
|
161
|
+
}) => {
|
|
162
|
+
try {
|
|
163
|
+
const forRemove = Boolean(isCustomSubOpExPid && listID && id)
|
|
164
|
+
if (forRemove) {
|
|
165
|
+
DeleteExtFoodSubsOptional({
|
|
166
|
+
variables: {
|
|
167
|
+
isCustomSubOpExPid,
|
|
168
|
+
opSubExPid: listID,
|
|
169
|
+
state: 1
|
|
43
170
|
}
|
|
44
171
|
})
|
|
45
172
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
173
|
+
// Ensure the provided listID exists in the data state
|
|
174
|
+
if (!data.lists[listID]) {
|
|
175
|
+
throw new Error(`List with ID "${listID}" does not exist.`);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Ensure the list has a cards array
|
|
179
|
+
if (!Array.isArray(data.lists[listID].cards)) {
|
|
180
|
+
throw new Error(`List with ID "${listID}" does not have a valid cards array.`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Get the current list from the data state using the provided listID
|
|
184
|
+
const currentList = data.lists[listID];
|
|
185
|
+
|
|
186
|
+
// Filter out the item with the specified ID from the current list's cards array
|
|
187
|
+
const totalCart = currentList.cards.filter((cart) => cart.id !== id);
|
|
188
|
+
|
|
189
|
+
// Update the current list's cards with the filtered array to remove the specified item
|
|
190
|
+
setData({
|
|
191
|
+
listIds: [...data.listIds],
|
|
192
|
+
lists: {
|
|
193
|
+
...data.lists,
|
|
194
|
+
[listID]: {
|
|
195
|
+
...currentList,
|
|
196
|
+
cards: totalCart,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error(error)
|
|
72
202
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
203
|
+
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
const addCard = async (title, listId) => {
|
|
208
|
+
const id = RandomCode(9)
|
|
209
|
+
const newCard = {
|
|
210
|
+
id: id,
|
|
211
|
+
title: title,
|
|
212
|
+
numberLimit: 5,
|
|
213
|
+
value: '',
|
|
214
|
+
required: setCheck.exState ? 1 : 0
|
|
215
|
+
}
|
|
216
|
+
const list = data.lists[listId]
|
|
217
|
+
list.cards = [...list.cards, newCard]
|
|
218
|
+
setData({
|
|
219
|
+
...data,
|
|
220
|
+
lists: {
|
|
221
|
+
...data.lists,
|
|
222
|
+
[listId]: list
|
|
77
223
|
}
|
|
224
|
+
})
|
|
225
|
+
handleMutateExtProductFoodsSubOptional({
|
|
226
|
+
pId,
|
|
227
|
+
title,
|
|
228
|
+
listId,
|
|
229
|
+
id,
|
|
230
|
+
state: 1
|
|
231
|
+
})
|
|
232
|
+
setTitle('')
|
|
233
|
+
}
|
|
234
|
+
const handleAdd = ({ listId }) => {
|
|
235
|
+
if (valueItems !== '' && valueItems.trim() !== '') {
|
|
236
|
+
addCard(valueItems, listId)
|
|
237
|
+
}
|
|
238
|
+
setValueItems('')
|
|
239
|
+
}
|
|
240
|
+
|
|
78
241
|
|
|
242
|
+
/**
|
|
243
|
+
* Handles the addition of a new list with the given title and number limit.
|
|
244
|
+
* @param {Object} params - The parameters for adding the new list.
|
|
245
|
+
* @param {string} params.title - The title of the new list.
|
|
246
|
+
* @param {number} params.numberLimit - The number limit for the new list.
|
|
247
|
+
*/
|
|
248
|
+
const handleAddList = async ({ title, numberLimit }) => {
|
|
249
|
+
// Check if the title is not empty
|
|
250
|
+
if (title.trim() === '') {
|
|
251
|
+
sendNotification({
|
|
252
|
+
description: 'El titulo no debe estar vacio',
|
|
253
|
+
title: 'Error',
|
|
254
|
+
backgroundColor: 'warning'
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Generate a new list ID using the RandomCode function (must be implemented elsewhere)
|
|
259
|
+
const newListId = RandomCode(9);
|
|
260
|
+
|
|
261
|
+
// Determine if the list is required based on the setCheck.exState state
|
|
262
|
+
const required = setCheck.exState ? 1 : 0;
|
|
79
263
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
value: '',
|
|
93
|
-
cards: []
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
handleUpdateExtProduct({
|
|
98
|
-
pId,
|
|
99
|
-
code: newListId,
|
|
100
|
-
OptionalProName: title,
|
|
101
|
-
required: setCheck.exState ? 1 : 0,
|
|
102
|
-
numbersOptionalOnly: numberLimit
|
|
103
|
-
})
|
|
104
|
-
setTitle('')
|
|
264
|
+
// Add the new list to the data state
|
|
265
|
+
setData({
|
|
266
|
+
listIds: [...data.listIds, newListId],
|
|
267
|
+
lists: {
|
|
268
|
+
...data.lists,
|
|
269
|
+
[newListId]: {
|
|
270
|
+
id: newListId,
|
|
271
|
+
title,
|
|
272
|
+
required,
|
|
273
|
+
numberLimit,
|
|
274
|
+
value: '',
|
|
275
|
+
cards: []
|
|
105
276
|
}
|
|
106
277
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
// Update the external product with the information of the new list
|
|
281
|
+
handleUpdateExtProduct({
|
|
282
|
+
pId,
|
|
283
|
+
code: newListId,
|
|
284
|
+
OptionalProName: title,
|
|
285
|
+
required,
|
|
286
|
+
numbersOptionalOnly: numberLimit
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// Clear the title field after adding the list
|
|
290
|
+
setTitle('');
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Handles the change of items in a specific list.
|
|
296
|
+
* @param {Object} params - The parameters for handling the change.
|
|
297
|
+
* @param {string} params.listID - The ID of the list where the change is happening.
|
|
298
|
+
* @param {Object} params.value - The event object containing the new value for the list items.
|
|
299
|
+
*/
|
|
300
|
+
const handleChangeItems = ({ listID, value: e }) => {
|
|
301
|
+
const value = e.target.value;
|
|
302
|
+
setValueItems(value);
|
|
303
|
+
|
|
304
|
+
// Get the current list from the data state using the provided listID
|
|
305
|
+
const currentList = data.lists[listID];
|
|
306
|
+
|
|
307
|
+
// Update the value of the current list with the new value
|
|
308
|
+
setData({
|
|
309
|
+
listIds: [...data.listIds],
|
|
310
|
+
lists: {
|
|
311
|
+
...data.lists,
|
|
312
|
+
[listID]: {
|
|
313
|
+
...currentList,
|
|
314
|
+
value: value,
|
|
315
|
+
},
|
|
316
|
+
},
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// Note: The return statement seems to be unnecessary, and the map function doesn't serve a purpose here.
|
|
320
|
+
// If you want to map through dataListIds for some other reason, you should use it separately from this function.
|
|
321
|
+
};
|
|
322
|
+
|
|
126
323
|
return {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
324
|
+
addCard,
|
|
325
|
+
data,
|
|
326
|
+
dataListIds,
|
|
327
|
+
isCompleteRequired,
|
|
328
|
+
handleAdd,
|
|
329
|
+
handleAddList,
|
|
330
|
+
handleChangeItems,
|
|
331
|
+
handleCheck,
|
|
332
|
+
handleRemoveList,
|
|
333
|
+
removeOneItem,
|
|
334
|
+
setCheck,
|
|
335
|
+
setData,
|
|
336
|
+
setTitle,
|
|
337
|
+
title,
|
|
140
338
|
}
|
|
141
339
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import { useQuery } from '@apollo/client'
|
|
3
|
+
import { GET_ALL_DEVICES } from './queries'
|
|
4
|
+
import { useFormatDate } from '../useFormatDate'
|
|
5
|
+
|
|
6
|
+
export const useDevices = () => {
|
|
7
|
+
const { data, loading } = useQuery(GET_ALL_DEVICES,{
|
|
8
|
+
onError: (error) => {
|
|
9
|
+
console.error(error)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
const [deviceId, setDeviceId] = useState(false)
|
|
13
|
+
const [date, setDate] = useState('')
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (window) {
|
|
17
|
+
setDeviceId(window.localStorage.getItem('deviceid'))
|
|
18
|
+
}
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
// Función para formatear la fecha
|
|
22
|
+
const formatDate = useFormatDate({ date: date })
|
|
23
|
+
|
|
24
|
+
const updateDate = (newDate) => {
|
|
25
|
+
setDate(newDate)
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
data: data?.getDeviceUsers || [],
|
|
29
|
+
date,
|
|
30
|
+
deviceId,
|
|
31
|
+
formatDate,
|
|
32
|
+
loading,
|
|
33
|
+
updateDate
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_ALL_DEVICES = gql`
|
|
4
|
+
query getDeviceUsers{
|
|
5
|
+
getDeviceUsers{
|
|
6
|
+
dId
|
|
7
|
+
locationFormat
|
|
8
|
+
deviceId
|
|
9
|
+
deviceName
|
|
10
|
+
type
|
|
11
|
+
short_name
|
|
12
|
+
platform
|
|
13
|
+
version
|
|
14
|
+
dState
|
|
15
|
+
DatCre
|
|
16
|
+
DatMod
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|