@planningcenter/chat-react-native 3.36.1 → 3.36.2-qa-726.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/components/conversation/message.d.ts.map +1 -1
- package/build/components/conversation/message.js +3 -3
- package/build/components/conversation/message.js.map +1 -1
- package/build/components/display/action_button.d.ts +3 -1
- package/build/components/display/action_button.d.ts.map +1 -1
- package/build/components/display/action_button.js +8 -1
- package/build/components/display/action_button.js.map +1 -1
- package/build/components/display/index.d.ts +1 -0
- package/build/components/display/index.d.ts.map +1 -1
- package/build/components/display/index.js +1 -0
- package/build/components/display/index.js.map +1 -1
- package/build/components/index.d.ts +2 -0
- package/build/components/index.d.ts.map +1 -1
- package/build/components/index.js +2 -0
- package/build/components/index.js.map +1 -1
- package/build/components/page/component_error_boundary.d.ts +4 -0
- package/build/components/page/component_error_boundary.d.ts.map +1 -0
- package/build/components/page/component_error_boundary.js +8 -0
- package/build/components/page/component_error_boundary.js.map +1 -0
- package/build/components/page/error_boundary.d.ts +13 -10
- package/build/components/page/error_boundary.d.ts.map +1 -1
- package/build/components/page/error_boundary.js +20 -90
- package/build/components/page/error_boundary.js.map +1 -1
- package/build/components/page/page_error_boundary.d.ts +4 -0
- package/build/components/page/page_error_boundary.d.ts.map +1 -0
- package/build/components/page/page_error_boundary.js +80 -0
- package/build/components/page/page_error_boundary.js.map +1 -0
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts +168 -0
- package/build/hooks/groups/use_group_chat_conversation_payload.d.ts.map +1 -0
- package/build/hooks/groups/use_group_chat_conversation_payload.js +23 -0
- package/build/hooks/groups/use_group_chat_conversation_payload.js.map +1 -0
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts +0 -4
- package/build/hooks/groups/use_group_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/groups/use_group_members_for_new_conversation.js +6 -18
- package/build/hooks/groups/use_group_members_for_new_conversation.js.map +1 -1
- package/build/hooks/groups/use_groups_conversation_create.js +1 -1
- package/build/hooks/groups/use_groups_conversation_create.js.map +1 -1
- package/build/hooks/index.d.ts +2 -1
- package/build/hooks/index.d.ts.map +1 -1
- package/build/hooks/index.js +2 -1
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/services/use_find_or_create_services_conversation.d.ts +11 -3
- package/build/hooks/services/use_find_or_create_services_conversation.d.ts.map +1 -1
- package/build/hooks/services/use_find_or_create_services_conversation.js +10 -14
- package/build/hooks/services/use_find_or_create_services_conversation.js.map +1 -1
- package/build/hooks/services/use_services_chat_conversation_payload.d.ts +164 -0
- package/build/hooks/services/use_services_chat_conversation_payload.d.ts.map +1 -0
- package/build/hooks/services/use_services_chat_conversation_payload.js +16 -0
- package/build/hooks/services/use_services_chat_conversation_payload.js.map +1 -0
- package/build/hooks/services/use_team_members_for_new_conversation.d.ts.map +1 -1
- package/build/hooks/services/use_team_members_for_new_conversation.js +11 -4
- package/build/hooks/services/use_team_members_for_new_conversation.js.map +1 -1
- package/build/hooks/use_conversation_validate.d.ts +12 -0
- package/build/hooks/use_conversation_validate.d.ts.map +1 -0
- package/build/hooks/use_conversation_validate.js +28 -0
- package/build/hooks/use_conversation_validate.js.map +1 -0
- package/build/hooks/use_enrich_people.d.ts +13 -0
- package/build/hooks/use_enrich_people.d.ts.map +1 -0
- package/build/hooks/use_enrich_people.js +25 -0
- package/build/hooks/use_enrich_people.js.map +1 -0
- package/build/hooks/use_features.d.ts +9 -6
- package/build/hooks/use_features.d.ts.map +1 -1
- package/build/hooks/use_features.js +1 -0
- package/build/hooks/use_features.js.map +1 -1
- package/build/hooks/use_jolt.d.ts +2 -1
- package/build/hooks/use_jolt.d.ts.map +1 -1
- package/build/hooks/use_jolt.js.map +1 -1
- package/build/hooks/use_product_analytics.d.ts +7 -1
- package/build/hooks/use_product_analytics.d.ts.map +1 -1
- package/build/hooks/use_product_analytics.js +4 -0
- package/build/hooks/use_product_analytics.js.map +1 -1
- package/build/index.d.ts +3 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/navigation/screenLayout.d.ts.map +1 -1
- package/build/navigation/screenLayout.js +5 -3
- package/build/navigation/screenLayout.js.map +1 -1
- package/build/screens/conversation_details_screen.js +1 -1
- package/build/screens/conversation_details_screen.js.map +1 -1
- package/build/screens/conversation_new/components/groups_form.d.ts.map +1 -1
- package/build/screens/conversation_new/components/groups_form.js +14 -1
- package/build/screens/conversation_new/components/groups_form.js.map +1 -1
- package/build/screens/conversation_new/components/services_form.d.ts.map +1 -1
- package/build/screens/conversation_new/components/services_form.js +20 -2
- package/build/screens/conversation_new/components/services_form.js.map +1 -1
- package/build/screens/conversation_screen.d.ts.map +1 -1
- package/build/screens/conversation_screen.js +2 -2
- package/build/screens/conversation_screen.js.map +1 -1
- package/build/screens/conversations/conversations_screen.js +2 -2
- package/build/screens/conversations/conversations_screen.js.map +1 -1
- package/build/screens/team_conversation_screen.d.ts.map +1 -1
- package/build/screens/team_conversation_screen.js +6 -3
- package/build/screens/team_conversation_screen.js.map +1 -1
- package/build/types/jolt_events/index.d.ts +2 -0
- package/build/types/jolt_events/index.d.ts.map +1 -1
- package/build/types/jolt_events/index.js.map +1 -1
- package/build/types/resources/conversation_validate.d.ts +10 -0
- package/build/types/resources/conversation_validate.d.ts.map +1 -0
- package/build/types/resources/conversation_validate.js +2 -0
- package/build/types/resources/conversation_validate.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/utils/cache/messages_cache.d.ts +1 -1
- package/build/utils/cache/messages_cache.d.ts.map +1 -1
- package/build/utils/client/instrumented_fetch.d.ts +2 -0
- package/build/utils/client/instrumented_fetch.d.ts.map +1 -0
- package/build/utils/client/instrumented_fetch.js +64 -0
- package/build/utils/client/instrumented_fetch.js.map +1 -0
- package/build/utils/client/request_helpers.d.ts.map +1 -1
- package/build/utils/client/request_helpers.js +2 -1
- package/build/utils/client/request_helpers.js.map +1 -1
- package/build/utils/native_adapters/log.d.ts +11 -0
- package/build/utils/native_adapters/log.d.ts.map +1 -1
- package/build/utils/native_adapters/log.js +9 -0
- package/build/utils/native_adapters/log.js.map +1 -1
- package/build/utils/performance_tracking.d.ts +1 -1
- package/build/utils/performance_tracking.d.ts.map +1 -1
- package/build/utils/performance_tracking.js.map +1 -1
- package/build/utils/request/get_chat_configuration.d.ts +1 -1
- package/build/utils/request/get_chat_configuration.d.ts.map +1 -1
- package/build/utils/request/get_features.d.ts +1 -1
- package/build/utils/request/get_features.d.ts.map +1 -1
- package/build/utils/request/get_message.d.ts +1 -1
- package/build/utils/request/get_message.d.ts.map +1 -1
- package/build/utils/request/get_messages.d.ts +1 -1
- package/build/utils/request/get_messages.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/__tests__/hooks/use_conversation_validate.test.tsx +117 -0
- package/src/__tests__/hooks/use_enrich_people.test.tsx +95 -0
- package/src/components/conversation/message.tsx +6 -4
- package/src/components/display/action_button.tsx +18 -0
- package/src/components/display/index.ts +1 -0
- package/src/components/index.tsx +2 -0
- package/src/components/page/__tests__/component_error_boundary.test.tsx +46 -0
- package/src/components/page/__tests__/error_boundary.test.tsx +93 -0
- package/src/components/page/__tests__/page_error_boundary.test.tsx +77 -0
- package/src/components/page/component_error_boundary.tsx +13 -0
- package/src/components/page/error_boundary.tsx +34 -118
- package/src/components/page/page_error_boundary.tsx +112 -0
- package/src/hooks/groups/use_group_chat_conversation_payload.ts +38 -0
- package/src/hooks/groups/use_group_members_for_new_conversation.ts +9 -23
- package/src/hooks/groups/use_groups_conversation_create.ts +1 -1
- package/src/hooks/index.ts +2 -1
- package/src/hooks/services/use_find_or_create_services_conversation.ts +27 -24
- package/src/hooks/services/use_services_chat_conversation_payload.ts +26 -0
- package/src/hooks/services/use_team_members_for_new_conversation.ts +18 -7
- package/src/hooks/use_conversation_validate.ts +45 -0
- package/src/hooks/use_enrich_people.ts +35 -0
- package/src/hooks/use_features.ts +5 -2
- package/src/hooks/use_jolt.ts +2 -1
- package/src/hooks/use_product_analytics.ts +13 -3
- package/src/index.tsx +3 -2
- package/src/navigation/screenLayout.tsx +6 -3
- package/src/screens/conversation_details_screen.tsx +1 -1
- package/src/screens/conversation_new/components/groups_form.tsx +17 -1
- package/src/screens/conversation_new/components/services_form.tsx +26 -2
- package/src/screens/conversation_screen.tsx +2 -1
- package/src/screens/conversations/conversations_screen.tsx +2 -2
- package/src/screens/team_conversation_screen.tsx +6 -6
- package/src/types/jolt_events/index.ts +3 -0
- package/src/types/resources/conversation_validate.ts +11 -0
- package/src/types/resources/index.ts +1 -0
- package/src/utils/client/__tests__/instrumented_fetch.test.ts +84 -0
- package/src/utils/client/instrumented_fetch.ts +69 -0
- package/src/utils/client/request_helpers.ts +2 -1
- package/src/utils/native_adapters/__tests__/log.test.ts +62 -0
- package/src/utils/native_adapters/log.ts +22 -0
- package/src/utils/performance_tracking.ts +1 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useNavigation } from '@react-navigation/native';
|
|
2
|
+
import { useQueryErrorResetBoundary } from '@tanstack/react-query';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo } from 'react';
|
|
4
|
+
import { onAuthRefresh } from '../../utils/auth_events';
|
|
5
|
+
import { ResponseError } from '../../utils/response_error';
|
|
6
|
+
import BlankState from '../primitive/blank_state_primitive';
|
|
7
|
+
import { ErrorBoundary } from './error_boundary';
|
|
8
|
+
const renderPageFallback = (error, reset) => (<ErrorView error={error} reset={reset}/>);
|
|
9
|
+
export function PageErrorBoundary({ children, ...props }) {
|
|
10
|
+
return (<ErrorBoundary scope="screen" fallback={renderPageFallback} {...props}>
|
|
11
|
+
{children}
|
|
12
|
+
</ErrorBoundary>);
|
|
13
|
+
}
|
|
14
|
+
function ErrorView({ error, reset }) {
|
|
15
|
+
const { reset: resetQueries } = useQueryErrorResetBoundary();
|
|
16
|
+
const handleReset = useCallback(() => {
|
|
17
|
+
resetQueries();
|
|
18
|
+
reset();
|
|
19
|
+
}, [resetQueries, reset]);
|
|
20
|
+
useEffect(() => handleReset, [handleReset]);
|
|
21
|
+
if (error instanceof ResponseError) {
|
|
22
|
+
return <ResponseErrorView response={error.response} onReset={handleReset}/>;
|
|
23
|
+
}
|
|
24
|
+
if (isNetworkError(error)) {
|
|
25
|
+
return (<ErrorContent heading={'Problem connecting!'} body={'Check your internet connection and try again.'}/>);
|
|
26
|
+
}
|
|
27
|
+
return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'}/>;
|
|
28
|
+
}
|
|
29
|
+
function isNetworkError(error) {
|
|
30
|
+
const networkFailedMessages = [
|
|
31
|
+
'Network request failed',
|
|
32
|
+
'Network request timed out',
|
|
33
|
+
'Failed to fetch',
|
|
34
|
+
];
|
|
35
|
+
return new RegExp(networkFailedMessages.join('|'), 'i').test(error.message);
|
|
36
|
+
}
|
|
37
|
+
function ResponseErrorView({ response, onReset }) {
|
|
38
|
+
const { status } = response;
|
|
39
|
+
const heading = useMemo(() => {
|
|
40
|
+
switch (status) {
|
|
41
|
+
case 403:
|
|
42
|
+
return 'Permission required';
|
|
43
|
+
case 404:
|
|
44
|
+
return 'Content not found';
|
|
45
|
+
default:
|
|
46
|
+
return 'Oops!';
|
|
47
|
+
}
|
|
48
|
+
}, [status]);
|
|
49
|
+
const body = useMemo(() => {
|
|
50
|
+
switch (status) {
|
|
51
|
+
case 403:
|
|
52
|
+
return 'Contact your administrator for access.';
|
|
53
|
+
case 404:
|
|
54
|
+
return 'If you believe something should be here, please reach out to your administrator.';
|
|
55
|
+
default:
|
|
56
|
+
return 'Something unexpected happened.';
|
|
57
|
+
}
|
|
58
|
+
}, [status]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (status !== 401)
|
|
61
|
+
return;
|
|
62
|
+
return onAuthRefresh(onReset);
|
|
63
|
+
}, [status, onReset]);
|
|
64
|
+
return <ErrorContent heading={heading} body={body}/>;
|
|
65
|
+
}
|
|
66
|
+
function ErrorContent({ heading, body }) {
|
|
67
|
+
const navigation = useNavigation();
|
|
68
|
+
return (<BlankState.Root>
|
|
69
|
+
<BlankState.Imagery name="people.noTextMessage"/>
|
|
70
|
+
<BlankState.Content>
|
|
71
|
+
<BlankState.Heading>{heading}</BlankState.Heading>
|
|
72
|
+
<BlankState.Text>{body}</BlankState.Text>
|
|
73
|
+
</BlankState.Content>
|
|
74
|
+
<BlankState.Button title="Go back" onPress={navigation.goBack} size="md" accessibilityRole="link"/>
|
|
75
|
+
<BlankState.TextButton onPress={() => navigation.navigate('BugReport')}>
|
|
76
|
+
Report a bug
|
|
77
|
+
</BlankState.TextButton>
|
|
78
|
+
</BlankState.Root>);
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=page_error_boundary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page_error_boundary.js","sourceRoot":"","sources":["../../../src/components/page/page_error_boundary.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AACxD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AAClE,OAAO,KAAK,EAAE,EAAqB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,UAAU,MAAM,oCAAoC,CAAA;AAC3D,OAAO,EAAE,aAAa,EAA6C,MAAM,kBAAkB,CAAA;AAE3F,MAAM,kBAAkB,GAA0B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAClE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,EAAG,CAC1C,CAAA;AAED,MAAM,UAAU,iBAAiB,CAAC,EAAE,QAAQ,EAAE,GAAG,KAAK,E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AAO,CACjB;QAAA,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EAAE,UAAU,CAAC,OAAO,CACjD;QAAA,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,UAAU,CAAC,IAAI,CAC1C;MAAA,EAAE,UAAU,CAAC,OAAO,CACpB;MAAA,CAAC,UAAU,CAAC,MAAM,CAChB,KAAK,CAAC,SAAS,CACf,OAAO,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAC3B,IAAI,CAAC,IAAI,CACT,iBAAiB,CAAC,MAAM,EAE1B;MAAA,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CACrE;;MACF,EAAE,UAAU,CAAC,UAAU,CACzB;IAAA,EAAE,UAAU,CAAC,IAAI,CAAC,CACnB,CAAA;AACH,CAAC","sourcesContent":["import { useNavigation } from '@react-navigation/native'\nimport { useQueryErrorResetBoundary } from '@tanstack/react-query'\nimport React, { PropsWithChildren, useCallback, useEffect, useMemo } from 'react'\nimport { onAuthRefresh } from '../../utils/auth_events'\nimport { ResponseError } from '../../utils/response_error'\nimport BlankState from '../primitive/blank_state_primitive'\nimport { ErrorBoundary, ErrorBoundaryFallback, ErrorBoundaryProps } from './error_boundary'\n\nconst renderPageFallback: ErrorBoundaryFallback = (error, reset) => (\n <ErrorView error={error} reset={reset} />\n)\n\nexport function PageErrorBoundary({ children, ...props }: PropsWithChildren<ErrorBoundaryProps>) {\n return (\n <ErrorBoundary scope=\"screen\" fallback={renderPageFallback} {...props}>\n {children}\n </ErrorBoundary>\n )\n}\n\nfunction ErrorView({ error, reset }: { error: Error; reset: () => void }) {\n const { reset: resetQueries } = useQueryErrorResetBoundary()\n\n const handleReset = useCallback(() => {\n resetQueries()\n reset()\n }, [resetQueries, reset])\n\n useEffect(() => handleReset, [handleReset])\n\n if (error instanceof ResponseError) {\n return <ResponseErrorView response={error.response} onReset={handleReset} />\n }\n\n if (isNetworkError(error)) {\n return (\n <ErrorContent\n heading={'Problem connecting!'}\n body={'Check your internet connection and try again.'}\n />\n )\n }\n\n return <ErrorContent heading={'Oops!'} body={'Something unexpected happened.'} />\n}\n\nfunction isNetworkError(error: Error) {\n const networkFailedMessages = [\n 'Network request failed',\n 'Network request timed out',\n 'Failed to fetch',\n ]\n\n return new RegExp(networkFailedMessages.join('|'), 'i').test(error.message)\n}\n\nfunction ResponseErrorView({ response, onReset }: { response: Response; onReset: () => void }) {\n const { status } = response\n\n const heading = useMemo(() => {\n switch (status) {\n case 403:\n return 'Permission required'\n case 404:\n return 'Content not found'\n default:\n return 'Oops!'\n }\n }, [status])\n\n const body = useMemo(() => {\n switch (status) {\n case 403:\n return 'Contact your administrator for access.'\n case 404:\n return 'If you believe something should be here, please reach out to your administrator.'\n default:\n return 'Something unexpected happened.'\n }\n }, [status])\n\n useEffect(() => {\n if (status !== 401) return\n\n return onAuthRefresh(onReset)\n }, [status, onReset])\n\n return <ErrorContent heading={heading} body={body} />\n}\n\nfunction ErrorContent({ heading, body }: { heading: string; body: string }) {\n const navigation = useNavigation()\n\n return (\n <BlankState.Root>\n <BlankState.Imagery name=\"people.noTextMessage\" />\n <BlankState.Content>\n <BlankState.Heading>{heading}</BlankState.Heading>\n <BlankState.Text>{body}</BlankState.Text>\n </BlankState.Content>\n <BlankState.Button\n title=\"Go back\"\n onPress={navigation.goBack}\n size=\"md\"\n accessibilityRole=\"link\"\n />\n <BlankState.TextButton onPress={() => navigation.navigate('BugReport')}>\n Report a bug\n </BlankState.TextButton>\n </BlankState.Root>\n )\n}\n"]}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { ApiResource, ResourceObject } from '../../types';
|
|
2
|
+
interface Props {
|
|
3
|
+
groupId: number;
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare function useGroupChatConversationPayload({ groupId, enabled }: Props): {
|
|
7
|
+
error: Error;
|
|
8
|
+
isError: true;
|
|
9
|
+
isPending: false;
|
|
10
|
+
isLoading: false;
|
|
11
|
+
isLoadingError: false;
|
|
12
|
+
isRefetchError: true;
|
|
13
|
+
isSuccess: false;
|
|
14
|
+
isPlaceholderData: false;
|
|
15
|
+
status: "error";
|
|
16
|
+
dataUpdatedAt: number;
|
|
17
|
+
errorUpdatedAt: number;
|
|
18
|
+
failureCount: number;
|
|
19
|
+
failureReason: Error | null;
|
|
20
|
+
errorUpdateCount: number;
|
|
21
|
+
isFetched: boolean;
|
|
22
|
+
isFetchedAfterMount: boolean;
|
|
23
|
+
isFetching: boolean;
|
|
24
|
+
isInitialLoading: boolean;
|
|
25
|
+
isPaused: boolean;
|
|
26
|
+
isRefetching: boolean;
|
|
27
|
+
isStale: boolean;
|
|
28
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
29
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
30
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
31
|
+
payload: string | undefined;
|
|
32
|
+
} | {
|
|
33
|
+
error: null;
|
|
34
|
+
isError: false;
|
|
35
|
+
isPending: false;
|
|
36
|
+
isLoading: false;
|
|
37
|
+
isLoadingError: false;
|
|
38
|
+
isRefetchError: false;
|
|
39
|
+
isSuccess: true;
|
|
40
|
+
isPlaceholderData: false;
|
|
41
|
+
status: "success";
|
|
42
|
+
dataUpdatedAt: number;
|
|
43
|
+
errorUpdatedAt: number;
|
|
44
|
+
failureCount: number;
|
|
45
|
+
failureReason: Error | null;
|
|
46
|
+
errorUpdateCount: number;
|
|
47
|
+
isFetched: boolean;
|
|
48
|
+
isFetchedAfterMount: boolean;
|
|
49
|
+
isFetching: boolean;
|
|
50
|
+
isInitialLoading: boolean;
|
|
51
|
+
isPaused: boolean;
|
|
52
|
+
isRefetching: boolean;
|
|
53
|
+
isStale: boolean;
|
|
54
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
55
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
56
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
57
|
+
payload: string | undefined;
|
|
58
|
+
} | {
|
|
59
|
+
error: Error;
|
|
60
|
+
isError: true;
|
|
61
|
+
isPending: false;
|
|
62
|
+
isLoading: false;
|
|
63
|
+
isLoadingError: true;
|
|
64
|
+
isRefetchError: false;
|
|
65
|
+
isSuccess: false;
|
|
66
|
+
isPlaceholderData: false;
|
|
67
|
+
status: "error";
|
|
68
|
+
dataUpdatedAt: number;
|
|
69
|
+
errorUpdatedAt: number;
|
|
70
|
+
failureCount: number;
|
|
71
|
+
failureReason: Error | null;
|
|
72
|
+
errorUpdateCount: number;
|
|
73
|
+
isFetched: boolean;
|
|
74
|
+
isFetchedAfterMount: boolean;
|
|
75
|
+
isFetching: boolean;
|
|
76
|
+
isInitialLoading: boolean;
|
|
77
|
+
isPaused: boolean;
|
|
78
|
+
isRefetching: boolean;
|
|
79
|
+
isStale: boolean;
|
|
80
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
81
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
82
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
83
|
+
payload: string | undefined;
|
|
84
|
+
} | {
|
|
85
|
+
error: null;
|
|
86
|
+
isError: false;
|
|
87
|
+
isPending: true;
|
|
88
|
+
isLoading: true;
|
|
89
|
+
isLoadingError: false;
|
|
90
|
+
isRefetchError: false;
|
|
91
|
+
isSuccess: false;
|
|
92
|
+
isPlaceholderData: false;
|
|
93
|
+
status: "pending";
|
|
94
|
+
dataUpdatedAt: number;
|
|
95
|
+
errorUpdatedAt: number;
|
|
96
|
+
failureCount: number;
|
|
97
|
+
failureReason: Error | null;
|
|
98
|
+
errorUpdateCount: number;
|
|
99
|
+
isFetched: boolean;
|
|
100
|
+
isFetchedAfterMount: boolean;
|
|
101
|
+
isFetching: boolean;
|
|
102
|
+
isInitialLoading: boolean;
|
|
103
|
+
isPaused: boolean;
|
|
104
|
+
isRefetching: boolean;
|
|
105
|
+
isStale: boolean;
|
|
106
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
107
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
108
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
109
|
+
payload: string | undefined;
|
|
110
|
+
} | {
|
|
111
|
+
error: null;
|
|
112
|
+
isError: false;
|
|
113
|
+
isPending: true;
|
|
114
|
+
isLoadingError: false;
|
|
115
|
+
isRefetchError: false;
|
|
116
|
+
isSuccess: false;
|
|
117
|
+
isPlaceholderData: false;
|
|
118
|
+
status: "pending";
|
|
119
|
+
dataUpdatedAt: number;
|
|
120
|
+
errorUpdatedAt: number;
|
|
121
|
+
failureCount: number;
|
|
122
|
+
failureReason: Error | null;
|
|
123
|
+
errorUpdateCount: number;
|
|
124
|
+
isFetched: boolean;
|
|
125
|
+
isFetchedAfterMount: boolean;
|
|
126
|
+
isFetching: boolean;
|
|
127
|
+
isLoading: boolean;
|
|
128
|
+
isInitialLoading: boolean;
|
|
129
|
+
isPaused: boolean;
|
|
130
|
+
isRefetching: boolean;
|
|
131
|
+
isStale: boolean;
|
|
132
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
133
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
134
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
135
|
+
payload: string | undefined;
|
|
136
|
+
} | {
|
|
137
|
+
isError: false;
|
|
138
|
+
error: null;
|
|
139
|
+
isPending: false;
|
|
140
|
+
isLoading: false;
|
|
141
|
+
isLoadingError: false;
|
|
142
|
+
isRefetchError: false;
|
|
143
|
+
isSuccess: true;
|
|
144
|
+
isPlaceholderData: true;
|
|
145
|
+
status: "success";
|
|
146
|
+
dataUpdatedAt: number;
|
|
147
|
+
errorUpdatedAt: number;
|
|
148
|
+
failureCount: number;
|
|
149
|
+
failureReason: Error | null;
|
|
150
|
+
errorUpdateCount: number;
|
|
151
|
+
isFetched: boolean;
|
|
152
|
+
isFetchedAfterMount: boolean;
|
|
153
|
+
isFetching: boolean;
|
|
154
|
+
isInitialLoading: boolean;
|
|
155
|
+
isPaused: boolean;
|
|
156
|
+
isRefetching: boolean;
|
|
157
|
+
isStale: boolean;
|
|
158
|
+
refetch: (options?: import("@tanstack/query-core").RefetchOptions) => Promise<import("@tanstack/query-core").QueryObserverResult<ApiResource<GroupChatConversationPayload>, Error>>;
|
|
159
|
+
fetchStatus: import("@tanstack/query-core").FetchStatus;
|
|
160
|
+
promise: Promise<ApiResource<GroupChatConversationPayload>>;
|
|
161
|
+
payload: string | undefined;
|
|
162
|
+
};
|
|
163
|
+
interface GroupChatConversationPayload extends ResourceObject {
|
|
164
|
+
type: 'GroupChatConversationPayload';
|
|
165
|
+
value: string;
|
|
166
|
+
}
|
|
167
|
+
export {};
|
|
168
|
+
//# sourceMappingURL=use_group_chat_conversation_payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_group_chat_conversation_payload.d.ts","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_chat_conversation_payload.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAKzD,UAAU,KAAK;IACb,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,+BAA+B,CAAC,EAAE,OAAO,EAAE,OAAc,EAAE,EAAE,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqBjF;AAED,UAAU,4BAA6B,SAAQ,cAAc;IAC3D,IAAI,EAAE,8BAA8B,CAAA;IACpC,KAAK,EAAE,MAAM,CAAA;CACd"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useApiClient } from '../use_api_client';
|
|
3
|
+
const STALE_TIME_MS = 25 * 60 * 1000; // under Groups' 30-min server-side expiry
|
|
4
|
+
export function useGroupChatConversationPayload({ groupId, enabled = true }) {
|
|
5
|
+
const apiClient = useApiClient();
|
|
6
|
+
const url = `/me/groups/${groupId}/chat_conversation_payload`;
|
|
7
|
+
const { data, ...rest } = useQuery({
|
|
8
|
+
queryKey: ['groups', url],
|
|
9
|
+
queryFn: () => apiClient.groups.post({
|
|
10
|
+
url,
|
|
11
|
+
data: {
|
|
12
|
+
data: {
|
|
13
|
+
type: 'GroupChatConversationPayload',
|
|
14
|
+
attributes: { title: '' },
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
staleTime: STALE_TIME_MS,
|
|
19
|
+
enabled,
|
|
20
|
+
});
|
|
21
|
+
return { payload: data?.data.value, ...rest };
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=use_group_chat_conversation_payload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use_group_chat_conversation_payload.js","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_chat_conversation_payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAA,CAAC,0CAA0C;AAO/E,MAAM,UAAU,+BAA+B,CAAC,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,EAAS;IAChF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAChC,MAAM,GAAG,GAAG,cAAc,OAAO,4BAA4B,CAAA;IAE7D,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;QACjC,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC;QACzB,OAAO,EAAE,GAAG,EAAE,CACZ,SAAS,CAAC,MAAM,CAAC,IAAI,CAA4C;YAC/D,GAAG;YACH,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,IAAI,EAAE,8BAA8B;oBACpC,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;iBAC1B;aACF;SACF,CAAC;QACJ,SAAS,EAAE,aAAa;QACxB,OAAO;KACR,CAAC,CAAA;IAEF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,EAAE,CAAA;AAC/C,CAAC","sourcesContent":["import { useQuery } from '@tanstack/react-query'\nimport { ApiResource, ResourceObject } from '../../types'\nimport { useApiClient } from '../use_api_client'\n\nconst STALE_TIME_MS = 25 * 60 * 1000 // under Groups' 30-min server-side expiry\n\ninterface Props {\n groupId: number\n enabled?: boolean\n}\n\nexport function useGroupChatConversationPayload({ groupId, enabled = true }: Props) {\n const apiClient = useApiClient()\n const url = `/me/groups/${groupId}/chat_conversation_payload`\n\n const { data, ...rest } = useQuery({\n queryKey: ['groups', url],\n queryFn: () =>\n apiClient.groups.post<ApiResource<GroupChatConversationPayload>>({\n url,\n data: {\n data: {\n type: 'GroupChatConversationPayload',\n attributes: { title: '' },\n },\n },\n }),\n staleTime: STALE_TIME_MS,\n enabled,\n })\n\n return { payload: data?.data.value, ...rest }\n}\n\ninterface GroupChatConversationPayload extends ResourceObject {\n type: 'GroupChatConversationPayload'\n value: string\n}\n"]}
|
|
@@ -8,10 +8,6 @@ export type GroupMembersForNewConversationResult = Omit<UseSuspensePaginatorResu
|
|
|
8
8
|
adultMembers: MemberResource[];
|
|
9
9
|
childMembers: MemberResource[];
|
|
10
10
|
};
|
|
11
|
-
/**
|
|
12
|
-
* This is specifically for the new conversation screen because we assign
|
|
13
|
-
* the "Conversation owner" badge to the current person.
|
|
14
|
-
*/
|
|
15
11
|
export declare function useGroupMembersForNewConversation({ id, gender, }: {
|
|
16
12
|
id: number;
|
|
17
13
|
gender: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_group_members_for_new_conversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_members_for_new_conversation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_group_members_for_new_conversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_members_for_new_conversation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iEAAiE,CAAA;AAE3G,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1D,KAAK,0BAA0B,CAAC,CAAC,SAAS,cAAc,IAAI,UAAU,CACpE,OAAO,oBAAoB,CAAC,CAAC,CAAC,CAC/B,CAAA;AAED,MAAM,MAAM,oCAAoC,GAAG,IAAI,CACrD,0BAA0B,CAAC,yBAAyB,CAAC,EAAE,8CAA8C;AACrG,MAAM,CACP,GAAG;IACF,IAAI,EAAE,cAAc,EAAE,CAAA;IACtB,YAAY,EAAE,cAAc,EAAE,CAAA;IAC9B,YAAY,EAAE,cAAc,EAAE,CAAA;CAC/B,CAAA;AAED,wBAAgB,iCAAiC,CAAC,EAChD,EAAE,EACF,MAAM,GACP,EAAE;IACD,EAAE,EAAE,MAAM,CAAA;IACV,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4CA"}
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useEnrichPeople } from '../use_enrich_people';
|
|
2
3
|
import { useSuspensePaginator } from '../use_suspense_api';
|
|
3
|
-
/**
|
|
4
|
-
* This is specifically for the new conversation screen because we assign
|
|
5
|
-
* the "Conversation owner" badge to the current person.
|
|
6
|
-
*/
|
|
7
4
|
export function useGroupMembersForNewConversation({ id, gender, }) {
|
|
8
|
-
const currentPerson = useCurrentPerson();
|
|
9
5
|
const response = useSuspensePaginator({
|
|
10
6
|
url: `/me/groups/${id}/memberships`,
|
|
11
7
|
data: {
|
|
@@ -20,12 +16,15 @@ export function useGroupMembersForNewConversation({ id, gender, }) {
|
|
|
20
16
|
app: 'groups',
|
|
21
17
|
});
|
|
22
18
|
const { data: memberships = [] } = response;
|
|
19
|
+
const personIds = useMemo(() => memberships.map(m => +m.person.id), [memberships]);
|
|
20
|
+
const enrichmentMap = useEnrichPeople({ personIds, groupId: id });
|
|
23
21
|
const members = memberships.map(membership => {
|
|
24
22
|
const { person } = membership;
|
|
23
|
+
const enrichment = enrichmentMap.get(+person.id);
|
|
25
24
|
return {
|
|
26
25
|
type: 'Member',
|
|
27
26
|
avatar: person.avatarUrl,
|
|
28
|
-
badges:
|
|
27
|
+
badges: enrichment?.badges ?? [],
|
|
29
28
|
child: person.child,
|
|
30
29
|
gender: person.gender,
|
|
31
30
|
id: +person.id,
|
|
@@ -43,15 +42,4 @@ export function useGroupMembersForNewConversation({ id, gender, }) {
|
|
|
43
42
|
childMembers,
|
|
44
43
|
};
|
|
45
44
|
}
|
|
46
|
-
function buildBadges(membership, currentPersonId) {
|
|
47
|
-
const { person } = membership;
|
|
48
|
-
const badges = [];
|
|
49
|
-
if (membership.role === 'leader') {
|
|
50
|
-
badges.push({ title: 'Leader' });
|
|
51
|
-
}
|
|
52
|
-
if (person.id === currentPersonId) {
|
|
53
|
-
badges.push({ title: 'Conversation owner' });
|
|
54
|
-
}
|
|
55
|
-
return badges;
|
|
56
|
-
}
|
|
57
45
|
//# sourceMappingURL=use_group_members_for_new_conversation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_group_members_for_new_conversation.js","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_members_for_new_conversation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use_group_members_for_new_conversation.js","sourceRoot":"","sources":["../../../src/hooks/groups/use_group_members_for_new_conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAG/B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAe1D,MAAM,UAAU,iCAAiC,CAAC,EAChD,EAAE,EACF,MAAM,GAIP;IACC,MAAM,QAAQ,GAAG,oBAAoB,CAA4B;QAC/D,GAAG,EAAE,cAAc,EAAE,cAAc;QACnC,IAAI,EAAE;YACJ,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,CAAC,QAAQ,CAAC;YACnB,MAAM,EAAE;gBACN,UAAU,EAAE,CAAC,cAAc,CAAC;gBAC5B,MAAM,EAAE,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC;aAC7E;YACD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACzC;QACD,GAAG,EAAE,QAAQ;KACd,CAAC,CAAA;IAEF,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA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} from '../../types'\nimport { GroupsGroupMemberResource } from '../../types/resources/groups/groups_member_resource_with_person'\nimport { useEnrichPeople } from '../use_enrich_people'\nimport { useSuspensePaginator } from '../use_suspense_api'\n\ntype UseSuspensePaginatorResult<T extends ResourceObject> = ReturnType<\n typeof useSuspensePaginator<T>\n>\n\nexport type GroupMembersForNewConversationResult = Omit<\n UseSuspensePaginatorResult<GroupsGroupMemberResource>, // We are passing our own \"members\" data shape\n 'data'\n> & {\n data: MemberResource[]\n adultMembers: MemberResource[]\n childMembers: MemberResource[]\n}\n\nexport function useGroupMembersForNewConversation({\n id,\n gender,\n}: {\n id: number\n gender: string | null\n}) {\n const response = useSuspensePaginator<GroupsGroupMemberResource>({\n url: `/me/groups/${id}/memberships`,\n data: {\n perPage: 100,\n include: ['person'],\n fields: {\n Membership: ['person, role'],\n Person: ['avatar_url', 'name', 'first_name', 'last_name', 'child', 'gender'],\n },\n ...(gender ? { where: { gender } } : {}),\n },\n app: 'groups',\n })\n\n const { data: memberships = [] } = response\n const personIds = useMemo(() => memberships.map(m => +m.person.id), [memberships])\n const enrichmentMap = useEnrichPeople({ personIds, groupId: id })\n\n const members: MemberResource[] = memberships.map(membership => {\n const { person } = membership\n const enrichment = enrichmentMap.get(+person.id)\n return {\n type: 'Member',\n avatar: person.avatarUrl,\n badges: enrichment?.badges ?? [],\n child: person.child,\n gender: person.gender,\n id: +person.id,\n name: `${person.firstName} ${person.lastName}`,\n source: [],\n role: membership.role,\n }\n })\n\n const adultMembers = members.filter(member => !member.child)\n const childMembers = members.filter(member => member.child)\n\n return {\n ...response,\n data: members,\n adultMembers,\n childMembers,\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_groups_conversation_create.js","sourceRoot":"","sources":["../../../src/hooks/groups/use_groups_conversation_create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAShD,MAAM,UAAU,2BAA2B,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAS;IACxF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,WAAW,CAAC;QACjB,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,MAAM,CAAC,EAAE;YAClB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC3B,CAAC;QACD,UAAU,EAAE,GAAG,EAAE,CACf,SAAS,CAAC,MAAM;aACb,IAAI,CAAuC;YAC1C,GAAG,EAAE,cAAc,OAAO,4BAA4B;YACtD,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"use_groups_conversation_create.js","sourceRoot":"","sources":["../../../src/hooks/groups/use_groups_conversation_create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAShD,MAAM,UAAU,2BAA2B,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAS;IACxF,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,OAAO,WAAW,CAAC;QACjB,YAAY,EAAE,IAAI;QAClB,SAAS,EAAE,MAAM,CAAC,EAAE;YAClB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAC3B,CAAC;QACD,UAAU,EAAE,GAAG,EAAE,CACf,SAAS,CAAC,MAAM;aACb,IAAI,CAAuC;YAC1C,GAAG,EAAE,cAAc,OAAO,4BAA4B;YACtD,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,IAAI,EAAE,8BAA8B;oBACpC,UAAU,EAAE;wBACV,KAAK;qBACN;iBACF;aACF;SACF,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;aAC3B,IAAI,CAAC,OAAO,CAAC,EAAE,CACd,SAAS,CAAC,IAAI,CAAC,IAAI,CAAoC;YACrD,GAAG,EAAE,mBAAmB;YACxB,IAAI,EAAE;gBACJ,IAAI,EAAE;oBACJ,IAAI,EAAE,cAAc;oBACpB,UAAU,EAAE;wBACV,OAAO;wBACP,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;qBAC7C;iBACF;aACF;SACF,CAAC,CACH;aACA,KAAK,CAAC,kBAAkB,CAAC;KAC/B,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { useMutation } from '@tanstack/react-query'\nimport { ApiResource, ConversationResource, ResourceObject } from '../../types'\nimport { throwResponseError } from '../../utils/response_error'\nimport { useApiClient } from '../use_api_client'\n\ninterface Props {\n groupId: number\n title?: string\n genderId?: string | null\n onSuccess: (conversationId: number) => void\n}\n\nexport function useGroupsConversationCreate({ groupId, title, genderId, onSuccess }: Props) {\n const apiClient = useApiClient()\n\n return useMutation({\n throwOnError: true,\n onSuccess: result => {\n onSuccess(result.data.id)\n },\n mutationFn: () =>\n apiClient.groups\n .post<ApiResource<ChatConversationPayload>>({\n url: `/me/groups/${groupId}/chat_conversation_payload`,\n data: {\n data: {\n type: 'GroupChatConversationPayload',\n attributes: {\n title,\n },\n },\n },\n })\n .then(res => res.data.value)\n .then(payload =>\n apiClient.chat.post<ApiResource<ConversationResource>>({\n url: '/me/conversations',\n data: {\n data: {\n type: 'Conversation',\n attributes: {\n payload,\n ...(genderId ? { gender_id: genderId } : {}),\n },\n },\n },\n })\n )\n .catch(throwResponseError),\n })\n}\n\ninterface ChatConversationPayload extends ResourceObject {\n value: string\n}\n"]}
|
package/build/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './use_animated_message_background_color';
|
|
2
|
-
export
|
|
2
|
+
export { useApiClient } from './use_api_client';
|
|
3
3
|
export * from './use_api';
|
|
4
|
+
export * from './use_app_state';
|
|
4
5
|
export * from './use_async_storage';
|
|
5
6
|
export * from './use_at_font_scale_breakpoint';
|
|
6
7
|
export * from './use_chat_permissions';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA;AACjD,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA"}
|
package/build/hooks/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './use_animated_message_background_color';
|
|
2
|
-
export
|
|
2
|
+
export { useApiClient } from './use_api_client';
|
|
3
3
|
export * from './use_api';
|
|
4
|
+
export * from './use_app_state';
|
|
4
5
|
export * from './use_async_storage';
|
|
5
6
|
export * from './use_at_font_scale_breakpoint';
|
|
6
7
|
export * from './use_chat_permissions';
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,yCAAyC,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAC/C,cAAc,WAAW,CAAA;AACzB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,mCAAmC,CAAA;AACjD,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,oBAAoB,CAAA;AAClC,cAAc,aAAa,CAAA","sourcesContent":["export * from './use_animated_message_background_color'\nexport { useApiClient } from './use_api_client'\nexport * from './use_api'\nexport * from './use_app_state'\nexport * from './use_async_storage'\nexport * from './use_at_font_scale_breakpoint'\nexport * from './use_chat_permissions'\nexport * from './use_create_android_ripple_color'\nexport * from './use_current_person'\nexport * from './use_deleting_ids'\nexport * from './use_font_scale'\nexport * from './use_groups_groups'\nexport * from './use_groups'\nexport * from './use_interaction_ghost_color'\nexport * from './use_message_reaction_toggle'\nexport * from './use_new_conversation_entry'\nexport * from './use_organization'\nexport * from './use_people_person'\nexport * from './use_product_analytics'\nexport * from './use_qualified_by_age'\nexport * from './use_scalable_number_of_lines'\nexport * from './use_submit_age_check'\nexport * from './use_suspense_api'\nexport * from './use_theme'\n"]}
|
|
@@ -115,16 +115,24 @@ export declare const useFindOrCreateServicesConversation: ({ teamIds, planId, on
|
|
|
115
115
|
created: boolean;
|
|
116
116
|
}, Error, void, unknown>;
|
|
117
117
|
};
|
|
118
|
-
export declare const findOrCreateServicesConversation: (apiClient
|
|
118
|
+
export declare const findOrCreateServicesConversation: ({ apiClient, teamIds, planId, }: {
|
|
119
|
+
apiClient: ApiClient;
|
|
120
|
+
teamIds: number[];
|
|
121
|
+
planId?: number;
|
|
122
|
+
}) => Promise<{
|
|
119
123
|
conversation: ConversationResource;
|
|
120
124
|
created: boolean;
|
|
121
125
|
}>;
|
|
122
|
-
export declare const
|
|
126
|
+
export declare const getServicesChatConversationPayload: ({ apiClient, teamIds, planId, }: {
|
|
127
|
+
apiClient: ApiClient;
|
|
128
|
+
teamIds: number[];
|
|
129
|
+
planId?: number;
|
|
130
|
+
}) => Promise<ApiResource<ServicesChatPayloadResource>>;
|
|
123
131
|
export declare const getGroupIdsFromServices: (apiClient: ApiClient, teamAndPlanParams: TeamAndPlanParams) => Promise<ApiResource<ServicesChatGroupIdentifiersResource>>;
|
|
124
132
|
export declare const findConversationWithExactTeams: (apiClient: ApiClient, groupIdentifiers: string[]) => Promise<ApiCollection<ConversationResource>>;
|
|
125
133
|
export declare const createConversation: (apiClient: ApiClient, payload: string) => Promise<ApiResource<ConversationResource>>;
|
|
126
134
|
export declare const findExactTeamConversation: (apiClient: ApiClient, groupIdentifiers: string[]) => Promise<ApiCollection<ConversationResource>>;
|
|
127
135
|
export declare const checkIfConversationWithGroupExists: (apiClient: ApiClient, teamAndPlanParams: TeamAndPlanParams) => Promise<boolean>;
|
|
128
|
-
export declare const buildTeamAndPlanParams: (teamIds?: number[], planId?: number) => import("lodash").Dictionary<string | number | undefined>;
|
|
136
|
+
export declare const buildTeamAndPlanParams: (teamIds?: number[], planId?: number) => import("lodash").Dictionary<string | number | null | undefined>;
|
|
129
137
|
export {};
|
|
130
138
|
//# sourceMappingURL=use_find_or_create_services_conversation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_find_or_create_services_conversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,oCAAoC,EACpC,2BAA2B,EAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,SAAS,EAAgB,MAAM,mBAAmB,CAAA;AAE3D,UAAU,KAAK;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,oBAAoB,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAA;CACrF;AAED,UAAU,iBAAiB;IACzB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,mCAAmC,GAAI,gCAAgC,KAAK;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"use_find_or_create_services_conversation.d.ts","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,oCAAoC,EACpC,2BAA2B,EAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAAE,SAAS,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CACvD,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,WAAW,SAAS,EACpB,mBAAmB,iBAAiB,KAU9B,OAAO,CAAC,WAAW,CAAC,oCAAoC,CAAC,CAChE,CAAA;AAED,eAAO,MAAM,8BAA8B,GACzC,WAAW,SAAS,EACpB,kBAAkB,MAAM,EAAE,KAWpB,OAAO,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAClD,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,WAAW,SAAS,EAAE,SAAS,MAAM,KAMhE,OAAO,CAAC,WAAW,CAAC,oBAAoB,CAAC,CAChD,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAI,WAAW,SAAS,EAAE,kBAAkB,MAAM,EAAE,KAUlF,OAAO,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAClD,CAAA;AAED,eAAO,MAAM,kCAAkC,GAC7C,WAAW,SAAS,EACpB,mBAAmB,iBAAiB,qBAMrC,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,UAAS,MAAM,EAAO,EAAE,SAAS,MAAM,oEAQ7E,CAAA"}
|
|
@@ -5,10 +5,7 @@ import { throwResponseError } from '../../utils/response_error';
|
|
|
5
5
|
import { useApiClient } from '../use_api_client';
|
|
6
6
|
export const useFindOrCreateServicesConversation = ({ teamIds, planId, onSuccess }) => {
|
|
7
7
|
const apiClient = useApiClient();
|
|
8
|
-
const teamAndPlanParams = useMemo(() =>
|
|
9
|
-
team_id: teamIds?.join(',') || null,
|
|
10
|
-
plan_id: planId,
|
|
11
|
-
}, isNil), [teamIds, planId]);
|
|
8
|
+
const teamAndPlanParams = useMemo(() => buildTeamAndPlanParams(teamIds, planId), [teamIds, planId]);
|
|
12
9
|
const { data: selectionHasConversation = false, isLoading: isLoadingConversationCheck } = useQuery({
|
|
13
10
|
queryKey: ['conversation-with-group-exists', teamAndPlanParams],
|
|
14
11
|
queryFn: () => checkIfConversationWithGroupExists(apiClient, teamAndPlanParams),
|
|
@@ -19,11 +16,12 @@ export const useFindOrCreateServicesConversation = ({ teamIds, planId, onSuccess
|
|
|
19
16
|
onSuccess: ({ conversation, created }) => {
|
|
20
17
|
onSuccess?.(conversation, { created });
|
|
21
18
|
},
|
|
22
|
-
mutationFn: async () => findOrCreateServicesConversation(apiClient,
|
|
19
|
+
mutationFn: async () => findOrCreateServicesConversation({ apiClient, teamIds: teamIds ?? [], planId }),
|
|
23
20
|
});
|
|
24
21
|
return { ...mutation, selectionHasConversation, isLoadingConversationCheck };
|
|
25
22
|
};
|
|
26
|
-
export const findOrCreateServicesConversation = async (apiClient,
|
|
23
|
+
export const findOrCreateServicesConversation = async ({ apiClient, teamIds, planId, }) => {
|
|
24
|
+
const teamAndPlanParams = buildTeamAndPlanParams(teamIds, planId);
|
|
27
25
|
const foundConversations = await getGroupIdsFromServices(apiClient, teamAndPlanParams)
|
|
28
26
|
.then(res => res.data.groupIdentifiers)
|
|
29
27
|
.then(groupIdentifiers => findConversationWithExactTeams(apiClient, groupIdentifiers))
|
|
@@ -32,20 +30,18 @@ export const findOrCreateServicesConversation = async (apiClient, teamAndPlanPar
|
|
|
32
30
|
if (foundConversation?.id) {
|
|
33
31
|
return { conversation: foundConversation, created: false };
|
|
34
32
|
}
|
|
35
|
-
return
|
|
33
|
+
return getServicesChatConversationPayload({ apiClient, teamIds, planId })
|
|
36
34
|
.then(res => res.data.payload)
|
|
37
35
|
.then(payload => createConversation(apiClient, payload))
|
|
38
36
|
.then(res => ({ conversation: res.data, created: true }))
|
|
39
37
|
.catch(throwResponseError);
|
|
40
38
|
};
|
|
41
|
-
export const
|
|
39
|
+
export const getServicesChatConversationPayload = ({ apiClient, teamIds, planId, }) => {
|
|
42
40
|
return apiClient.services.get({
|
|
43
|
-
url:
|
|
41
|
+
url: '/chat',
|
|
44
42
|
data: {
|
|
45
|
-
...
|
|
46
|
-
fields: {
|
|
47
|
-
Chat: ['payload'],
|
|
48
|
-
},
|
|
43
|
+
...buildTeamAndPlanParams(teamIds, planId),
|
|
44
|
+
fields: { Chat: ['payload'] },
|
|
49
45
|
},
|
|
50
46
|
});
|
|
51
47
|
};
|
|
@@ -100,7 +96,7 @@ export const checkIfConversationWithGroupExists = (apiClient, teamAndPlanParams)
|
|
|
100
96
|
};
|
|
101
97
|
export const buildTeamAndPlanParams = (teamIds = [], planId) => {
|
|
102
98
|
return omitBy({
|
|
103
|
-
team_id: teamIds.join(','),
|
|
99
|
+
team_id: teamIds.length ? teamIds.join(',') : null,
|
|
104
100
|
plan_id: planId,
|
|
105
101
|
}, isNil);
|
|
106
102
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use_find_or_create_services_conversation.js","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAQ/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAa,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAa3D,MAAM,CAAC,MAAM,mCAAmC,GAAG,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAS,EAAE,EAAE;IAC3F,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,MAAM,iBAAiB,GAAsB,OAAO,CAClD,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"use_find_or_create_services_conversation.js","sourceRoot":"","sources":["../../../src/hooks/services/use_find_or_create_services_conversation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AA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BAAmB;QACxB,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,YAAY,EAAE,CAAC,OAAO,CAAC;aACxB;YACD,MAAM,EAAE,mBAAmB;YAC3B,IAAI,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC;SACjC;KACF,CAAiD,CAAA;AACpD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,SAAoB,EACpB,iBAAoC,EACpC,EAAE;IACF,OAAO,uBAAuB,CAAC,SAAS,EAAE,iBAAiB,CAAC;SACzD,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC;SACtC,IAAI,CAAC,gBAAgB,CAAC,EAAE,CAAC,yBAAyB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;SAChF,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC/C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,UAAoB,EAAE,EAAE,MAAe,EAAE,EAAE;IAChF,OAAO,MAAM,CACX;QACE,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI;QAClD,OAAO,EAAE,MAAM;KAChB,EACD,KAAK,CACN,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { useMutation, useQuery } from '@tanstack/react-query'\nimport { isNil, omitBy } from 'lodash'\nimport { useMemo } from 'react'\nimport {\n ApiCollection,\n ApiResource,\n ConversationResource,\n ServicesChatGroupIdentifiersResource,\n ServicesChatPayloadResource,\n} from '../../types'\nimport { throwResponseError } from '../../utils/response_error'\nimport { ApiClient, useApiClient } from '../use_api_client'\n\ninterface Props {\n teamIds?: number[]\n planId?: number\n onSuccess?: (conversation: ConversationResource, meta: { created: boolean }) => void\n}\n\ninterface TeamAndPlanParams {\n team_id?: string | null\n plan_id?: number\n}\n\nexport const useFindOrCreateServicesConversation = ({ teamIds, planId, onSuccess }: Props) => {\n const apiClient = useApiClient()\n\n const teamAndPlanParams: TeamAndPlanParams = useMemo(\n () => buildTeamAndPlanParams(teamIds, planId),\n [teamIds, planId]\n )\n\n const { data: selectionHasConversation = false, isLoading: isLoadingConversationCheck } =\n useQuery({\n queryKey: ['conversation-with-group-exists', teamAndPlanParams],\n queryFn: () => checkIfConversationWithGroupExists(apiClient, teamAndPlanParams),\n enabled: !!(teamIds?.length || planId),\n })\n\n const mutation = useMutation({\n throwOnError: true,\n onSuccess: ({ conversation, created }) => {\n onSuccess?.(conversation, { created })\n },\n mutationFn: async () =>\n findOrCreateServicesConversation({ apiClient, teamIds: teamIds ?? [], planId }),\n })\n\n return { ...mutation, selectionHasConversation, isLoadingConversationCheck }\n}\n\nexport const findOrCreateServicesConversation = async ({\n apiClient,\n teamIds,\n planId,\n}: {\n apiClient: ApiClient\n teamIds: number[]\n planId?: number\n}): Promise<{ conversation: ConversationResource; created: boolean }> => {\n const teamAndPlanParams = buildTeamAndPlanParams(teamIds, planId)\n const foundConversations = await getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findConversationWithExactTeams(apiClient, groupIdentifiers))\n .catch(() => null)\n const foundConversation = foundConversations?.data[0]\n\n if (foundConversation?.id) {\n return { conversation: foundConversation, created: false }\n }\n\n return getServicesChatConversationPayload({ apiClient, teamIds, planId })\n .then(res => res.data.payload)\n .then(payload => createConversation(apiClient, payload))\n .then(res => ({ conversation: res.data, created: true }))\n .catch(throwResponseError)\n}\n\nexport const getServicesChatConversationPayload = ({\n apiClient,\n teamIds,\n planId,\n}: {\n apiClient: ApiClient\n teamIds: number[]\n planId?: number\n}) => {\n return apiClient.services.get({\n url: '/chat',\n data: {\n ...buildTeamAndPlanParams(teamIds, planId),\n fields: { Chat: ['payload'] },\n },\n }) as Promise<ApiResource<ServicesChatPayloadResource>>\n}\n\nexport const getGroupIdsFromServices = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return apiClient.services.get({\n url: '/chat',\n data: {\n ...teamAndPlanParams,\n fields: {\n Chat: ['group_identifiers'],\n },\n },\n }) as Promise<ApiResource<ServicesChatGroupIdentifiersResource>>\n}\n\nexport const findConversationWithExactTeams = (\n apiClient: ApiClient,\n groupIdentifiers: string[]\n) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const createConversation = (apiClient: ApiClient, payload: string) => {\n return apiClient.chat.post({\n url: '/me/conversations',\n data: {\n data: { type: 'Conversation', attributes: { payload } },\n },\n }) as Promise<ApiResource<ConversationResource>>\n}\n\nexport const findExactTeamConversation = (apiClient: ApiClient, groupIdentifiers: string[]) => {\n return apiClient.chat.get({\n url: '/me/conversations',\n data: {\n fields: {\n Conversation: ['title'],\n },\n filter: 'with_exact_groups',\n gids: groupIdentifiers.join(','),\n },\n }) as Promise<ApiCollection<ConversationResource>>\n}\n\nexport const checkIfConversationWithGroupExists = (\n apiClient: ApiClient,\n teamAndPlanParams: TeamAndPlanParams\n) => {\n return getGroupIdsFromServices(apiClient, teamAndPlanParams)\n .then(res => res.data.groupIdentifiers)\n .then(groupIdentifiers => findExactTeamConversation(apiClient, groupIdentifiers))\n .then(response => response.data.length > 0)\n}\n\nexport const buildTeamAndPlanParams = (teamIds: number[] = [], planId?: number) => {\n return omitBy(\n {\n team_id: teamIds.length ? teamIds.join(',') : null,\n plan_id: planId,\n },\n isNil\n )\n}\n"]}
|