npm-pkg-hook 1.5.0 → 1.5.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/package.json +1 -1
- package/src/hooks/handleLogin/index.js +9 -9
- package/src/hooks/useAsideCart/index.js +7 -1
- package/src/hooks/useCart/useCart/index.js +4 -3
- package/src/hooks/useManageQueryParams/index.js +3 -3
- package/src/hooks/useRestaurant/helpers/index.js +29 -0
- package/src/hooks/useRestaurant/index.js +50 -6
- package/src/hooks/useRestaurant/queries.js +1 -2
- package/next.config.js +0 -126
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export async function handleLogin(body) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
export async function handleLogin (body) {
|
|
2
|
+
const response = await fetch(`${process.env.URL_BASE}/api/auth/login`, {
|
|
3
|
+
method: 'POST',
|
|
4
|
+
headers: { 'Content-Type': 'application/json' },
|
|
5
|
+
body: JSON.stringify(body),
|
|
6
|
+
credentials: 'include'
|
|
7
|
+
})
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
}
|
|
9
|
+
return response.json()
|
|
10
|
+
}
|
|
@@ -9,6 +9,7 @@ import { useCart, useGetCart } from '../useCart'
|
|
|
9
9
|
import { useManageQueryParams } from '../useManageQueryParams'
|
|
10
10
|
import { calculateTotalPrice } from './helpers'
|
|
11
11
|
export * from './helpers'
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Custom hook for managing the shopping cart functionality.
|
|
14
15
|
* @param {Object} props - Props to control various UI elements.
|
|
@@ -19,18 +20,23 @@ export * from './helpers'
|
|
|
19
20
|
*/
|
|
20
21
|
export const useAsideCart = ({
|
|
21
22
|
openModalProduct = false,
|
|
23
|
+
location = {},
|
|
22
24
|
setCountItemProduct = () => { },
|
|
23
25
|
setAlertBox = () => { },
|
|
24
26
|
setOpenModalProduct = () => { },
|
|
25
27
|
handleMenu = () => { }
|
|
26
28
|
} = {}) => {
|
|
29
|
+
|
|
27
30
|
const { getOneProduct } = useCart({
|
|
28
31
|
handleMenu,
|
|
29
32
|
openModalProduct,
|
|
33
|
+
location,
|
|
30
34
|
setOpenModalProduct
|
|
31
35
|
})
|
|
32
36
|
|
|
33
|
-
const { handleQuery } = useManageQueryParams(
|
|
37
|
+
const { handleQuery } = useManageQueryParams({
|
|
38
|
+
location
|
|
39
|
+
})
|
|
34
40
|
|
|
35
41
|
const [totalProductPrice, setTotalProductPrice] = useState(0)
|
|
36
42
|
|
|
@@ -5,7 +5,6 @@ import { RandomCode, updateCacheMod, numberFormat } from '../../../utils'
|
|
|
5
5
|
import { useExtProductFoodsAll, useGetOneProductsFood } from '../../useProductsFood'
|
|
6
6
|
import { useGetExtProductFoodsSubOptionalAll } from '../../useGetExtProductFoodsSubOptionalAll'
|
|
7
7
|
import { useGetCart } from '../useGetCart'
|
|
8
|
-
import { useRouter } from 'next/router'
|
|
9
8
|
import {
|
|
10
9
|
filterDataOptional,
|
|
11
10
|
filterExtra,
|
|
@@ -29,19 +28,21 @@ import { useManageQueryParams } from '../../useManageQueryParams'
|
|
|
29
28
|
* @returns The `useCart` function returns an object with the following properties and methods:
|
|
30
29
|
*/
|
|
31
30
|
export const useCart = ({
|
|
31
|
+
location = {},
|
|
32
32
|
openModalProduct = false,
|
|
33
33
|
handleMenu = () => { },
|
|
34
34
|
setOpenModalProduct = () => { },
|
|
35
35
|
setAlertBox = () => { }
|
|
36
36
|
} = {}) => {
|
|
37
37
|
// sub products
|
|
38
|
-
const { handleCleanQuery } = useManageQueryParams(
|
|
38
|
+
const { handleCleanQuery } = useManageQueryParams({
|
|
39
|
+
location
|
|
40
|
+
})
|
|
39
41
|
|
|
40
42
|
const [dataOptional, setDataOptional] = useState([])
|
|
41
43
|
const [dataExtra, setDataExtra] = useState([])
|
|
42
44
|
const [quantity, setQuantity] = useState(1)
|
|
43
45
|
const [comments, setComments] = useState('')
|
|
44
|
-
const location = useRouter()
|
|
45
46
|
const queryParamProduct = location.query.plato
|
|
46
47
|
const [registerShoppingCard] = useMutation(CREATE_SHOPPING_CARD, {
|
|
47
48
|
onError: (error) => {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function filterAndSortByDate (array = []) {
|
|
2
|
+
const isError = !Array.isArray(array) || !array.length
|
|
3
|
+
try {
|
|
4
|
+
if (isError) return []
|
|
5
|
+
|
|
6
|
+
const currentDate = new Date()
|
|
7
|
+
const sevenDaysAgo = currentDate.getTime() - 7 * 24 * 60 * 60 * 1000 // Calculating timestamp for 7 days ago
|
|
8
|
+
|
|
9
|
+
const filteredAndSorted = array.map(item => {
|
|
10
|
+
const createdAtDate = new Date(item.createdAt)
|
|
11
|
+
const isNew = createdAtDate.getTime() >= sevenDaysAgo
|
|
12
|
+
return { ...item, isNew }
|
|
13
|
+
}).sort((a, b) => {
|
|
14
|
+
// Ordenar primero por 'open' en 1 y luego por 'createdAt'
|
|
15
|
+
if (a.open !== b.open) {
|
|
16
|
+
return b.open - a.open // Orden descendente para 'open' en 1 primero
|
|
17
|
+
} else {
|
|
18
|
+
const dateA = new Date(a.createdAt).getTime()
|
|
19
|
+
const dateB = new Date(b.createdAt).getTime()
|
|
20
|
+
return dateA - dateB
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return filteredAndSorted
|
|
25
|
+
} catch (error) {
|
|
26
|
+
if (isError) return []
|
|
27
|
+
if (Array.isArray(array)) return array
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,19 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { useLazyQuery } from '@apollo/client'
|
|
2
3
|
import { GET_ALL_RESTAURANT } from './queries'
|
|
4
|
+
import { filterAndSortByDate } from './helpers'
|
|
5
|
+
import { useManageQueryParams } from '../useManageQueryParams'
|
|
3
6
|
|
|
4
|
-
export const useRestaurant = (
|
|
5
|
-
|
|
7
|
+
export const useRestaurant = ({
|
|
8
|
+
location = {
|
|
9
|
+
pathname: ''
|
|
10
|
+
}
|
|
11
|
+
} = {}) => {
|
|
12
|
+
const [loadingFilter, setLoadingFilter] = useState(false)
|
|
13
|
+
const { handleQuery, handleCleanQuery } = useManageQueryParams({
|
|
14
|
+
location
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
const [getAllStoreInStore, {
|
|
6
18
|
data,
|
|
7
19
|
loading,
|
|
8
20
|
error,
|
|
9
21
|
fetchMore
|
|
10
|
-
} =
|
|
22
|
+
}] = useLazyQuery(GET_ALL_RESTAURANT, {
|
|
11
23
|
fetchPolicy: 'cache-and-network',
|
|
12
24
|
notifyOnNetworkStatusChange: true,
|
|
13
25
|
nextFetchPolicy: 'cache-first',
|
|
14
26
|
refetchWritePolicy: 'merge',
|
|
15
27
|
context: { clientName: 'admin-store' }
|
|
16
28
|
})
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
getAllStoreInStore({})
|
|
32
|
+
}, [location])
|
|
33
|
+
const handleSendQueries = (name, value) => {
|
|
34
|
+
if (value) handleQuery(name, value)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const handleCleanQueries = (name) => {
|
|
38
|
+
handleCleanQuery(name)
|
|
39
|
+
}
|
|
40
|
+
const handleFilterStore = async () => {
|
|
41
|
+
setLoadingFilter(true)
|
|
42
|
+
try {
|
|
43
|
+
getAllStoreInStore({
|
|
44
|
+
|
|
45
|
+
}).then(() => {
|
|
46
|
+
setLoadingFilter(false)
|
|
47
|
+
})
|
|
48
|
+
} catch (error) {
|
|
49
|
+
setLoadingFilter(false)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const dataRestaurant = data?.getAllStoreInStore || []
|
|
53
|
+
const dataSort = filterAndSortByDate(dataRestaurant)
|
|
54
|
+
return [dataSort, {
|
|
55
|
+
loading,
|
|
56
|
+
loadingFilter,
|
|
57
|
+
error,
|
|
58
|
+
fetchMore,
|
|
59
|
+
handleSendQueries,
|
|
60
|
+
handleFilterStore,
|
|
61
|
+
handleCleanQueries
|
|
62
|
+
}]
|
|
19
63
|
}
|
package/next.config.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/* eslint-disable consistent-return */
|
|
2
|
-
/** @type {import('next').NextConfig} */
|
|
3
|
-
const {
|
|
4
|
-
PHASE_DEVELOPMENT_SERVER,
|
|
5
|
-
PHASE_PRODUCTION_BUILD
|
|
6
|
-
} = require('next/constants')
|
|
7
|
-
const nextConfig = {
|
|
8
|
-
reactStrictMode: true
|
|
9
|
-
}
|
|
10
|
-
module.exports = (phase) => {
|
|
11
|
-
// npm run dev or next dev
|
|
12
|
-
const isDev = phase === PHASE_DEVELOPMENT_SERVER
|
|
13
|
-
// npm run build or next build
|
|
14
|
-
const isProd = phase === PHASE_PRODUCTION_BUILD && process.env.STAGING !== '1'
|
|
15
|
-
// npm run build or next build
|
|
16
|
-
const isStaging = phase === PHASE_PRODUCTION_BUILD && process.env.STAGING === '1'
|
|
17
|
-
const env = {
|
|
18
|
-
NAMEDB: (() => {
|
|
19
|
-
if (isDev) return 'app'
|
|
20
|
-
if (isProd) return 'railway'
|
|
21
|
-
})(),
|
|
22
|
-
USERDB: (() => {
|
|
23
|
-
if (isDev) return 'root'
|
|
24
|
-
if (isProd) return 'root'
|
|
25
|
-
})(),
|
|
26
|
-
PASSDB: (() => {
|
|
27
|
-
if (isDev) return ''
|
|
28
|
-
if (isProd) return '8jpgm70bhVjWIxEFbsrt'
|
|
29
|
-
})(),
|
|
30
|
-
HOSTDB: (() => {
|
|
31
|
-
if (isDev) return 'localhost'
|
|
32
|
-
if (isProd) return 'containers-us-west-65.railway.app'
|
|
33
|
-
})(),
|
|
34
|
-
DIALECTDB: 'mysql',
|
|
35
|
-
SESSION_NAME: 'vp.client',
|
|
36
|
-
SESSION_KEY: '12ba105efUaGjihGrh0LfJHTGIBGu6jXa',
|
|
37
|
-
URL_BASE: (() => {
|
|
38
|
-
if (isDev) return 'http://localhost:3001/'
|
|
39
|
-
if (isProd) return 'http://localhost:3001/'
|
|
40
|
-
// if (isStaging) return 'Title Stg'
|
|
41
|
-
})(),
|
|
42
|
-
MAIN_URL_BASE: (() => {
|
|
43
|
-
if (isDev) return 'http://localhost:3000/'
|
|
44
|
-
if (isProd) return 'http://localhost:3000/'
|
|
45
|
-
if (isStaging) return 'Title Stg'
|
|
46
|
-
})(),
|
|
47
|
-
// URL_BASE_WS
|
|
48
|
-
URL_ADMIN_SERVER: (() => {
|
|
49
|
-
if (isDev) return 'http://localhost:4000/'
|
|
50
|
-
// if (isDev) return 'https://server-image-food.herokuapp.com/'
|
|
51
|
-
if (isProd) return 'http://localhost:4000/'
|
|
52
|
-
})(),
|
|
53
|
-
// BANCOLOMBIA
|
|
54
|
-
BANCOLOMBIA_CLIENT_KEY: '55929729-85fe-4ffe-928d-0bd317817be4',
|
|
55
|
-
BANCOLOMBIA_SECRET_KEY: 'E1aM2bV2lD7vS8cH1qJ8oN0nD7eN0eP0rM8gU0cG2lL6uY5sO7',
|
|
56
|
-
JWT_EXPIRY: 333300,
|
|
57
|
-
REFRESH_TOKEN_EXPIRY: '604800',
|
|
58
|
-
AUTHO_USER_KEY: '12ba105efUaGjihGrh0LfJHTGIBGu6jXV',
|
|
59
|
-
ACCESS_SID_TWILIO: 'AC7c9ccbdb50400c504faf629e35aea8e4',
|
|
60
|
-
REACT_APP_API_KEY_GOOGLE_MAPS: 'AIzaSyAy0SY1G3OFqesWSTQRHJvzyJzNgURPoN8',
|
|
61
|
-
ACCESS_TOKEN_AUTH_TWILIO: '22e090d4d776ace7bb596ca77cba6b18'
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const resolveUniqueReactForHooks = {
|
|
65
|
-
webpack: (config, options) => {
|
|
66
|
-
if (options.isServer) {
|
|
67
|
-
config.externals = ['react', ...config.externals]
|
|
68
|
-
}
|
|
69
|
-
// eslint-disable-next-line no-undef
|
|
70
|
-
config.resolve.alias.react = reactPath
|
|
71
|
-
return config
|
|
72
|
-
},
|
|
73
|
-
images: {
|
|
74
|
-
domains: ['http2.mlstatic.com', 'localhost', 'server-image-food.herokuapp.com']
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const headers = () => {
|
|
78
|
-
return [
|
|
79
|
-
{
|
|
80
|
-
source: '',
|
|
81
|
-
headers: [
|
|
82
|
-
{
|
|
83
|
-
key: 'x-custom-header-1',
|
|
84
|
-
value: 'my custom header 1'
|
|
85
|
-
}
|
|
86
|
-
]
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
}
|
|
90
|
-
const redirects = () => {
|
|
91
|
-
return [
|
|
92
|
-
{
|
|
93
|
-
source: '/home',
|
|
94
|
-
destination: '/',
|
|
95
|
-
permanent: true
|
|
96
|
-
}
|
|
97
|
-
]
|
|
98
|
-
}
|
|
99
|
-
// puedes sobre escribir la ruta
|
|
100
|
-
const rewrites = () => {
|
|
101
|
-
return [
|
|
102
|
-
{
|
|
103
|
-
source: '/ab',
|
|
104
|
-
destination: '/about'
|
|
105
|
-
}
|
|
106
|
-
]
|
|
107
|
-
}
|
|
108
|
-
const assetPrefix = isProd ? 'https://cdn.mydomain.com' : ''
|
|
109
|
-
const images = {
|
|
110
|
-
domains: ['http2.mlstatic.com', 'localhost', 'server-image-food.herokuapp.com', '*']
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
env,
|
|
114
|
-
swcMinify: false,
|
|
115
|
-
images,
|
|
116
|
-
headers,
|
|
117
|
-
optimizeFonts: false,
|
|
118
|
-
nextConfig,
|
|
119
|
-
// basePath,
|
|
120
|
-
rewrites,
|
|
121
|
-
redirects,
|
|
122
|
-
assetPrefix,
|
|
123
|
-
resolveUniqueReactForHooks
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// module.exports = nextConfig
|