2023-07-19 13:56:00 +08:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
2023-07-21 15:04:44 +08:00
|
|
|
import useSubscription from './use-subscription';
|
2023-07-19 13:56:00 +08:00
|
|
|
import useSubscriptionPlans from './use-subscription-plans';
|
|
|
|
|
2023-07-21 15:04:44 +08:00
|
|
|
const useSubscriptionPlan = (tenantId: string) => {
|
|
|
|
const { data: subscription, error: fetchSubscriptionError } = useSubscription(tenantId);
|
2023-07-19 13:56:00 +08:00
|
|
|
const { data: subscriptionPlans, error: fetchSubscriptionPlansError } = useSubscriptionPlans();
|
|
|
|
|
|
|
|
const currentPlan = useMemo(
|
|
|
|
() => subscriptionPlans?.find(({ id: planId }) => planId === subscription?.planId),
|
|
|
|
[subscription?.planId, subscriptionPlans]
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: currentPlan,
|
|
|
|
error: fetchSubscriptionError ?? fetchSubscriptionPlansError,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-07-21 15:04:44 +08:00
|
|
|
export default useSubscriptionPlan;
|