import { ApiError } from "@/lib/types" import { useState } from "react" import { OWNER_ID } from "@/hooks/constants" import { root } from '@repo/core'; import { ActivityController, ListActivitiesResult, ListActivitiesInput } from "@repo/sdk"; import { useError } from "./use-error"; export const useActivities = () => { const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [data, setData] = useState() const load = async (params: ListActivitiesInput = { page: 1, limit: 10, orderBy: 'createdAt', order: 'desc' }) => { try { setLoading(true) const activity = root.get(ActivityController) const { data, error } = await useError(async () => await activity.list({ isActive: true, ownerId: OWNER_ID, ...params })) if (error) { setError(error) return } setData(data) } catch (e) { setError(e as ApiError) } finally { setLoading(false) } } return { load, loading, error, data } }