mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
26 lines
No EOL
821 B
TypeScript
26 lines
No EOL
821 B
TypeScript
// hooks/usePaymentsEnabled.ts
|
|
import { useOrg } from '@components/Contexts/OrgContext';
|
|
import { useLHSession } from '@components/Contexts/LHSessionContext';
|
|
import useSWR from 'swr';
|
|
import { getPaymentConfigs } from '@services/payments/payments';
|
|
|
|
export function usePaymentsEnabled() {
|
|
const org = useOrg() as any;
|
|
const session = useLHSession() as any;
|
|
const access_token = session?.data?.tokens?.access_token;
|
|
|
|
const { data: paymentConfigs, error, isLoading } = useSWR(
|
|
org && access_token ? [`/payments/${org.id}/config`, access_token] : null,
|
|
([url, token]) => getPaymentConfigs(org.id, token)
|
|
);
|
|
|
|
const isStripeEnabled = paymentConfigs?.some(
|
|
(config: any) => config.provider === 'stripe' && config.active
|
|
);
|
|
|
|
return {
|
|
isEnabled: !!isStripeEnabled,
|
|
isLoading,
|
|
error
|
|
};
|
|
} |