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