MCPcopy Create free account
hub / github.com/dailydotdev/apps / useIntegration

Function useIntegration

packages/shared/src/hooks/integrations/useIntegration.ts:39–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37};
38
39export const useIntegration = (): UseIntegration => {
40 const { user } = useAuthContext();
41 const queryClient = useQueryClient();
42 const { showPrompt } = usePrompt();
43 const { logEvent } = useLogContext();
44
45 const { mutateAsync: removeIntegration } = useMutation({
46 mutationFn: async ({
47 integrationId,
48 integrationType,
49 }: {
50 integrationId: string;
51 integrationType: UserIntegrationType;
52 }) => {
53 const deleteConfirmed = await showPrompt(deleteIntegrationPromptOptions);
54
55 if (!deleteConfirmed) {
56 throw new Error('User cancelled integration deletion');
57 }
58
59 logEvent({
60 event_name: LogEvent.RevokeIntegrationAccess,
61 target_id: integrationType,
62 });
63
64 await gqlClient.request(REMOVE_INTEGRATION_MUTATION, {
65 integrationId,
66 });
67 },
68
69 onSuccess: async (data, { integrationId }) => {
70 queryClient.setQueryData<UserIntegration[]>(
71 generateQueryKey(RequestKey.UserIntegrations, user),
72 (currentIntegrations) => {
73 return currentIntegrations?.filter(
74 (integration) => integration.id !== integrationId,
75 );
76 },
77 );
78 },
79 });
80
81 const { mutateAsync: removeSourceIntegration } = useMutation({
82 mutationFn: async ({
83 sourceId,
84 integrationId,
85 integrationType,
86 }: {
87 sourceId: string;
88 integrationId: string;
89 integrationType: UserIntegrationType;
90 }) => {
91 const deleteConfirmed = await showPrompt(
92 deleteSourceIntegrationPromptOptions,
93 );
94
95 if (!deleteConfirmed) {
96 throw new Error('User cancelled source integration deletion');

Callers 3

SlackIntegrationModalFunction · 0.90
UserIntegrationItemFunction · 0.90

Calls 5

useAuthContextFunction · 0.90
usePromptFunction · 0.90
useLogContextFunction · 0.90
generateQueryKeyFunction · 0.90
logEventFunction · 0.85

Tested by

no test coverage detected