@quiltt/react 4.0.1 → 4.1.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @quiltt/react
|
|
2
2
|
|
|
3
|
+
## 4.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#342](https://github.com/quiltt/quiltt-js/pull/342) [`6a387ba`](https://github.com/quiltt/quiltt-js/commit/6a387ba0db77912df85c6cd1924f63edf50f9cdd) Thanks [@sirwolfgang](https://github.com/sirwolfgang)! - Create useQuilttInstitutions hook
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`6a387ba`](https://github.com/quiltt/quiltt-js/commit/6a387ba0db77912df85c6cd1924f63edf50f9cdd)]:
|
|
12
|
+
- @quiltt/core@4.1.0
|
|
13
|
+
|
|
3
14
|
## 4.0.1
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ export { u as useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect-clie
|
|
|
4
4
|
import { Q as QuilttAuthProvider } from './QuilttAuthProvider-client-CER-TOln.js';
|
|
5
5
|
export { b as useAuthenticateSession, a as useIdentifySession, u as useImportSession, c as useRevokeSession } from './QuilttAuthProvider-client-CER-TOln.js';
|
|
6
6
|
export { u as useQuilttClient } from './useQuilttClient-client-CAAUait1.js';
|
|
7
|
-
import { u as useQuilttConnector } from './useQuilttConnector-client-
|
|
7
|
+
import { u as useQuilttConnector } from './useQuilttConnector-client-BB7kw8vs.js';
|
|
8
8
|
export { u as useQuilttSession } from './useQuilttSession-client-D2mjVT4S.js';
|
|
9
9
|
export { u as useQuilttSettings } from './useQuilttSettings-client-BOCBjFXe.js';
|
|
10
10
|
export { u as useSession } from './useSession-client-CCAvnROP.js';
|
package/dist/{useQuilttConnector-client-sRplTzek.js → useQuilttConnector-client-BB7kw8vs.js}
RENAMED
|
@@ -4,13 +4,15 @@ import { cdnBase } from '@quiltt/core';
|
|
|
4
4
|
import { u as useQuilttSession } from './useQuilttSession-client-D2mjVT4S.js';
|
|
5
5
|
import { u as useScript } from './useScript-client-JCgaTW9n.js';
|
|
6
6
|
|
|
7
|
-
var version = "4.0
|
|
7
|
+
var version = "4.1.0";
|
|
8
8
|
|
|
9
9
|
const useQuilttConnector = (connectorId, options)=>{
|
|
10
10
|
const status = useScript(`${cdnBase}/v1/connector.js?agent=react-${version}`, {
|
|
11
11
|
nonce: options?.nonce
|
|
12
12
|
});
|
|
13
|
-
|
|
13
|
+
// This ensures we're not destructuring `session` before the script has loaded
|
|
14
|
+
const useQuilttSessionReturn = useQuilttSession();
|
|
15
|
+
const session = useQuilttSessionReturn?.session || null;
|
|
14
16
|
const [connector, setConnector] = useState();
|
|
15
17
|
const [isOpening, setIsOpening] = useState(false);
|
|
16
18
|
// Set Session
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quiltt/react",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "React Components and Hooks for Quiltt Connector",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"quiltt",
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
"main": "dist/index.js",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@apollo/client": "^3.12.4",
|
|
38
|
-
"
|
|
38
|
+
"use-debounce": "^10.0.4",
|
|
39
|
+
"@quiltt/core": "4.1.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@biomejs/biome": "1.9.4",
|
|
@@ -22,7 +22,11 @@ export const useQuilttConnector = (
|
|
|
22
22
|
const status = useScript(`${cdnBase}/v1/connector.js?agent=react-${version}`, {
|
|
23
23
|
nonce: options?.nonce,
|
|
24
24
|
})
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
// This ensures we're not destructuring `session` before the script has loaded
|
|
27
|
+
const useQuilttSessionReturn = useQuilttSession()
|
|
28
|
+
const session = useQuilttSessionReturn?.session || null
|
|
29
|
+
|
|
26
30
|
const [connector, setConnector] = useState<ConnectorSDKConnector>()
|
|
27
31
|
const [isOpening, setIsOpening] = useState<boolean>(false)
|
|
28
32
|
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react'
|
|
4
|
+
|
|
5
|
+
import { useDebounce } from 'use-debounce'
|
|
6
|
+
|
|
7
|
+
import { InstitutionsAPI } from '@quiltt/core'
|
|
8
|
+
import type { ErrorData, InstitutionsData } from '@quiltt/core'
|
|
9
|
+
|
|
10
|
+
import { version } from '@/version'
|
|
11
|
+
import useSession from './useSession'
|
|
12
|
+
|
|
13
|
+
export type UseQuilttInstitutions = (
|
|
14
|
+
connectorId: string,
|
|
15
|
+
onErrorCallback?: (msg: string) => void
|
|
16
|
+
) => {
|
|
17
|
+
searchTerm: string
|
|
18
|
+
searchResults: InstitutionsData
|
|
19
|
+
isSearching: boolean
|
|
20
|
+
setSearchTerm: (term: string) => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const useQuilttInstitutions: UseQuilttInstitutions = (connectorId, onErrorCallback) => {
|
|
24
|
+
const agent = useMemo(() => {
|
|
25
|
+
// Try deprecated navigator.product first (still used in some RN versions)
|
|
26
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
27
|
+
return `react-native-${version}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Detect React Native by its unique environment characteristics
|
|
31
|
+
const isReactNative = !!(
|
|
32
|
+
// Has window (unlike Node.js)
|
|
33
|
+
(
|
|
34
|
+
typeof window !== 'undefined' &&
|
|
35
|
+
// No document in window (unlike browsers)
|
|
36
|
+
typeof window.document === 'undefined' &&
|
|
37
|
+
// Has navigator (unlike Node.js)
|
|
38
|
+
typeof navigator !== 'undefined'
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
return isReactNative ? `react-native-${version}` : `react-${version}`
|
|
43
|
+
}, [])
|
|
44
|
+
|
|
45
|
+
const institutionsAPI = useMemo(
|
|
46
|
+
() => new InstitutionsAPI(connectorId, agent),
|
|
47
|
+
[connectorId, agent]
|
|
48
|
+
)
|
|
49
|
+
const [session] = useSession()
|
|
50
|
+
|
|
51
|
+
const [searchTermInput, setSearchTermInput] = useState('')
|
|
52
|
+
const [searchTerm] = useDebounce(searchTermInput, 350)
|
|
53
|
+
const [searchResults, setSearchResults] = useState<InstitutionsData>([])
|
|
54
|
+
|
|
55
|
+
const [isSearching, setIsSearching] = useState(false)
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Start Search
|
|
59
|
+
* This function is used to initiate a search for institutions based on the provided term with
|
|
60
|
+
* a minimum length of 2 characters. Debouncing is applied to avoid excessive API calls.
|
|
61
|
+
*/
|
|
62
|
+
const startSearch = useCallback((term: string) => {
|
|
63
|
+
if (term.trim().length < 2) {
|
|
64
|
+
setSearchResults([])
|
|
65
|
+
setIsSearching(false)
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
setIsSearching(true)
|
|
70
|
+
setSearchTermInput(term)
|
|
71
|
+
}, [])
|
|
72
|
+
|
|
73
|
+
const handleError = useCallback(
|
|
74
|
+
(message: string) => {
|
|
75
|
+
const errorMessage = message || 'Unknown error occurred while searching institutions'
|
|
76
|
+
|
|
77
|
+
console.error('Quiltt Institutions Search Error:', errorMessage)
|
|
78
|
+
if (onErrorCallback) onErrorCallback(errorMessage)
|
|
79
|
+
},
|
|
80
|
+
[onErrorCallback]
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Run Search
|
|
85
|
+
* This effect will run when the searchTerm changes and is at least 2 characters long.
|
|
86
|
+
*/
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (!session?.token || !connectorId || !searchTerm || searchTerm.trim().length < 2) {
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const abortController = new AbortController()
|
|
93
|
+
|
|
94
|
+
institutionsAPI
|
|
95
|
+
.search(session?.token, connectorId, searchTerm, abortController.signal)
|
|
96
|
+
.then((response) => {
|
|
97
|
+
if (!abortController.signal.aborted) {
|
|
98
|
+
if (response.status === 200) {
|
|
99
|
+
setSearchResults(response.data as InstitutionsData)
|
|
100
|
+
} else {
|
|
101
|
+
handleError((response.data as ErrorData).message || 'Failed to fetch institutions')
|
|
102
|
+
}
|
|
103
|
+
setIsSearching(false)
|
|
104
|
+
}
|
|
105
|
+
})
|
|
106
|
+
.catch((error) => {
|
|
107
|
+
if (!abortController.signal.aborted) {
|
|
108
|
+
handleError(error.message)
|
|
109
|
+
setIsSearching(false)
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
return () => abortController.abort()
|
|
114
|
+
}, [session?.token, connectorId, searchTerm, institutionsAPI, handleError])
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
searchTerm,
|
|
118
|
+
searchResults,
|
|
119
|
+
isSearching,
|
|
120
|
+
setSearchTerm: startSearch,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default useQuilttInstitutions
|