File size: 1,093 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 25 26 27 28 29 30 31 32 |
import { HelpCenterSelect } from '@automattic/data-stores';
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 { useSelect } from '@wordpress/data';
export const useResetSupportInteraction = () => {
const { currentSupportInteraction } = useSelect( ( select ) => {
const store = select( HELP_CENTER_STORE ) as HelpCenterSelect;
return {
currentSupportInteraction: store.getCurrentSupportInteraction(),
};
}, [] );
const { startNewInteraction, resolveInteraction } = useManageSupportInteraction();
const queryClient = useQueryClient();
return async () => {
if ( currentSupportInteraction ) {
resolveInteraction( { interactionId: currentSupportInteraction.uuid } );
await queryClient.invalidateQueries( {
queryKey: [ 'support-interactions', 'get-interactions' ],
} );
}
return await startNewInteraction( {
event_source: 'help-center',
event_external_id: crypto.randomUUID(),
} );
};
};
|