npm-pkg-hook 1.11.3 → 1.11.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/.env +5 -1
- package/package.json +3 -2
- package/src/config/client/errors.js +1 -1
- package/src/config/content/en.json +5 -0
- package/src/config/content/es.json +5 -0
- package/src/config/content/index.js +16 -0
- package/src/hooks/index.js +6 -0
- package/src/hooks/newStoreOrderSubscription/index.js +1 -12
- package/src/hooks/updateExtProductFoodsOptional/index.js +2 -2
- package/src/hooks/useCatWithProduct/queries.js +50 -24
- package/src/hooks/useCategoriesProduct/index.js +1 -0
- package/src/hooks/useCategoriesProduct/queries.js +2 -2
- package/src/hooks/useCategoryInStore/queries.js +2 -2
- package/src/hooks/useClients/queries.js +72 -23
- package/src/hooks/useCreateProduct/helpers/index.js +2 -2
- package/src/hooks/useCreateProduct/index.js +45 -46
- package/src/hooks/useDessert/index.js +20 -3
- package/src/hooks/useDessertWithPrice/helpers/index.js +2 -2
- package/src/hooks/useDessertWithPrice/index.js +70 -60
- package/src/hooks/useDessertWithPrice/queries.js +2 -2
- package/src/hooks/useDevices/queries.js +16 -7
- package/src/hooks/useDevices/useGetDevices.js +12 -19
- package/src/hooks/useDevices/useRegisterDevices.js +3 -3
- package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +21 -0
- package/src/hooks/useDownloadReports/index.ts +2 -0
- package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +103 -0
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +115 -0
- package/src/hooks/useEditCategory/index.js +10 -10
- package/src/hooks/useFormTools/index.js +2 -1
- package/src/hooks/useFormatDate/index.js +56 -3
- package/src/hooks/useGetStoreCookie/index.js +1 -1
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +130 -0
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +53 -0
- package/src/hooks/useImageUploaderProduct/helper/index.ts +5 -0
- package/src/hooks/useImageUploaderProduct/index.ts +292 -0
- package/src/hooks/useImagesStore/index.js +100 -58
- package/src/hooks/useImagesStore/queries.js +2 -2
- package/src/hooks/useImagesStore/utils/index.js +4 -0
- package/src/hooks/useInventory/queries.js +1 -1
- package/src/hooks/useLocationManager/index.js +3 -1
- package/src/hooks/useLogout/helpers/fetchData.js +1 -1
- package/src/hooks/useLogout/helpers/logger.js +8 -8
- package/src/hooks/useLogout/index.js +6 -4
- package/src/hooks/useManageNewOrder/index.js +3 -3
- package/src/hooks/useManageQueryParams/index.js +28 -28
- package/src/hooks/useMobile/index.js +38 -8
- package/src/hooks/useOrderStatusTypes/index.ts +2 -0
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +52 -0
- package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +97 -0
- package/src/hooks/useOrders/index.js +2 -74
- package/src/hooks/useOrders/queries.js +31 -195
- package/src/hooks/useOrders/useChangeOrderState/index.ts +125 -0
- package/src/hooks/useOrders/useOrdersFromStore/index.ts +83 -0
- package/src/hooks/usePortFetcher/index.ts +33 -0
- package/src/hooks/useProductsFood/index.js +3 -3
- package/src/hooks/useProductsFood/queriesStore.js +120 -64
- package/src/hooks/useProductsFood/useEditProduct.js +42 -2
- package/src/hooks/useProductsFood/usetagsProducts.js +47 -43
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +4 -4
- package/src/hooks/useSales/index.js +29 -19
- package/src/hooks/useSales/queries.js +140 -162
- package/src/hooks/useSales/useGetSale.js +3 -3
- package/src/hooks/useSaveAvailableProduct/index.js +1 -0
- package/src/hooks/useSetImageProducts/index.js +42 -13
- package/src/hooks/useSetImageProducts/queries.js +5 -0
- package/src/hooks/useStore/index.js +5 -1
- package/src/hooks/useStore/queries.js +71 -72
- package/src/hooks/useTagProducts/index.ts +3 -0
- package/src/hooks/useTagProducts/useDeleteOneTag.ts +106 -0
- package/src/hooks/useTagProducts/useGetAllTags.ts +68 -0
- package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +156 -0
- package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
- package/src/hooks/useUpdateExistingOrders/index.js +3 -9
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +25 -3
- package/src/hooks/useUpdateMultipleExtProduct/index.js +33 -0
- package/src/hooks/useUpdateMultipleExtProduct/queries.js +33 -0
- package/src/hooks/useUploadProducts/index.js +0 -1
- package/src/hooks/useUser/queries.js +0 -1
- package/src/utils/index.js +97 -5
- package/tsconfig.json +5 -0
- package/src/hooks/useUpdateMultipleExtProductFoods/index.js +0 -21
- package/src/hooks/useUpdateMultipleExtProductFoods/queries.js +0 -19
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL mutation to delete a tag by ID or name.
|
|
5
|
+
*/
|
|
6
|
+
const DELETE_ONE_TAG = gql`
|
|
7
|
+
mutation deleteOneTag($tgId: ID, $nameTag: String) {
|
|
8
|
+
deleteOneTag(tgId: $tgId, nameTag: $nameTag) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
data {
|
|
12
|
+
tgId
|
|
13
|
+
nameTag
|
|
14
|
+
state
|
|
15
|
+
}
|
|
16
|
+
errors {
|
|
17
|
+
path
|
|
18
|
+
message
|
|
19
|
+
type
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Custom hook to delete a tag by ID or name.
|
|
27
|
+
* @returns {Object} An object with the deleteTag function and mutation state.
|
|
28
|
+
*/
|
|
29
|
+
export const useDeleteOneTag = () => {
|
|
30
|
+
const [deleteOneTag, { data, loading, error }] = useMutation(DELETE_ONE_TAG, {
|
|
31
|
+
update(cache, { data }) {
|
|
32
|
+
const deleted = data?.deleteOneTag?.data
|
|
33
|
+
const success = data?.deleteOneTag?.success
|
|
34
|
+
|
|
35
|
+
if (!success || !deleted?.tgId) return
|
|
36
|
+
|
|
37
|
+
// Update cache for getAllTags
|
|
38
|
+
cache.modify({
|
|
39
|
+
fields: {
|
|
40
|
+
getAllTags(existing = {}) {
|
|
41
|
+
const filteredData = existing?.data?.filter(
|
|
42
|
+
(tag: any) => tag.tgId !== deleted.tgId
|
|
43
|
+
) || []
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...existing,
|
|
47
|
+
data: filteredData,
|
|
48
|
+
pagination: {
|
|
49
|
+
...existing.pagination,
|
|
50
|
+
totalRecords: Math.max((existing.pagination?.totalRecords || 1) - 1, 0)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
},
|
|
57
|
+
// optional, remove if you prefer default behavior
|
|
58
|
+
onError(err) {
|
|
59
|
+
console.error('❌ Apollo error in deleteOneTag:', err)
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
/**
|
|
63
|
+
* Deletes a tag by ID or name.
|
|
64
|
+
* @param {Object} variables - Mutation input.
|
|
65
|
+
* @param {string} [variables.tgId] - Tag ID (optional).
|
|
66
|
+
* @param {string} [variables.nameTag] - Tag name (optional).
|
|
67
|
+
* @returns {Promise<Object>} Response from server.
|
|
68
|
+
*/
|
|
69
|
+
const handleDeleteTag = async ({
|
|
70
|
+
tgId,
|
|
71
|
+
nameTag
|
|
72
|
+
}: {
|
|
73
|
+
tgId?: string
|
|
74
|
+
nameTag?: string
|
|
75
|
+
}) => {
|
|
76
|
+
try {
|
|
77
|
+
const { data } = await deleteOneTag({
|
|
78
|
+
variables: {
|
|
79
|
+
tgId,
|
|
80
|
+
nameTag
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
return data.deleteOneTag
|
|
85
|
+
} catch (err: any) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
message: 'An error occurred while deleting the tag.',
|
|
89
|
+
data: null,
|
|
90
|
+
errors: [
|
|
91
|
+
{
|
|
92
|
+
path: 'mutation',
|
|
93
|
+
message: err.message || 'Unknown error',
|
|
94
|
+
type: 'server'
|
|
95
|
+
}
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return [handleDeleteTag, {
|
|
102
|
+
data,
|
|
103
|
+
loading,
|
|
104
|
+
error
|
|
105
|
+
}]
|
|
106
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch all tags
|
|
5
|
+
*/
|
|
6
|
+
export const GET_ALL_TAGS = gql`
|
|
7
|
+
query getAllTags {
|
|
8
|
+
getAllTags {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
pagination {
|
|
12
|
+
totalRecords
|
|
13
|
+
totalPages
|
|
14
|
+
currentPage
|
|
15
|
+
}
|
|
16
|
+
data {
|
|
17
|
+
tgId
|
|
18
|
+
idUser
|
|
19
|
+
idStore
|
|
20
|
+
pId
|
|
21
|
+
nameTag
|
|
22
|
+
aName
|
|
23
|
+
}
|
|
24
|
+
errors {
|
|
25
|
+
path
|
|
26
|
+
message
|
|
27
|
+
type
|
|
28
|
+
context {
|
|
29
|
+
limit
|
|
30
|
+
value
|
|
31
|
+
label
|
|
32
|
+
key
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Custom hook to fetch all tags
|
|
41
|
+
*
|
|
42
|
+
* @returns {{
|
|
43
|
+
* tags: any[],
|
|
44
|
+
* loading: boolean,
|
|
45
|
+
* error: Error | null,
|
|
46
|
+
* message: string,
|
|
47
|
+
* success: boolean,
|
|
48
|
+
* pagination: { totalRecords: number, totalPages: number, currentPage: number } | null,
|
|
49
|
+
* errors: any[] | null
|
|
50
|
+
* }}
|
|
51
|
+
*/
|
|
52
|
+
export const useGetAllTags = () => {
|
|
53
|
+
const { data, loading, error } = useQuery(GET_ALL_TAGS, {
|
|
54
|
+
fetchPolicy: 'network-only',
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
const result = data?.getAllTags ?? {}
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
tags: result?.data || [],
|
|
61
|
+
loading,
|
|
62
|
+
error,
|
|
63
|
+
message: result?.message ?? '',
|
|
64
|
+
success: result?.success ?? false,
|
|
65
|
+
pagination: result?.pagination ?? null,
|
|
66
|
+
errors: result?.errors ?? null,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { useMutation, gql, useApolloClient } from '@apollo/client'
|
|
2
|
+
import { GET_ALL_TAGS } from './useGetAllTags'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL mutation to register multiple tags.
|
|
6
|
+
*/
|
|
7
|
+
const REGISTER_MULTIPLE_TAGS = gql`
|
|
8
|
+
mutation registerMultipleTags($input: [String!]!) {
|
|
9
|
+
registerMultipleTags(input: $input) {
|
|
10
|
+
success
|
|
11
|
+
message
|
|
12
|
+
errors {
|
|
13
|
+
path
|
|
14
|
+
message
|
|
15
|
+
}
|
|
16
|
+
data {
|
|
17
|
+
tgId
|
|
18
|
+
nameTag
|
|
19
|
+
idStore
|
|
20
|
+
idUser
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Response structure for tag registration errors.
|
|
28
|
+
*/
|
|
29
|
+
interface ITagError {
|
|
30
|
+
path: string
|
|
31
|
+
message: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Structure for a registered tag.
|
|
36
|
+
*/
|
|
37
|
+
interface ITag {
|
|
38
|
+
tgId: string
|
|
39
|
+
nameTag: string
|
|
40
|
+
idStore: string
|
|
41
|
+
idUser: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* General GraphQL response for registering tags.
|
|
46
|
+
*/
|
|
47
|
+
interface IResponseTag {
|
|
48
|
+
success: boolean
|
|
49
|
+
message: string
|
|
50
|
+
errors: ITagError[]
|
|
51
|
+
data: ITag[]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Options for the useRegisterMultipleTags hook.
|
|
56
|
+
*/
|
|
57
|
+
interface UseRegisterMultipleTagsOptions {
|
|
58
|
+
callback?: (response: IResponseTag) => void
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Return type for the useRegisterMultipleTags hook.
|
|
63
|
+
*/
|
|
64
|
+
type UseRegisterMultipleTagsReturn = [
|
|
65
|
+
(tags: string[]) => Promise<IResponseTag>,
|
|
66
|
+
{
|
|
67
|
+
loading: boolean
|
|
68
|
+
error: any
|
|
69
|
+
data: IResponseTag | null
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Hook to register multiple tags via GraphQL mutation.
|
|
75
|
+
*
|
|
76
|
+
* @param {UseRegisterMultipleTagsOptions} [options] - Optional callback for post-mutation handling.
|
|
77
|
+
* @returns {UseRegisterMultipleTagsReturn} - Mutation handler and state.
|
|
78
|
+
*/
|
|
79
|
+
export const useRegisterMultipleTags = (
|
|
80
|
+
{ callback = () => { } }: UseRegisterMultipleTagsOptions = {}
|
|
81
|
+
): UseRegisterMultipleTagsReturn => {
|
|
82
|
+
const client = useApolloClient()
|
|
83
|
+
const [registerMultipleTags, { loading, error, data }] = useMutation<
|
|
84
|
+
{ registerMultipleTags: IResponseTag },
|
|
85
|
+
{ input: string[] }
|
|
86
|
+
>(REGISTER_MULTIPLE_TAGS, {
|
|
87
|
+
onCompleted: (data) => {
|
|
88
|
+
if (typeof callback === 'function') {
|
|
89
|
+
callback(data.registerMultipleTags)
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Register multiple tags with the provided names.
|
|
96
|
+
*
|
|
97
|
+
* @param {string[]} tags - Array of tag names.
|
|
98
|
+
* @returns {Promise<IResponseTag>} - Mutation response.
|
|
99
|
+
*/
|
|
100
|
+
const handleRegisterTags = async (tags: string[]): Promise<IResponseTag> => {
|
|
101
|
+
if (!Array.isArray(tags) || tags.length === 0 || tags.some(tag => typeof tag !== 'string')) {
|
|
102
|
+
throw new Error('Tag list must be a non-empty array of strings.')
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const response = await registerMultipleTags({
|
|
106
|
+
variables: {
|
|
107
|
+
input: tags
|
|
108
|
+
},
|
|
109
|
+
update: (cache, { data }) => {
|
|
110
|
+
if (!data?.registerMultipleTags?.data?.length) return;
|
|
111
|
+
|
|
112
|
+
const newTags = data.registerMultipleTags.data;
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const existing = client.readQuery({ query: GET_ALL_TAGS });
|
|
116
|
+
|
|
117
|
+
const updatedTags = [
|
|
118
|
+
...newTags,
|
|
119
|
+
...(existing?.getAllTags?.data || [])
|
|
120
|
+
];
|
|
121
|
+
|
|
122
|
+
cache.writeQuery({
|
|
123
|
+
query: GET_ALL_TAGS,
|
|
124
|
+
data: {
|
|
125
|
+
getAllTags: {
|
|
126
|
+
...existing.getAllTags,
|
|
127
|
+
data: updatedTags,
|
|
128
|
+
pagination: {
|
|
129
|
+
...existing.getAllTags.pagination,
|
|
130
|
+
totalRecords: updatedTags.length,
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.warn('Failed to update cache for GET_ALL_TAGS:', error);
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
})
|
|
140
|
+
return response.data?.registerMultipleTags ?? {
|
|
141
|
+
success: false,
|
|
142
|
+
message: 'No response from server',
|
|
143
|
+
errors: [],
|
|
144
|
+
data: []
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return [
|
|
149
|
+
handleRegisterTags,
|
|
150
|
+
{
|
|
151
|
+
loading,
|
|
152
|
+
error,
|
|
153
|
+
data: data?.registerMultipleTags ?? null
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL mutation for updating a dashboard component.
|
|
5
|
+
*/
|
|
6
|
+
const UPDATE_DASHBOARD_COMPONENT = gql`
|
|
7
|
+
mutation UpdateDashboardComponent($input: [DashboardComponentUpdateInput]) {
|
|
8
|
+
updateDashboardComponent(input: $input) {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
data {
|
|
12
|
+
id
|
|
13
|
+
idStore
|
|
14
|
+
idUser
|
|
15
|
+
coordinates
|
|
16
|
+
createAt
|
|
17
|
+
updateAt
|
|
18
|
+
title
|
|
19
|
+
}
|
|
20
|
+
errors {
|
|
21
|
+
path
|
|
22
|
+
message
|
|
23
|
+
type
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Types for the mutation response and input.
|
|
31
|
+
*/
|
|
32
|
+
interface DashboardComponent {
|
|
33
|
+
id: string;
|
|
34
|
+
idStore: string;
|
|
35
|
+
idUser: string;
|
|
36
|
+
coordinates: any;
|
|
37
|
+
createAt: string;
|
|
38
|
+
updateAt: string;
|
|
39
|
+
title: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface ErrorResponse {
|
|
43
|
+
message: string;
|
|
44
|
+
field?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface UpdateDashboardComponentResponse {
|
|
48
|
+
updateDashboardComponent: {
|
|
49
|
+
success: boolean;
|
|
50
|
+
message?: string;
|
|
51
|
+
data?: DashboardComponent;
|
|
52
|
+
errors?: ErrorResponse[];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface UpdateDashboardComponentInput {
|
|
57
|
+
id: string;
|
|
58
|
+
coordinates?: any;
|
|
59
|
+
title?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Custom hook to update a dashboard component.
|
|
64
|
+
*/
|
|
65
|
+
export const useUpdateDashboardComponent = () => {
|
|
66
|
+
const [mutate, { loading, error, data }] = useMutation<
|
|
67
|
+
UpdateDashboardComponentResponse,
|
|
68
|
+
{ input: UpdateDashboardComponentInput[] }
|
|
69
|
+
>(UPDATE_DASHBOARD_COMPONENT);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Calls the mutation with the provided input.
|
|
73
|
+
* @param input DashboardComponentUpdateInput
|
|
74
|
+
*/
|
|
75
|
+
const updateComponent = async (input: UpdateDashboardComponentInput[]) => {
|
|
76
|
+
try {
|
|
77
|
+
const response = await mutate({ variables: { input } });
|
|
78
|
+
return response.data?.updateDashboardComponent;
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error('UpdateDashboardComponent Error:', err);
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
updateComponent,
|
|
87
|
+
loading,
|
|
88
|
+
error,
|
|
89
|
+
data: data?.updateDashboardComponent,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
@@ -2,11 +2,6 @@ export const isValidCodeRef = (codeRef) => {
|
|
|
2
2
|
return typeof codeRef === 'string' && codeRef.trim() !== ''
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
export const isValidState = (state) => {
|
|
6
|
-
const validStates = [1, 2, 3, 4, 5]
|
|
7
|
-
return validStates.includes(state)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
export const updateExistingOrders = (
|
|
11
6
|
existingOrders,
|
|
12
7
|
pCodeRef,
|
|
@@ -17,11 +12,11 @@ export const updateExistingOrders = (
|
|
|
17
12
|
// existingOrders no es un objeto válido
|
|
18
13
|
return existingOrders
|
|
19
14
|
}
|
|
20
|
-
if (typeof pCodeRef !== 'string'
|
|
21
|
-
// Los tipos de datos de pCodeRef
|
|
15
|
+
if (typeof pCodeRef !== 'string') {
|
|
16
|
+
// Los tipos de datos de pCodeRef
|
|
22
17
|
return existingOrders
|
|
23
18
|
}
|
|
24
|
-
if (!isValidCodeRef(pCodeRef)
|
|
19
|
+
if (!isValidCodeRef(pCodeRef)) {
|
|
25
20
|
// Valores de entrada no válidos, devuelve existingOrders sin cambios
|
|
26
21
|
return existingOrders
|
|
27
22
|
}
|
|
@@ -41,7 +36,6 @@ export const updateExistingOrders = (
|
|
|
41
36
|
// El valor de pSState no está mapeado a ninguna propiedad existente en existingOrders
|
|
42
37
|
return existingOrders
|
|
43
38
|
}
|
|
44
|
-
|
|
45
39
|
Object.keys(updatedExistingOrders).forEach((key) => {
|
|
46
40
|
if (Array.isArray(updatedExistingOrders[key])) {
|
|
47
41
|
const oneSale = updatedExistingOrders[key].find((order) => {
|
|
@@ -2,8 +2,30 @@ import { useMutation } from '@apollo/client'
|
|
|
2
2
|
import { updateCacheMod } from '../../utils'
|
|
3
3
|
import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL, GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL } from '../useProductsFood/queriesStore'
|
|
4
4
|
|
|
5
|
-
export const useUpdateExtProductFoodsSubOptional = (
|
|
6
|
-
|
|
5
|
+
export const useUpdateExtProductFoodsSubOptional = ({
|
|
6
|
+
sendNotification = (args) => { return args }
|
|
7
|
+
} = {}) => {
|
|
8
|
+
const [updateExtProductSubOptional] = useMutation(GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL, {
|
|
9
|
+
onCompleted: (data) => {
|
|
10
|
+
console.log('🚀 ~ useUpdateExtProductFoodsSubOptional ~ data:', data)
|
|
11
|
+
const { updateExtProductSubOptional } = data ?? {}
|
|
12
|
+
const { success, message, errors } = updateExtProductSubOptional ?? {}
|
|
13
|
+
sendNotification({
|
|
14
|
+
description: message,
|
|
15
|
+
title: success ? 'Sub item creado' : 'Error',
|
|
16
|
+
backgroundColor: success ? 'success' : 'error'
|
|
17
|
+
})
|
|
18
|
+
for (const err of errors || []) {
|
|
19
|
+
const { message: msg } = err || {}
|
|
20
|
+
sendNotification({
|
|
21
|
+
description: msg,
|
|
22
|
+
title: 'Error',
|
|
23
|
+
backgroundColor: 'error'
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return data
|
|
27
|
+
}
|
|
28
|
+
})
|
|
7
29
|
|
|
8
30
|
const handleMutateExtProductFoodsSubOptional = ({
|
|
9
31
|
pId,
|
|
@@ -12,7 +34,7 @@ export const useUpdateExtProductFoodsSubOptional = () => {
|
|
|
12
34
|
id,
|
|
13
35
|
state = 1
|
|
14
36
|
}) => {
|
|
15
|
-
|
|
37
|
+
updateExtProductSubOptional({
|
|
16
38
|
variables: {
|
|
17
39
|
input: {
|
|
18
40
|
pId,
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { UPDATE_MULTI_EXTRAS_PRODUCT_FOOD } from './queries'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Custom hook para manejar la actualización de múltiples extras de productos alimenticios.
|
|
6
|
+
* @param {Function} cleanLines - Función para limpiar líneas después de completar la mutación.
|
|
7
|
+
* @param {Function} handleCleanLines - Función.
|
|
8
|
+
* @returns {Array} Retorna un array con la función de mutación y el estado de carga.
|
|
9
|
+
*/
|
|
10
|
+
export const useUpdateMultipleExtProduct = ({
|
|
11
|
+
cleanLines = () => { },
|
|
12
|
+
handleCleanLines = () => { },
|
|
13
|
+
sendNotification = () => { }
|
|
14
|
+
} = {
|
|
15
|
+
cleanLines: () => { },
|
|
16
|
+
handleCleanLines: () => { },
|
|
17
|
+
sendNotification: () => { }
|
|
18
|
+
}) => {
|
|
19
|
+
const [updateMultipleExtProduct, { loading }] = useMutation(UPDATE_MULTI_EXTRAS_PRODUCT_FOOD, {
|
|
20
|
+
onCompleted: (data) => {
|
|
21
|
+
const { updateMultipleExtProduct: result } = data
|
|
22
|
+
const { success, message } = result ?? {}
|
|
23
|
+
sendNotification({
|
|
24
|
+
title: message,
|
|
25
|
+
description: success ? 'Operación exitosa' : 'Error',
|
|
26
|
+
backgroundColor: success ? 'success' : 'error'
|
|
27
|
+
})
|
|
28
|
+
cleanLines()
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return [updateMultipleExtProduct, { loading }]
|
|
33
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
// CREATE EXTRAS PRODUCT
|
|
4
|
+
export const UPDATE_MULTI_EXTRAS_PRODUCT_FOOD = gql`
|
|
5
|
+
mutation updateMultipleExtProduct($inputLineItems: ILineItemsExtraFinal) {
|
|
6
|
+
updateMultipleExtProduct(inputLineItems: $inputLineItems) {
|
|
7
|
+
success
|
|
8
|
+
message
|
|
9
|
+
data {
|
|
10
|
+
pId
|
|
11
|
+
exPid
|
|
12
|
+
exState
|
|
13
|
+
extraName
|
|
14
|
+
extraPrice
|
|
15
|
+
state
|
|
16
|
+
createdAt
|
|
17
|
+
updatedAt
|
|
18
|
+
}
|
|
19
|
+
errors {
|
|
20
|
+
path
|
|
21
|
+
message
|
|
22
|
+
type
|
|
23
|
+
context {
|
|
24
|
+
limit
|
|
25
|
+
value
|
|
26
|
+
label
|
|
27
|
+
key
|
|
28
|
+
__typename
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`
|
|
@@ -14,7 +14,6 @@ export const useUploadProducts = ({
|
|
|
14
14
|
sendNotification: () => { return null }
|
|
15
15
|
}) => {
|
|
16
16
|
const [data, setData] = useState([])
|
|
17
|
-
console.log("🚀 ~ data:", data)
|
|
18
17
|
const [isLoading, setIsLoading] = useState(false)
|
|
19
18
|
const [active, setActive] = useState(STEPS.UPLOAD_FILE)
|
|
20
19
|
const [overActive, setOverActive] = useState(STEPS.UPLOAD_FILE)
|
package/src/utils/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { randomBytes } from 'crypto'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @description It takes an array of elements and returns an object with a submit hook for each element.
|
|
3
5
|
* @version 0.1.1
|
|
@@ -57,15 +59,33 @@ export const getCurrentDomain = () => {
|
|
|
57
59
|
return typeof window !== 'undefined' && window.location.hostname
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Generates a cryptographically secure random string of given length.
|
|
64
|
+
* @param length - Desired length of the generated code.
|
|
65
|
+
* @param options - Optional prefix/suffix configuration.
|
|
66
|
+
* @returns Random alphanumeric string with optional prefix and suffix.
|
|
67
|
+
*/
|
|
68
|
+
export const RandomCode = (
|
|
69
|
+
length,
|
|
70
|
+
options
|
|
71
|
+
) => {
|
|
72
|
+
if (length <= 0) {
|
|
73
|
+
throw new Error('Length must be greater than 0')
|
|
74
|
+
}
|
|
75
|
+
|
|
62
76
|
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
|
|
63
77
|
const charactersLength = characters.length
|
|
78
|
+
|
|
79
|
+
// Generate enough random bytes
|
|
80
|
+
const randomBuffer = randomBytes(length)
|
|
81
|
+
let code = ''
|
|
82
|
+
|
|
64
83
|
for (let i = 0; i < length; i++) {
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
const index = randomBuffer[i] % charactersLength
|
|
85
|
+
code += characters.charAt(index)
|
|
67
86
|
}
|
|
68
|
-
|
|
87
|
+
|
|
88
|
+
return `${options?.prefix ?? ''}${code}${options?.suffix ?? ''}`
|
|
69
89
|
}
|
|
70
90
|
|
|
71
91
|
/**
|
|
@@ -212,3 +232,75 @@ export const paymentMethodCards = [
|
|
|
212
232
|
export const CATEGORY_EMPTY = 'NINGUNO'
|
|
213
233
|
|
|
214
234
|
export * from './UtilDateRange'
|
|
235
|
+
|
|
236
|
+
const cleanValue = ({ value, decimalSeparator, groupSeparator, allowDecimals, decimalsLimit, allowNegativeValue, disableAbbreviations }) => {
|
|
237
|
+
if (typeof value !== 'string') return null
|
|
238
|
+
|
|
239
|
+
// Remove currency symbols and whitespace
|
|
240
|
+
let cleaned = value.replace(/[$€£¥]/g, '').trim()
|
|
241
|
+
|
|
242
|
+
// Handle abbreviations like K, M, B
|
|
243
|
+
if (!disableAbbreviations) {
|
|
244
|
+
cleaned = cleaned.replace(/([kmb])\b/i, (match) => {
|
|
245
|
+
const multipliers = { k: 1e3, m: 1e6, b: 1e9 }
|
|
246
|
+
return multipliers[match.toLowerCase()] ? `*${multipliers[match.toLowerCase()]}` : ''
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Replace group separator with empty string
|
|
251
|
+
if (groupSeparator) {
|
|
252
|
+
cleaned = cleaned.replace(new RegExp(`\\${groupSeparator}`, 'g'), '')
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Replace decimal separator with a dot
|
|
256
|
+
if (decimalSeparator) {
|
|
257
|
+
cleaned = cleaned.replace(new RegExp(`\\${decimalSeparator}`, 'g'), '.')
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Remove any non-numeric characters except for the decimal point
|
|
261
|
+
cleaned = cleaned.replace(/[^0-9.-]/g, '')
|
|
262
|
+
|
|
263
|
+
// Limit decimals if specified
|
|
264
|
+
if (allowDecimals && decimalsLimit > 0) {
|
|
265
|
+
const parts = cleaned.split('.')
|
|
266
|
+
if (parts.length > 1) {
|
|
267
|
+
parts[1] = parts[1].slice(0, decimalsLimit)
|
|
268
|
+
cleaned = parts.join('.')
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Handle negative values
|
|
273
|
+
if (!allowNegativeValue) {
|
|
274
|
+
cleaned = cleaned.replace(/-/g, '')
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return cleaned
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Converts a formatted string with group and decimal separators into a float number.
|
|
281
|
+
*
|
|
282
|
+
* @param value - The formatted string input, e.g., "$ 1.234,56"
|
|
283
|
+
* @param decimalSeparator - The character used as decimal separator, e.g., ','
|
|
284
|
+
* @param groupSeparator - The character used as group/thousands separator, e.g., '.'
|
|
285
|
+
* @returns The parsed float value or null if input is invalid
|
|
286
|
+
*/
|
|
287
|
+
export function parseFormattedFloat (value) {
|
|
288
|
+
if (!value) return 0
|
|
289
|
+
const options = {
|
|
290
|
+
decimalSeparator: ',',
|
|
291
|
+
groupSeparator: '.',
|
|
292
|
+
allowDecimals: true,
|
|
293
|
+
decimalsLimit: 20,
|
|
294
|
+
allowNegativeValue: true,
|
|
295
|
+
disableAbbreviations: false
|
|
296
|
+
}
|
|
297
|
+
const cleaned = cleanValue({ value, ...options })
|
|
298
|
+
|
|
299
|
+
const normalized = (typeof options.decimalSeparator === 'string' && options.decimalSeparator !== '')
|
|
300
|
+
// Replace the decimal separator with a dot for parsing
|
|
301
|
+
? cleaned.replace(options.decimalSeparator, '.')
|
|
302
|
+
: cleaned
|
|
303
|
+
|
|
304
|
+
const num = parseFloat(normalized)
|
|
305
|
+
return isNaN(num) ? 0 : num
|
|
306
|
+
}
|