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