mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-05 16:19:55 -06:00
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com> Co-authored-by: Dhruwang <dhruwangjariwala18@gmail.com> Co-authored-by: Johannes <72809645+jobenjada@users.noreply.github.com> Co-authored-by: Johannes <johannes@formbricks.com>
34 lines
1008 B
TypeScript
34 lines
1008 B
TypeScript
import { useEffect, useState } from "react";
|
|
import { TOrganizationBilling } from "@formbricks/types/organizations";
|
|
import { getOrganizationBillingInfoAction } from "./actions";
|
|
|
|
export const useGetBillingInfo = (organizationId: string) => {
|
|
const [billingInfo, setBillingInfo] = useState<TOrganizationBilling>();
|
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
|
const [error, setError] = useState<string>("");
|
|
|
|
useEffect(() => {
|
|
const getBillingInfo = async () => {
|
|
try {
|
|
setIsLoading(true);
|
|
const billingInfo = await getOrganizationBillingInfoAction({ organizationId });
|
|
|
|
if (billingInfo?.data) {
|
|
setIsLoading(false);
|
|
setBillingInfo(billingInfo.data);
|
|
}
|
|
|
|
setError("No billing info found");
|
|
setIsLoading(false);
|
|
} catch (err: any) {
|
|
setIsLoading(false);
|
|
setError(err.message);
|
|
}
|
|
};
|
|
|
|
getBillingInfo();
|
|
}, [organizationId]);
|
|
|
|
return { billingInfo, isLoading, error };
|
|
};
|