npm-pkg-hook 1.7.9 → 1.8.1

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
@@ -44,5 +44,5 @@
44
44
  "rm": "rm -rf node_modules package-lock.json && npm i",
45
45
  "test": "echo \"Error: no test specified\" && exit 1"
46
46
  },
47
- "version": "1.7.9"
47
+ "version": "1.8.1"
48
48
  }
@@ -0,0 +1,24 @@
1
+ export const getCardType = (cardNum) => {
2
+ let payCardType = ''
3
+
4
+ if (cardNum.startsWith('4')) {
5
+ payCardType = 'VISA'
6
+ } else if (cardNum.startsWith('5')) {
7
+ payCardType = 'MASTERCARD'
8
+ } else {
9
+ const regexMap = [
10
+ { regEx: /^4[0-9]{5}/gi, cardType: 'VISA' },
11
+ { regEx: /^5[1-5][0-9]{4}/gi, cardType: 'MASTERCARD' },
12
+ { regEx: /^(5[06-8]\d{4}|6\d{5})/gi, cardType: 'MAESTRO' }
13
+ ]
14
+
15
+ for (const { regEx, cardType } of regexMap) {
16
+ if (cardNum.match(regEx)) {
17
+ payCardType = cardType
18
+ break
19
+ }
20
+ }
21
+ }
22
+
23
+ return payCardType
24
+ }
@@ -7,11 +7,14 @@ export * from './useCatWithProduct'
7
7
  export * from './useManageQueryParams'
8
8
  export * from './useDeliveryTime'
9
9
  export * from './getTotalHours'
10
+ export * from './useFreeSubscriptionValidation'
10
11
  export * from './convertToMilitaryTime'
11
12
  export * from './statusOpenStores'
12
13
  export * from './completeSchedules'
13
14
  export * from './useLogout/helpers/BroadcastChannel'
15
+ export * from './getCardType'
14
16
  export * from './newMessageSubscription'
17
+ export * from './useGetCookies'
15
18
  export * from './isTokenExpired'
16
19
  export * from './useCreateDeliveryTime'
17
20
  export * from './addTenMinutes'
@@ -0,0 +1,41 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { gql, useQuery } from '@apollo/client'
3
+
4
+ const VALIDATE_SUBSCRIPTION_QUERY = gql`
5
+ query validateFreeSubscription($idStore: ID) {
6
+ validateFreeSubscription(idStore: $idStore) {
7
+ subscriptionId
8
+ status
9
+ businessName
10
+ currentPeriodEnd
11
+ currentPeriodStart
12
+ }
13
+ }
14
+ `
15
+
16
+ export const useFreeSubscriptionValidation = (idStore) => {
17
+ const { loading, error, data } = useQuery(VALIDATE_SUBSCRIPTION_QUERY, {
18
+ variables: { idStore }
19
+ })
20
+ const [daysRemaining, setDaysRemaining] = useState(null)
21
+ const [daysElapsed, setDaysElapsed] = useState(null)
22
+
23
+ useEffect(() => {
24
+ if (data && data.validateFreeSubscription) {
25
+ const { currentPeriodEnd, currentPeriodStart } = data.validateFreeSubscription
26
+ const currentDate = new Date()
27
+ const endOfPeriod = new Date(parseInt(currentPeriodEnd))
28
+ const startOfPeriod = new Date(parseInt(currentPeriodStart))
29
+
30
+ const differenceInTimeUntilEnd = endOfPeriod.getTime() - currentDate.getTime()
31
+ const differenceInDaysUntilEnd = Math.ceil(differenceInTimeUntilEnd / (1000 * 3600 * 24))
32
+ setDaysRemaining(isNaN(differenceInDaysUntilEnd) ? 0 : differenceInDaysUntilEnd)
33
+
34
+ const differenceInTimeSinceStart = currentDate.getTime() - startOfPeriod.getTime()
35
+ const differenceInDaysSinceStart = Math.ceil(differenceInTimeSinceStart / (1000 * 3600 * 24))
36
+ setDaysElapsed(isNaN(differenceInDaysSinceStart) ? 0 : differenceInDaysSinceStart)
37
+ }
38
+ }, [data])
39
+
40
+ return { loading, error, subscriptionData: data?.validateFreeSubscription, daysRemaining, daysElapsed }
41
+ }
@@ -0,0 +1,27 @@
1
+ import Cookies from 'js-cookie'
2
+
3
+ export const useGetCookies = () => {
4
+ const getCookies = (cookieNames) => {
5
+ try {
6
+ if (!Array.isArray(cookieNames)) {
7
+ throw new Error('Input cookie names should be an array.')
8
+ }
9
+
10
+ const cookiesData = []
11
+
12
+ for (const cookieName of cookieNames) {
13
+ const cookieValue = Cookies.get(cookieName)
14
+ console.log({ cookieValue })
15
+ if (cookieValue) {
16
+ cookiesData.push({ name: cookieName, value: cookieValue })
17
+ }
18
+ }
19
+ return cookiesData
20
+ } catch (error) {
21
+ console.error('Error al traer las cookies:', error)
22
+ return []
23
+ }
24
+ }
25
+
26
+ return { getCookies }
27
+ }
@@ -1,22 +1,21 @@
1
- import { useState, useEffect } from 'react';
2
- import Cookies from 'js-cookie';
1
+ import { useState, useEffect } from 'react'
2
+ import Cookies from 'js-cookie'
3
3
 
4
4
  export const useGetStoreCookie = () => {
5
- const [vpStoreCookie, setVpStoreCookie] = useState(null);
5
+ const [vpStoreCookie, setVpStoreCookie] = useState(null)
6
6
 
7
7
  useEffect(() => {
8
8
  const getCookieValue = () => {
9
- const cookieValue = Cookies.get(process.env.SESSION_NAME);
10
- console.log('Cookie Value:', cookieValue);
9
+ const cookieValue = Cookies.get(process.env.SESSION_NAME)
10
+ console.log('Cookie Value:', cookieValue)
11
11
 
12
12
  if (cookieValue) {
13
- setVpStoreCookie(cookieValue);
13
+ setVpStoreCookie(cookieValue)
14
14
  }
15
- };
15
+ }
16
16
 
17
- getCookieValue();
18
- }, []); // Empty dependency array, so this effect runs once
19
-
20
- return vpStoreCookie;
21
- };
17
+ getCookieValue()
18
+ }, []) // Empty dependency array, so this effect runs once
22
19
 
20
+ return vpStoreCookie
21
+ }