22 lines
650 B
TypeScript
22 lines
650 B
TypeScript
"use client";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { licence, type LicenseInfo } from "@/lib/api";
|
|
|
|
export function useLicense() {
|
|
const { data, isLoading } = useQuery<LicenseInfo>({
|
|
queryKey: ["license"],
|
|
queryFn: licence.get,
|
|
staleTime: 60_000,
|
|
});
|
|
|
|
return {
|
|
license: data,
|
|
isLoading,
|
|
isActive: data?.state === "valid",
|
|
// Features render disabled rather than hidden, so treat "unknown while
|
|
// loading" as available to avoid a flash of disabled controls.
|
|
hasFeature: (name: string) => (data ? Boolean(data.features?.[name]) : true),
|
|
};
|
|
}
|