23 lines
735 B
TypeScript
23 lines
735 B
TypeScript
import { TicketWithCorporate } from "@/interfaces/ticket";
|
|
import { Code, Group, User } from "@/interfaces/user";
|
|
import axios from "axios";
|
|
import { useEffect, useState, useCallback } from "react";
|
|
|
|
export default function useTickets() {
|
|
const [tickets, setTickets] = useState<TicketWithCorporate[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const getData = useCallback(() => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<TicketWithCorporate[]>(`/api/tickets`)
|
|
.then((response) => setTickets(response.data))
|
|
.finally(() => setIsLoading(false));
|
|
}, []);
|
|
|
|
useEffect(getData, [getData]);
|
|
|
|
return { tickets, isLoading, isError, reload: getData };
|
|
}
|