npm-pkg-hook 1.9.3 → 1.9.5
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/index.js +1 -0
- package/src/hooks/useColorByLetters/helpers/alea.js +54 -0
- package/src/hooks/useColorByLetters/helpers/colors.js +45 -0
- package/src/hooks/useColorByLetters/helpers/index.js +18 -0
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.js +118 -0
- package/src/hooks/useColorByLetters/index.js +27 -0
- package/src/hooks/useEmployee/queries.js +28 -0
- package/src/hooks/useEmployee/useCreateEmployee.js +28 -2
- package/src/hooks/useFormTools/index.js +17 -9
- package/src/hooks/useRoles/useCreateRole.js +24 -2
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from './getCardType'
|
|
|
20
20
|
export * from './useLoginEmployeeInStore'
|
|
21
21
|
export * from './useUploadProducts'
|
|
22
22
|
export * from './useAmountInput'
|
|
23
|
+
export * from './useColorByLetters'
|
|
23
24
|
export * from './newMessageSubscription'
|
|
24
25
|
export * from './useGetCookies'
|
|
25
26
|
export * from './generateTemplate'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
class AleaGen {
|
|
2
|
+
constructor (seed) {
|
|
3
|
+
if (seed == null) { seed = +(new Date()) }
|
|
4
|
+
let n = 0xefc8249d
|
|
5
|
+
// Apply the seeding algorithm from Baagoe.
|
|
6
|
+
this.c = 1
|
|
7
|
+
this.s0 = mash(' ')
|
|
8
|
+
this.s1 = mash(' ')
|
|
9
|
+
this.s2 = mash(' ')
|
|
10
|
+
this.s0 -= mash(seed)
|
|
11
|
+
if (this.s0 < 0) {
|
|
12
|
+
this.s0 += 1
|
|
13
|
+
}
|
|
14
|
+
this.s1 -= mash(seed)
|
|
15
|
+
if (this.s1 < 0) {
|
|
16
|
+
this.s1 += 1
|
|
17
|
+
}
|
|
18
|
+
this.s2 -= mash(seed)
|
|
19
|
+
if (this.s2 < 0) {
|
|
20
|
+
this.s2 += 1
|
|
21
|
+
}
|
|
22
|
+
function mash (data) {
|
|
23
|
+
data = String(data)
|
|
24
|
+
for (let i = 0; i < data.length; i++) {
|
|
25
|
+
n += data.charCodeAt(i)
|
|
26
|
+
let h = 0.02519603282416938 * n
|
|
27
|
+
n = h >>> 0
|
|
28
|
+
h -= n
|
|
29
|
+
h *= n
|
|
30
|
+
n = h >>> 0
|
|
31
|
+
h -= n
|
|
32
|
+
n += h * 0x100000000 // 2^32
|
|
33
|
+
}
|
|
34
|
+
return (n >>> 0) * 2.3283064365386963e-10 // 2^-32
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
next () {
|
|
39
|
+
const { c, s0, s1, s2 } = this
|
|
40
|
+
const t = 2091639 * s0 + c * 2.3283064365386963e-10 // 2^-32
|
|
41
|
+
this.s0 = s1
|
|
42
|
+
this.s1 = s2
|
|
43
|
+
return this.s2 = t - (this.c = t | 0)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
copy (f, t) {
|
|
47
|
+
t.c = f.c
|
|
48
|
+
t.s0 = f.s0
|
|
49
|
+
t.s1 = f.s1
|
|
50
|
+
t.s2 = f.s2
|
|
51
|
+
return t
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export default AleaGen
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const BACKGROUND_COLORS = [
|
|
2
|
+
'#F7F9FC',
|
|
3
|
+
'#EEEDFD',
|
|
4
|
+
'#FFEBEE',
|
|
5
|
+
'#FDEFE2',
|
|
6
|
+
'#E7F9F3',
|
|
7
|
+
'#EDEEFD',
|
|
8
|
+
'#ECFAFE',
|
|
9
|
+
'#F2FFD1',
|
|
10
|
+
'#FFF7E0',
|
|
11
|
+
'#FDF1F7',
|
|
12
|
+
'#EAEFE6',
|
|
13
|
+
'#E0E6EB',
|
|
14
|
+
'#E4E2F3',
|
|
15
|
+
'#E6DFEC',
|
|
16
|
+
'#E2F4E8',
|
|
17
|
+
'#E6EBEF',
|
|
18
|
+
'#EBE6EF',
|
|
19
|
+
'#E8DEF6',
|
|
20
|
+
'#D8E8F3',
|
|
21
|
+
'#ECE1FE'
|
|
22
|
+
]
|
|
23
|
+
|
|
24
|
+
export const TEXT_COLORS = [
|
|
25
|
+
'#060A23',
|
|
26
|
+
'#4409B9',
|
|
27
|
+
'#BD0F2C',
|
|
28
|
+
'#C56511',
|
|
29
|
+
'#216E55',
|
|
30
|
+
'#05128A',
|
|
31
|
+
'#1F84A3',
|
|
32
|
+
'#526E0C',
|
|
33
|
+
'#935F10',
|
|
34
|
+
'#973562',
|
|
35
|
+
'#69785E',
|
|
36
|
+
'#2D3A46',
|
|
37
|
+
'#280F6D',
|
|
38
|
+
'#37364F',
|
|
39
|
+
'#363548',
|
|
40
|
+
'#4D176E',
|
|
41
|
+
'#AB133E',
|
|
42
|
+
'#420790',
|
|
43
|
+
'#222A54',
|
|
44
|
+
'#192251'
|
|
45
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import MersenneTwister from './mersenne_twister.js'
|
|
2
|
+
import AleaGen from './alea.js'
|
|
3
|
+
|
|
4
|
+
function minMax (opts) {
|
|
5
|
+
const { random, min, max } = opts
|
|
6
|
+
return Math.floor(random * (max - min + 1) + min)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const randomNumber = (opts) => {
|
|
10
|
+
const { value, min, max } = opts
|
|
11
|
+
|
|
12
|
+
const prepareSeed = new AleaGen(value)
|
|
13
|
+
const seedOutput = prepareSeed.s1 * 10000000
|
|
14
|
+
|
|
15
|
+
const mersenne = new MersenneTwister(seedOutput)
|
|
16
|
+
|
|
17
|
+
return minMax({ random: mersenne.random(), min, max })
|
|
18
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
const MersenneTwister = function (seed) {
|
|
2
|
+
if (seed === undefined) {
|
|
3
|
+
// kept random number same size as time used previously to ensure no unexpected results downstream
|
|
4
|
+
seed = Math.floor(Math.random() * Math.pow(10, 13))
|
|
5
|
+
}
|
|
6
|
+
/* Period parameters */
|
|
7
|
+
this.N = 624
|
|
8
|
+
this.M = 397
|
|
9
|
+
this.MATRIX_A = 0x9908b0df /* constant vector a */
|
|
10
|
+
this.UPPER_MASK = 0x80000000 /* most significant w-r bits */
|
|
11
|
+
this.LOWER_MASK = 0x7fffffff /* least significant r bits */
|
|
12
|
+
this.mt = new Array(this.N) /* the array for the state vector */
|
|
13
|
+
this.mti = this.N + 1 /* mti==N + 1 means mt[N] is not initialized */
|
|
14
|
+
this.init_genrand(seed)
|
|
15
|
+
}
|
|
16
|
+
/* initializes mt[N] with a seed */
|
|
17
|
+
MersenneTwister.prototype.init_genrand = function (s) {
|
|
18
|
+
this.mt[0] = s >>> 0
|
|
19
|
+
for (this.mti = 1; this.mti < this.N; this.mti++) {
|
|
20
|
+
s = this.mt[this.mti - 1] ^ (this.mt[this.mti - 1] >>> 30)
|
|
21
|
+
this.mt[this.mti] = (((((s & 0xffff0000) >>> 16) * 1812433253) << 16) + (s & 0x0000ffff) * 1812433253) + this.mti
|
|
22
|
+
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
|
23
|
+
/* In the previous versions, MSBs of the seed affect */
|
|
24
|
+
/* only MSBs of the array mt[]. */
|
|
25
|
+
/* 2002/01/09 modified by Makoto Matsumoto */
|
|
26
|
+
this.mt[this.mti] >>>= 0
|
|
27
|
+
/* for >32 bit machines */
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/* initialize by an array with array-length */
|
|
31
|
+
/* init_key is the array for initializing keys */
|
|
32
|
+
/* key_length is its length */
|
|
33
|
+
/* slight change for C++, 2004/2/26 */
|
|
34
|
+
MersenneTwister.prototype.init_by_array = function (init_key, key_length) {
|
|
35
|
+
let i = 1; let j = 0; let k; let s
|
|
36
|
+
this.init_genrand(19650218)
|
|
37
|
+
k = (this.N > key_length ? this.N : key_length)
|
|
38
|
+
for (; k; k--) {
|
|
39
|
+
s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30)
|
|
40
|
+
this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1664525) << 16) + ((s & 0x0000ffff) * 1664525))) + init_key[j] + j /* non linear */
|
|
41
|
+
this.mt[i] >>>= 0 /* for WORDSIZE > 32 machines */
|
|
42
|
+
i++
|
|
43
|
+
j++
|
|
44
|
+
if (i >= this.N) {
|
|
45
|
+
this.mt[0] = this.mt[this.N - 1]
|
|
46
|
+
i = 1
|
|
47
|
+
}
|
|
48
|
+
if (j >= key_length) {
|
|
49
|
+
j = 0
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (k = this.N - 1; k; k--) {
|
|
53
|
+
s = this.mt[i - 1] ^ (this.mt[i - 1] >>> 30)
|
|
54
|
+
this.mt[i] = (this.mt[i] ^ (((((s & 0xffff0000) >>> 16) * 1566083941) << 16) + (s & 0x0000ffff) * 1566083941)) - i /* non linear */
|
|
55
|
+
this.mt[i] >>>= 0 /* for WORDSIZE > 32 machines */
|
|
56
|
+
i++
|
|
57
|
+
if (i >= this.N) {
|
|
58
|
+
this.mt[0] = this.mt[this.N - 1]
|
|
59
|
+
i = 1
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.mt[0] = 0x80000000 /* MSB is 1; assuring non-zero initial array */
|
|
63
|
+
}
|
|
64
|
+
/* generates a random number on [0,0xffffffff]-interval */
|
|
65
|
+
MersenneTwister.prototype.genrand_int32 = function () {
|
|
66
|
+
let y
|
|
67
|
+
const mag01 = new Array(0x0, this.MATRIX_A)
|
|
68
|
+
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
|
69
|
+
if (this.mti >= this.N) { /* generate N words at one time */
|
|
70
|
+
let kk
|
|
71
|
+
if (this.mti === this.N + 1) { /* if init_genrand() has not been called, */
|
|
72
|
+
this.init_genrand(5489) /* a default initial seed is used */
|
|
73
|
+
}
|
|
74
|
+
for (kk = 0; kk < this.N - this.M; kk++) {
|
|
75
|
+
y = (this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK)
|
|
76
|
+
this.mt[kk] = this.mt[kk + this.M] ^ (y >>> 1) ^ mag01[y & 0x1]
|
|
77
|
+
}
|
|
78
|
+
for (; kk < this.N - 1; kk++) {
|
|
79
|
+
y = (this.mt[kk] & this.UPPER_MASK) | (this.mt[kk + 1] & this.LOWER_MASK)
|
|
80
|
+
this.mt[kk] = this.mt[kk + (this.M - this.N)] ^ (y >>> 1) ^ mag01[y & 0x1]
|
|
81
|
+
}
|
|
82
|
+
y = (this.mt[this.N - 1] & this.UPPER_MASK) | (this.mt[0] & this.LOWER_MASK)
|
|
83
|
+
this.mt[this.N - 1] = this.mt[this.M - 1] ^ (y >>> 1) ^ mag01[y & 0x1]
|
|
84
|
+
this.mti = 0
|
|
85
|
+
}
|
|
86
|
+
y = this.mt[this.mti++]
|
|
87
|
+
/* Tempering */
|
|
88
|
+
y ^= (y >>> 11)
|
|
89
|
+
y ^= (y << 7) & 0x9d2c5680
|
|
90
|
+
y ^= (y << 15) & 0xefc60000
|
|
91
|
+
y ^= (y >>> 18)
|
|
92
|
+
return y >>> 0
|
|
93
|
+
}
|
|
94
|
+
/* generates a random number on [0,0x7fffffff]-interval */
|
|
95
|
+
MersenneTwister.prototype.genrand_int31 = function () {
|
|
96
|
+
return (this.genrand_int32() >>> 1)
|
|
97
|
+
}
|
|
98
|
+
/* generates a random number on [0,1]-real-interval */
|
|
99
|
+
MersenneTwister.prototype.genrand_real1 = function () {
|
|
100
|
+
return this.genrand_int32() * (1.0 / 4294967295.0)
|
|
101
|
+
/* divided by 2^32-1 */
|
|
102
|
+
}
|
|
103
|
+
/* generates a random number on [0,1)-real-interval */
|
|
104
|
+
MersenneTwister.prototype.random = function () {
|
|
105
|
+
return this.genrand_int32() * (1.0 / 4294967296.0)
|
|
106
|
+
/* divided by 2^32 */
|
|
107
|
+
}
|
|
108
|
+
/* generates a random number on (0,1)-real-interval */
|
|
109
|
+
MersenneTwister.prototype.genrand_real3 = function () {
|
|
110
|
+
return (this.genrand_int32() + 0.5) * (1.0 / 4294967296.0)
|
|
111
|
+
/* divided by 2^32 */
|
|
112
|
+
}
|
|
113
|
+
/* generates a random number on [0,1) with 53-bit resolution */
|
|
114
|
+
MersenneTwister.prototype.genrand_res53 = function () {
|
|
115
|
+
const a = this.genrand_int32() >>> 5; const b = this.genrand_int32() >>> 6
|
|
116
|
+
return (a * 67108864.0 + b) * (1.0 / 9007199254740992.0)
|
|
117
|
+
}
|
|
118
|
+
export default MersenneTwister
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { randomNumber } from './helpers'
|
|
2
|
+
import { BACKGROUND_COLORS, TEXT_COLORS } from './helpers/colors'
|
|
3
|
+
|
|
4
|
+
export const useColorByLetters = ({
|
|
5
|
+
value = ''
|
|
6
|
+
} = {
|
|
7
|
+
value: ''
|
|
8
|
+
}) => {
|
|
9
|
+
const key = randomNumber({ value, min: 0, max: 19 })
|
|
10
|
+
|
|
11
|
+
const getCustomColors = (text) => {
|
|
12
|
+
const key = randomNumber({ text, min: 0, max: 19 })
|
|
13
|
+
return {
|
|
14
|
+
key,
|
|
15
|
+
color: TEXT_COLORS[key],
|
|
16
|
+
borderColor: TEXT_COLORS[key],
|
|
17
|
+
bgColor: BACKGROUND_COLORS[key]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
key,
|
|
22
|
+
color: TEXT_COLORS[key],
|
|
23
|
+
borderColor: TEXT_COLORS[key],
|
|
24
|
+
bgColor: BACKGROUND_COLORS[key],
|
|
25
|
+
getCustomColors
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -10,6 +10,34 @@ query employees {
|
|
|
10
10
|
eEmail
|
|
11
11
|
eState
|
|
12
12
|
status
|
|
13
|
+
user {
|
|
14
|
+
id
|
|
15
|
+
name
|
|
16
|
+
username
|
|
17
|
+
lastName
|
|
18
|
+
email
|
|
19
|
+
avatar
|
|
20
|
+
uToken
|
|
21
|
+
uPhoNum
|
|
22
|
+
ULocation
|
|
23
|
+
upLat
|
|
24
|
+
uState
|
|
25
|
+
upLon
|
|
26
|
+
upIdeDoc
|
|
27
|
+
siteWeb
|
|
28
|
+
description
|
|
29
|
+
createAt
|
|
30
|
+
associateStore
|
|
31
|
+
}
|
|
32
|
+
roles {
|
|
33
|
+
idRole
|
|
34
|
+
name
|
|
35
|
+
priority
|
|
36
|
+
description
|
|
37
|
+
permissions
|
|
38
|
+
createdAt
|
|
39
|
+
updatedAt
|
|
40
|
+
}
|
|
13
41
|
}
|
|
14
42
|
success
|
|
15
43
|
message
|
|
@@ -12,8 +12,34 @@ import { CREATE_ONE_EMPLOYEE_STORE_AND_USER } from './queries'
|
|
|
12
12
|
* data: Object | null
|
|
13
13
|
* }} An object containing the mutation function, loading status, error, and data.
|
|
14
14
|
*/
|
|
15
|
-
export const useCreateEmployeeStoreAndUser = (
|
|
16
|
-
|
|
15
|
+
export const useCreateEmployeeStoreAndUser = ({
|
|
16
|
+
sendNotification = () => {
|
|
17
|
+
return {
|
|
18
|
+
description: '',
|
|
19
|
+
title: '',
|
|
20
|
+
backgroundColor: ''
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
onCompleted = () => {
|
|
24
|
+
return {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} = {}) => {
|
|
28
|
+
const [createEmployeeStoreAndUserMutation, { loading, error, data }] = useMutation(CREATE_ONE_EMPLOYEE_STORE_AND_USER, {
|
|
29
|
+
onCompleted: (response) => {
|
|
30
|
+
console.log(response)
|
|
31
|
+
const { createOneEmployeeStoreAndUser } = response ?? {}
|
|
32
|
+
const { message, success } = createOneEmployeeStoreAndUser ?? {}
|
|
33
|
+
if (success) {
|
|
34
|
+
onCompleted()
|
|
35
|
+
}
|
|
36
|
+
sendNotification({
|
|
37
|
+
description: message,
|
|
38
|
+
title: success ? 'Exito' : 'Error',
|
|
39
|
+
backgroundColor: success ? 'success' : 'error'
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
})
|
|
17
43
|
const [errors, setErrors] = useState([])
|
|
18
44
|
|
|
19
45
|
/**
|
|
@@ -81,17 +81,25 @@ export const useFormTools = ({
|
|
|
81
81
|
if (errSub) return setErrorSubmit(errSub)
|
|
82
82
|
|
|
83
83
|
// Ejecuta la accion si es válido
|
|
84
|
-
if (!errSub && action) {
|
|
85
|
-
action()
|
|
86
|
-
|
|
84
|
+
if (!errSub && typeof action === 'function') {
|
|
85
|
+
const result = action()
|
|
86
|
+
if (result && typeof result.then === 'function') {
|
|
87
|
+
result.then((res) => {
|
|
88
|
+
if (res) {
|
|
89
|
+
sendNotification({
|
|
90
|
+
message: msgSuccess ?? 'Operación exitosa',
|
|
91
|
+
description: 'Operación exitosa',
|
|
92
|
+
backgroundColor: 'success'
|
|
93
|
+
})
|
|
94
|
+
if (actionAfterSuccess) actionAfterSuccess()
|
|
95
|
+
}
|
|
96
|
+
}).catch((e) => {
|
|
87
97
|
sendNotification({
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
backgroundColor: 'success'
|
|
98
|
+
title: msgError || e?.message || 'Ha ocurrido un error',
|
|
99
|
+
backgroundColor: 'error'
|
|
91
100
|
})
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}).catch(e => { return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', backgroundColor: 'error' }) })
|
|
101
|
+
})
|
|
102
|
+
}
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
setErrorSubmit(errSub)
|
|
@@ -4,8 +4,30 @@ import { CREATE_ROLE_MUTATION } from './queries'
|
|
|
4
4
|
* Custom hook para crear un nuevo rol
|
|
5
5
|
* @returns {Object} - Estado de la mutación, incluyendo loading, error, data y la función createRoleMutation
|
|
6
6
|
*/
|
|
7
|
-
export const useCreateRole = (
|
|
8
|
-
|
|
7
|
+
export const useCreateRole = ({
|
|
8
|
+
sendNotification = () => {
|
|
9
|
+
return {
|
|
10
|
+
title: '',
|
|
11
|
+
description: '',
|
|
12
|
+
backgroundColor: ''
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
} = {
|
|
16
|
+
sendNotification: () => {
|
|
17
|
+
}
|
|
18
|
+
}) => {
|
|
19
|
+
const [createRoleMutation, { loading, error, data }] = useMutation(CREATE_ROLE_MUTATION, {
|
|
20
|
+
onError: () => {
|
|
21
|
+
sendNotification({
|
|
22
|
+
title: 'Error',
|
|
23
|
+
description: 'Ocurrió un error inesperado',
|
|
24
|
+
backgroundColor: 'error'
|
|
25
|
+
})
|
|
26
|
+
},
|
|
27
|
+
onCompleted: () => {
|
|
28
|
+
return null
|
|
29
|
+
}
|
|
30
|
+
})
|
|
9
31
|
|
|
10
32
|
return [createRoleMutation, {
|
|
11
33
|
loading,
|