File size: 861 Bytes
5da4770 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
'use client';
import { createMutationHook, createQueryHook } from '@/hooks/use-query';
import {
getSubscription,
createPortalSession,
SubscriptionStatus,
} from '@/lib/api';
import { subscriptionKeys } from './keys';
export const useSubscription = createQueryHook(
subscriptionKeys.details(),
getSubscription,
{
staleTime: 1000 * 60 * 5,
refetchOnWindowFocus: true,
},
);
export const useCreatePortalSession = createMutationHook(
(params: { return_url: string }) => createPortalSession(params),
{
onSuccess: (data) => {
if (data?.url) {
window.location.href = data.url;
}
},
},
);
export const isPlan = (
subscriptionData: SubscriptionStatus | null | undefined,
planId?: string,
): boolean => {
if (!subscriptionData) return planId === 'free';
return subscriptionData.plan_name === planId;
};
|