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,31 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const CREATE_PROVIDERS = gql`
|
|
4
|
+
mutation registerProviders($input: IProviders) {
|
|
5
|
+
registerProviders(input: $input) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
export const GET_ALL_PROVIDERS = gql`
|
|
12
|
+
query getAllProviders($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
|
|
13
|
+
getAllProviders(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
|
|
14
|
+
idProvider
|
|
15
|
+
idStore
|
|
16
|
+
prImage
|
|
17
|
+
prPathImage
|
|
18
|
+
PrNit
|
|
19
|
+
prName
|
|
20
|
+
PrNumberPhone
|
|
21
|
+
PrNumberIdentity
|
|
22
|
+
PrAdres
|
|
23
|
+
PrMail
|
|
24
|
+
TotalBysPr
|
|
25
|
+
TotalDeuda
|
|
26
|
+
prState
|
|
27
|
+
DatCre
|
|
28
|
+
DatMod
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMutation } from "@apollo/client"
|
|
2
|
+
import { CREATE_PROVIDERS } from "../queries"
|
|
3
|
+
|
|
4
|
+
export const useProvidersCreateStore = ({ setAlertBox = () => { return } } = {}) => {
|
|
5
|
+
|
|
6
|
+
const [registerProviders, { loading, error }] = useMutation(CREATE_PROVIDERS, {
|
|
7
|
+
onCompleted: (data) => {
|
|
8
|
+
setAlertBox({ message: `${data.registerProviders.message}` })
|
|
9
|
+
}
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
return [registerProviders, { loading, error }]
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useQuery } from "@apollo/client"
|
|
2
|
+
import { GET_ALL_PROVIDERS } from "../queries"
|
|
3
|
+
|
|
4
|
+
export const useProvidersStore = () => {
|
|
5
|
+
const {
|
|
6
|
+
data,
|
|
7
|
+
fetchMore,
|
|
8
|
+
loading,
|
|
9
|
+
error,
|
|
10
|
+
called
|
|
11
|
+
} = useQuery(GET_ALL_PROVIDERS, {
|
|
12
|
+
fetchPolicy: 'cache-and-network',
|
|
13
|
+
notifyOnNetworkStatusChange: true,
|
|
14
|
+
nextFetchPolicy: 'cache-first',
|
|
15
|
+
refetchWritePolicy: 'merge'
|
|
16
|
+
})
|
|
17
|
+
const providerData = data?.getAllProviders || []
|
|
18
|
+
return [providerData, {
|
|
19
|
+
fetchMore,
|
|
20
|
+
called,
|
|
21
|
+
error,
|
|
22
|
+
loading
|
|
23
|
+
}]
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useQuery } from "@apollo/client"
|
|
2
|
+
import { GET_ALL_PROVIDERS } from "./queries"
|
|
3
|
+
|
|
4
|
+
export const useProvidersStore = () => {
|
|
5
|
+
const {
|
|
6
|
+
data,
|
|
7
|
+
fetchMore,
|
|
8
|
+
loading,
|
|
9
|
+
error,
|
|
10
|
+
called
|
|
11
|
+
} = useQuery(GET_ALL_PROVIDERS, {
|
|
12
|
+
fetchPolicy: 'cache-and-network',
|
|
13
|
+
notifyOnNetworkStatusChange: true,
|
|
14
|
+
nextFetchPolicy: 'cache-first',
|
|
15
|
+
refetchWritePolicy: 'merge'
|
|
16
|
+
})
|
|
17
|
+
const providerData = data?.getAllProviders || []
|
|
18
|
+
return [providerData, {
|
|
19
|
+
fetchMore,
|
|
20
|
+
called,
|
|
21
|
+
error,
|
|
22
|
+
loading
|
|
23
|
+
}]
|
|
24
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const CREATE_PROVIDERS = gql`
|
|
4
|
+
mutation registerProviders($input: IProviders) {
|
|
5
|
+
registerProviders(input: $input) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
export const GET_ALL_PROVIDERS = gql`
|
|
12
|
+
query getAllProviders($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
|
|
13
|
+
getAllProviders(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
|
|
14
|
+
idProvider
|
|
15
|
+
idStore
|
|
16
|
+
prImage
|
|
17
|
+
prPathImage
|
|
18
|
+
PrNit
|
|
19
|
+
prName
|
|
20
|
+
PrNumberPhone
|
|
21
|
+
PrNumberIdentity
|
|
22
|
+
PrAdres
|
|
23
|
+
PrMail
|
|
24
|
+
TotalBysPr
|
|
25
|
+
TotalDeuda
|
|
26
|
+
prState
|
|
27
|
+
DatCre
|
|
28
|
+
DatMod
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
`
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useQuery } from '@apollo/client';
|
|
3
|
+
import { GET_All_RATING_STORE } from './queries';
|
|
4
|
+
|
|
5
|
+
export const useRatingData = () => {
|
|
6
|
+
const { data: dataRating } = useQuery(GET_All_RATING_STORE);
|
|
7
|
+
|
|
8
|
+
const calculateTotalRatings = (ratings = []) => {
|
|
9
|
+
return ratings.reduce(
|
|
10
|
+
(total, rating) => ({
|
|
11
|
+
rAppearance: total?.rAppearance + rating.rAppearance,
|
|
12
|
+
rTasty: total?.rTasty + rating.rTasty,
|
|
13
|
+
rGoodCondition: total?.rGoodCondition + rating.rGoodCondition,
|
|
14
|
+
rGoodTemperature: total?.rGoodTemperature + rating.rGoodTemperature,
|
|
15
|
+
}),
|
|
16
|
+
{
|
|
17
|
+
rAppearance: 0,
|
|
18
|
+
rTasty: 0,
|
|
19
|
+
rGoodCondition: 0,
|
|
20
|
+
rGoodTemperature: 0,
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const [totalRatings, setTotalRatings] = useState(
|
|
26
|
+
calculateTotalRatings(dataRating?.getAllRating || [])
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setTotalRatings(calculateTotalRatings(dataRating?.getAllRating || []));
|
|
31
|
+
}, [dataRating]);
|
|
32
|
+
|
|
33
|
+
const dataArr = [
|
|
34
|
+
{
|
|
35
|
+
name: 'Buena apariencia',
|
|
36
|
+
value: totalRatings.rAppearance || 0,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'Es deliciosa',
|
|
40
|
+
value: totalRatings.rTasty || 0,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: 'Buenas condiciones',
|
|
44
|
+
value: totalRatings.rGoodCondition || 0,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'Buena temperatura',
|
|
48
|
+
value: totalRatings.rGoodTemperature || 0,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
return dataArr;
|
|
53
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_All_RATING_STORE = gql`
|
|
4
|
+
query getAllRating($idStore: ID){
|
|
5
|
+
getAllRating(idStore: $idStore){
|
|
6
|
+
idStore
|
|
7
|
+
rId
|
|
8
|
+
id
|
|
9
|
+
rAppearance
|
|
10
|
+
rTasty
|
|
11
|
+
rGoodTemperature
|
|
12
|
+
rGoodCondition
|
|
13
|
+
rState
|
|
14
|
+
createAt
|
|
15
|
+
updateAt
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { DELETE_CAT_EXTRA_PRODUCTS } from './queries'
|
|
3
|
+
|
|
4
|
+
export const useRemoveExtraProductFoodsOptional = () => {
|
|
5
|
+
const [DeleteExtProductFoodsOptional, { loading, error }] = useMutation(DELETE_CAT_EXTRA_PRODUCTS)
|
|
6
|
+
|
|
7
|
+
const handleDeleteOptional = async elem => {
|
|
8
|
+
const { state, opExPid } = elem || {}
|
|
9
|
+
DeleteExtProductFoodsOptional({
|
|
10
|
+
variables: {
|
|
11
|
+
state: state,
|
|
12
|
+
opExPid: opExPid,
|
|
13
|
+
isCustomOpExPid: true
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
handleDeleteOptional,
|
|
19
|
+
DeleteExtProductFoodsOptional,
|
|
20
|
+
loading,
|
|
21
|
+
error
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { gql } from "@apollo/client";
|
|
2
|
+
|
|
3
|
+
export const DELETE_CAT_EXTRA_PRODUCTS = gql`
|
|
4
|
+
mutation DeleteExtProductFoodsOptional($opExPid: ID, $state: Int, $isCustomOpExPid: Boolean) {
|
|
5
|
+
DeleteExtProductFoodsOptional(opExPid: $opExPid, state: $state, isCustomOpExPid: $isCustomOpExPid) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const GET_EXTRAS_PRODUCT_FOOD_OPTIONAL = gql`
|
|
13
|
+
query ExtProductFoodsOptionalAll(
|
|
14
|
+
$search: String
|
|
15
|
+
$min: Int
|
|
16
|
+
$max: Int
|
|
17
|
+
$pId: ID
|
|
18
|
+
) {
|
|
19
|
+
ExtProductFoodsOptionalAll(
|
|
20
|
+
search: $search
|
|
21
|
+
min: $min
|
|
22
|
+
max: $max
|
|
23
|
+
pId: $pId
|
|
24
|
+
) {
|
|
25
|
+
pId
|
|
26
|
+
opExPid
|
|
27
|
+
OptionalProName
|
|
28
|
+
state
|
|
29
|
+
code
|
|
30
|
+
numbersOptionalOnly
|
|
31
|
+
pDatCre
|
|
32
|
+
required
|
|
33
|
+
pDatMod
|
|
34
|
+
ExtProductFoodsSubOptionalAll {
|
|
35
|
+
pId
|
|
36
|
+
opExPid
|
|
37
|
+
idStore
|
|
38
|
+
opSubExPid
|
|
39
|
+
OptionalSubProName
|
|
40
|
+
exCodeOptionExtra
|
|
41
|
+
exCode
|
|
42
|
+
state
|
|
43
|
+
pDatCre
|
|
44
|
+
pDatMod
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import { useQuery } from '@apollo/client'
|
|
1
|
+
import { useQuery, useLazyQuery } from '@apollo/client'
|
|
2
2
|
import { GET_ALL_SALES, GET_ALL_TOTAL_SALES } from './queries'
|
|
3
3
|
|
|
4
4
|
export const useReport = ({
|
|
5
|
+
fromDate = '',
|
|
5
6
|
more,
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
search = '',
|
|
8
|
+
channel = null,
|
|
9
|
+
toDate = '',
|
|
10
|
+
lazyQuery = false
|
|
8
11
|
}) => {
|
|
9
|
-
const { data
|
|
12
|
+
const [getAllSalesStore, { data: lazyDataSales, loading: lazyLoading }] = useLazyQuery(GET_ALL_SALES)
|
|
13
|
+
|
|
14
|
+
const { data: dataSales, fetchMore, loading } = useQuery(GET_ALL_SALES,{
|
|
10
15
|
fetchPolicy: 'network-only',
|
|
16
|
+
skip: lazyQuery,
|
|
11
17
|
variables: {
|
|
12
18
|
min: 0,
|
|
13
19
|
fromDate,
|
|
20
|
+
channel: channel,
|
|
21
|
+
search,
|
|
14
22
|
toDate,
|
|
15
23
|
max: more
|
|
16
24
|
}
|
|
@@ -22,11 +30,12 @@ export const useReport = ({
|
|
|
22
30
|
toDate,
|
|
23
31
|
}
|
|
24
32
|
})
|
|
25
|
-
|
|
33
|
+
const data = lazyQuery ? lazyDataSales : dataSales
|
|
26
34
|
|
|
27
35
|
return {
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
getAllSalesStore,
|
|
37
|
+
data: data,
|
|
38
|
+
loading: lazyLoading || loading,
|
|
30
39
|
totalSales: totalSales?.getAllSalesStoreTotal.TOTAL ?? 0,
|
|
31
40
|
restaurant: totalSales?.getAllSalesStoreTotal.restaurant ?? 0,
|
|
32
41
|
delivery: totalSales?.getAllSalesStoreTotal.delivery ?? 0,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { gql } from '@apollo/client'
|
|
2
2
|
|
|
3
3
|
export const GET_ALL_SALES = gql`
|
|
4
|
-
query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime ) {
|
|
5
|
-
getAllSalesStore(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate) {
|
|
4
|
+
query getAllSalesStore($idStore: ID,$search: String, $min: Int, $max: Int $fromDate: DateTime, $toDate: DateTime, $channel: Int) {
|
|
5
|
+
getAllSalesStore(idStore: $idStore, search: $search, min: $min, max: $max, toDate: $toDate, fromDate: $fromDate, channel: $channel) {
|
|
6
6
|
totalProductsPrice
|
|
7
|
-
channel
|
|
8
7
|
pDatCre
|
|
9
8
|
pCodeRef
|
|
9
|
+
change
|
|
10
|
+
channel
|
|
10
11
|
}
|
|
11
12
|
}
|
|
12
13
|
`
|
|
@@ -21,19 +22,33 @@ query getAllSalesStoreTotal($idStore: ID,$search: String, $min: Int, $max: Int $
|
|
|
21
22
|
}
|
|
22
23
|
`
|
|
23
24
|
export const GET_ALL_SALES_STATISTICS = gql`
|
|
24
|
-
query getAllSalesStoreStatistic(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
query getAllSalesStoreStatistic(
|
|
26
|
+
$idStore: ID
|
|
27
|
+
$search: String
|
|
28
|
+
$min: Int
|
|
29
|
+
$max: Int
|
|
30
|
+
$fromDate: DateTime
|
|
31
|
+
$toDate: DateTime
|
|
32
|
+
) {
|
|
33
|
+
getAllSalesStoreStatistic(
|
|
34
|
+
idStore: $idStore
|
|
35
|
+
search: $search
|
|
36
|
+
min: $min
|
|
37
|
+
max: $max
|
|
38
|
+
toDate: $toDate
|
|
39
|
+
fromDate: $fromDate
|
|
40
|
+
) {
|
|
41
|
+
pdpId
|
|
42
|
+
idStore
|
|
43
|
+
pCodeRef
|
|
44
|
+
payMethodPState
|
|
45
|
+
pPRecoger
|
|
46
|
+
totalProductsPrice
|
|
47
|
+
pSState
|
|
48
|
+
pDatCre
|
|
49
|
+
locationUser
|
|
50
|
+
pDatMod
|
|
51
|
+
getAllPedidoStore {
|
|
37
52
|
pdpId
|
|
38
53
|
pId
|
|
39
54
|
idStore
|
|
@@ -49,26 +64,26 @@ query getAllSalesStoreStatistic($idStore: ID,$search: String, $min: Int, $max: I
|
|
|
49
64
|
comments
|
|
50
65
|
cantProducts
|
|
51
66
|
pId
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
productFood {
|
|
68
|
+
pId
|
|
69
|
+
carProId
|
|
70
|
+
colorId
|
|
71
|
+
idStore
|
|
72
|
+
pName
|
|
73
|
+
ProPrice
|
|
74
|
+
ProDescuento
|
|
75
|
+
ProDescription
|
|
76
|
+
ValueDelivery
|
|
77
|
+
ProImage
|
|
78
|
+
ProStar
|
|
79
|
+
pState
|
|
80
|
+
pDatCre
|
|
81
|
+
pDatMod
|
|
82
|
+
}
|
|
67
83
|
}
|
|
68
84
|
}
|
|
69
85
|
}
|
|
70
86
|
}
|
|
71
|
-
}
|
|
72
87
|
`
|
|
73
88
|
|
|
74
89
|
export const GET_ONE_SALES = gql`
|
|
@@ -20,13 +20,11 @@ import {
|
|
|
20
20
|
GET_ONE_PRODUCTS_FOOD,
|
|
21
21
|
} from "../useProductsFood/queriesStore";
|
|
22
22
|
import { useStore } from "../useStore";
|
|
23
|
-
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
GET_ALL_SALES_STATISTICS,
|
|
29
|
-
} from "./queries";
|
|
23
|
+
import { CREATE_SHOPPING_CARD_TO_USER_STORE, GET_ALL_COUNT_SALES } from "./queries";
|
|
24
|
+
import { useLogout } from "../useLogout";
|
|
25
|
+
import { updateExistingOrders } from "../useUpdateExistingOrders";
|
|
26
|
+
import { useGetSale } from "../useSales/useGetSale";
|
|
27
|
+
export * from './useGetAllSales'
|
|
30
28
|
|
|
31
29
|
const initialState = {
|
|
32
30
|
PRODUCT: [],
|
|
@@ -51,9 +49,10 @@ const initializer = (initialValue = initialState) => {
|
|
|
51
49
|
|
|
52
50
|
export const useSales = ({
|
|
53
51
|
disabled,
|
|
54
|
-
sendNotification,
|
|
55
52
|
router,
|
|
56
|
-
|
|
53
|
+
sendNotification = () => { return },
|
|
54
|
+
setAlertBox = () => { return },
|
|
55
|
+
setSalesOpen = () => { return },
|
|
57
56
|
}) => {
|
|
58
57
|
const domain = getCurrentDomain();
|
|
59
58
|
const [loadingSale, setLoadingSale] = useState(false);
|
|
@@ -84,22 +83,31 @@ export const useSales = ({
|
|
|
84
83
|
const [loadingExtraProduct, setLoadingExtraProduct] = useState(false);
|
|
85
84
|
const [dataOptional, setDataOptional] = useState([]);
|
|
86
85
|
const [dataExtra, setDataExtra] = useState([]);
|
|
86
|
+
const [onClickLogout] = useLogout({ setAlertBox })
|
|
87
87
|
|
|
88
88
|
const [registerSalesStore, { loading: loadingRegisterSale }] = useMutation(
|
|
89
89
|
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
90
90
|
{
|
|
91
91
|
onCompleted: (data) => {
|
|
92
92
|
const message = `${data?.registerSalesStore?.Response?.message}`;
|
|
93
|
-
const
|
|
93
|
+
const isSuccess = data?.registerSalesStore?.Response.success === true
|
|
94
|
+
const error = isSuccess
|
|
94
95
|
? "Éxito"
|
|
95
96
|
: "Error";
|
|
97
|
+
if (message === 'Token expired') {
|
|
98
|
+
setSalesOpen(false)
|
|
99
|
+
onClickLogout()
|
|
100
|
+
}
|
|
96
101
|
sendNotification({
|
|
97
|
-
backgroundColor:
|
|
102
|
+
backgroundColor: isSuccess ? 'success' : 'error',
|
|
98
103
|
title: error,
|
|
99
104
|
description: message
|
|
100
105
|
});
|
|
101
106
|
setAlertBox({ message: message, type: "success" });
|
|
102
|
-
|
|
107
|
+
|
|
108
|
+
if (isSuccess) {
|
|
109
|
+
setOpenCurrentSale(isSuccess);
|
|
110
|
+
}
|
|
103
111
|
},
|
|
104
112
|
onError: (error) => {
|
|
105
113
|
console.log(error)
|
|
@@ -754,6 +762,7 @@ export const useSales = ({
|
|
|
754
762
|
}
|
|
755
763
|
const totalProductsPrice = totalProductPrice;
|
|
756
764
|
const client = useApolloClient()
|
|
765
|
+
const { getOnePedidoStore, error: saleError } = useGetSale()
|
|
757
766
|
|
|
758
767
|
const handleSubmit = () => {
|
|
759
768
|
if (!values?.cliId)
|
|
@@ -777,14 +786,15 @@ export const useSales = ({
|
|
|
777
786
|
discount: discount.discount || 0,
|
|
778
787
|
totalProductsPrice: totalProductsPrice || 0,
|
|
779
788
|
}
|
|
780
|
-
})
|
|
781
|
-
.then((responseRegisterR) => {
|
|
789
|
+
}).then((responseRegisterR) => {
|
|
782
790
|
if (responseRegisterR) {
|
|
783
791
|
const { data } = responseRegisterR || {};
|
|
784
792
|
const { registerSalesStore } = data || {};
|
|
785
793
|
const { Response } = registerSalesStore || {};
|
|
786
|
-
|
|
787
|
-
|
|
794
|
+
const success = Response?.success === true
|
|
795
|
+
if (success) {
|
|
796
|
+
console.log(responseRegisterR)
|
|
797
|
+
if (!process.env.NODE_ENV === 'development') dispatch({ type: 'REMOVE_ALL_PRODUCTS' })
|
|
788
798
|
client.query({
|
|
789
799
|
query: GET_ALL_COUNT_SALES,
|
|
790
800
|
fetchPolicy: 'network-only',
|
|
@@ -792,6 +802,28 @@ export const useSales = ({
|
|
|
792
802
|
client.writeQuery({ query: GET_ALL_COUNT_SALES, data: { getTodaySales: data.countSales.todaySales } })
|
|
793
803
|
}
|
|
794
804
|
})
|
|
805
|
+
getOnePedidoStore({
|
|
806
|
+
variables: {
|
|
807
|
+
pCodeRef: code || ''
|
|
808
|
+
}
|
|
809
|
+
}).then((res) => {
|
|
810
|
+
console.log(res)
|
|
811
|
+
const currentSale = res?.data?.getOnePedidoStore
|
|
812
|
+
if (currentSale && !saleError) {
|
|
813
|
+
client.cache.modify({
|
|
814
|
+
fields: {
|
|
815
|
+
getAllOrdersFromStore(existingOrders = []) {
|
|
816
|
+
try {
|
|
817
|
+
const cache = updateExistingOrders(existingOrders, code, 4, currentSale)
|
|
818
|
+
return cache
|
|
819
|
+
} catch (e) {
|
|
820
|
+
return existingOrders
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
})
|
|
825
|
+
}
|
|
826
|
+
})
|
|
795
827
|
router.push(
|
|
796
828
|
{
|
|
797
829
|
query: {
|
|
@@ -802,7 +834,7 @@ export const useSales = ({
|
|
|
802
834
|
undefined,
|
|
803
835
|
{ shallow: true }
|
|
804
836
|
);
|
|
805
|
-
|
|
837
|
+
if (!process.env.NODE_ENV === 'development') setValues({})
|
|
806
838
|
}
|
|
807
839
|
}
|
|
808
840
|
setLoadingSale(false);
|
|
@@ -830,18 +862,17 @@ export const useSales = ({
|
|
|
830
862
|
const optionalAll = await ExtProductFoodsSubOptionalAll({
|
|
831
863
|
variables: { pId },
|
|
832
864
|
});
|
|
833
|
-
const optionalFetch = optionalAll
|
|
865
|
+
const optionalFetch = optionalAll?.data?.ExtProductFoodsOptionalAll || [];
|
|
834
866
|
setDataOptional(optionalFetch || []);
|
|
835
867
|
const existOptionalCookies = originalArray?.dataOptional;
|
|
836
868
|
const filteredDataOptional = existOptionalCookies?.length
|
|
837
869
|
? existOptionalCookies
|
|
838
870
|
?.map((obj) => {
|
|
839
|
-
const filteredSubOptions =
|
|
840
|
-
|
|
841
|
-
(subObj) => subObj.check === true
|
|
871
|
+
const filteredSubOptions = obj?.ExtProductFoodsSubOptionalAll?.filter(
|
|
872
|
+
(subObj) => subObj?.check === true
|
|
842
873
|
);
|
|
843
874
|
// Excluya todo el objeto padre si filteredSubOptions está vacío
|
|
844
|
-
if (filteredSubOptions
|
|
875
|
+
if (filteredSubOptions?.length === 0) {
|
|
845
876
|
return null;
|
|
846
877
|
}
|
|
847
878
|
return {
|
|
@@ -94,52 +94,60 @@ export const GET_ALL_SALES_STATISTICS = gql`
|
|
|
94
94
|
`;
|
|
95
95
|
|
|
96
96
|
export const GET_ONE_SALES = gql`
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
query getOnePedidoStore($pCodeRef: String) {
|
|
98
|
+
getOnePedidoStore(pCodeRef: $pCodeRef) {
|
|
99
|
+
pdpId
|
|
100
|
+
pCodeRef
|
|
101
|
+
idStore
|
|
102
|
+
pPDate
|
|
103
|
+
channel
|
|
104
|
+
change
|
|
105
|
+
pSState
|
|
106
|
+
pDatCre
|
|
107
|
+
id
|
|
108
|
+
pDatMod
|
|
109
|
+
pPRecoger
|
|
110
|
+
payMethodPState
|
|
111
|
+
pdpId
|
|
112
|
+
totalProductsPrice
|
|
113
|
+
locationUser
|
|
114
|
+
getUser {
|
|
115
|
+
id
|
|
116
|
+
email
|
|
117
|
+
uPhoNum
|
|
118
|
+
ULocation
|
|
119
|
+
}
|
|
120
|
+
getAllPedidoStore {
|
|
99
121
|
pdpId
|
|
100
|
-
pCodeRef
|
|
101
122
|
idStore
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
pDatCre
|
|
106
|
-
pDatMod
|
|
107
|
-
pPRecoger
|
|
108
|
-
payMethodPState
|
|
109
|
-
pdpId
|
|
110
|
-
totalProductsPrice
|
|
111
|
-
locationUser
|
|
112
|
-
getAllPedidoStore {
|
|
113
|
-
pdpId
|
|
114
|
-
idStore
|
|
115
|
-
pCodeRef
|
|
123
|
+
pCodeRef
|
|
124
|
+
ShoppingCard
|
|
125
|
+
getAllShoppingCard {
|
|
116
126
|
ShoppingCard
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
127
|
+
cantProducts
|
|
128
|
+
subProductsId
|
|
129
|
+
comments
|
|
130
|
+
pId
|
|
131
|
+
productFood {
|
|
122
132
|
pId
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
pDatCre
|
|
137
|
-
pDatMod
|
|
138
|
-
}
|
|
133
|
+
carProId
|
|
134
|
+
colorId
|
|
135
|
+
idStore
|
|
136
|
+
pName
|
|
137
|
+
ProPrice
|
|
138
|
+
ProDescuento
|
|
139
|
+
ProDescription
|
|
140
|
+
ValueDelivery
|
|
141
|
+
ProImage
|
|
142
|
+
ProStar
|
|
143
|
+
pState
|
|
144
|
+
pDatCre
|
|
145
|
+
pDatMod
|
|
139
146
|
}
|
|
140
147
|
}
|
|
141
148
|
}
|
|
142
149
|
}
|
|
150
|
+
}
|
|
143
151
|
`;
|
|
144
152
|
|
|
145
153
|
export const CREATE_CLIENTS = gql`
|
|
@@ -258,7 +266,9 @@ export const GET_ONE_SALE = gql`
|
|
|
258
266
|
pCodeRef
|
|
259
267
|
idStore
|
|
260
268
|
pPDate
|
|
269
|
+
id
|
|
261
270
|
channel
|
|
271
|
+
change
|
|
262
272
|
pSState
|
|
263
273
|
pDatCre
|
|
264
274
|
pDatMod
|