File size: 821 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
33
34
35
import { useMutation } from '@tanstack/react-query';
import apiFetch, { APIFetchOptions } from '@wordpress/api-fetch';
import wpcomRequest, { canAccessWpcomApis } from 'wpcom-proxy-request';

type Ticket = {
	subject: string;
	message: string;
	locale: string;
	client: string;
	is_chat_overflow: boolean;
	source: string;
	blog_url: string;
	ai_chat_id?: string;
	ai_message?: string;
};

export function useSubmitTicketMutation() {
	return useMutation( {
		mutationFn: ( newTicket: Ticket ) =>
			canAccessWpcomApis()
				? wpcomRequest( {
						path: '/help/ticket/new',
						apiNamespace: 'wpcom/v2',
						method: 'POST',
						body: newTicket,
				  } )
				: apiFetch( {
						global: true,
						path: '/help-center/ticket/new',
						method: 'POST',
						data: newTicket,
				  } as APIFetchOptions ),
	} );
}