npm-pkg-hook 1.8.7 → 1.8.9

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.8.7"
50
+ "version": "1.8.9"
51
51
  }
@@ -1,4 +1,5 @@
1
1
  export async function handleLogin (body) {
2
+ console.log("🚀 ~ handleLogin ~ body:", body)
2
3
  const response = await fetch(`${process.env.URL_BASE}/api/auth/login`, {
3
4
  method: 'POST',
4
5
  headers: { 'Content-Type': 'application/json' },
@@ -16,7 +16,9 @@ export * from './statusOpenStores'
16
16
  export * from './completeSchedules'
17
17
  export * from './useLogout/helpers/BroadcastChannel'
18
18
  export * from './getCardType'
19
+ export * from './useLoginEmployeeInStore'
19
20
  export * from './useUploadProducts'
21
+ export * from './useAmountInput'
20
22
  export * from './newMessageSubscription'
21
23
  export * from './useGetCookies'
22
24
  export * from './generateTemplate'
@@ -0,0 +1,117 @@
1
+ import { useState } from 'react'
2
+
3
+ const formatCurrency = (
4
+ prefix,
5
+ amountValue,
6
+ number,
7
+ groupSeparator,
8
+ decimalSeparator,
9
+ allowDecimals = false,
10
+ decimalsLimit = 0
11
+ ) => {
12
+ if (isNaN(number)) {
13
+ return prefix + '0'
14
+ }
15
+
16
+ const amountWithoutDecimals = parseInt(number.toString())
17
+ const decimalIdx = amountValue.indexOf(decimalSeparator)
18
+ const notAllowedChars = new RegExp('[^' + decimalSeparator + '\\d]', 'g')
19
+ const decimalsWithSeparator =
20
+ decimalIdx >= 0
21
+ ? amountValue
22
+ .slice(decimalIdx, amountValue.length)
23
+ .replace(notAllowedChars, '')
24
+ .slice(0, decimalsLimit + 1)
25
+ : ''
26
+
27
+ return (
28
+ prefix +
29
+ amountWithoutDecimals
30
+ .toString()
31
+ .replace(/\B(?=(\d{3}){1,5}(?!\d))/g, groupSeparator) +
32
+ decimalsWithSeparator
33
+ )
34
+ }
35
+
36
+ const processInputValue = (input, decimalSeparator) => {
37
+ const decimalRegex = new RegExp('[' + decimalSeparator + ']', 'g')
38
+ const notAllowedChars = new RegExp('[^' + decimalSeparator + '\\d¬]', 'g')
39
+
40
+ return parseFloat(
41
+ input
42
+ .replace(decimalRegex, '¬')
43
+ .replace(notAllowedChars, '')
44
+ .replace('¬', '.')
45
+ )
46
+ }
47
+ /**
48
+ * Truncate excess decimals from a number based on a limit.
49
+ *
50
+ * @param {number} number The number to truncate.
51
+ * @param {number} decimalsLimit The maximum number of decimal places allowed.
52
+ * @returns {number} The number with truncated decimals.
53
+ */
54
+ const truncateDecimals = (number, decimalsLimit) => {
55
+ if (isNaN(number)) {
56
+ return 0;
57
+ }
58
+
59
+ const multiplier = Math.pow(10, decimalsLimit);
60
+ return Math.floor(number * multiplier) / multiplier;
61
+ };
62
+ export const useAmountInput = props => {
63
+ const {
64
+ onChange = () => {},
65
+ prefix = '$',
66
+ groupSeparator = '.',
67
+ decimalSeparator = ',',
68
+ allowDecimals,
69
+ decimalsLimit,
70
+ defaultValue
71
+ } = props
72
+
73
+ const inputVal = defaultValue ?? ''
74
+ const [inputValue, setInputValue] = useState(inputVal)
75
+
76
+ const preProcess = amount => {
77
+ const amountValue = amount.trim()
78
+ const oldInputValue = inputValue
79
+
80
+ if (oldInputValue !== amountValue) {
81
+ const amountFloatValue = processInputValue(amount, decimalSeparator)
82
+ let inputValue = ''
83
+ // This allows for people to use `.` but still input decimals
84
+ const isAboutToIntroduceDecimals =
85
+ oldInputValue + decimalSeparator === amountValue ||
86
+ oldInputValue + '.' === amountValue
87
+ if (allowDecimals === true && isAboutToIntroduceDecimals) {
88
+ inputValue = oldInputValue + decimalSeparator
89
+ } else if (
90
+ (allowDecimals === false || allowDecimals === undefined) &&
91
+ isAboutToIntroduceDecimals
92
+ ) {
93
+ inputValue = oldInputValue
94
+ } else {
95
+ inputValue = formatCurrency(
96
+ prefix,
97
+ amountValue,
98
+ amountFloatValue,
99
+ groupSeparator,
100
+ decimalSeparator,
101
+ allowDecimals,
102
+ decimalsLimit
103
+ )
104
+ }
105
+ setInputValue(inputValue)
106
+
107
+ const callbackValue = isNaN(amountFloatValue) ? 0 : amountFloatValue
108
+ if (typeof onChange === 'function') {
109
+ onChange(truncateDecimals(callbackValue, decimalsLimit))
110
+ }
111
+ }
112
+ }
113
+ return {
114
+ inputValue,
115
+ preProcess
116
+ }
117
+ }
@@ -13,15 +13,36 @@ import {
13
13
 
14
14
  export const useGetClients = ({
15
15
  max,
16
+ order = 'DESC',
16
17
  search,
17
18
  sendNotification = () => { }
18
19
  } = {}) => {
19
- const { loading, error, called, data } = useQuery(GET_ALL_CLIENTS, {
20
+ const {
21
+ loading,
22
+ error,
23
+ called,
24
+ data,
25
+ refetch
26
+ } = useQuery(GET_ALL_CLIENTS, {
27
+ onError: () => {
28
+ sendNotification({
29
+ title: 'Error',
30
+ description: 'Algo salió mal',
31
+ backgroundColor: 'error'
32
+ })
33
+ },
20
34
  variables: {
21
- search
35
+ search,
36
+ max: max || 100,
37
+ order
22
38
  }
23
39
  })
24
- return [data?.getAllClients || [], { loading: called ? false : loading, error }]
40
+ return [data?.getAllClients || [], {
41
+ loading: called ? false : loading,
42
+ buttonLoading: loading,
43
+ error,
44
+ refetch
45
+ }]
25
46
  }
26
47
 
27
48
  export const useDeleteClients = ({ sendNotification = () => { } } = {}) => {
@@ -48,7 +69,7 @@ export const useEditClient = ({ sendNotification = () => { } } = {}) => {
48
69
  onCompleted: (data) => {
49
70
  if (data?.editOneClient?.success) {
50
71
  return sendNotification({
51
- title: 'Exito',
72
+ title: 'Éxito',
52
73
  description: data?.editOneClient?.message,
53
74
  backgroundColor: 'success'
54
75
  })
@@ -3,6 +3,20 @@ import { gql } from '@apollo/client'
3
3
  export const CREATE_CLIENTS = gql`
4
4
  mutation createClients ($input: IClients) {
5
5
  createClients(input: $input) {
6
+ success
7
+ message
8
+ errors {
9
+ path
10
+ message
11
+ type
12
+ context {
13
+ limit
14
+ value
15
+ label
16
+ key
17
+ }
18
+ }
19
+ data {
6
20
  cliId
7
21
  idStore
8
22
  idUser
@@ -15,6 +29,7 @@ mutation createClients ($input: IClients) {
15
29
  clientName
16
30
  createAt
17
31
  updateAt
32
+ }
18
33
  }
19
34
  }
20
35
  `
@@ -27,23 +42,44 @@ mutation deleteClient($cliId: ID, $clState: Int!) {
27
42
  }
28
43
  `
29
44
  export const GET_ALL_CLIENTS = gql`
30
- query getAllClients($idStore: ID, $cId: ID, $dId: ID, $ctId: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime ) {
31
- getAllClients(idStore: $idStore, cId: $cId, dId: $dId, ctId: $ctId, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate) {
32
- cliId
33
- idStore
34
- gender
35
- # idUser
36
- clState
37
- clientNumber
38
- ccClient
39
- clientLastName
40
- clientName
41
- ClientAddress
42
- createAt
43
- updateAt
44
-
45
+ query getAllClients($idStore: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime, $page: Int) {
46
+ getAllClients(idStore: $idStore, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate, page: $page) {
47
+ success
48
+ message
49
+ data {
50
+
51
+ cliId
52
+ idStore
53
+ gender
54
+ clState
55
+ clientNumber
56
+ ccClient
57
+ clientLastName
58
+
59
+ clientName
60
+ createAt
61
+ updateAt
62
+ }
63
+ pagination {
64
+ totalRecords
65
+ totalPages
66
+ currentPage
67
+ }
68
+ errors {
69
+ path
70
+ message
71
+ type
72
+ context {
73
+ limit
74
+ value
75
+ label
76
+ key
77
+ }
78
+ }
45
79
  }
46
80
  }
81
+
82
+
47
83
  `
48
84
  export const GET_ONE_CLIENT = gql`
49
85
  query getOneClients($cliId: ID) {
@@ -202,12 +202,12 @@ export const useDessertWithPrice = ({
202
202
 
203
203
  const prepareAndValidateData = useCallback((pId) => {
204
204
  const dataArr = LineItems?.Lines?.map(({ extraPrice, exState, extraName }) => ({
205
- extraPrice: parseFloat(extraPrice),
205
+ extraPrice,
206
206
  exState: exState === true ? 1 : 0,
207
207
  extraName,
208
208
  pId
209
209
  }))
210
-
210
+ console.log(dataArr)
211
211
  const message = 'Complete los campos vacíos'
212
212
  const findInputEmpty = dataArr?.find(({ extraName }) => extraName === '')
213
213
  const findInputEmptyPrice = dataArr?.find(({ extraPrice }) => isNaN(extraPrice) || extraPrice === '')
@@ -291,7 +291,7 @@ export const useDessertWithPrice = ({
291
291
  // Luego, transformar los elementos filtrados
292
292
  return filteredItems.map(({ exPid, extraPrice, exState, extraName }) => ({
293
293
  exPid,
294
- extraPrice: stringToInt(extraPrice), // Asumiendo que tienes una función stringToInt definida
294
+ extraPrice,
295
295
  exState: exState === true ? 1 : 0,
296
296
  extraName,
297
297
  pId
@@ -1,13 +1,17 @@
1
1
  import { useQuery } from '@apollo/client'
2
- import { useEffect, useState } from 'react'
3
2
  import { GET_EMPLOYEES } from './queries'
4
3
 
5
4
  export const useEmployee = () => {
6
- const [clientes, setClients] = useState([])
7
- const [more, setMore] = useState(100)
8
- const { data, loading, error, fetchMore } = useQuery(GET_EMPLOYEES)
9
- useEffect(() => {
10
- setClients(data)
11
- }, [clientes, data])
12
- return [clientes?.employees, { loading, error, fetchMore, setMore, more }]
5
+ const {
6
+ data,
7
+ loading,
8
+ error,
9
+ fetchMore
10
+ } = useQuery(GET_EMPLOYEES)
11
+ return [data?.employees?.data ?? [], {
12
+ loading,
13
+ error,
14
+ fetchMore,
15
+ pagination: data?.employees?.pagination
16
+ }]
13
17
  }
@@ -3,15 +3,33 @@ import { gql } from '@apollo/client'
3
3
  export const GET_EMPLOYEES = gql`
4
4
  query employees {
5
5
  employees {
6
- eId
7
- idStore
8
- idEmployee
9
- eSalary
10
- typeContract
11
- tpEmail
12
- termContract
13
- eDatAdm
14
- eState
6
+ data {
7
+ eId
8
+ idStore
9
+ idRole
10
+ eEmail
11
+ eState
12
+ status
13
+ }
14
+ success
15
+ message
16
+ pagination {
17
+ totalRecords
18
+ totalPages
19
+ currentPage
20
+ }
21
+ errors {
22
+ path
23
+ message
24
+ type
25
+ context {
26
+ limit
27
+ value
28
+ label
29
+ key
30
+ }
31
+ }
32
+
15
33
  }
16
34
  }
17
- `
35
+ `
@@ -11,7 +11,6 @@ export const useGetCookies = () => {
11
11
 
12
12
  for (const cookieName of cookieNames) {
13
13
  const cookieValue = Cookies.get(cookieName)
14
- console.log({ cookieValue })
15
14
  if (cookieValue) {
16
15
  cookiesData.push({ name: cookieName, value: cookieValue })
17
16
  }
@@ -23,5 +22,22 @@ export const useGetCookies = () => {
23
22
  }
24
23
  }
25
24
 
26
- return { getCookies }
25
+ const getCookie = (cookieName) => {
26
+ try {
27
+ if (typeof cookieName !== 'string') {
28
+ throw new Error('Input cookie name should be a string.')
29
+ }
30
+
31
+ const cookieValue = Cookies.get(cookieName)
32
+ if (cookieValue) {
33
+ return { name: cookieName, value: cookieValue }
34
+ }
35
+ return null
36
+ } catch (error) {
37
+ console.error('Error al traer la cookie:', error)
38
+ return null
39
+ }
40
+ }
41
+
42
+ return { getCookies, getCookie }
27
43
  }
@@ -0,0 +1,38 @@
1
+ import { gql, useMutation } from '@apollo/client'
2
+
3
+ const LOGIN_EMPLOYEE_IN_STORE = gql`
4
+ mutation loginEmployeeInStore($eId: ID, $tenantId: String, $idStore: ID, $idUser: ID, $eEmail: String) {
5
+ loginEmployeeInStore(eId: $eId, tenantId: $tenantId, idStore: $idStore, idUser: $idUser, eEmail: $eEmail) {
6
+ success
7
+ message
8
+ token
9
+ idStore
10
+ }
11
+ }
12
+ `
13
+
14
+ export const useLoginEmployeeInStore = () => {
15
+ const [loginEmployeeInStore, { data, loading, error }] = useMutation(LOGIN_EMPLOYEE_IN_STORE)
16
+
17
+ const loginEmployee = async (idStore, eEmail) => {
18
+ try {
19
+ const response = await loginEmployeeInStore({
20
+ variables: {
21
+ idStore,
22
+ eEmail
23
+ }
24
+ })
25
+ return response.data.loginEmployeeInStore
26
+ } catch (err) {
27
+ console.error('Error during loginEmployeeInStore mutation:', err)
28
+ throw err
29
+ }
30
+ }
31
+
32
+ return {
33
+ loginEmployee,
34
+ data,
35
+ loading,
36
+ error
37
+ }
38
+ }
@@ -1,8 +1,14 @@
1
1
  import { useMutation, useQuery } from '@apollo/client'
2
2
  import { GET_USER, GET_USER_PROFILE, SET_USER_PROFILE } from './queries'
3
3
 
4
- export const useUser = () => {
5
- const { data, loading, error } = useQuery(GET_USER)
4
+ export const useUser = (email) => {
5
+ const { data, loading, error } = useQuery(GET_USER, email !== ''
6
+ ? {
7
+ variables: {
8
+ email
9
+ }
10
+ }
11
+ : {})
6
12
  return [data?.getUser, { loading, error }]
7
13
  }
8
14
 
@@ -48,8 +48,8 @@ query getOneUserProfile($id: ID) {
48
48
  `
49
49
 
50
50
  export const GET_USER = gql`
51
- query getUser($id: ID){
52
- getUser(id: $id ){
51
+ query getUser($id: ID, $email: String){
52
+ getUser(id: $id email: $email){
53
53
  id
54
54
  name
55
55
  username
@@ -65,9 +65,9 @@ upLon
65
65
  upIdeDoc
66
66
  siteWeb
67
67
  description
68
+ associateStore
68
69
  createAt
69
70
  role {
70
- id
71
71
  name
72
72
  }
73
73
  }