24 lines
755 B
TypeScript
24 lines
755 B
TypeScript
import { EntityWithRoles } from "@/interfaces/entity";
|
|
import { Discount } from "@/interfaces/paypal";
|
|
import { Code, Group, User } from "@/interfaces/user";
|
|
import axios from "axios";
|
|
import { useEffect, useState } from "react";
|
|
|
|
export default function useEntities() {
|
|
const [entities, setEntities] = useState<EntityWithRoles[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isError, setIsError] = useState(false);
|
|
|
|
const getData = () => {
|
|
setIsLoading(true);
|
|
axios
|
|
.get<EntityWithRoles[]>("/api/entities?showRoles=true")
|
|
.then((response) => setEntities(response.data))
|
|
.finally(() => setIsLoading(false));
|
|
};
|
|
|
|
useEffect(getData, []);
|
|
|
|
return { entities, isLoading, isError, reload: getData };
|
|
}
|