48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import { loomart } from "@/lib/auth"
|
|
import { ApiError } from "@/lib/types"
|
|
import { useState } from "react"
|
|
export const useActivates = () => {
|
|
const [loading, setLoading] = useState<boolean>(false)
|
|
const [error, setError] = useState<ApiError | null>(null)
|
|
const [data, setData] = useState<{
|
|
activities: {
|
|
title: string;
|
|
titleEn: string;
|
|
desc: string;
|
|
descEn: string;
|
|
coverUrl: string;
|
|
link: string;
|
|
createdAt: Date;
|
|
updatedAt: Date;
|
|
id: string;
|
|
videoUrl?: string | null | undefined;
|
|
isActive?: boolean | null | undefined;
|
|
sortOrder?: number | null | undefined;
|
|
}[];
|
|
total: number;
|
|
page: number;
|
|
limit: number;
|
|
totalPages: number;
|
|
}>()
|
|
const load = async () => {
|
|
try {
|
|
setLoading(true)
|
|
const { data, error } = await loomart.activities.list({ isActive: true })
|
|
console.log({ data, error })
|
|
if (error) {
|
|
setError(error)
|
|
return;
|
|
}
|
|
setData(data)
|
|
} catch (e) {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
return {
|
|
load,
|
|
loading,
|
|
error,
|
|
data
|
|
}
|
|
} |