npm-pkg-hook 1.3.7 → 1.3.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/.eslintrc.js +38 -38
- package/.eslintrc.json +127 -127
- package/.github/pull_request_template.md +17 -17
- package/.github/workflows/pepeline.yaml +29 -29
- package/package.json +46 -46
- package/script.txt +6 -6
- package/src/config/client/index.js +1 -1
- package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -7
- package/src/hooks/getCategoriesWithProduct/index.js +62 -62
- package/src/hooks/getSession/index.js +18 -18
- package/src/hooks/useAnimationFrame/index.js +45 -45
- package/src/hooks/useAsideCart/index.js +155 -155
- package/src/hooks/useAsideCart/queries.js +10 -10
- package/src/hooks/useCart/index.js +2 -2
- package/src/hooks/useCart/queries.js +164 -164
- package/src/hooks/useCart/useCart/helpers/index.js +75 -75
- package/src/hooks/useCart/useCart/index.js +410 -410
- package/src/hooks/useCart/useGetCart/index.js +31 -31
- package/src/hooks/useCatWithProductClient/index.js +56 -56
- package/src/hooks/useCatWithProductClient/queries.js +55 -55
- package/src/hooks/useCategoriesProduct/index.js +12 -12
- package/src/hooks/useCategoriesProduct/queries.js +16 -16
- package/src/hooks/useCategoryInStore/queries.js +78 -78
- package/src/hooks/useChartData/useChartData/index.js +199 -199
- package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
- package/src/hooks/useCheckbox/index.js +115 -115
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +52 -0
- package/src/hooks/useCreateProduct/index.js +8 -3
- package/src/hooks/useDeleteSubProductOptional/index.js +30 -30
- package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
- package/src/hooks/useDessert/helpers/index.js +51 -51
- package/src/hooks/useDevices/index.js +35 -35
- package/src/hooks/useDevices/queries.js +19 -19
- package/src/hooks/useDropzone/index.js +94 -94
- package/src/hooks/useDynamicAuth/index.js +13 -13
- package/src/hooks/useDynamicAuth/queries.js +24 -24
- package/src/hooks/useEditSubProductOptional/queries.js +10 -10
- package/src/hooks/useEvent/index.js +33 -33
- package/src/hooks/useFavoriteStores/index.js +19 -19
- package/src/hooks/useFavoriteStores/queries.js +47 -47
- package/src/hooks/useFetchJson/index.js +25 -25
- package/src/hooks/useFingerprintjs/index.js +172 -172
- package/src/hooks/useFullScreenMode/index.js +65 -65
- package/src/hooks/useGenerateNumberArray/index.js +17 -17
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -14
- package/src/hooks/useGetFoodRecomended/index.js +32 -33
- package/src/hooks/useGetFoodRecomended/queries.js +47 -47
- package/src/hooks/useGetMinPrice/index.js +12 -12
- package/src/hooks/useGetMinPrice/queries.js +7 -7
- package/src/hooks/useGetOneStoreRating/index.js +40 -40
- package/src/hooks/useGetOneStoreRating/queries.js +18 -18
- package/src/hooks/useGoogleLogin/index.js +160 -160
- package/src/hooks/useGoogleLogin/loadScript.js +15 -15
- package/src/hooks/useGoogleLogin/removeScript.js +7 -7
- package/src/hooks/useHover/index.js +29 -29
- package/src/hooks/useImagesStore/index.js +5 -4
- package/src/hooks/useInnerHtml/index.js +39 -39
- package/src/hooks/useKeypress/index.js +28 -28
- package/src/hooks/useLocationNavigate/index.js +54 -54
- package/src/hooks/useLogout/index.js +29 -21
- package/src/hooks/useManageQueryParams/index.js +37 -36
- package/src/hooks/useMobile/index.js +39 -39
- package/src/hooks/useOrderClient/index.js +5 -5
- package/src/hooks/useProviders/index.js +3 -3
- package/src/hooks/useProviders/queries.js +31 -31
- package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -12
- package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
- package/src/hooks/useProvidersStore/index.js +24 -24
- package/src/hooks/useProvidersStore/queries.js +31 -31
- package/src/hooks/useRatingArrayData/index.js +54 -54
- package/src/hooks/useRatingArrayData/queries.js +19 -19
- package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
- package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
- package/src/hooks/useRestaurant/index.js +19 -19
- package/src/hooks/useRestaurant/queries.js +80 -80
- package/src/hooks/useSales/useGetAllSales/index.js +25 -25
- package/src/hooks/useSchedule/index.js +72 -72
- package/src/hooks/useSchedule/index.jsx +22 -22
- package/src/hooks/useSchedule/queries.js +43 -43
- package/src/hooks/useScheduleData/index.js +123 -123
- package/src/hooks/useScroll/index.js +56 -56
- package/src/hooks/useScrollRotate/index.js +16 -16
- package/src/hooks/useStatusOpenStore/helpers/index.js +101 -101
- package/src/hooks/useStatusOpenStore/index.js +172 -172
- package/src/hooks/useStatusOrdersClient/queries.js +80 -80
- package/src/hooks/useStore/queries.js +163 -163
- package/src/hooks/useStoreCalendar/index.js +5 -5
- package/src/hooks/useStoreContacts/queries.js +1 -1
- package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -38
- package/src/hooks/useWindowSize/index.js +38 -38
- package/src/mock/dessert/index.js +16 -16
- package/src/mock/index.js +1 -1
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -8
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
export const GET_ALL_PRODUCT_STORE_RECOMENDED = gql`
|
|
4
|
-
query productFoodsAllRecommended($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
|
|
5
|
-
productFoodsAllRecommended(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
|
|
6
|
-
pId
|
|
7
|
-
sizeId #Talla
|
|
8
|
-
colorId #Color
|
|
9
|
-
cId #Country
|
|
10
|
-
dId #Department
|
|
11
|
-
ctId #Cuidad
|
|
12
|
-
fId #Características
|
|
13
|
-
pName
|
|
14
|
-
ProPrice
|
|
15
|
-
ProDescuento
|
|
16
|
-
ProUniDisponibles
|
|
17
|
-
ProDescription
|
|
18
|
-
ProProtegido
|
|
19
|
-
ProAssurance
|
|
20
|
-
ProStar
|
|
21
|
-
sTateLogistic
|
|
22
|
-
ProImage
|
|
23
|
-
ProWidth
|
|
24
|
-
ProHeight
|
|
25
|
-
ProLength
|
|
26
|
-
ProWeight
|
|
27
|
-
ProQuantity
|
|
28
|
-
ProOutstanding
|
|
29
|
-
pDatCre
|
|
30
|
-
pDatMod
|
|
31
|
-
ProDelivery
|
|
32
|
-
ProVoltaje
|
|
33
|
-
pState
|
|
34
|
-
feat {
|
|
35
|
-
fId
|
|
36
|
-
thpId
|
|
37
|
-
hpqrQuestion
|
|
38
|
-
}
|
|
39
|
-
area {
|
|
40
|
-
aId
|
|
41
|
-
aName
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
`
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_ALL_PRODUCT_STORE_RECOMENDED = gql`
|
|
4
|
+
query productFoodsAllRecommended($search: String, $min: Int, $max: Int, $gender: [String], $desc: [String], $categories: [ID], ) {
|
|
5
|
+
productFoodsAllRecommended(search: $search, min: $min, max: $max, gender: $gender, desc: $desc, categories: $categories,) {
|
|
6
|
+
pId
|
|
7
|
+
sizeId #Talla
|
|
8
|
+
colorId #Color
|
|
9
|
+
cId #Country
|
|
10
|
+
dId #Department
|
|
11
|
+
ctId #Cuidad
|
|
12
|
+
fId #Características
|
|
13
|
+
pName
|
|
14
|
+
ProPrice
|
|
15
|
+
ProDescuento
|
|
16
|
+
ProUniDisponibles
|
|
17
|
+
ProDescription
|
|
18
|
+
ProProtegido
|
|
19
|
+
ProAssurance
|
|
20
|
+
ProStar
|
|
21
|
+
sTateLogistic
|
|
22
|
+
ProImage
|
|
23
|
+
ProWidth
|
|
24
|
+
ProHeight
|
|
25
|
+
ProLength
|
|
26
|
+
ProWeight
|
|
27
|
+
ProQuantity
|
|
28
|
+
ProOutstanding
|
|
29
|
+
pDatCre
|
|
30
|
+
pDatMod
|
|
31
|
+
ProDelivery
|
|
32
|
+
ProVoltaje
|
|
33
|
+
pState
|
|
34
|
+
feat {
|
|
35
|
+
fId
|
|
36
|
+
thpId
|
|
37
|
+
hpqrQuestion
|
|
38
|
+
}
|
|
39
|
+
area {
|
|
40
|
+
aId
|
|
41
|
+
aName
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
`
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useQuery } from '@apollo/client'
|
|
2
|
-
import { GET_MIN_PEDIDO } from './queries'
|
|
3
|
-
|
|
4
|
-
export const useGetMinPrice = ({ idStore = '' } = {}) => {
|
|
5
|
-
const { data, loading, error } = useQuery(GET_MIN_PEDIDO, {
|
|
6
|
-
variables: {
|
|
7
|
-
idStore
|
|
8
|
-
}
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
return [data, { loading, error }]
|
|
12
|
-
}
|
|
1
|
+
import { useQuery } from '@apollo/client'
|
|
2
|
+
import { GET_MIN_PEDIDO } from './queries'
|
|
3
|
+
|
|
4
|
+
export const useGetMinPrice = ({ idStore = '' } = {}) => {
|
|
5
|
+
const { data, loading, error } = useQuery(GET_MIN_PEDIDO, {
|
|
6
|
+
variables: {
|
|
7
|
+
idStore
|
|
8
|
+
}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
return [data, { loading, error }]
|
|
12
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
export const GET_MIN_PEDIDO = gql`
|
|
4
|
-
query getMinPrice($idStore: ID){
|
|
5
|
-
getMinPrice(idStore: $idStore)
|
|
6
|
-
}
|
|
7
|
-
`
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_MIN_PEDIDO = gql`
|
|
4
|
+
query getMinPrice($idStore: ID){
|
|
5
|
+
getMinPrice(idStore: $idStore)
|
|
6
|
+
}
|
|
7
|
+
`
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
2
|
-
import { useLazyQuery } from '@apollo/client'
|
|
3
|
-
import { GET_ONE_RATING_STORE } from './queries'
|
|
4
|
-
|
|
5
|
-
export const useGetOneStoreRating = () => {
|
|
6
|
-
const [ratings, setRatings] = useState({
|
|
7
|
-
rGoodTemperature: 0,
|
|
8
|
-
rGoodCondition: 0,
|
|
9
|
-
rTasty: 0,
|
|
10
|
-
appearance: 0
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
const [getOneRating] = useLazyQuery(GET_ONE_RATING_STORE, {
|
|
14
|
-
onCompleted: res => {
|
|
15
|
-
if (res) {
|
|
16
|
-
setRatings((prevState) => {
|
|
17
|
-
const {
|
|
18
|
-
rGoodTemperature,
|
|
19
|
-
rGoodCondition,
|
|
20
|
-
rTasty,
|
|
21
|
-
rAppearance
|
|
22
|
-
} = res.getOneRating || {}
|
|
23
|
-
return {
|
|
24
|
-
...prevState,
|
|
25
|
-
rGoodTemperature: rGoodTemperature || 0,
|
|
26
|
-
rGoodCondition: rGoodCondition || 0,
|
|
27
|
-
rTasty: rTasty || 0,
|
|
28
|
-
appearance: rAppearance || 0
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
ratings,
|
|
37
|
-
setRatings,
|
|
38
|
-
getOneRating
|
|
39
|
-
}
|
|
40
|
-
}
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { useLazyQuery } from '@apollo/client'
|
|
3
|
+
import { GET_ONE_RATING_STORE } from './queries'
|
|
4
|
+
|
|
5
|
+
export const useGetOneStoreRating = () => {
|
|
6
|
+
const [ratings, setRatings] = useState({
|
|
7
|
+
rGoodTemperature: 0,
|
|
8
|
+
rGoodCondition: 0,
|
|
9
|
+
rTasty: 0,
|
|
10
|
+
appearance: 0
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const [getOneRating] = useLazyQuery(GET_ONE_RATING_STORE, {
|
|
14
|
+
onCompleted: res => {
|
|
15
|
+
if (res) {
|
|
16
|
+
setRatings((prevState) => {
|
|
17
|
+
const {
|
|
18
|
+
rGoodTemperature,
|
|
19
|
+
rGoodCondition,
|
|
20
|
+
rTasty,
|
|
21
|
+
rAppearance
|
|
22
|
+
} = res.getOneRating || {}
|
|
23
|
+
return {
|
|
24
|
+
...prevState,
|
|
25
|
+
rGoodTemperature: rGoodTemperature || 0,
|
|
26
|
+
rGoodCondition: rGoodCondition || 0,
|
|
27
|
+
rTasty: rTasty || 0,
|
|
28
|
+
appearance: rAppearance || 0
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
ratings,
|
|
37
|
+
setRatings,
|
|
38
|
+
getOneRating
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
export const GET_ONE_RATING_STORE = gql`
|
|
4
|
-
query getOneRating($idStore: ID){
|
|
5
|
-
getOneRating(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
|
-
`
|
|
1
|
+
import { gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
export const GET_ONE_RATING_STORE = gql`
|
|
4
|
+
query getOneRating($idStore: ID){
|
|
5
|
+
getOneRating(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
|
+
`
|
|
@@ -1,160 +1,160 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react'
|
|
2
|
-
import loadScript from './loadScript'
|
|
3
|
-
import removeScript from './removeScript'
|
|
4
|
-
|
|
5
|
-
export const useGoogleLogin = ({
|
|
6
|
-
onSuccess = () => {},
|
|
7
|
-
onAutoLoadFinished = () => {},
|
|
8
|
-
onFailure = () => {},
|
|
9
|
-
onRequest = () => {},
|
|
10
|
-
onScriptLoadFailure,
|
|
11
|
-
clientId,
|
|
12
|
-
cookiePolicy,
|
|
13
|
-
loginHint,
|
|
14
|
-
hostedDomain,
|
|
15
|
-
autoLoad,
|
|
16
|
-
isSignedIn,
|
|
17
|
-
fetchBasicProfile,
|
|
18
|
-
redirectUri,
|
|
19
|
-
discoveryDocs,
|
|
20
|
-
uxMode,
|
|
21
|
-
scope,
|
|
22
|
-
accessType,
|
|
23
|
-
responseType,
|
|
24
|
-
jsSrc = 'https://apis.google.com/js/api.js',
|
|
25
|
-
prompt
|
|
26
|
-
}) => {
|
|
27
|
-
const [loaded, setLoaded] = useState(false)
|
|
28
|
-
|
|
29
|
-
function handleSigninSuccess (res) {
|
|
30
|
-
/*
|
|
31
|
-
offer renamed response keys to names that match use
|
|
32
|
-
*/
|
|
33
|
-
const basicProfile = res.getBasicProfile()
|
|
34
|
-
const authResponse = res.getAuthResponse(true)
|
|
35
|
-
res.googleId = basicProfile.getId()
|
|
36
|
-
res.tokenObj = authResponse
|
|
37
|
-
res.tokenId = authResponse.id_token
|
|
38
|
-
res.accessToken = authResponse.access_token
|
|
39
|
-
res.profileObj = {
|
|
40
|
-
googleId: basicProfile.getId(),
|
|
41
|
-
imageUrl: basicProfile.getImageUrl(),
|
|
42
|
-
email: basicProfile.getEmail(),
|
|
43
|
-
name: basicProfile.getName(),
|
|
44
|
-
givenName: basicProfile.getGivenName(),
|
|
45
|
-
familyName: basicProfile.getFamilyName()
|
|
46
|
-
}
|
|
47
|
-
onSuccess(res)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function signIn (e) {
|
|
51
|
-
if (e) {
|
|
52
|
-
e.preventDefault() // to prevent submit if used within form
|
|
53
|
-
}
|
|
54
|
-
if (loaded) {
|
|
55
|
-
const GoogleAuth = window.gapi.auth2.getAuthInstance()
|
|
56
|
-
const options = {
|
|
57
|
-
prompt
|
|
58
|
-
}
|
|
59
|
-
onRequest()
|
|
60
|
-
if (responseType === 'code') {
|
|
61
|
-
GoogleAuth.grantOfflineAccess(options).then(
|
|
62
|
-
res => onSuccess(res),
|
|
63
|
-
err => onFailure(err)
|
|
64
|
-
)
|
|
65
|
-
} else {
|
|
66
|
-
GoogleAuth.signIn(options).then(
|
|
67
|
-
res => handleSigninSuccess(res),
|
|
68
|
-
err => onFailure(err)
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
useEffect(() => {
|
|
75
|
-
let unmounted = false
|
|
76
|
-
const onLoadFailure = onScriptLoadFailure || onFailure
|
|
77
|
-
loadScript(
|
|
78
|
-
document,
|
|
79
|
-
'script',
|
|
80
|
-
'google-login',
|
|
81
|
-
jsSrc,
|
|
82
|
-
() => {
|
|
83
|
-
const params = {
|
|
84
|
-
client_id: clientId,
|
|
85
|
-
cookie_policy: cookiePolicy,
|
|
86
|
-
login_hint: loginHint,
|
|
87
|
-
hosted_domain: hostedDomain,
|
|
88
|
-
fetch_basic_profile: fetchBasicProfile,
|
|
89
|
-
discoveryDocs,
|
|
90
|
-
ux_mode: uxMode,
|
|
91
|
-
redirect_uri: redirectUri,
|
|
92
|
-
scope,
|
|
93
|
-
access_type: accessType
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (responseType === 'code') {
|
|
97
|
-
params.access_type = 'offline'
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
window.gapi.load('auth2', () => {
|
|
101
|
-
const GoogleAuth = window.gapi.auth2.getAuthInstance()
|
|
102
|
-
if (!GoogleAuth) {
|
|
103
|
-
window.gapi.auth2.init(params).then(
|
|
104
|
-
res => {
|
|
105
|
-
if (!unmounted) {
|
|
106
|
-
setLoaded(true)
|
|
107
|
-
const signedIn = isSignedIn && res.isSignedIn.get()
|
|
108
|
-
onAutoLoadFinished(signedIn)
|
|
109
|
-
if (signedIn) {
|
|
110
|
-
handleSigninSuccess(res.currentUser.get())
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
err => {
|
|
115
|
-
setLoaded(true)
|
|
116
|
-
onAutoLoadFinished(false)
|
|
117
|
-
onLoadFailure(err)
|
|
118
|
-
}
|
|
119
|
-
)
|
|
120
|
-
} else {
|
|
121
|
-
GoogleAuth.then(
|
|
122
|
-
() => {
|
|
123
|
-
if (unmounted) {
|
|
124
|
-
return
|
|
125
|
-
}
|
|
126
|
-
if (isSignedIn && GoogleAuth.isSignedIn.get()) {
|
|
127
|
-
setLoaded(true)
|
|
128
|
-
onAutoLoadFinished(true)
|
|
129
|
-
handleSigninSuccess(GoogleAuth.currentUser.get())
|
|
130
|
-
} else {
|
|
131
|
-
setLoaded(true)
|
|
132
|
-
onAutoLoadFinished(false)
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
err => {
|
|
136
|
-
onFailure(err)
|
|
137
|
-
}
|
|
138
|
-
)
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
},
|
|
142
|
-
err => {
|
|
143
|
-
onLoadFailure(err)
|
|
144
|
-
}
|
|
145
|
-
)
|
|
146
|
-
|
|
147
|
-
return () => {
|
|
148
|
-
unmounted = true
|
|
149
|
-
removeScript(document, 'google-login')
|
|
150
|
-
}
|
|
151
|
-
}, [])
|
|
152
|
-
|
|
153
|
-
useEffect(() => {
|
|
154
|
-
if (autoLoad) {
|
|
155
|
-
signIn()
|
|
156
|
-
}
|
|
157
|
-
}, [loaded])
|
|
158
|
-
|
|
159
|
-
return { signIn, loaded }
|
|
160
|
-
}
|
|
1
|
+
import { useState, useEffect } from 'react'
|
|
2
|
+
import loadScript from './loadScript'
|
|
3
|
+
import removeScript from './removeScript'
|
|
4
|
+
|
|
5
|
+
export const useGoogleLogin = ({
|
|
6
|
+
onSuccess = () => {},
|
|
7
|
+
onAutoLoadFinished = () => {},
|
|
8
|
+
onFailure = () => {},
|
|
9
|
+
onRequest = () => {},
|
|
10
|
+
onScriptLoadFailure,
|
|
11
|
+
clientId,
|
|
12
|
+
cookiePolicy,
|
|
13
|
+
loginHint,
|
|
14
|
+
hostedDomain,
|
|
15
|
+
autoLoad,
|
|
16
|
+
isSignedIn,
|
|
17
|
+
fetchBasicProfile,
|
|
18
|
+
redirectUri,
|
|
19
|
+
discoveryDocs,
|
|
20
|
+
uxMode,
|
|
21
|
+
scope,
|
|
22
|
+
accessType,
|
|
23
|
+
responseType,
|
|
24
|
+
jsSrc = 'https://apis.google.com/js/api.js',
|
|
25
|
+
prompt
|
|
26
|
+
}) => {
|
|
27
|
+
const [loaded, setLoaded] = useState(false)
|
|
28
|
+
|
|
29
|
+
function handleSigninSuccess (res) {
|
|
30
|
+
/*
|
|
31
|
+
offer renamed response keys to names that match use
|
|
32
|
+
*/
|
|
33
|
+
const basicProfile = res.getBasicProfile()
|
|
34
|
+
const authResponse = res.getAuthResponse(true)
|
|
35
|
+
res.googleId = basicProfile.getId()
|
|
36
|
+
res.tokenObj = authResponse
|
|
37
|
+
res.tokenId = authResponse.id_token
|
|
38
|
+
res.accessToken = authResponse.access_token
|
|
39
|
+
res.profileObj = {
|
|
40
|
+
googleId: basicProfile.getId(),
|
|
41
|
+
imageUrl: basicProfile.getImageUrl(),
|
|
42
|
+
email: basicProfile.getEmail(),
|
|
43
|
+
name: basicProfile.getName(),
|
|
44
|
+
givenName: basicProfile.getGivenName(),
|
|
45
|
+
familyName: basicProfile.getFamilyName()
|
|
46
|
+
}
|
|
47
|
+
onSuccess(res)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function signIn (e) {
|
|
51
|
+
if (e) {
|
|
52
|
+
e.preventDefault() // to prevent submit if used within form
|
|
53
|
+
}
|
|
54
|
+
if (loaded) {
|
|
55
|
+
const GoogleAuth = window.gapi.auth2.getAuthInstance()
|
|
56
|
+
const options = {
|
|
57
|
+
prompt
|
|
58
|
+
}
|
|
59
|
+
onRequest()
|
|
60
|
+
if (responseType === 'code') {
|
|
61
|
+
GoogleAuth.grantOfflineAccess(options).then(
|
|
62
|
+
res => onSuccess(res),
|
|
63
|
+
err => onFailure(err)
|
|
64
|
+
)
|
|
65
|
+
} else {
|
|
66
|
+
GoogleAuth.signIn(options).then(
|
|
67
|
+
res => handleSigninSuccess(res),
|
|
68
|
+
err => onFailure(err)
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
let unmounted = false
|
|
76
|
+
const onLoadFailure = onScriptLoadFailure || onFailure
|
|
77
|
+
loadScript(
|
|
78
|
+
document,
|
|
79
|
+
'script',
|
|
80
|
+
'google-login',
|
|
81
|
+
jsSrc,
|
|
82
|
+
() => {
|
|
83
|
+
const params = {
|
|
84
|
+
client_id: clientId,
|
|
85
|
+
cookie_policy: cookiePolicy,
|
|
86
|
+
login_hint: loginHint,
|
|
87
|
+
hosted_domain: hostedDomain,
|
|
88
|
+
fetch_basic_profile: fetchBasicProfile,
|
|
89
|
+
discoveryDocs,
|
|
90
|
+
ux_mode: uxMode,
|
|
91
|
+
redirect_uri: redirectUri,
|
|
92
|
+
scope,
|
|
93
|
+
access_type: accessType
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (responseType === 'code') {
|
|
97
|
+
params.access_type = 'offline'
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
window.gapi.load('auth2', () => {
|
|
101
|
+
const GoogleAuth = window.gapi.auth2.getAuthInstance()
|
|
102
|
+
if (!GoogleAuth) {
|
|
103
|
+
window.gapi.auth2.init(params).then(
|
|
104
|
+
res => {
|
|
105
|
+
if (!unmounted) {
|
|
106
|
+
setLoaded(true)
|
|
107
|
+
const signedIn = isSignedIn && res.isSignedIn.get()
|
|
108
|
+
onAutoLoadFinished(signedIn)
|
|
109
|
+
if (signedIn) {
|
|
110
|
+
handleSigninSuccess(res.currentUser.get())
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
err => {
|
|
115
|
+
setLoaded(true)
|
|
116
|
+
onAutoLoadFinished(false)
|
|
117
|
+
onLoadFailure(err)
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
} else {
|
|
121
|
+
GoogleAuth.then(
|
|
122
|
+
() => {
|
|
123
|
+
if (unmounted) {
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
if (isSignedIn && GoogleAuth.isSignedIn.get()) {
|
|
127
|
+
setLoaded(true)
|
|
128
|
+
onAutoLoadFinished(true)
|
|
129
|
+
handleSigninSuccess(GoogleAuth.currentUser.get())
|
|
130
|
+
} else {
|
|
131
|
+
setLoaded(true)
|
|
132
|
+
onAutoLoadFinished(false)
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
err => {
|
|
136
|
+
onFailure(err)
|
|
137
|
+
}
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
},
|
|
142
|
+
err => {
|
|
143
|
+
onLoadFailure(err)
|
|
144
|
+
}
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
return () => {
|
|
148
|
+
unmounted = true
|
|
149
|
+
removeScript(document, 'google-login')
|
|
150
|
+
}
|
|
151
|
+
}, [])
|
|
152
|
+
|
|
153
|
+
useEffect(() => {
|
|
154
|
+
if (autoLoad) {
|
|
155
|
+
signIn()
|
|
156
|
+
}
|
|
157
|
+
}, [loaded])
|
|
158
|
+
|
|
159
|
+
return { signIn, loaded }
|
|
160
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export default (d, s, id, jsSrc, cb, onError) => {
|
|
2
|
-
const element = d.getElementsByTagName(s)[0]
|
|
3
|
-
const fjs = element
|
|
4
|
-
let js = element
|
|
5
|
-
js = d.createElement(s)
|
|
6
|
-
js.id = id
|
|
7
|
-
js.src = jsSrc
|
|
8
|
-
if (fjs && fjs.parentNode) {
|
|
9
|
-
fjs.parentNode.insertBefore(js, fjs)
|
|
10
|
-
} else {
|
|
11
|
-
d.head.appendChild(js)
|
|
12
|
-
}
|
|
13
|
-
js.onerror = onError
|
|
14
|
-
js.onload = cb
|
|
15
|
-
}
|
|
1
|
+
export default (d, s, id, jsSrc, cb, onError) => {
|
|
2
|
+
const element = d.getElementsByTagName(s)[0]
|
|
3
|
+
const fjs = element
|
|
4
|
+
let js = element
|
|
5
|
+
js = d.createElement(s)
|
|
6
|
+
js.id = id
|
|
7
|
+
js.src = jsSrc
|
|
8
|
+
if (fjs && fjs.parentNode) {
|
|
9
|
+
fjs.parentNode.insertBefore(js, fjs)
|
|
10
|
+
} else {
|
|
11
|
+
d.head.appendChild(js)
|
|
12
|
+
}
|
|
13
|
+
js.onerror = onError
|
|
14
|
+
js.onload = cb
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default (d, id) => {
|
|
2
|
-
const element = d.getElementById(id)
|
|
3
|
-
|
|
4
|
-
if (element) {
|
|
5
|
-
element.parentNode.removeChild(element)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
export default (d, id) => {
|
|
2
|
+
const element = d.getElementById(id)
|
|
3
|
+
|
|
4
|
+
if (element) {
|
|
5
|
+
element.parentNode.removeChild(element)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { useRef, useState, useEffect } from 'react'
|
|
2
|
-
|
|
3
|
-
export function useHover () {
|
|
4
|
-
const [value, setValue] = useState(false)
|
|
5
|
-
|
|
6
|
-
const ref = useRef(null)
|
|
7
|
-
|
|
8
|
-
const handleMouseOver = () => { return setValue(true) }
|
|
9
|
-
const handleMouseOut = () => { return setValue(false) }
|
|
10
|
-
|
|
11
|
-
useEffect(
|
|
12
|
-
() => {
|
|
13
|
-
const node = ref.current
|
|
14
|
-
if (node) {
|
|
15
|
-
node.addEventListener('mouseover', handleMouseOver)
|
|
16
|
-
node.addEventListener('mouseout', handleMouseOut)
|
|
17
|
-
|
|
18
|
-
return () => {
|
|
19
|
-
node.removeEventListener('mouseover', handleMouseOver)
|
|
20
|
-
node.removeEventListener('mouseout', handleMouseOut)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return {}
|
|
24
|
-
},
|
|
25
|
-
[] // Recall only if ref changes
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
return [ref, value]
|
|
29
|
-
}
|
|
1
|
+
import { useRef, useState, useEffect } from 'react'
|
|
2
|
+
|
|
3
|
+
export function useHover () {
|
|
4
|
+
const [value, setValue] = useState(false)
|
|
5
|
+
|
|
6
|
+
const ref = useRef(null)
|
|
7
|
+
|
|
8
|
+
const handleMouseOver = () => { return setValue(true) }
|
|
9
|
+
const handleMouseOut = () => { return setValue(false) }
|
|
10
|
+
|
|
11
|
+
useEffect(
|
|
12
|
+
() => {
|
|
13
|
+
const node = ref.current
|
|
14
|
+
if (node) {
|
|
15
|
+
node.addEventListener('mouseover', handleMouseOver)
|
|
16
|
+
node.addEventListener('mouseout', handleMouseOut)
|
|
17
|
+
|
|
18
|
+
return () => {
|
|
19
|
+
node.removeEventListener('mouseover', handleMouseOver)
|
|
20
|
+
node.removeEventListener('mouseout', handleMouseOut)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return {}
|
|
24
|
+
},
|
|
25
|
+
[] // Recall only if ref changes
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
return [ref, value]
|
|
29
|
+
}
|