@planningcenter/chat-react-native 3.36.2-rc.3 → 3.37.0-rc.1
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/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/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/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 +1 -0
- 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/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/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/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/package.json +2 -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/display/action_button.tsx +18 -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/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 +1 -0
- 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/team_conversation_screen.tsx +6 -6
- package/src/types/resources/conversation_validate.ts +11 -0
- package/src/types/resources/index.ts +1 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { ConversationWarning } from '../../types';
|
|
2
3
|
import { IconString } from './icon';
|
|
3
|
-
export declare const ActionButton: ({ visible, disabled, onPress, title, infoText, buttonIconNameLeft, secondaryButton, loading, }: {
|
|
4
|
+
export declare const ActionButton: ({ visible, disabled, onPress, title, infoText, buttonIconNameLeft, secondaryButton, loading, warnings, }: {
|
|
4
5
|
visible?: boolean;
|
|
5
6
|
disabled?: boolean;
|
|
6
7
|
onPress: () => void;
|
|
@@ -9,5 +10,6 @@ export declare const ActionButton: ({ visible, disabled, onPress, title, infoTex
|
|
|
9
10
|
buttonIconNameLeft?: IconString;
|
|
10
11
|
secondaryButton?: React.ReactNode;
|
|
11
12
|
loading?: boolean;
|
|
13
|
+
warnings?: ConversationWarning[];
|
|
12
14
|
}) => React.JSX.Element | null;
|
|
13
15
|
//# sourceMappingURL=action_button.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_button.d.ts","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"action_button.d.ts","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAA;AAKvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAIjD,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAGnC,eAAO,MAAM,YAAY,GAAI,0GAU1B;IACD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kBAAkB,CAAC,EAAE,UAAU,CAAA;IAC/B,eAAe,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,QAAQ,CAAC,EAAE,mBAAmB,EAAE,CAAA;CACjC,6BAiDA,CAAA"}
|
|
@@ -4,9 +4,10 @@ import { Animated, LayoutAnimation, StyleSheet, useWindowDimensions, View } from
|
|
|
4
4
|
import { useSafeAreaInsets } from 'react-native-safe-area-context';
|
|
5
5
|
import { useTheme } from '../../hooks';
|
|
6
6
|
import { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../utils';
|
|
7
|
+
import { Banner } from './banner';
|
|
7
8
|
import { Button } from './button';
|
|
8
9
|
import { Text } from './text';
|
|
9
|
-
export const ActionButton = ({ visible = true, disabled = false, onPress, title, infoText, buttonIconNameLeft, secondaryButton, loading = false, }) => {
|
|
10
|
+
export const ActionButton = ({ visible = true, disabled = false, onPress, title, infoText, buttonIconNameLeft, secondaryButton, loading = false, warnings = [], }) => {
|
|
10
11
|
const styles = useStyles();
|
|
11
12
|
const [show, setShow] = useState(visible);
|
|
12
13
|
useEffect(() => {
|
|
@@ -18,6 +19,9 @@ export const ActionButton = ({ visible = true, disabled = false, onPress, title,
|
|
|
18
19
|
if (!visible)
|
|
19
20
|
return null;
|
|
20
21
|
return (<Animated.View style={styles.container}>
|
|
22
|
+
{warnings.length > 0 && (<View style={styles.warnings}>
|
|
23
|
+
{warnings.map((warning, index) => (<Banner key={`${warning.attribute}-${index}`} appearance="error" description={warning.fullMessage}/>))}
|
|
24
|
+
</View>)}
|
|
21
25
|
{Boolean(infoText) && (<Text style={styles.infoText} variant="footnote">
|
|
22
26
|
{infoText}
|
|
23
27
|
</Text>)}
|
|
@@ -55,6 +59,9 @@ const useStyles = () => {
|
|
|
55
59
|
infoText: {
|
|
56
60
|
textAlign: 'center',
|
|
57
61
|
},
|
|
62
|
+
warnings: {
|
|
63
|
+
gap: 8,
|
|
64
|
+
},
|
|
58
65
|
});
|
|
59
66
|
};
|
|
60
67
|
//# sourceMappingURL=action_button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_button.js","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"action_button.js","sourceRoot":"","sources":["../../../src/components/display/action_button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,mBAAmB,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,iCAAiC,EAAE,MAAM,aAAa,CAAA;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO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AC;YACjB,cAAc,EAAE,MAAM,CAAC,qBAAqB;YAC5C,GAAG,EAAE,EAAE;SACR;QACD,SAAS,EAAE;YACT,aAAa,EAAE,KAAK;YACpB,cAAc,EAAE,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,eAAe;YAC1D,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,EAAE;YACP,QAAQ,EAAE,cAAc;SACzB;QACD,eAAe,EAAE;YACf,QAAQ,EAAE,CAAC;SACZ;QACD,QAAQ,EAAE;YACR,SAAS,EAAE,QAAQ;SACpB;QACD,QAAQ,EAAE;YACR,GAAG,EAAE,CAAC;SACP;KACF,CAAC,CAAA;AACJ,CAAC,CAAA","sourcesContent":["import React, { useState } from 'react'\nimport { useEffect } from 'react'\nimport { Animated, LayoutAnimation, StyleSheet, useWindowDimensions, View } from 'react-native'\nimport { useSafeAreaInsets } from 'react-native-safe-area-context'\nimport { useTheme } from '../../hooks'\nimport { ConversationWarning } from '../../types'\nimport { MAX_FONT_SIZE_MULTIPLIER_LANDMARK } from '../../utils'\nimport { Banner } from './banner'\nimport { Button } from './button'\nimport { IconString } from './icon'\nimport { Text } from './text'\n\nexport const ActionButton = ({\n visible = true,\n disabled = false,\n onPress,\n title,\n infoText,\n buttonIconNameLeft,\n secondaryButton,\n loading = false,\n warnings = [],\n}: {\n visible?: boolean\n disabled?: boolean\n onPress: () => void\n title: string\n infoText?: string\n buttonIconNameLeft?: IconString\n secondaryButton?: React.ReactNode\n loading?: boolean\n warnings?: ConversationWarning[]\n}) => {\n const styles = useStyles()\n const [show, setShow] = useState(visible)\n\n useEffect(() => {\n if (show === visible) return\n\n setShow(visible)\n LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)\n }, [show, visible])\n\n if (!visible) return null\n\n return (\n <Animated.View style={styles.container}>\n {warnings.length > 0 && (\n <View style={styles.warnings}>\n {warnings.map((warning, index) => (\n <Banner\n key={`${warning.attribute}-${index}`}\n appearance=\"error\"\n description={warning.fullMessage}\n />\n ))}\n </View>\n )}\n {Boolean(infoText) && (\n <Text style={styles.infoText} variant=\"footnote\">\n {infoText}\n </Text>\n )}\n <View style={styles.buttonRow}>\n {secondaryButton}\n <Button\n variant=\"fill\"\n size=\"lg\"\n onPress={onPress}\n title={title}\n disabled={disabled}\n style={secondaryButton ? null : styles.fullWidthButton}\n iconNameLeft={buttonIconNameLeft}\n loading={loading}\n maxFontSizeMultiplier={MAX_FONT_SIZE_MULTIPLIER_LANDMARK}\n accessibilityShowsLargeContentViewer\n accessibilityLargeContentTitle={title}\n />\n </View>\n </Animated.View>\n )\n}\n\nconst useStyles = () => {\n const { fontScale } = useWindowDimensions()\n const { bottom } = useSafeAreaInsets()\n const { colors } = useTheme()\n const containerVerticalPadding = 16\n\n return StyleSheet.create({\n container: {\n backgroundColor: colors.surfaceColor090,\n paddingHorizontal: 24,\n paddingTop: containerVerticalPadding,\n paddingBottom: bottom + containerVerticalPadding,\n borderTopWidth: 1,\n borderTopColor: colors.borderColorDefaultDim,\n gap: 16,\n },\n buttonRow: {\n flexDirection: 'row',\n justifyContent: fontScale > 1 ? 'center' : 'space-between',\n alignItems: 'center',\n gap: 16,\n flexWrap: 'wrap-reverse',\n },\n fullWidthButton: {\n flexGrow: 1,\n },\n infoText: {\n textAlign: 'center',\n },\n warnings: {\n gap: 8,\n },\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;IAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAClF,MAAM,aAAa,GAAG,eAAe,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAA;IAEjE,MAAM,OAAO,GAAqB,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;QAC7D,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAA;QAC7B,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAChD,OAAO;YACL,IAAI,EAAE,QAAQ;YACd,MAAM,EAAE,MAAM,CAAC,SAAS;YACxB,MAAM,EAAE,UAAU,EAAE,MAAM,IAAI,EAAE;YAChC,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,EAAE,EAAE,CAAC,MAAM,CAAC,EAAE;YACd,IAAI,EAAE,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC9C,MAAM,EAAE,EAAE;YACV,IAAI,EAAE,UAAU,CAAC,IAAI;SACtB,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAC5D,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAE3D,OAAO;QACL,GAAG,QAAQ;QACX,IAAI,EAAE,OAAO;QACb,YAAY;QACZ,YAAY;KACb,CAAA;AACH,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport { MemberResource, ResourceObject } 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"]}
|
|
@@ -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,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;;;;;;;;;;;;sBAmC7D,oBAAoB;iBAAW,OAAO;;;;;;;;;sBAAtC,oBAAoB;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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;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,CAAC,sBAAsB,CAAC,OAAO,EAAE,MAAM,CAAC,EAC7C,CAAC,OAAO,EAAE,MAAM,CAAC,CAClB,CAAA;IAED,MAAM,EAAE,IAAI,EAAE,wBAAwB,GAAG,KAAK,EAAE,SAAS,EAAE,0BAA0B,EAAE,G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,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"]}
|