File size: 849 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { HELP_CENTER_STORE } from '@automattic/help-center/src/stores';
import { useManageSupportInteraction } from '@automattic/odie-client/src/data';
import { useQueryClient } from '@tanstack/react-query';
import { useDispatch } from '@wordpress/data';

export const useStartSupportInteraction = () => {
	const { setCurrentSupportInteraction } = useDispatch( HELP_CENTER_STORE );
	const { startNewInteraction } = useManageSupportInteraction();
	const queryClient = useQueryClient();

	const startInteraction = async () => {
		const interaction = await startNewInteraction( {
			event_source: 'help-center',
			event_external_id: crypto.randomUUID(),
		} );
		await queryClient.invalidateQueries( {
			queryKey: [ 'support-interactions', 'get-interactions' ],
		} );
		setCurrentSupportInteraction( interaction );
	};

	return startInteraction;
};