@planningcenter/chat-react-native 4.6.0 → 4.6.1-rc.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/build/navigation/chat_access_gate.d.ts.map +1 -1
- package/build/navigation/chat_access_gate.js +51 -36
- package/build/navigation/chat_access_gate.js.map +1 -1
- package/package.json +2 -2
- package/src/navigation/__tests__/chat_access_gate.test.tsx +131 -0
- package/src/navigation/chat_access_gate.tsx +15 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_access_gate.d.ts","sourceRoot":"","sources":["../../src/navigation/chat_access_gate.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,iBAAiB,EAAqB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"chat_access_gate.d.ts","sourceRoot":"","sources":["../../src/navigation/chat_access_gate.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,iBAAiB,EAAqB,MAAM,OAAO,CAAA;AAWnE,wBAAgB,cAAc,CAAC,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CA6B7D"}
|
|
@@ -2,74 +2,89 @@ import { c as _c } from "react/compiler-runtime";
|
|
|
2
2
|
import React, { useEffect, useRef } from 'react';
|
|
3
3
|
import { DefaultLoading } from '../components/page/loading';
|
|
4
4
|
import { useChatContext } from '../contexts/chat_context';
|
|
5
|
-
import { useApiGet
|
|
5
|
+
import { useApiGet } from '../hooks';
|
|
6
6
|
import { currentPersonRequestArgs } from '../hooks/use_current_person';
|
|
7
|
+
import { organizationRequestArgs } from '../hooks/use_organization';
|
|
7
8
|
import { AgeCheckRequiredScreen } from '../screens/age_check/age_check_required_screen';
|
|
8
9
|
import { AgeCheckUnderageScreen } from '../screens/age_check/age_check_underage_screen';
|
|
9
10
|
import { AgeQualificationStatus } from '../types';
|
|
11
|
+
import { ONE_HOUR } from '../utils/time';
|
|
10
12
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
13
|
export function ChatAccessGate(t0) {
|
|
12
|
-
const $ = _c(
|
|
14
|
+
const $ = _c(7);
|
|
13
15
|
const {
|
|
14
16
|
children
|
|
15
17
|
} = t0;
|
|
16
18
|
const {
|
|
17
19
|
data: person,
|
|
18
|
-
|
|
20
|
+
error: personError
|
|
19
21
|
} = useApiGet(currentPersonRequestArgs);
|
|
22
|
+
let t1;
|
|
23
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
24
|
+
t1 = {
|
|
25
|
+
staleTime: ONE_HOUR
|
|
26
|
+
};
|
|
27
|
+
$[0] = t1;
|
|
28
|
+
} else {
|
|
29
|
+
t1 = $[0];
|
|
30
|
+
}
|
|
20
31
|
const {
|
|
21
|
-
data: organization
|
|
22
|
-
|
|
23
|
-
|
|
32
|
+
data: organization,
|
|
33
|
+
error: organizationError
|
|
34
|
+
} = useApiGet(organizationRequestArgs, t1);
|
|
35
|
+
const ageQualificationStatus = organization ? person?.ageQualificationStatus : undefined;
|
|
24
36
|
const contactEmail = organization?.contactEmail;
|
|
25
37
|
useAgeDisqualification(ageQualificationStatus, contactEmail);
|
|
26
|
-
if (!
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
38
|
+
if (!person || !organization) {
|
|
39
|
+
if (personError) {
|
|
40
|
+
throw personError;
|
|
41
|
+
}
|
|
42
|
+
if (organizationError) {
|
|
43
|
+
throw organizationError;
|
|
44
|
+
}
|
|
45
|
+
let t2;
|
|
46
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
47
|
+
t2 = /*#__PURE__*/_jsx(DefaultLoading, {});
|
|
48
|
+
$[1] = t2;
|
|
31
49
|
} else {
|
|
32
|
-
|
|
50
|
+
t2 = $[1];
|
|
33
51
|
}
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
if (!person) {
|
|
37
|
-
throw new Error("Current person not found");
|
|
52
|
+
return t2;
|
|
38
53
|
}
|
|
39
54
|
if (ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED) {
|
|
40
|
-
let
|
|
41
|
-
if ($[
|
|
42
|
-
|
|
55
|
+
let t2;
|
|
56
|
+
if ($[2] !== contactEmail) {
|
|
57
|
+
t2 = /*#__PURE__*/_jsx(AgeCheckUnderageScreen, {
|
|
43
58
|
contactEmail: contactEmail
|
|
44
59
|
});
|
|
45
|
-
$[
|
|
46
|
-
$[
|
|
60
|
+
$[2] = contactEmail;
|
|
61
|
+
$[3] = t2;
|
|
47
62
|
} else {
|
|
48
|
-
|
|
63
|
+
t2 = $[3];
|
|
49
64
|
}
|
|
50
|
-
return
|
|
65
|
+
return t2;
|
|
51
66
|
}
|
|
52
67
|
if (ageQualificationStatus === AgeQualificationStatus.UNKNOWN) {
|
|
53
|
-
let
|
|
54
|
-
if ($[
|
|
55
|
-
|
|
56
|
-
$[
|
|
68
|
+
let t2;
|
|
69
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
70
|
+
t2 = /*#__PURE__*/_jsx(AgeCheckRequiredScreen, {});
|
|
71
|
+
$[4] = t2;
|
|
57
72
|
} else {
|
|
58
|
-
|
|
73
|
+
t2 = $[4];
|
|
59
74
|
}
|
|
60
|
-
return
|
|
75
|
+
return t2;
|
|
61
76
|
}
|
|
62
|
-
let
|
|
63
|
-
if ($[
|
|
64
|
-
|
|
77
|
+
let t2;
|
|
78
|
+
if ($[5] !== children) {
|
|
79
|
+
t2 = /*#__PURE__*/_jsx(_Fragment, {
|
|
65
80
|
children: children
|
|
66
81
|
});
|
|
67
|
-
$[
|
|
68
|
-
$[
|
|
82
|
+
$[5] = children;
|
|
83
|
+
$[6] = t2;
|
|
69
84
|
} else {
|
|
70
|
-
|
|
85
|
+
t2 = $[6];
|
|
71
86
|
}
|
|
72
|
-
return
|
|
87
|
+
return t2;
|
|
73
88
|
}
|
|
74
89
|
|
|
75
90
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat_access_gate.js","names":["React","useEffect","useRef","DefaultLoading","useChatContext","useApiGet","
|
|
1
|
+
{"version":3,"file":"chat_access_gate.js","names":["React","useEffect","useRef","DefaultLoading","useChatContext","useApiGet","currentPersonRequestArgs","organizationRequestArgs","AgeCheckRequiredScreen","AgeCheckUnderageScreen","AgeQualificationStatus","ONE_HOUR","jsx","_jsx","Fragment","_Fragment","ChatAccessGate","t0","$","_c","children","data","person","error","personError","t1","Symbol","for","staleTime","organization","organizationError","ageQualificationStatus","undefined","contactEmail","useAgeDisqualification","t2","DISQUALIFIED","UNKNOWN","onAgeDisqualification","hasCalledCallbackRef","current"],"sources":["../../src/navigation/chat_access_gate.tsx"],"sourcesContent":["import React, { PropsWithChildren, useEffect, useRef } from 'react'\nimport { DefaultLoading } from '../components/page/loading'\nimport { useChatContext } from '../contexts/chat_context'\nimport { useApiGet } from '../hooks'\nimport { currentPersonRequestArgs } from '../hooks/use_current_person'\nimport { organizationRequestArgs } from '../hooks/use_organization'\nimport { AgeCheckRequiredScreen } from '../screens/age_check/age_check_required_screen'\nimport { AgeCheckUnderageScreen } from '../screens/age_check/age_check_underage_screen'\nimport { AgeQualificationStatus, CurrentPersonResource, OrganizationResource } from '../types'\nimport { ONE_HOUR } from '../utils/time'\n\nexport function ChatAccessGate({ children }: PropsWithChildren) {\n const { data: person, error: personError } =\n useApiGet<CurrentPersonResource>(currentPersonRequestArgs)\n const { data: organization, error: organizationError } = useApiGet<OrganizationResource>(\n organizationRequestArgs,\n { staleTime: ONE_HOUR }\n )\n\n const ageQualificationStatus = organization ? person?.ageQualificationStatus : undefined\n const contactEmail = organization?.contactEmail\n\n useAgeDisqualification(ageQualificationStatus, contactEmail)\n\n if (!person || !organization) {\n if (personError) throw personError\n if (organizationError) throw organizationError\n\n return <DefaultLoading />\n }\n\n if (ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED) {\n return <AgeCheckUnderageScreen contactEmail={contactEmail} />\n }\n\n if (ageQualificationStatus === AgeQualificationStatus.UNKNOWN) {\n return <AgeCheckRequiredScreen />\n }\n\n return <>{children}</>\n}\n\n/**\n * Helper hook that handles the age disqualification logic.\n *\n * If a host app provides an onAgeDisqualification callback, it will be called\n * when a user is found to be disqualified by their age.\n */\nfunction useAgeDisqualification(\n ageQualificationStatus: CurrentPersonResource['ageQualificationStatus'],\n contactEmail: string | undefined\n) {\n const { onAgeDisqualification } = useChatContext()\n const hasCalledCallbackRef = useRef(false)\n\n useEffect(() => {\n if (\n ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED &&\n !hasCalledCallbackRef.current\n ) {\n hasCalledCallbackRef.current = true\n onAgeDisqualification({ contactEmail: contactEmail || '' })\n }\n }, [ageQualificationStatus, onAgeDisqualification, contactEmail])\n}\n"],"mappings":";AAAA,OAAOA,KAAK,IAAuBC,SAAS,EAAEC,MAAM,QAAQ,OAAO;AACnE,SAASC,cAAc,QAAQ,4BAA4B;AAC3D,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,SAAS,QAAQ,UAAU;AACpC,SAASC,wBAAwB,QAAQ,6BAA6B;AACtE,SAASC,uBAAuB,QAAQ,2BAA2B;AACnE,SAASC,sBAAsB,QAAQ,gDAAgD;AACvF,SAASC,sBAAsB,QAAQ,gDAAgD;AACvF,SAASC,sBAAsB,QAAqD,UAAU;AAC9F,SAASC,QAAQ,QAAQ,eAAe;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAExC,OAAO,SAAAC,eAAAC,EAAA;EAAA,MAAAC,CAAA,GAAAC,EAAA;EAAwB;IAAAC;EAAA,IAAAH,EAA+B;EAC5D;IAAAI,IAAA,EAAAC,MAAA;IAAAC,KAAA,EAAAC;EAAA,IACEnB,SAAS,CAAwBC,wBAAwB,CAAC;EAAA,IAAAmB,EAAA;EAAA,IAAAP,CAAA,QAAAQ,MAAA,CAAAC,GAAA;IAG1DF,EAAA;MAAAG,SAAA,EAAajB;IAAS,CAAC;IAAAO,CAAA,MAAAO,EAAA;EAAA;IAAAA,EA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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "4.6.0",
|
|
3
|
+
"version": "4.6.1-rc.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"sf-symbols-typescript": "^2.2.0",
|
|
85
85
|
"typescript": "~6.0.3"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "b14eef4873eda58631646b19f8b5383c89c089b2"
|
|
88
88
|
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
2
|
+
import { render, screen } from '@testing-library/react-native'
|
|
3
|
+
import React, { Suspense } from 'react'
|
|
4
|
+
import { Text } from 'react-native'
|
|
5
|
+
import { buildTestQueryClient } from '../../__utils__/query_client'
|
|
6
|
+
import { ErrorBoundary } from '../../components/page/error_boundary'
|
|
7
|
+
import { ChatContext, ChatContextValue } from '../../contexts/chat_context'
|
|
8
|
+
import { ApiClient, useApiClient } from '../../hooks/use_api_client'
|
|
9
|
+
import { currentPersonQueryKey } from '../../hooks/use_current_person'
|
|
10
|
+
import { organizationRequestArgs } from '../../hooks/use_organization'
|
|
11
|
+
import { getRequestQueryKey } from '../../hooks/use_suspense_api'
|
|
12
|
+
import { Session } from '../../utils'
|
|
13
|
+
import { ResponseError } from '../../utils/response_error'
|
|
14
|
+
import { FIVE_MINUTES } from '../../utils/time'
|
|
15
|
+
import { ChatAccessGate } from '../chat_access_gate'
|
|
16
|
+
|
|
17
|
+
jest.mock('../../hooks/use_api_client')
|
|
18
|
+
jest.mock('../../components/page/loading', () => ({ DefaultLoading: () => null }))
|
|
19
|
+
|
|
20
|
+
const mockedUseApiClient = useApiClient as jest.MockedFunction<typeof useApiClient>
|
|
21
|
+
|
|
22
|
+
const failedResponse = (status: number) =>
|
|
23
|
+
new ResponseError({ status, statusText: '', errors: [] } as never)
|
|
24
|
+
|
|
25
|
+
const person = { type: 'Person', id: 1, ageQualificationStatus: 'qualified' }
|
|
26
|
+
const organization = { type: 'Organization', id: 1 }
|
|
27
|
+
|
|
28
|
+
let get: jest.Mock
|
|
29
|
+
|
|
30
|
+
const requestCount = (path: string) => get.mock.calls.filter(([{ url }]) => url === path).length
|
|
31
|
+
|
|
32
|
+
const queryClients: QueryClient[] = []
|
|
33
|
+
const buildQueryClient = () => {
|
|
34
|
+
const queryClient = buildTestQueryClient({
|
|
35
|
+
defaultOptions: { queries: { gcTime: FIVE_MINUTES } },
|
|
36
|
+
})
|
|
37
|
+
queryClients.push(queryClient)
|
|
38
|
+
|
|
39
|
+
return queryClient
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cacheFailure = (queryClient: QueryClient, queryKey: readonly unknown[], status: number) =>
|
|
43
|
+
queryClient
|
|
44
|
+
.getQueryCache()
|
|
45
|
+
.build(queryClient, { queryKey })
|
|
46
|
+
.setState({ status: 'error', error: failedResponse(status), errorUpdateCount: 1 })
|
|
47
|
+
|
|
48
|
+
const renderGate = (queryClient: QueryClient) => {
|
|
49
|
+
const session = new Session({ token: { access_token: 'token' } })
|
|
50
|
+
const value = {
|
|
51
|
+
session,
|
|
52
|
+
token: session.token,
|
|
53
|
+
env: 'production',
|
|
54
|
+
onAgeDisqualification: () => {},
|
|
55
|
+
} as unknown as ChatContextValue
|
|
56
|
+
|
|
57
|
+
return render(
|
|
58
|
+
<ChatContext.Provider value={value}>
|
|
59
|
+
<QueryClientProvider client={queryClient}>
|
|
60
|
+
<ErrorBoundary
|
|
61
|
+
fallback={error => (
|
|
62
|
+
<Text>{error instanceof ResponseError ? `failed ${error.status}` : error.message}</Text>
|
|
63
|
+
)}
|
|
64
|
+
>
|
|
65
|
+
<Suspense fallback={null}>
|
|
66
|
+
<ChatAccessGate>
|
|
67
|
+
<Text>chat</Text>
|
|
68
|
+
</ChatAccessGate>
|
|
69
|
+
</Suspense>
|
|
70
|
+
</ErrorBoundary>
|
|
71
|
+
</QueryClientProvider>
|
|
72
|
+
</ChatContext.Provider>
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
get = jest.fn(({ url }: { url: string }) =>
|
|
78
|
+
Promise.resolve({ data: url === '/me' ? person : organization })
|
|
79
|
+
)
|
|
80
|
+
mockedUseApiClient.mockReturnValue({ chat: { get } } as unknown as ApiClient)
|
|
81
|
+
jest.spyOn(console, 'error').mockImplementation(() => {})
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
afterEach(() => {
|
|
85
|
+
queryClients.splice(0).forEach(queryClient => queryClient.clear())
|
|
86
|
+
jest.restoreAllMocks()
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
describe('ChatAccessGate', () => {
|
|
90
|
+
it('refetches the current person when a cached request failed earlier', async () => {
|
|
91
|
+
const queryClient = buildQueryClient()
|
|
92
|
+
cacheFailure(queryClient, currentPersonQueryKey, 401)
|
|
93
|
+
|
|
94
|
+
renderGate(queryClient)
|
|
95
|
+
|
|
96
|
+
expect(await screen.findByText('chat')).toBeTruthy()
|
|
97
|
+
expect(requestCount('/me')).toBe(1)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('refetches both requests when an expired token failed them together', async () => {
|
|
101
|
+
const queryClient = buildQueryClient()
|
|
102
|
+
cacheFailure(queryClient, currentPersonQueryKey, 401)
|
|
103
|
+
cacheFailure(queryClient, getRequestQueryKey(organizationRequestArgs), 401)
|
|
104
|
+
|
|
105
|
+
renderGate(queryClient)
|
|
106
|
+
|
|
107
|
+
expect(await screen.findByText('chat')).toBeTruthy()
|
|
108
|
+
expect(requestCount('/me')).toBe(1)
|
|
109
|
+
expect(requestCount('/')).toBe(1)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('passes a failed current person request to the error boundary', async () => {
|
|
113
|
+
get.mockImplementation(({ url }: { url: string }) =>
|
|
114
|
+
url === '/me' ? Promise.reject(failedResponse(429)) : Promise.resolve({ data: organization })
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
renderGate(buildQueryClient())
|
|
118
|
+
|
|
119
|
+
expect(await screen.findByText('failed 429')).toBeTruthy()
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('passes a failed organization request to the error boundary', async () => {
|
|
123
|
+
get.mockImplementation(({ url }: { url: string }) =>
|
|
124
|
+
url === '/' ? Promise.reject(failedResponse(401)) : Promise.resolve({ data: person })
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
renderGate(buildQueryClient())
|
|
128
|
+
|
|
129
|
+
expect(await screen.findByText('failed 401')).toBeTruthy()
|
|
130
|
+
})
|
|
131
|
+
})
|
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useEffect, useRef } from 'react'
|
|
2
2
|
import { DefaultLoading } from '../components/page/loading'
|
|
3
3
|
import { useChatContext } from '../contexts/chat_context'
|
|
4
|
-
import { useApiGet
|
|
4
|
+
import { useApiGet } from '../hooks'
|
|
5
5
|
import { currentPersonRequestArgs } from '../hooks/use_current_person'
|
|
6
|
+
import { organizationRequestArgs } from '../hooks/use_organization'
|
|
6
7
|
import { AgeCheckRequiredScreen } from '../screens/age_check/age_check_required_screen'
|
|
7
8
|
import { AgeCheckUnderageScreen } from '../screens/age_check/age_check_underage_screen'
|
|
8
|
-
import { AgeQualificationStatus, CurrentPersonResource } from '../types'
|
|
9
|
+
import { AgeQualificationStatus, CurrentPersonResource, OrganizationResource } from '../types'
|
|
10
|
+
import { ONE_HOUR } from '../utils/time'
|
|
9
11
|
|
|
10
12
|
export function ChatAccessGate({ children }: PropsWithChildren) {
|
|
11
|
-
const { data: person,
|
|
12
|
-
|
|
13
|
+
const { data: person, error: personError } =
|
|
14
|
+
useApiGet<CurrentPersonResource>(currentPersonRequestArgs)
|
|
15
|
+
const { data: organization, error: organizationError } = useApiGet<OrganizationResource>(
|
|
16
|
+
organizationRequestArgs,
|
|
17
|
+
{ staleTime: ONE_HOUR }
|
|
18
|
+
)
|
|
13
19
|
|
|
14
|
-
const ageQualificationStatus = person?.ageQualificationStatus
|
|
20
|
+
const ageQualificationStatus = organization ? person?.ageQualificationStatus : undefined
|
|
15
21
|
const contactEmail = organization?.contactEmail
|
|
16
22
|
|
|
17
23
|
useAgeDisqualification(ageQualificationStatus, contactEmail)
|
|
18
24
|
|
|
19
|
-
if (!
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
if (!person || !organization) {
|
|
26
|
+
if (personError) throw personError
|
|
27
|
+
if (organizationError) throw organizationError
|
|
22
28
|
|
|
23
|
-
|
|
24
|
-
throw new Error('Current person not found')
|
|
29
|
+
return <DefaultLoading />
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
if (ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED) {
|