refactor: sorted hooks
This commit is contained in:
31
src/hooks/lists/useStatusesList.ts
Normal file
31
src/hooks/lists/useStatusesList.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { StatusSchema } from "@/lib/client";
|
||||
import { getStatusesOptions } from "@/lib/client/@tanstack/react-query.gen";
|
||||
|
||||
type Props = {
|
||||
boardId?: number;
|
||||
};
|
||||
|
||||
const useStatusesList = ({ boardId }: Props) => {
|
||||
const [statuses, setStatuses] = useState<StatusSchema[]>([]);
|
||||
|
||||
const { data, refetch, isLoading } = useQuery({
|
||||
...getStatusesOptions({ path: { boardId: boardId! } }),
|
||||
enabled: boardId !== undefined,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (boardId === undefined) {
|
||||
setStatuses([]);
|
||||
return;
|
||||
}
|
||||
if (data?.statuses) {
|
||||
setStatuses(data.statuses);
|
||||
}
|
||||
}, [data?.statuses, boardId]);
|
||||
|
||||
return { statuses, setStatuses, refetch, isLoading };
|
||||
};
|
||||
|
||||
export default useStatusesList;
|
||||
Reference in New Issue
Block a user