Prevent lookup if not enabled
This commit is contained in:
parent
14aafa2526
commit
53988e2581
2 changed files with 5 additions and 2 deletions
|
@ -12,7 +12,7 @@ function useGroupLookup(slug: string) {
|
|||
Entities.GROUPS,
|
||||
(group) => group.slug === slug,
|
||||
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
|
||||
{ schema: groupSchema },
|
||||
{ schema: groupSchema, enabled: !!slug },
|
||||
);
|
||||
|
||||
const { entity: relationship } = useGroupRelationship(group?.id);
|
||||
|
|
|
@ -25,6 +25,7 @@ function useEntityLookup<TEntity extends Entity>(
|
|||
const [isFetching, setPromise] = useLoading(true);
|
||||
|
||||
const entity = useAppSelector(state => findEntity(state, entityType, lookupFn));
|
||||
const isEnabled = opts.enabled ?? true;
|
||||
const isLoading = isFetching && !entity;
|
||||
|
||||
const fetchEntity = async () => {
|
||||
|
@ -38,10 +39,12 @@ function useEntityLookup<TEntity extends Entity>(
|
|||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isEnabled) return;
|
||||
|
||||
if (!entity || opts.refetch) {
|
||||
fetchEntity();
|
||||
}
|
||||
}, []);
|
||||
}, [isEnabled]);
|
||||
|
||||
return {
|
||||
entity,
|
||||
|
|
Loading…
Reference in a new issue