Files
encoach_ui_odoo19/src/hooks/useEntities.tsx
José Marques Lima 37216e2a5a ENCOA-316 ENCOA-317:
Refactor components to remove Layout wrapper and pass it in the App component , implemented a skeleton feedback while loading page and improved API calls related to Dashboard/User Profile
2025-01-25 19:38:29 +00:00

23 lines
743 B
TypeScript

import { EntityWithRoles } from "@/interfaces/entity";
import axios from "axios";
import { useCallback, useEffect, useState } from "react";
export default function useEntities(shouldNot?: boolean) {
const [entities, setEntities] = useState<EntityWithRoles[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const getData = useCallback(() => {
if (shouldNot) return;
setIsLoading(true);
axios
.get<EntityWithRoles[]>("/api/entities?showRoles=true")
.then((response) => setEntities(response.data))
.finally(() => setIsLoading(false));
}, [shouldNot]);
useEffect(getData, [getData])
return { entities, isLoading, isError, reload: getData };
}