Files
bigcapital/packages/webapp/src/containers/PaymentLink/dialogs/SelectPaymentMethodsDialog/SelectPaymentMethodsBoot.tsx
2024-09-18 19:24:01 +02:00

43 lines
1.1 KiB
TypeScript

import { useGetPaymentServices } from '@/hooks/query/payment-services';
import React, { createContext, useContext, ReactNode } from 'react';
interface SelectPaymentMethodsContextType {}
const SelectPaymentMethodsContext =
createContext<SelectPaymentMethodsContextType>(
{} as SelectPaymentMethodsContextType,
);
export const useSelectPaymentMethods = () => {
const context = useContext(SelectPaymentMethodsContext);
if (!context) {
throw new Error(
'useSelectPaymentMethods must be used within a SelectPaymentMethodsProvider',
);
}
return context;
};
interface SelectPaymentMethodsProviderProps {
children: ReactNode;
}
export const SelectPaymentMethodsBoot: React.FC<
SelectPaymentMethodsProviderProps
> = ({ children }) => {
const { isLoading: isPaymentServicesLoading, data: paymentServices } =
useGetPaymentServices();
const value = {
paymentServices,
isPaymentServicesLoading,
};
return (
<SelectPaymentMethodsContext.Provider value={value}>
{children}
</SelectPaymentMethodsContext.Provider>
);
};