@planningcenter/chat-react-native 3.16.0-rc.5 → 3.16.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/contexts/chat_context.d.ts +3 -0
- package/build/contexts/chat_context.d.ts.map +1 -1
- package/build/contexts/chat_context.js +3 -1
- package/build/contexts/chat_context.js.map +1 -1
- package/build/hooks/index.d.ts +3 -0
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +3 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use_current_person.d.ts.map +1 -1
- package/build/hooks/use_current_person.js +9 -1
- package/build/hooks/use_current_person.js.map +1 -1
- package/build/hooks/use_organization.d.ts +39 -0
- package/build/hooks/use_organization.d.ts.map +1 -0
- package/build/hooks/use_organization.js +14 -0
- package/build/hooks/use_organization.js.map +1 -0
- package/build/hooks/use_qualified_by_age.d.ts +2 -0
- package/build/hooks/use_qualified_by_age.d.ts.map +1 -0
- package/build/hooks/use_qualified_by_age.js +14 -0
- package/build/hooks/use_qualified_by_age.js.map +1 -0
- package/build/hooks/use_submit_age_check.d.ts +78 -0
- package/build/hooks/use_submit_age_check.d.ts.map +1 -0
- package/build/hooks/use_submit_age_check.js +37 -0
- package/build/hooks/use_submit_age_check.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/navigation/chat_access_gate.d.ts +3 -0
- package/build/navigation/chat_access_gate.d.ts.map +1 -0
- package/build/navigation/chat_access_gate.js +46 -0
- package/build/navigation/chat_access_gate.js.map +1 -0
- package/build/navigation/index.d.ts +6 -4
- package/build/navigation/index.d.ts.map +1 -1
- package/build/navigation/index.js +6 -3
- package/build/navigation/index.js.map +1 -1
- package/build/navigation/screenLayout.d.ts +3 -0
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +8 -0
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/screens/age_check/age_check_required_screen.d.ts +3 -0
- package/build/screens/age_check/age_check_required_screen.d.ts.map +1 -0
- package/build/screens/age_check/age_check_required_screen.js +148 -0
- package/build/screens/age_check/age_check_required_screen.js.map +1 -0
- package/build/screens/age_check/age_check_underage_screen.d.ts +6 -0
- package/build/screens/age_check/age_check_underage_screen.d.ts.map +1 -0
- package/build/screens/age_check/age_check_underage_screen.js +71 -0
- package/build/screens/age_check/age_check_underage_screen.js.map +1 -0
- package/build/screens/age_check/components/age_check_select_birthdate_modal.d.ts +11 -0
- package/build/screens/age_check/components/age_check_select_birthdate_modal.d.ts.map +1 -0
- package/build/screens/age_check/components/age_check_select_birthdate_modal.js +91 -0
- package/build/screens/age_check/components/age_check_select_birthdate_modal.js.map +1 -0
- package/build/screens/age_check/index.d.ts +3 -0
- package/build/screens/age_check/index.d.ts.map +1 -0
- package/build/screens/age_check/index.js +3 -0
- package/build/screens/age_check/index.js.map +1 -0
- package/build/screens/age_check/screen_props.d.ts +5 -0
- package/build/screens/age_check/screen_props.d.ts.map +1 -0
- package/build/screens/age_check/screen_props.js +2 -0
- package/build/screens/age_check/screen_props.js.map +1 -0
- package/build/types/resources/index.d.ts +1 -0
- package/build/types/resources/index.d.ts.map +1 -1
- package/build/types/resources/index.js +1 -0
- package/build/types/resources/index.js.map +1 -1
- package/build/types/resources/organization.d.ts +6 -0
- package/build/types/resources/organization.d.ts.map +1 -0
- package/build/types/resources/organization.js +2 -0
- package/build/types/resources/organization.js.map +1 -0
- package/build/types/resources/person.d.ts +7 -0
- package/build/types/resources/person.d.ts.map +1 -1
- package/build/types/resources/person.js +5 -1
- package/build/types/resources/person.js.map +1 -1
- package/package.json +3 -2
- package/src/contexts/chat_context.tsx +14 -1
- package/src/hooks/index.ts +3 -0
- package/src/hooks/use_current_person.ts +9 -1
- package/src/hooks/use_organization.ts +17 -0
- package/src/hooks/use_qualified_by_age.ts +17 -0
- package/src/hooks/use_submit_age_check.ts +48 -0
- package/src/index.tsx +1 -0
- package/src/navigation/chat_access_gate.tsx +60 -0
- package/src/navigation/index.tsx +6 -3
- package/src/navigation/screenLayout.tsx +11 -0
- package/src/screens/age_check/age_check_required_screen.tsx +197 -0
- package/src/screens/age_check/age_check_underage_screen.tsx +96 -0
- package/src/screens/age_check/components/age_check_select_birthdate_modal.tsx +143 -0
- package/src/screens/age_check/index.ts +2 -0
- package/src/screens/age_check/screen_props.ts +3 -0
- package/src/types/resources/index.ts +1 -0
- package/src/types/resources/organization.ts +6 -0
- package/src/types/resources/person.ts +10 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"organization.js","sourceRoot":"","sources":["../../../src/types/resources/organization.ts"],"names":[],"mappings":"","sourcesContent":["import { ResourceObject } from '../api_primitives'\n\nexport interface OrganizationResource extends ResourceObject {\n type: 'Organization'\n contactEmail?: string\n}\n"]}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { ResourceObject } from '../api_primitives';
|
|
2
|
+
export declare const AgeQualificationStatus: {
|
|
3
|
+
readonly QUALIFIED: "qualified";
|
|
4
|
+
readonly DISQUALIFIED: "disqualified";
|
|
5
|
+
readonly UNKNOWN: "unknown";
|
|
6
|
+
};
|
|
7
|
+
export type AgeQualificationStatus = (typeof AgeQualificationStatus)[keyof typeof AgeQualificationStatus];
|
|
2
8
|
export interface PersonResource extends ResourceObject {
|
|
3
9
|
id: number;
|
|
4
10
|
type: 'Person';
|
|
@@ -9,5 +15,6 @@ export interface CurrentPersonResource extends PersonResource {
|
|
|
9
15
|
canChat: boolean;
|
|
10
16
|
unreadCount: number;
|
|
11
17
|
pcoChatEnabled: boolean;
|
|
18
|
+
ageQualificationStatus?: AgeQualificationStatus;
|
|
12
19
|
}
|
|
13
20
|
//# sourceMappingURL=person.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"person.d.ts","sourceRoot":"","sources":["../../../src/types/resources/person.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"person.d.ts","sourceRoot":"","sources":["../../../src/types/resources/person.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAElD,eAAO,MAAM,sBAAsB;;;;CAIzB,CAAA;AAEV,MAAM,MAAM,sBAAsB,GAChC,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,OAAO,sBAAsB,CAAC,CAAA;AAEtE,MAAM,WAAW,cAAe,SAAQ,cAAc;IACpD,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,QAAQ,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,OAAO,EAAE,OAAO,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,CAAC,EAAE,sBAAsB,CAAA;CAChD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"person.js","sourceRoot":"","sources":["../../../src/types/resources/person.ts"],"names":[],"mappings":"","sourcesContent":["import { ResourceObject } from '../api_primitives'\n\nexport interface PersonResource extends ResourceObject {\n id: number\n type: 'Person'\n name: string\n avatar: string\n}\n\nexport interface CurrentPersonResource extends PersonResource {\n canChat: boolean\n unreadCount: number\n pcoChatEnabled: boolean\n}\n"]}
|
|
1
|
+
{"version":3,"file":"person.js","sourceRoot":"","sources":["../../../src/types/resources/person.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,SAAS,EAAE,WAAW;IACtB,YAAY,EAAE,cAAc;IAC5B,OAAO,EAAE,SAAS;CACV,CAAA","sourcesContent":["import { ResourceObject } from '../api_primitives'\n\nexport const AgeQualificationStatus = {\n QUALIFIED: 'qualified',\n DISQUALIFIED: 'disqualified',\n UNKNOWN: 'unknown',\n} as const\n\nexport type AgeQualificationStatus =\n (typeof AgeQualificationStatus)[keyof typeof AgeQualificationStatus]\n\nexport interface PersonResource extends ResourceObject {\n id: number\n type: 'Person'\n name: string\n avatar: string\n}\n\nexport interface CurrentPersonResource extends PersonResource {\n canChat: boolean\n unreadCount: number\n pcoChatEnabled: boolean\n ageQualificationStatus?: AgeQualificationStatus\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/chat-react-native",
|
|
3
|
-
"version": "3.16.0
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"@planningcenter/datetime-fmt": ">=1.0.0",
|
|
24
24
|
"@planningcenter/icons": "^15.24.0",
|
|
25
25
|
"@planningcenter/jolt-client": ">=2.0.0",
|
|
26
|
+
"@react-native-community/datetimepicker": ">=7.6.2",
|
|
26
27
|
"@react-navigation/elements": "*",
|
|
27
28
|
"@react-navigation/native": ">=7.0.0",
|
|
28
29
|
"@react-navigation/native-stack": ">=7.0.0",
|
|
@@ -55,5 +56,5 @@
|
|
|
55
56
|
"react-native-url-polyfill": "^2.0.0",
|
|
56
57
|
"typescript": "<5.6.0"
|
|
57
58
|
},
|
|
58
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "50e57c8326463d1645cc4ca23f32b130df7ba22b"
|
|
59
60
|
}
|
|
@@ -4,10 +4,12 @@ import { ColorSchemeName, useColorScheme } from 'react-native'
|
|
|
4
4
|
import { DeepPartial } from '../types'
|
|
5
5
|
import { ENV, OauthType, PartialToken, ResponseError, Session } from '../utils'
|
|
6
6
|
import { ChatTheme, defaultTheme, DefaultTheme } from '../utils/theme'
|
|
7
|
+
import { AgeCheckContactInfo } from '../screens/age_check/screen_props'
|
|
7
8
|
|
|
8
9
|
export interface ChatProviderProps {
|
|
9
10
|
env?: ENV
|
|
10
11
|
giphyApiKey?: string
|
|
12
|
+
onAgeDisqualification?: (params: AgeCheckContactInfo) => void
|
|
11
13
|
onUnauthorizedResponse: (_response: ResponseError) => void
|
|
12
14
|
token?: PartialToken
|
|
13
15
|
tokenType?: OauthType
|
|
@@ -18,11 +20,13 @@ export interface ChatProviderProps {
|
|
|
18
20
|
export interface ChatContextValue extends Omit<ChatProviderProps, 'theme'> {
|
|
19
21
|
session: Session
|
|
20
22
|
theme: ChatTheme
|
|
23
|
+
onAgeDisqualification: (params: AgeCheckContactInfo) => void
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export const ChatContext = createContext<ChatContextValue>({
|
|
24
27
|
env: undefined,
|
|
25
28
|
giphyApiKey: undefined,
|
|
29
|
+
onAgeDisqualification: (_params: AgeCheckContactInfo) => {},
|
|
26
30
|
onUnauthorizedResponse: () => {},
|
|
27
31
|
session: new Session(),
|
|
28
32
|
theme: defaultTheme('light'),
|
|
@@ -31,7 +35,15 @@ export const ChatContext = createContext<ChatContextValue>({
|
|
|
31
35
|
})
|
|
32
36
|
|
|
33
37
|
export function ChatProvider({ children, value }: { children: any; value: ChatProviderProps }) {
|
|
34
|
-
const {
|
|
38
|
+
const {
|
|
39
|
+
env,
|
|
40
|
+
token,
|
|
41
|
+
onAgeDisqualification = (_params: AgeCheckContactInfo) => {},
|
|
42
|
+
onUnauthorizedResponse,
|
|
43
|
+
giphyApiKey,
|
|
44
|
+
tokenType,
|
|
45
|
+
edgeToEdge = true,
|
|
46
|
+
} = value
|
|
35
47
|
const theme = useCreateChatTheme(value.theme || {})
|
|
36
48
|
const session = useMemo(
|
|
37
49
|
() => new Session({ token, env, type: tokenType }),
|
|
@@ -42,6 +54,7 @@ export function ChatProvider({ children, value }: { children: any; value: ChatPr
|
|
|
42
54
|
edgeToEdge,
|
|
43
55
|
env,
|
|
44
56
|
giphyApiKey,
|
|
57
|
+
onAgeDisqualification,
|
|
45
58
|
onUnauthorizedResponse,
|
|
46
59
|
session,
|
|
47
60
|
theme,
|
package/src/hooks/index.ts
CHANGED
|
@@ -14,4 +14,7 @@ export * from './use_api_client'
|
|
|
14
14
|
export * from './use_message_reaction_toggle'
|
|
15
15
|
export * from './use_interaction_ghost_color'
|
|
16
16
|
export * from './use_at_font_scale_breakpoint'
|
|
17
|
+
export * from './use_qualified_by_age'
|
|
17
18
|
export * from './use_scalable_number_of_lines'
|
|
19
|
+
export * from './use_submit_age_check'
|
|
20
|
+
export * from './use_organization'
|
|
@@ -7,7 +7,15 @@ export const currentPersonRequestArgs = {
|
|
|
7
7
|
url: '/me',
|
|
8
8
|
data: {
|
|
9
9
|
fields: {
|
|
10
|
-
Person: [
|
|
10
|
+
Person: [
|
|
11
|
+
'id',
|
|
12
|
+
'name',
|
|
13
|
+
'avatar',
|
|
14
|
+
'can_chat',
|
|
15
|
+
'unread_count',
|
|
16
|
+
'pco_chat_enabled',
|
|
17
|
+
'age_qualification_status',
|
|
18
|
+
],
|
|
11
19
|
},
|
|
12
20
|
},
|
|
13
21
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { OrganizationResource } from '../types'
|
|
2
|
+
import { useSuspenseGet } from './use_suspense_api'
|
|
3
|
+
import { App } from './use_api_client'
|
|
4
|
+
|
|
5
|
+
export const organizationRequestArgs = {
|
|
6
|
+
url: '/',
|
|
7
|
+
data: {
|
|
8
|
+
fields: {
|
|
9
|
+
Organization: ['contact_email'],
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
app: 'chat' as App,
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useOrganization() {
|
|
16
|
+
return useSuspenseGet<OrganizationResource>(organizationRequestArgs)
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AgeQualificationStatus, CurrentPersonResource } from '../types'
|
|
2
|
+
import { useApiGet } from './use_api'
|
|
3
|
+
import { currentPersonRequestArgs } from './use_current_person'
|
|
4
|
+
|
|
5
|
+
export const useQualifiedByAge = (): boolean => {
|
|
6
|
+
const { data: person, isFetched } = useApiGet<CurrentPersonResource>(currentPersonRequestArgs)
|
|
7
|
+
|
|
8
|
+
if (!isFetched) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (!person) {
|
|
13
|
+
return false
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return person.ageQualificationStatus === AgeQualificationStatus.QUALIFIED
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Alert } from 'react-native'
|
|
2
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
3
|
+
import { useApiClient } from './use_api_client'
|
|
4
|
+
import { currentPersonQueryKey } from './use_current_person'
|
|
5
|
+
import { ApiResource } from '../types/api_primitives'
|
|
6
|
+
import { Haptic } from '../utils/native_adapters'
|
|
7
|
+
|
|
8
|
+
interface AgeCheckResource {
|
|
9
|
+
type: 'AgeCheck'
|
|
10
|
+
id: string
|
|
11
|
+
stated_date: string
|
|
12
|
+
status: 'passed' | 'failed'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useSubmitAgeCheck() {
|
|
16
|
+
const apiClient = useApiClient()
|
|
17
|
+
const queryClient = useQueryClient()
|
|
18
|
+
|
|
19
|
+
const { mutateAsync: submitAgeCheck, ...mutation } = useMutation({
|
|
20
|
+
mutationKey: ['submitAgeCheck'],
|
|
21
|
+
mutationFn: (date: Date) =>
|
|
22
|
+
apiClient.people.post<ApiResource<AgeCheckResource>>({
|
|
23
|
+
url: '/me/age_checks',
|
|
24
|
+
data: {
|
|
25
|
+
fields: { AgeCheck: 'stated_date,status' },
|
|
26
|
+
data: {
|
|
27
|
+
type: 'AgeCheck',
|
|
28
|
+
attributes: {
|
|
29
|
+
stated_date: date.toISOString(),
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
onSuccess: (response: ApiResource<AgeCheckResource>) => {
|
|
35
|
+
queryClient.invalidateQueries({ queryKey: currentPersonQueryKey })
|
|
36
|
+
if (response.data.status === 'passed') {
|
|
37
|
+
Haptic.notificationSuccess()
|
|
38
|
+
Alert.alert('Profile updated', `Your birthdate has been updated.`)
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
onError: () => {
|
|
42
|
+
Haptic.notificationError()
|
|
43
|
+
Alert.alert('Oops', `We were unable to update your birthdate. Please try again.`)
|
|
44
|
+
},
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
return { submitAgeCheck, ...mutation }
|
|
48
|
+
}
|
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ export * from './contexts/chat_context'
|
|
|
4
4
|
export * from './navigation'
|
|
5
5
|
export { ScreenLayout } from './navigation/screenLayout'
|
|
6
6
|
export * from './screens'
|
|
7
|
+
export { AgeCheckUnderageScreen } from './screens/age_check/age_check_underage_screen' // TODO: add to barrel
|
|
7
8
|
export * from './types'
|
|
8
9
|
export { platformFontWeightBold, Session, TemporaryDefaultColorsType, Uri } from './utils'
|
|
9
10
|
export * from './utils/client'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React, { PropsWithChildren, useEffect, useRef } from 'react'
|
|
2
|
+
import { currentPersonRequestArgs } from '../hooks/use_current_person'
|
|
3
|
+
import { AgeCheckRequiredScreen } from '../screens/age_check/age_check_required_screen'
|
|
4
|
+
import { DefaultLoading } from '../components/page/loading'
|
|
5
|
+
import { useApiGet, useOrganization } from '../hooks'
|
|
6
|
+
import { AgeQualificationStatus, CurrentPersonResource } from '../types'
|
|
7
|
+
import { useChatContext } from '../contexts/chat_context'
|
|
8
|
+
import { AgeCheckUnderageScreen } from '../screens/age_check/age_check_underage_screen'
|
|
9
|
+
|
|
10
|
+
export function ChatAccessGate({ children }: PropsWithChildren) {
|
|
11
|
+
const { data: person, isFetched } = useApiGet<CurrentPersonResource>(currentPersonRequestArgs)
|
|
12
|
+
const { data: organization } = useOrganization()
|
|
13
|
+
|
|
14
|
+
const ageQualificationStatus = person?.ageQualificationStatus
|
|
15
|
+
const contactEmail = organization?.contactEmail
|
|
16
|
+
|
|
17
|
+
useAgeDisqualification(ageQualificationStatus, contactEmail)
|
|
18
|
+
|
|
19
|
+
if (!isFetched) {
|
|
20
|
+
return <DefaultLoading />
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!person) {
|
|
24
|
+
throw new Error('Current person not found')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED) {
|
|
28
|
+
return <AgeCheckUnderageScreen contactEmail={contactEmail} />
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (ageQualificationStatus === AgeQualificationStatus.UNKNOWN) {
|
|
32
|
+
return <AgeCheckRequiredScreen />
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return <>{children}</>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Helper hook that handles the age disqualification logic.
|
|
40
|
+
*
|
|
41
|
+
* If a host app provides an onAgeDisqualification callback, it will be called
|
|
42
|
+
* when a user is found to be disqualified by their age.
|
|
43
|
+
*/
|
|
44
|
+
function useAgeDisqualification(
|
|
45
|
+
ageQualificationStatus: CurrentPersonResource['ageQualificationStatus'],
|
|
46
|
+
contactEmail: string | undefined
|
|
47
|
+
) {
|
|
48
|
+
const { onAgeDisqualification } = useChatContext()
|
|
49
|
+
const hasCalledCallbackRef = useRef(false)
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (
|
|
53
|
+
ageQualificationStatus === AgeQualificationStatus.DISQUALIFIED &&
|
|
54
|
+
!hasCalledCallbackRef.current
|
|
55
|
+
) {
|
|
56
|
+
hasCalledCallbackRef.current = true
|
|
57
|
+
onAgeDisqualification({ contactEmail: contactEmail || '' })
|
|
58
|
+
}
|
|
59
|
+
}, [ageQualificationStatus, onAgeDisqualification, contactEmail])
|
|
60
|
+
}
|
package/src/navigation/index.tsx
CHANGED
|
@@ -45,9 +45,10 @@ import {
|
|
|
45
45
|
} from '../screens/message_actions_screen'
|
|
46
46
|
import { NotFound } from '../screens/not_found'
|
|
47
47
|
import { ReactionsScreen, ReactionsScreenOptions } from '../screens/reactions_screen'
|
|
48
|
+
import { ScreenLayoutWithChatAccessGate } from './screenLayout'
|
|
48
49
|
import { SendGiphyScreen, SendGiphyScreenOptions } from '../screens/send_giphy_screen'
|
|
49
50
|
import { TeamConversationScreen } from '../screens/team_conversation_screen'
|
|
50
|
-
import {
|
|
51
|
+
import { useQualifiedByAge } from '../hooks'
|
|
51
52
|
|
|
52
53
|
const HEADER_BACK_BUTTON_LAYOUT_RESET_STYLES = {
|
|
53
54
|
marginLeft: Platform.select({ ios: -8, default: -3 }),
|
|
@@ -59,7 +60,7 @@ export const NewConversationStack = createNativeStackNavigator({
|
|
|
59
60
|
screenOptions: {
|
|
60
61
|
headerBackButtonDisplayMode: 'minimal',
|
|
61
62
|
},
|
|
62
|
-
screenLayout:
|
|
63
|
+
screenLayout: ScreenLayoutWithChatAccessGate,
|
|
63
64
|
screens: {
|
|
64
65
|
ConversationSelectRecipients: {
|
|
65
66
|
screen: ConversationSelectRecipientsScreen,
|
|
@@ -122,7 +123,7 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
122
123
|
screenOptions: {
|
|
123
124
|
headerBackButtonDisplayMode: 'minimal',
|
|
124
125
|
},
|
|
125
|
-
screenLayout:
|
|
126
|
+
screenLayout: ScreenLayoutWithChatAccessGate,
|
|
126
127
|
screens: {
|
|
127
128
|
Conversations: {
|
|
128
129
|
screen: ConversationsScreen,
|
|
@@ -192,6 +193,7 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
192
193
|
},
|
|
193
194
|
TeamConversation: {
|
|
194
195
|
screen: TeamConversationScreen,
|
|
196
|
+
if: useQualifiedByAge,
|
|
195
197
|
options: {
|
|
196
198
|
title: 'Finding conversation...',
|
|
197
199
|
animation: 'none',
|
|
@@ -210,6 +212,7 @@ export const ChatStack = createNativeStackNavigator({
|
|
|
210
212
|
},
|
|
211
213
|
New: {
|
|
212
214
|
screen: NewConversationStack,
|
|
215
|
+
if: useQualifiedByAge,
|
|
213
216
|
options: {
|
|
214
217
|
headerShown: false,
|
|
215
218
|
presentation: 'modal',
|
|
@@ -2,6 +2,7 @@ import React from 'react'
|
|
|
2
2
|
import ErrorBoundary from '../components/page/error_boundary'
|
|
3
3
|
import { Suspense } from 'react'
|
|
4
4
|
import { DefaultLoading } from '../components/page/loading'
|
|
5
|
+
import { ChatAccessGate } from './chat_access_gate'
|
|
5
6
|
|
|
6
7
|
export function ScreenLayout({ children }: { children: React.ReactElement }) {
|
|
7
8
|
return (
|
|
@@ -10,3 +11,13 @@ export function ScreenLayout({ children }: { children: React.ReactElement }) {
|
|
|
10
11
|
</ErrorBoundary>
|
|
11
12
|
)
|
|
12
13
|
}
|
|
14
|
+
|
|
15
|
+
export function ScreenLayoutWithChatAccessGate({ children }: { children: React.ReactElement }) {
|
|
16
|
+
return (
|
|
17
|
+
<ScreenLayout>
|
|
18
|
+
<ChatAccessGate>
|
|
19
|
+
<Suspense fallback={<DefaultLoading />}>{children}</Suspense>
|
|
20
|
+
</ChatAccessGate>
|
|
21
|
+
</ScreenLayout>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { date as formatDate } from '@planningcenter/datetime-fmt'
|
|
3
|
+
import { StyleSheet, View } from 'react-native'
|
|
4
|
+
import { Button } from '../../components/display/button'
|
|
5
|
+
import { Text } from '../../components/display/text'
|
|
6
|
+
import { Icon } from '../../components/display/icon'
|
|
7
|
+
import { Avatar } from '../../components/display/avatar'
|
|
8
|
+
import { Banner } from '../../components/display/banner'
|
|
9
|
+
import { useCurrentPerson, useTheme, useSubmitAgeCheck } from '../../hooks'
|
|
10
|
+
import { Heading } from '../../components'
|
|
11
|
+
import { platformFontWeightBold } from '../../utils/styles'
|
|
12
|
+
import { AgeCheckSelectBirthdateModal } from './components/age_check_select_birthdate_modal'
|
|
13
|
+
|
|
14
|
+
function calculateAge(birthdate: Date) {
|
|
15
|
+
const today = new Date()
|
|
16
|
+
const age = today.getFullYear() - birthdate.getFullYear()
|
|
17
|
+
const hasHadBirthdayThisYear =
|
|
18
|
+
today.getMonth() > birthdate.getMonth() ||
|
|
19
|
+
(today.getMonth() === birthdate.getMonth() && today.getDate() >= birthdate.getDate())
|
|
20
|
+
return hasHadBirthdayThisYear ? age : age - 1
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function AgeCheckRequiredScreen() {
|
|
24
|
+
const person = useCurrentPerson()
|
|
25
|
+
|
|
26
|
+
const [birthdate, setBirthdate] = useState<Date | null>(null)
|
|
27
|
+
const [draftBirthdate, setDraftBirthdate] = useState<Date | null>(null)
|
|
28
|
+
const [isBirthdateModalOpen, setBirthdateModalOpen] = useState(false)
|
|
29
|
+
const { submitAgeCheck, isPending, isSuccess } = useSubmitAgeCheck()
|
|
30
|
+
const styles = useStyles()
|
|
31
|
+
|
|
32
|
+
const birthdateStamp = birthdate
|
|
33
|
+
? formatDate(birthdate, { style: 'standard', year: true })
|
|
34
|
+
: 'Missing'
|
|
35
|
+
|
|
36
|
+
const age = birthdate ? calculateAge(birthdate) : null
|
|
37
|
+
|
|
38
|
+
const confirmationText =
|
|
39
|
+
birthdate !== null
|
|
40
|
+
? `Your birthdate is ${birthdateStamp} and you are ${age} years old. Is that correct?`
|
|
41
|
+
: ''
|
|
42
|
+
|
|
43
|
+
const openBirthdateModal = () => {
|
|
44
|
+
setDraftBirthdate(birthdate || new Date())
|
|
45
|
+
setBirthdateModalOpen(true)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const closeBirthdateModal = () => {
|
|
49
|
+
setBirthdateModalOpen(false)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const handleSubmitAgeConfirmation = () => {
|
|
53
|
+
if (!birthdate) return
|
|
54
|
+
submitAgeCheck(birthdate)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<View style={styles.container}>
|
|
59
|
+
<View style={styles.header}>
|
|
60
|
+
<View style={styles.heading}>
|
|
61
|
+
<Icon name="general.exclamationTriangle" size={20} style={styles.warningIcon} />
|
|
62
|
+
<Heading variant="h2">Your age is required to use chat</Heading>
|
|
63
|
+
</View>
|
|
64
|
+
<Text>To help protect those who may be underage, we need to verify your birthdate.</Text>
|
|
65
|
+
</View>
|
|
66
|
+
<View style={styles.cards}>
|
|
67
|
+
<View style={styles.card}>
|
|
68
|
+
<Heading variant="h3">My profile</Heading>
|
|
69
|
+
<View style={styles.profileContent}>
|
|
70
|
+
<Avatar sourceUri={person.avatar || ''} size="lg" showFallback={!person.avatar} />
|
|
71
|
+
<View style={styles.personInfo}>
|
|
72
|
+
<Text style={styles.name} numberOfLines={1}>
|
|
73
|
+
{person.name}
|
|
74
|
+
</Text>
|
|
75
|
+
<View style={styles.birthdateInfo}>
|
|
76
|
+
<Text variant="tertiary" style={styles.birthdateLabel}>
|
|
77
|
+
Birthdate:
|
|
78
|
+
</Text>
|
|
79
|
+
<Text variant="tertiary">{birthdateStamp}</Text>
|
|
80
|
+
</View>
|
|
81
|
+
</View>
|
|
82
|
+
{birthdate && (
|
|
83
|
+
<Button
|
|
84
|
+
title="Edit"
|
|
85
|
+
accessibilityHint="Choose a new birthdate for your profile"
|
|
86
|
+
size="sm"
|
|
87
|
+
variant="outline"
|
|
88
|
+
style={styles.editButton}
|
|
89
|
+
onPress={openBirthdateModal}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
92
|
+
</View>
|
|
93
|
+
{!birthdate && (
|
|
94
|
+
<Button
|
|
95
|
+
title="Add birthdate"
|
|
96
|
+
accessibilityHint="Choose a birthdate for your profile"
|
|
97
|
+
size="lg"
|
|
98
|
+
style={styles.primaryButton}
|
|
99
|
+
onPress={openBirthdateModal}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
</View>
|
|
103
|
+
{birthdate && (
|
|
104
|
+
<View style={styles.card}>
|
|
105
|
+
<Heading variant="h3">Age confirmation</Heading>
|
|
106
|
+
{age !== null && age < 13 ? (
|
|
107
|
+
<Banner appearance="warning" description={confirmationText} />
|
|
108
|
+
) : (
|
|
109
|
+
<Text>{confirmationText}</Text>
|
|
110
|
+
)}
|
|
111
|
+
<Button
|
|
112
|
+
title="Yes, update my profile"
|
|
113
|
+
size="lg"
|
|
114
|
+
style={styles.primaryButton}
|
|
115
|
+
onPress={handleSubmitAgeConfirmation}
|
|
116
|
+
disabled={isPending || isSuccess}
|
|
117
|
+
/>
|
|
118
|
+
</View>
|
|
119
|
+
)}
|
|
120
|
+
</View>
|
|
121
|
+
<Text variant="tertiary">
|
|
122
|
+
Your birthdate will be added to your profile, but it is only visible to church
|
|
123
|
+
administrators. It will not be shared with other church members, unless you give permission.
|
|
124
|
+
</Text>
|
|
125
|
+
|
|
126
|
+
<AgeCheckSelectBirthdateModal
|
|
127
|
+
onChange={setDraftBirthdate}
|
|
128
|
+
onDismiss={closeBirthdateModal}
|
|
129
|
+
onRequestClose={closeBirthdateModal}
|
|
130
|
+
onSubmit={setBirthdate}
|
|
131
|
+
value={draftBirthdate || new Date()}
|
|
132
|
+
visible={isBirthdateModalOpen}
|
|
133
|
+
/>
|
|
134
|
+
</View>
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const useStyles = () => {
|
|
139
|
+
const { colors } = useTheme()
|
|
140
|
+
return StyleSheet.create({
|
|
141
|
+
container: {
|
|
142
|
+
flex: 1,
|
|
143
|
+
backgroundColor: colors.surfaceColor080,
|
|
144
|
+
padding: 16,
|
|
145
|
+
gap: 16,
|
|
146
|
+
},
|
|
147
|
+
header: {
|
|
148
|
+
gap: 8,
|
|
149
|
+
},
|
|
150
|
+
heading: {
|
|
151
|
+
flexDirection: 'row',
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
gap: 8,
|
|
154
|
+
},
|
|
155
|
+
warningIcon: {
|
|
156
|
+
color: colors.statusErrorIcon,
|
|
157
|
+
},
|
|
158
|
+
card: {
|
|
159
|
+
backgroundColor: colors.surfaceColor100,
|
|
160
|
+
borderRadius: 8,
|
|
161
|
+
padding: 16,
|
|
162
|
+
gap: 8,
|
|
163
|
+
},
|
|
164
|
+
cards: {
|
|
165
|
+
gap: 8,
|
|
166
|
+
},
|
|
167
|
+
profileContent: {
|
|
168
|
+
flexDirection: 'row',
|
|
169
|
+
alignItems: 'center',
|
|
170
|
+
gap: 8,
|
|
171
|
+
},
|
|
172
|
+
personInfo: {
|
|
173
|
+
flex: 1,
|
|
174
|
+
},
|
|
175
|
+
primaryButton: {
|
|
176
|
+
alignSelf: 'center',
|
|
177
|
+
marginTop: 8,
|
|
178
|
+
},
|
|
179
|
+
name: {
|
|
180
|
+
fontWeight: platformFontWeightBold,
|
|
181
|
+
},
|
|
182
|
+
birthdateLabel: {
|
|
183
|
+
fontWeight: platformFontWeightBold,
|
|
184
|
+
},
|
|
185
|
+
birthdateInfo: {
|
|
186
|
+
flexDirection: 'row',
|
|
187
|
+
alignItems: 'center',
|
|
188
|
+
gap: 4,
|
|
189
|
+
},
|
|
190
|
+
editButton: {
|
|
191
|
+
alignSelf: 'flex-end',
|
|
192
|
+
},
|
|
193
|
+
formSheetContent: {
|
|
194
|
+
flex: 1,
|
|
195
|
+
},
|
|
196
|
+
})
|
|
197
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Linking, StyleSheet, View } from 'react-native'
|
|
3
|
+
import { Heading } from '../../components'
|
|
4
|
+
import { Icon, Text, TextInlineButton } from '../../components/display'
|
|
5
|
+
import { useTheme } from '../../hooks'
|
|
6
|
+
import { useRoute, RouteProp } from '@react-navigation/native'
|
|
7
|
+
import type { AgeCheckParams } from './screen_props'
|
|
8
|
+
|
|
9
|
+
export interface AgeCheckUnderageScreenProps {
|
|
10
|
+
contactEmail?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function AgeCheckUnderageScreen({ contactEmail }: AgeCheckUnderageScreenProps = {}) {
|
|
14
|
+
const styles = useStyles()
|
|
15
|
+
const route = useRoute<RouteProp<AgeCheckParams, 'UnderagePerson'>>()
|
|
16
|
+
|
|
17
|
+
const email = contactEmail ?? route?.params?.contactEmail
|
|
18
|
+
|
|
19
|
+
const openChurchAdminHelp = () => {
|
|
20
|
+
if (!email) return
|
|
21
|
+
Linking.openURL(`mailto:${email}`)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const openTerms = () => {
|
|
25
|
+
Linking.openURL('https://www.planningcenter.com/terms')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<View style={styles.container}>
|
|
30
|
+
<Icon name="general.outlinedTextMessage" size={32} style={styles.icon} />
|
|
31
|
+
|
|
32
|
+
<View style={styles.content}>
|
|
33
|
+
<Heading variant="h3" style={styles.baseText}>
|
|
34
|
+
Your age does not meet the minimum safety requirements to use chat.
|
|
35
|
+
</Heading>
|
|
36
|
+
<Text variant="tertiary" style={styles.baseText}>
|
|
37
|
+
If you submitted the wrong birthdate by accident,{` `}
|
|
38
|
+
{email ? (
|
|
39
|
+
<TextInlineButton
|
|
40
|
+
onPress={openChurchAdminHelp}
|
|
41
|
+
accessibilityRole="link"
|
|
42
|
+
accessibilityHint="Opens email client to contact your church administrator"
|
|
43
|
+
style={styles.linkText}
|
|
44
|
+
>
|
|
45
|
+
please contact your church administrator
|
|
46
|
+
</TextInlineButton>
|
|
47
|
+
) : (
|
|
48
|
+
<>please contact your church administrator</>
|
|
49
|
+
)}
|
|
50
|
+
{` `}
|
|
51
|
+
to update your profile.
|
|
52
|
+
</Text>
|
|
53
|
+
<Text variant="tertiary" style={styles.baseText}>
|
|
54
|
+
For more information, view our{` `}
|
|
55
|
+
<TextInlineButton
|
|
56
|
+
onPress={openTerms}
|
|
57
|
+
accessibilityRole="link"
|
|
58
|
+
accessibilityHint="Opens terms of service in browser"
|
|
59
|
+
style={styles.linkText}
|
|
60
|
+
>
|
|
61
|
+
terms of service
|
|
62
|
+
</TextInlineButton>
|
|
63
|
+
.
|
|
64
|
+
</Text>
|
|
65
|
+
</View>
|
|
66
|
+
</View>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const useStyles = () => {
|
|
71
|
+
const { colors } = useTheme()
|
|
72
|
+
return StyleSheet.create({
|
|
73
|
+
container: {
|
|
74
|
+
flex: 1,
|
|
75
|
+
alignItems: 'center',
|
|
76
|
+
justifyContent: 'center',
|
|
77
|
+
gap: 16,
|
|
78
|
+
padding: 16,
|
|
79
|
+
},
|
|
80
|
+
icon: {
|
|
81
|
+
color: colors.iconColorDefaultDisabled,
|
|
82
|
+
},
|
|
83
|
+
content: {
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
gap: 8,
|
|
86
|
+
maxWidth: 250,
|
|
87
|
+
},
|
|
88
|
+
baseText: {
|
|
89
|
+
textAlign: 'center',
|
|
90
|
+
color: colors.textColorDefaultSecondary,
|
|
91
|
+
},
|
|
92
|
+
linkText: {
|
|
93
|
+
fontSize: 14,
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
}
|