Initial commit
This commit is contained in:
29
hooks/useTicket.ts
Normal file
29
hooks/useTicket.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import axios from "axios";
|
||||
import { useMutation, UseMutationOptions } from "react-query";
|
||||
|
||||
interface CreateTicketOpts {
|
||||
domain: string;
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
|
||||
export interface CreateTicketResp {
|
||||
data: {
|
||||
ticket: string;
|
||||
CSRFPreventionToken: string;
|
||||
};
|
||||
}
|
||||
|
||||
export async function createTicket({
|
||||
domain,
|
||||
username,
|
||||
password,
|
||||
}: CreateTicketOpts) {
|
||||
const url = `${domain}/api2/json/access/ticket`;
|
||||
const headers = { "Content-Type": "application/json" };
|
||||
return axios.post<CreateTicketResp>(url, { username, password }, { headers });
|
||||
}
|
||||
|
||||
export function useTicketMut(options: UseMutationOptions) {
|
||||
return useMutation({ mutationFn: createTicket, ...options });
|
||||
}
|
||||
Reference in New Issue
Block a user