@burdenoff/microfe-billing 2026.513.1 → 2026.514.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- import { GetBillingAccountsByOrgDocument as e, GetBillingAddressDocument as t, GetCreditTransactionsSummaryDocument as n, GetDefaultBillingAccountDashboardDocument as r, useAddPaymentMethodDashboardMutation as i, useCreateBillingAccountMutation as a, useDeletePaymentMethodDashboardMutation as o, useGetDefaultBillingAccountDashboardQuery as s, useGetPaymentProviderConfigQuery as c, useInitiatePaymentMutation as l, useSetBillingAddressMutation as u, useSetDefaultBillingAccountMutation as d, useSpendCreditsMutation as f, useUpdateBillingAccountMutation as p, useUpdatePaymentMethodDashboardMutation as m, useVerifyPaymentMethodMutation as h } from "../../../../generated/global-operations.js";
2
- import { useCallback as g } from "react";
3
- import { useApolloClient as _ } from "@apollo/client/react";
1
+ import { GetBillingAccountsByOrgDocument as e, GetBillingAddressDocument as t, GetCreditTransactionsSummaryDocument as n, GetDefaultBillingAccountDashboardDocument as r, useAddPaymentMethodDashboardMutation as i, useCreateBillingAccountMutation as a, useDeletePaymentMethodDashboardMutation as o, useGetBillingAccountsByOrgQuery as s, useGetDefaultBillingAccountDashboardQuery as c, useGetPaymentProviderConfigQuery as l, useInitiatePaymentMutation as u, useSetBillingAddressMutation as d, useSetDefaultBillingAccountMutation as f, useSpendCreditsMutation as p, useUpdateBillingAccountMutation as m, useUpdatePaymentMethodDashboardMutation as h, useVerifyPaymentMethodMutation as g } from "../../../../generated/global-operations.js";
2
+ import { useCallback as _ } from "react";
3
+ import { useApolloClient as v } from "@apollo/client/react";
4
4
  //#region src/billing/modules/dashboard/hooks/useDashboard.ts
5
- function v(e = !1) {
6
- let { data: t, loading: n, error: r } = c({
5
+ function y(e = !1) {
6
+ let { data: t, loading: n, error: r } = l({
7
7
  fetchPolicy: "cache-first",
8
8
  skip: e
9
9
  }), i = t?.getPaymentProviderConfig || null;
@@ -17,8 +17,19 @@ function v(e = !1) {
17
17
  error: r
18
18
  };
19
19
  }
20
- function y() {
21
- let { data: e, loading: t, error: n, refetch: r } = s({ fetchPolicy: "cache-and-network" }), i = g(async () => {
20
+ function b() {
21
+ let { data: e, loading: t, error: n, refetch: r } = s({ fetchPolicy: "cache-and-network" }), i = _(async () => {
22
+ await r();
23
+ }, [r]);
24
+ return {
25
+ billingAccounts: e?.getBillingAccountsByOrg || [],
26
+ isLoading: t,
27
+ error: n,
28
+ refetch: i
29
+ };
30
+ }
31
+ function x() {
32
+ let { data: e, loading: t, error: n, refetch: r } = c({ fetchPolicy: "cache-and-network" }), i = _(async () => {
22
33
  await r();
23
34
  }, [r]), a = e?.getDefaultBillingAccount || null;
24
35
  return {
@@ -30,37 +41,37 @@ function y() {
30
41
  refetch: i
31
42
  };
32
43
  }
33
- function b() {
34
- let s = _(), [c, { loading: v }] = a(), [y, { loading: b }] = p(), [x, { loading: S }] = d(), [C, { loading: w }] = i(), [T, { loading: E }] = m(), [D, { loading: O }] = o(), [k, { loading: A }] = u(), [j, { loading: M }] = l(), [N, { loading: P }] = f(), [F, { loading: I }] = h();
44
+ function S() {
45
+ let s = v(), [c, { loading: l }] = a(), [y, { loading: b }] = m(), [x, { loading: S }] = f(), [C, { loading: w }] = i(), [T, { loading: E }] = h(), [D, { loading: O }] = o(), [k, { loading: A }] = d(), [j, { loading: M }] = u(), [N, { loading: P }] = p(), [F, { loading: I }] = g();
35
46
  return {
36
- createBillingAccount: g(async (t) => {
47
+ createBillingAccount: _(async (t) => {
37
48
  let { data: n, error: i } = await c({ variables: { input: t } });
38
49
  if (i) throw Error(i.message ?? "Failed to create billing account");
39
50
  if (!n?.createBillingAccount) throw Error("Failed to create billing account: no data returned");
40
51
  return await s.refetchQueries({ include: [e, r] }), n.createBillingAccount;
41
52
  }, [c, s]),
42
- updateBillingAccount: g(async (e) => {
53
+ updateBillingAccount: _(async (e) => {
43
54
  let { data: t, error: n } = await y({ variables: { input: e } });
44
55
  if (n) throw Error(n.message ?? "Failed to update billing account");
45
56
  if (!t?.updateBillingAccount) throw Error("Failed to update billing account: no data returned");
46
57
  return await s.refetchQueries({ include: [r] }), t.updateBillingAccount;
47
58
  }, [y, s]),
48
- setDefaultBillingAccount: g(async (t) => {
59
+ setDefaultBillingAccount: _(async (t) => {
49
60
  let { data: n, error: i } = await x({ variables: { id: t } });
50
61
  if (i) throw Error(i.message ?? "Failed to set default billing account");
51
62
  if (!n?.setDefaultBillingAccount) throw Error("Failed to set default billing account: no data returned");
52
63
  return await s.refetchQueries({ include: [e, r] }), n.setDefaultBillingAccount;
53
64
  }, [x, s]),
54
- isCreatingAccount: v,
65
+ isCreatingAccount: l,
55
66
  isUpdatingAccount: b,
56
67
  isSettingDefaultAccount: S,
57
- addPaymentMethod: g(async (e) => {
68
+ addPaymentMethod: _(async (e) => {
58
69
  let { data: t, error: n } = await C({ variables: { input: e } });
59
70
  if (n) throw Error(n.message ?? "Failed to add payment method");
60
71
  if (!t?.addPaymentMethod) throw Error("Failed to add payment method: no data returned");
61
72
  return t.addPaymentMethod;
62
73
  }, [C]),
63
- setDefaultPaymentMethod: g(async (e, t) => {
74
+ setDefaultPaymentMethod: _(async (e, t) => {
64
75
  let { data: n, error: r } = await T({ variables: {
65
76
  id: e,
66
77
  isDefault: !0,
@@ -70,7 +81,7 @@ function b() {
70
81
  if (!n?.updatePaymentMethod) throw Error("Failed to update payment method: no data returned");
71
82
  return n.updatePaymentMethod;
72
83
  }, [T]),
73
- deletePaymentMethod: g(async (e, t) => {
84
+ deletePaymentMethod: _(async (e, t) => {
74
85
  let { data: n, error: r } = await D({ variables: {
75
86
  id: e,
76
87
  billingAccountId: t
@@ -82,26 +93,26 @@ function b() {
82
93
  isAddingPaymentMethod: w,
83
94
  isUpdatingPaymentMethod: E,
84
95
  isDeletingPaymentMethod: O,
85
- setBillingAddress: g(async (e) => {
96
+ setBillingAddress: _(async (e) => {
86
97
  let { data: n, error: i } = await k({ variables: { input: e } });
87
98
  if (i) throw Error(i.message ?? "Failed to set billing address");
88
99
  if (!n?.setBillingAddress) throw Error("Failed to set billing address: no data returned");
89
100
  return await s.refetchQueries({ include: [t, r] }), n.setBillingAddress;
90
101
  }, [k, s]),
91
102
  isSettingAddress: A,
92
- initiatePayment: g(async (e) => {
103
+ initiatePayment: _(async (e) => {
93
104
  let { data: t, error: n } = await j({ variables: { input: e } });
94
105
  if (n) throw Error(n.message ?? "Failed to initiate payment");
95
106
  if (!t?.initiatePayment) throw Error("Failed to initiate payment: no data returned");
96
107
  return t.initiatePayment;
97
108
  }, [j]),
98
- spendCredits: g(async (e) => {
109
+ spendCredits: _(async (e) => {
99
110
  let { data: t, error: i } = await N({ variables: { input: e } });
100
111
  if (i) throw Error(i.message ?? "Failed to spend credits");
101
112
  if (!t?.spendCredits) throw Error("Failed to spend credits: no data returned");
102
113
  return await s.refetchQueries({ include: [r, n] }), t.spendCredits;
103
114
  }, [N, s]),
104
- verifyPaymentMethod: g(async (e) => {
115
+ verifyPaymentMethod: _(async (e) => {
105
116
  let { data: t, error: n } = await F({ variables: { input: e } });
106
117
  if (n) throw Error(n.message ?? "Failed to verify payment method");
107
118
  if (!t?.verifyBillingPaymentMethod) throw Error("Failed to verify payment method: no data returned");
@@ -113,6 +124,6 @@ function b() {
113
124
  };
114
125
  }
115
126
  //#endregion
116
- export { b as useDashboardMutations, y as useDefaultDashboardAccount, v as usePaymentProviderConfig };
127
+ export { b as useBillingAccounts, S as useDashboardMutations, x as useDefaultDashboardAccount, y as usePaymentProviderConfig };
117
128
 
118
129
  //# sourceMappingURL=useDashboard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useDashboard.js","names":[],"sources":["../../../../../src/billing/modules/dashboard/hooks/useDashboard.ts"],"sourcesContent":["/**\n * Dashboard Module - useDashboard Hook\n * Provides access to dashboard data and mutations for billing overview\n */\n\nimport { useApolloClient } from '@apollo/client/react';\nimport { useCallback, useMemo } from 'react';\nimport {\n useGetPaymentProviderConfigQuery,\n useGetBillingAccountsByOrgQuery,\n useGetDefaultBillingAccountDashboardQuery,\n useGetBillingAccountDashboardQuery,\n useGetActiveSubscriptionsQuery,\n useGetPaymentMethodsDashboardQuery,\n useGetBillingAddressQuery,\n useGetCreditTransactionsSummaryQuery,\n useGetRecommendedAddonsQuery,\n useGetAvailablePlansQuery,\n useCreateBillingAccountMutation,\n useUpdateBillingAccountMutation,\n useSetDefaultBillingAccountMutation,\n useAddPaymentMethodDashboardMutation,\n useUpdatePaymentMethodDashboardMutation,\n useDeletePaymentMethodDashboardMutation,\n useSetBillingAddressMutation,\n useInitiatePaymentMutation,\n useSpendCreditsMutation,\n useVerifyPaymentMethodMutation,\n GetBillingAccountsByOrgDocument,\n GetDefaultBillingAccountDashboardDocument,\n GetBillingAddressDocument,\n GetCreditTransactionsSummaryDocument,\n} from '../../../../generated/global-operations';\nimport type {\n BillingAccount,\n BillingSubscription,\n PaymentMethod,\n BillingAddress,\n CreditTransaction,\n Addon,\n Plan,\n CreateBillingAccountInput,\n UpdateBillingAccountInput,\n CreatePaymentMethodInput,\n SetBillingAddressInput,\n InitiatePaymentInput,\n InitiatePaymentResponse,\n SpendCreditsInput,\n VerifyPaymentMethodInput,\n VerifyPaymentMethodResponse,\n} from '../../../shared/types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ninterface UseBillingAccountsResult {\n billingAccounts: BillingAccount[];\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseDashboardAccountResult {\n billingAccount: BillingAccount | null;\n paymentMethods: PaymentMethod[];\n billingAddresses: BillingAddress[];\n activeSubscriptions: BillingSubscription[];\n hasActiveSubscription: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseActiveSubscriptionsResult {\n activeSubscriptions: BillingSubscription[];\n hasActiveSubscription: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UsePaymentMethodsResult {\n paymentMethods: PaymentMethod[];\n defaultPaymentMethod: PaymentMethod | null;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseCreditTransactionsResult {\n creditTransactions: CreditTransaction[];\n totalCount: number;\n hasMore: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseRecommendedAddonsResult {\n addons: Addon[];\n recommendedAddons: Addon[];\n isLoading: boolean;\n error: Error | undefined;\n}\n\ninterface UseAvailablePlansResult {\n plans: Plan[];\n activePlans: Plan[];\n isLoading: boolean;\n error: Error | undefined;\n}\n\ninterface UseDashboardMutationsResult {\n // Billing account\n createBillingAccount: (input: CreateBillingAccountInput) => Promise<BillingAccount>;\n updateBillingAccount: (input: UpdateBillingAccountInput) => Promise<BillingAccount>;\n setDefaultBillingAccount: (id: string) => Promise<BillingAccount>;\n isCreatingAccount: boolean;\n isUpdatingAccount: boolean;\n isSettingDefaultAccount: boolean;\n\n // Payment methods\n addPaymentMethod: (input: CreatePaymentMethodInput) => Promise<PaymentMethod>;\n setDefaultPaymentMethod: (id: string, billingAccountId: string) => Promise<PaymentMethod>;\n deletePaymentMethod: (id: string, billingAccountId: string) => Promise<boolean>;\n isAddingPaymentMethod: boolean;\n isUpdatingPaymentMethod: boolean;\n isDeletingPaymentMethod: boolean;\n\n // Billing address\n setBillingAddress: (input: SetBillingAddressInput) => Promise<BillingAddress>;\n isSettingAddress: boolean;\n\n // Payments\n initiatePayment: (input: InitiatePaymentInput) => Promise<InitiatePaymentResponse>;\n spendCredits: (input: SpendCreditsInput) => Promise<{ creditTransactionID: string }>;\n verifyPaymentMethod: (input: VerifyPaymentMethodInput) => Promise<VerifyPaymentMethodResponse>;\n isInitiatingPayment: boolean;\n isSpendingCredits: boolean;\n isVerifyingPaymentMethod: boolean;\n}\n\ninterface PaymentProviderConfig {\n stripeEnabled: boolean;\n stripePublishableKey: string | null;\n razorpayEnabled: boolean;\n razorpayKeyId: string | null;\n}\n\ninterface UsePaymentProviderConfigResult {\n config: PaymentProviderConfig | null;\n stripeEnabled: boolean;\n stripePublishableKey: string | null;\n razorpayEnabled: boolean;\n razorpayKeyId: string | null;\n isLoading: boolean;\n error: Error | undefined;\n}\n\n// ============================================================================\n// Hooks\n// ============================================================================\n\n/**\n * Hook for fetching payment provider configuration from backend\n * @param skip - Skip the query (useful for modals that only need data when open)\n */\nexport function usePaymentProviderConfig(skip = false): UsePaymentProviderConfigResult {\n const { data, loading, error } = useGetPaymentProviderConfigQuery({\n fetchPolicy: 'cache-first', // Cache the config as it rarely changes\n skip,\n });\n\n const config = data?.getPaymentProviderConfig || null;\n\n return {\n config,\n stripeEnabled: config?.stripeEnabled ?? false,\n stripePublishableKey: config?.stripePublishableKey ?? null,\n razorpayEnabled: config?.razorpayEnabled ?? false,\n razorpayKeyId: config?.razorpayKeyId ?? null,\n isLoading: skip ? false : loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for fetching all billing accounts for an org\n */\nexport function useBillingAccounts(): UseBillingAccountsResult {\n const { data, loading, error, refetch } = useGetBillingAccountsByOrgQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n return {\n billingAccounts: data?.getBillingAccountsByOrg || [],\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching active subscriptions for a billing account (optimized - only active status)\n */\nexport function useActiveSubscriptions(\n billingAccountId: string | undefined\n): UseActiveSubscriptionsResult {\n const { data, loading, error, refetch } = useGetActiveSubscriptionsQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const activeSubscriptions = data?.getActiveSubscriptions || [];\n\n return {\n activeSubscriptions,\n hasActiveSubscription: activeSubscriptions.length > 0,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching default billing account with dashboard details\n * Note: Subscriptions are NOT included - use useActiveSubscriptions separately\n */\nexport function useDefaultDashboardAccount(): Omit<\n UseDashboardAccountResult,\n 'activeSubscriptions' | 'hasActiveSubscription'\n> {\n const { data, loading, error, refetch } = useGetDefaultBillingAccountDashboardQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const billingAccount = data?.getDefaultBillingAccount || null;\n const paymentMethods = (billingAccount?.paymentMethods || []).filter(Boolean) as PaymentMethod[];\n const billingAddresses = (billingAccount?.billingAddresses || []).filter(\n Boolean\n ) as BillingAddress[];\n\n return {\n billingAccount,\n paymentMethods,\n billingAddresses,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching billing account by ID with dashboard details\n * Note: Subscriptions are NOT included - use useActiveSubscriptions separately\n */\nexport function useDashboardAccount(\n id: string | undefined\n): Omit<UseDashboardAccountResult, 'activeSubscriptions' | 'hasActiveSubscription'> {\n const { data, loading, error, refetch } = useGetBillingAccountDashboardQuery({\n variables: { id: id! },\n skip: !id,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const billingAccount = data?.getBillingAccount || null;\n const paymentMethods = (billingAccount?.paymentMethods || []).filter(Boolean) as PaymentMethod[];\n const billingAddresses = (billingAccount?.billingAddresses || []).filter(\n Boolean\n ) as BillingAddress[];\n\n return {\n billingAccount,\n paymentMethods,\n billingAddresses,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching payment methods for a billing account\n */\nexport function usePaymentMethods(billingAccountId: string | undefined): UsePaymentMethodsResult {\n const { data, loading, error, refetch } = useGetPaymentMethodsDashboardQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const paymentMethods = useMemo<PaymentMethod[]>(\n () => data?.getPaymentMethods || [],\n [data?.getPaymentMethods]\n );\n const defaultPaymentMethod = useMemo(() => {\n return paymentMethods.find((pm: PaymentMethod) => pm.isDefault) || null;\n }, [paymentMethods]);\n\n return {\n paymentMethods,\n defaultPaymentMethod,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching billing address\n */\nexport function useBillingAddress(billingAccountId: string | undefined) {\n const { data, loading, error, refetch } = useGetBillingAddressQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n return {\n billingAddress: data?.getBillingAddress || null,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching credit transactions summary\n */\nexport function useCreditTransactionsSummary(\n billingAccountId: string | undefined,\n days = 30,\n page = 1,\n pageSize = 5\n): UseCreditTransactionsResult {\n const { data, loading, error, refetch } = useGetCreditTransactionsSummaryQuery({\n variables: { billingAccountID: billingAccountId!, days, page, pageSize },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const result = data?.getBillingAccountCreditTransactions || {\n creditTransactions: [],\n totalCount: 0,\n hasMore: false,\n };\n\n return {\n creditTransactions: result.creditTransactions,\n totalCount: result.totalCount,\n hasMore: result.hasMore,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching recommended addons (limited to 3 at backend level)\n */\nexport function useRecommendedAddons(): UseRecommendedAddonsResult {\n const { data, loading, error } = useGetRecommendedAddonsQuery({\n variables: { limit: 3 },\n fetchPolicy: 'cache-and-network',\n });\n\n const addons = useMemo<Addon[]>(() => data?.getAllAddOns || [], [data?.getAllAddOns]);\n\n // Filter to only active addons (limit already applied at backend)\n const recommendedAddons = useMemo(() => {\n return addons.filter((a: Addon) => a.isActive);\n }, [addons]);\n\n return {\n addons,\n recommendedAddons,\n isLoading: loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for fetching available plans\n */\nexport function useAvailablePlans(): UseAvailablePlansResult {\n const { data, loading, error } = useGetAvailablePlansQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const plans = useMemo<Plan[]>(() => data?.getAllPlans || [], [data?.getAllPlans]);\n\n const activePlans = useMemo(() => {\n return plans.filter((p: Plan) => p.isActive);\n }, [plans]);\n\n return {\n plans,\n activePlans,\n isLoading: loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for dashboard mutations\n */\nexport function useDashboardMutations(): UseDashboardMutationsResult {\n const client = useApolloClient();\n\n // Billing account mutations\n const [createBillingAccountMutation, { loading: isCreatingAccount }] =\n useCreateBillingAccountMutation();\n const [updateBillingAccountMutation, { loading: isUpdatingAccount }] =\n useUpdateBillingAccountMutation();\n const [setDefaultBillingAccountMutation, { loading: isSettingDefaultAccount }] =\n useSetDefaultBillingAccountMutation();\n\n // Payment method mutations\n const [addPaymentMethodMutation, { loading: isAddingPaymentMethod }] =\n useAddPaymentMethodDashboardMutation();\n const [updatePaymentMethodMutation, { loading: isUpdatingPaymentMethod }] =\n useUpdatePaymentMethodDashboardMutation();\n const [deletePaymentMethodMutation, { loading: isDeletingPaymentMethod }] =\n useDeletePaymentMethodDashboardMutation();\n\n // Billing address mutation\n const [setBillingAddressMutation, { loading: isSettingAddress }] = useSetBillingAddressMutation();\n\n // Payment mutations\n const [initiatePaymentMutation, { loading: isInitiatingPayment }] = useInitiatePaymentMutation();\n const [spendCreditsMutation, { loading: isSpendingCredits }] = useSpendCreditsMutation();\n const [verifyPaymentMethodMutation, { loading: isVerifyingPaymentMethod }] =\n useVerifyPaymentMethodMutation();\n\n // Billing account handlers\n const createBillingAccount = useCallback(\n async (input: CreateBillingAccountInput): Promise<BillingAccount> => {\n const { data, error } = await createBillingAccountMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to create billing account');\n }\n if (!data?.createBillingAccount) {\n throw new Error('Failed to create billing account: no data returned');\n }\n await client.refetchQueries({\n include: [GetBillingAccountsByOrgDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.createBillingAccount;\n },\n [createBillingAccountMutation, client]\n );\n\n const updateBillingAccount = useCallback(\n async (input: UpdateBillingAccountInput): Promise<BillingAccount> => {\n const { data, error } = await updateBillingAccountMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to update billing account');\n }\n if (!data?.updateBillingAccount) {\n throw new Error('Failed to update billing account: no data returned');\n }\n // Only refetch the default dashboard - component handles selected account refetch\n await client.refetchQueries({\n include: [GetDefaultBillingAccountDashboardDocument],\n });\n return data.updateBillingAccount;\n },\n [updateBillingAccountMutation, client]\n );\n\n const setDefaultBillingAccount = useCallback(\n async (id: string): Promise<BillingAccount> => {\n const { data, error } = await setDefaultBillingAccountMutation({\n variables: { id },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to set default billing account');\n }\n if (!data?.setDefaultBillingAccount) {\n throw new Error('Failed to set default billing account: no data returned');\n }\n // Refetch all billing accounts and default account to update isDefault flags\n await client.refetchQueries({\n include: [GetBillingAccountsByOrgDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.setDefaultBillingAccount;\n },\n [setDefaultBillingAccountMutation, client]\n );\n\n // Payment method handlers\n // Note: We don't use client.refetchQueries here because it tries to refetch ALL matching queries\n // including those that were skipped (e.g., GET_BILLING_ACCOUNT_DASHBOARD with no id).\n // The calling component should handle refetching the appropriate queries.\n const addPaymentMethod = useCallback(\n async (input: CreatePaymentMethodInput): Promise<PaymentMethod> => {\n const { data, error } = await addPaymentMethodMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to add payment method');\n }\n if (!data?.addPaymentMethod) {\n throw new Error('Failed to add payment method: no data returned');\n }\n return data.addPaymentMethod;\n },\n [addPaymentMethodMutation]\n );\n\n const setDefaultPaymentMethod = useCallback(\n async (id: string, billingAccountId: string): Promise<PaymentMethod> => {\n const { data, error } = await updatePaymentMethodMutation({\n variables: { id, isDefault: true, billingAccountId },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to update payment method');\n }\n if (!data?.updatePaymentMethod) {\n throw new Error('Failed to update payment method: no data returned');\n }\n return data.updatePaymentMethod;\n },\n [updatePaymentMethodMutation]\n );\n\n const deletePaymentMethod = useCallback(\n async (id: string, billingAccountId: string): Promise<boolean> => {\n const { data, error } = await deletePaymentMethodMutation({\n variables: { id, billingAccountId },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to delete payment method');\n }\n if (!data) {\n throw new Error('Failed to delete payment method: no data returned');\n }\n return data.deletePaymentMethod;\n },\n [deletePaymentMethodMutation]\n );\n\n // Billing address handler\n const setBillingAddress = useCallback(\n async (input: SetBillingAddressInput): Promise<BillingAddress> => {\n const { data, error } = await setBillingAddressMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to set billing address');\n }\n if (!data?.setBillingAddress) {\n throw new Error('Failed to set billing address: no data returned');\n }\n // Only refetch queries that don't have conditional required variables\n await client.refetchQueries({\n include: [GetBillingAddressDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.setBillingAddress;\n },\n [setBillingAddressMutation, client]\n );\n\n // Payment handlers\n const initiatePayment = useCallback(\n async (input: InitiatePaymentInput): Promise<InitiatePaymentResponse> => {\n const { data, error } = await initiatePaymentMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to initiate payment');\n }\n if (!data?.initiatePayment) {\n throw new Error('Failed to initiate payment: no data returned');\n }\n return data.initiatePayment;\n },\n [initiatePaymentMutation]\n );\n\n const spendCredits = useCallback(\n async (input: SpendCreditsInput): Promise<{ creditTransactionID: string }> => {\n const { data, error } = await spendCreditsMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to spend credits');\n }\n if (!data?.spendCredits) {\n throw new Error('Failed to spend credits: no data returned');\n }\n // Only refetch queries that don't have conditional required variables\n await client.refetchQueries({\n include: [GetDefaultBillingAccountDashboardDocument, GetCreditTransactionsSummaryDocument],\n });\n return data.spendCredits;\n },\n [spendCreditsMutation, client]\n );\n\n // Verify payment method handler\n const verifyPaymentMethod = useCallback(\n async (input: VerifyPaymentMethodInput): Promise<VerifyPaymentMethodResponse> => {\n const { data, error } = await verifyPaymentMethodMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to verify payment method');\n }\n if (!data?.verifyBillingPaymentMethod) {\n throw new Error('Failed to verify payment method: no data returned');\n }\n return data.verifyBillingPaymentMethod;\n },\n [verifyPaymentMethodMutation]\n );\n\n return {\n // Billing account\n createBillingAccount,\n updateBillingAccount,\n setDefaultBillingAccount,\n isCreatingAccount,\n isUpdatingAccount,\n isSettingDefaultAccount,\n\n // Payment methods\n addPaymentMethod,\n setDefaultPaymentMethod,\n deletePaymentMethod,\n isAddingPaymentMethod,\n isUpdatingPaymentMethod,\n isDeletingPaymentMethod,\n\n // Billing address\n setBillingAddress,\n isSettingAddress,\n\n // Payments\n initiatePayment,\n spendCredits,\n verifyPaymentMethod,\n isInitiatingPayment,\n isSpendingCredits,\n isVerifyingPaymentMethod,\n };\n}\n"],"mappings":";;;;AAwKA,SAAgB,EAAyB,IAAO,IAAuC;CACrF,IAAM,EAAE,SAAM,YAAS,aAAU,EAAiC;EAChE,aAAa;EACb;EACD,CAAC,EAEI,IAAS,GAAM,4BAA4B;AAEjD,QAAO;EACL;EACA,eAAe,GAAQ,iBAAiB;EACxC,sBAAsB,GAAQ,wBAAwB;EACtD,iBAAiB,GAAQ,mBAAmB;EAC5C,eAAe,GAAQ,iBAAiB;EACxC,WAAW,IAAO,KAAQ;EACnB;EACR;;AAsDH,SAAgB,IAGd;CACA,IAAM,EAAE,SAAM,YAAS,UAAO,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AW,EAAE,UAAO,EACrB,CAAC;AACF,OAAI,EACF,OAAU,MAAM,EAAM,WAAW,kCAAkC;AAErE,OAAI,CAAC,GAAM,2BACT,OAAU,MAAM,oDAAoD;AAEtE,UAAO,EAAK;KAEd,CAAC,EAA4B,CAC9B;EA2BC;EACA;EACA;EACD"}
1
+ {"version":3,"file":"useDashboard.js","names":[],"sources":["../../../../../src/billing/modules/dashboard/hooks/useDashboard.ts"],"sourcesContent":["/**\n * Dashboard Module - useDashboard Hook\n * Provides access to dashboard data and mutations for billing overview\n */\n\nimport { useApolloClient } from '@apollo/client/react';\nimport { useCallback, useMemo } from 'react';\nimport {\n useGetPaymentProviderConfigQuery,\n useGetBillingAccountsByOrgQuery,\n useGetDefaultBillingAccountDashboardQuery,\n useGetBillingAccountDashboardQuery,\n useGetActiveSubscriptionsQuery,\n useGetPaymentMethodsDashboardQuery,\n useGetBillingAddressQuery,\n useGetCreditTransactionsSummaryQuery,\n useGetRecommendedAddonsQuery,\n useGetAvailablePlansQuery,\n useCreateBillingAccountMutation,\n useUpdateBillingAccountMutation,\n useSetDefaultBillingAccountMutation,\n useAddPaymentMethodDashboardMutation,\n useUpdatePaymentMethodDashboardMutation,\n useDeletePaymentMethodDashboardMutation,\n useSetBillingAddressMutation,\n useInitiatePaymentMutation,\n useSpendCreditsMutation,\n useVerifyPaymentMethodMutation,\n GetBillingAccountsByOrgDocument,\n GetDefaultBillingAccountDashboardDocument,\n GetBillingAddressDocument,\n GetCreditTransactionsSummaryDocument,\n} from '../../../../generated/global-operations';\nimport type {\n BillingAccount,\n BillingSubscription,\n PaymentMethod,\n BillingAddress,\n CreditTransaction,\n Addon,\n Plan,\n CreateBillingAccountInput,\n UpdateBillingAccountInput,\n CreatePaymentMethodInput,\n SetBillingAddressInput,\n InitiatePaymentInput,\n InitiatePaymentResponse,\n SpendCreditsInput,\n VerifyPaymentMethodInput,\n VerifyPaymentMethodResponse,\n} from '../../../shared/types';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ninterface UseBillingAccountsResult {\n billingAccounts: BillingAccount[];\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseDashboardAccountResult {\n billingAccount: BillingAccount | null;\n paymentMethods: PaymentMethod[];\n billingAddresses: BillingAddress[];\n activeSubscriptions: BillingSubscription[];\n hasActiveSubscription: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseActiveSubscriptionsResult {\n activeSubscriptions: BillingSubscription[];\n hasActiveSubscription: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UsePaymentMethodsResult {\n paymentMethods: PaymentMethod[];\n defaultPaymentMethod: PaymentMethod | null;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseCreditTransactionsResult {\n creditTransactions: CreditTransaction[];\n totalCount: number;\n hasMore: boolean;\n isLoading: boolean;\n error: Error | undefined;\n refetch: () => Promise<void>;\n}\n\ninterface UseRecommendedAddonsResult {\n addons: Addon[];\n recommendedAddons: Addon[];\n isLoading: boolean;\n error: Error | undefined;\n}\n\ninterface UseAvailablePlansResult {\n plans: Plan[];\n activePlans: Plan[];\n isLoading: boolean;\n error: Error | undefined;\n}\n\ninterface UseDashboardMutationsResult {\n // Billing account\n createBillingAccount: (input: CreateBillingAccountInput) => Promise<BillingAccount>;\n updateBillingAccount: (input: UpdateBillingAccountInput) => Promise<BillingAccount>;\n setDefaultBillingAccount: (id: string) => Promise<BillingAccount>;\n isCreatingAccount: boolean;\n isUpdatingAccount: boolean;\n isSettingDefaultAccount: boolean;\n\n // Payment methods\n addPaymentMethod: (input: CreatePaymentMethodInput) => Promise<PaymentMethod>;\n setDefaultPaymentMethod: (id: string, billingAccountId: string) => Promise<PaymentMethod>;\n deletePaymentMethod: (id: string, billingAccountId: string) => Promise<boolean>;\n isAddingPaymentMethod: boolean;\n isUpdatingPaymentMethod: boolean;\n isDeletingPaymentMethod: boolean;\n\n // Billing address\n setBillingAddress: (input: SetBillingAddressInput) => Promise<BillingAddress>;\n isSettingAddress: boolean;\n\n // Payments\n initiatePayment: (input: InitiatePaymentInput) => Promise<InitiatePaymentResponse>;\n spendCredits: (input: SpendCreditsInput) => Promise<{ creditTransactionID: string }>;\n verifyPaymentMethod: (input: VerifyPaymentMethodInput) => Promise<VerifyPaymentMethodResponse>;\n isInitiatingPayment: boolean;\n isSpendingCredits: boolean;\n isVerifyingPaymentMethod: boolean;\n}\n\ninterface PaymentProviderConfig {\n stripeEnabled: boolean;\n stripePublishableKey: string | null;\n razorpayEnabled: boolean;\n razorpayKeyId: string | null;\n}\n\ninterface UsePaymentProviderConfigResult {\n config: PaymentProviderConfig | null;\n stripeEnabled: boolean;\n stripePublishableKey: string | null;\n razorpayEnabled: boolean;\n razorpayKeyId: string | null;\n isLoading: boolean;\n error: Error | undefined;\n}\n\n// ============================================================================\n// Hooks\n// ============================================================================\n\n/**\n * Hook for fetching payment provider configuration from backend\n * @param skip - Skip the query (useful for modals that only need data when open)\n */\nexport function usePaymentProviderConfig(skip = false): UsePaymentProviderConfigResult {\n const { data, loading, error } = useGetPaymentProviderConfigQuery({\n fetchPolicy: 'cache-first', // Cache the config as it rarely changes\n skip,\n });\n\n const config = data?.getPaymentProviderConfig || null;\n\n return {\n config,\n stripeEnabled: config?.stripeEnabled ?? false,\n stripePublishableKey: config?.stripePublishableKey ?? null,\n razorpayEnabled: config?.razorpayEnabled ?? false,\n razorpayKeyId: config?.razorpayKeyId ?? null,\n isLoading: skip ? false : loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for fetching all billing accounts for an org\n */\nexport function useBillingAccounts(): UseBillingAccountsResult {\n const { data, loading, error, refetch } = useGetBillingAccountsByOrgQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n return {\n billingAccounts: data?.getBillingAccountsByOrg || [],\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching active subscriptions for a billing account (optimized - only active status)\n */\nexport function useActiveSubscriptions(\n billingAccountId: string | undefined\n): UseActiveSubscriptionsResult {\n const { data, loading, error, refetch } = useGetActiveSubscriptionsQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const activeSubscriptions = data?.getActiveSubscriptions || [];\n\n return {\n activeSubscriptions,\n hasActiveSubscription: activeSubscriptions.length > 0,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching default billing account with dashboard details\n * Note: Subscriptions are NOT included - use useActiveSubscriptions separately\n */\nexport function useDefaultDashboardAccount(): Omit<\n UseDashboardAccountResult,\n 'activeSubscriptions' | 'hasActiveSubscription'\n> {\n const { data, loading, error, refetch } = useGetDefaultBillingAccountDashboardQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const billingAccount = data?.getDefaultBillingAccount || null;\n const paymentMethods = (billingAccount?.paymentMethods || []).filter(Boolean) as PaymentMethod[];\n const billingAddresses = (billingAccount?.billingAddresses || []).filter(\n Boolean\n ) as BillingAddress[];\n\n return {\n billingAccount,\n paymentMethods,\n billingAddresses,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching billing account by ID with dashboard details\n * Note: Subscriptions are NOT included - use useActiveSubscriptions separately\n */\nexport function useDashboardAccount(\n id: string | undefined\n): Omit<UseDashboardAccountResult, 'activeSubscriptions' | 'hasActiveSubscription'> {\n const { data, loading, error, refetch } = useGetBillingAccountDashboardQuery({\n variables: { id: id! },\n skip: !id,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const billingAccount = data?.getBillingAccount || null;\n const paymentMethods = (billingAccount?.paymentMethods || []).filter(Boolean) as PaymentMethod[];\n const billingAddresses = (billingAccount?.billingAddresses || []).filter(\n Boolean\n ) as BillingAddress[];\n\n return {\n billingAccount,\n paymentMethods,\n billingAddresses,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching payment methods for a billing account\n */\nexport function usePaymentMethods(billingAccountId: string | undefined): UsePaymentMethodsResult {\n const { data, loading, error, refetch } = useGetPaymentMethodsDashboardQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const paymentMethods = useMemo<PaymentMethod[]>(\n () => data?.getPaymentMethods || [],\n [data?.getPaymentMethods]\n );\n const defaultPaymentMethod = useMemo(() => {\n return paymentMethods.find((pm: PaymentMethod) => pm.isDefault) || null;\n }, [paymentMethods]);\n\n return {\n paymentMethods,\n defaultPaymentMethod,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching billing address\n */\nexport function useBillingAddress(billingAccountId: string | undefined) {\n const { data, loading, error, refetch } = useGetBillingAddressQuery({\n variables: { billingAccountId: billingAccountId! },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n return {\n billingAddress: data?.getBillingAddress || null,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching credit transactions summary\n */\nexport function useCreditTransactionsSummary(\n billingAccountId: string | undefined,\n days = 30,\n page = 1,\n pageSize = 5\n): UseCreditTransactionsResult {\n const { data, loading, error, refetch } = useGetCreditTransactionsSummaryQuery({\n variables: { billingAccountID: billingAccountId!, days, page, pageSize },\n skip: !billingAccountId,\n fetchPolicy: 'cache-and-network',\n });\n\n const handleRefetch = useCallback(async () => {\n await refetch();\n }, [refetch]);\n\n const result = data?.getBillingAccountCreditTransactions || {\n creditTransactions: [],\n totalCount: 0,\n hasMore: false,\n };\n\n return {\n creditTransactions: result.creditTransactions,\n totalCount: result.totalCount,\n hasMore: result.hasMore,\n isLoading: loading,\n error: error as Error | undefined,\n refetch: handleRefetch,\n };\n}\n\n/**\n * Hook for fetching recommended addons (limited to 3 at backend level)\n */\nexport function useRecommendedAddons(): UseRecommendedAddonsResult {\n const { data, loading, error } = useGetRecommendedAddonsQuery({\n variables: { limit: 3 },\n fetchPolicy: 'cache-and-network',\n });\n\n const addons = useMemo<Addon[]>(() => data?.getAllAddOns || [], [data?.getAllAddOns]);\n\n // Filter to only active addons (limit already applied at backend)\n const recommendedAddons = useMemo(() => {\n return addons.filter((a: Addon) => a.isActive);\n }, [addons]);\n\n return {\n addons,\n recommendedAddons,\n isLoading: loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for fetching available plans\n */\nexport function useAvailablePlans(): UseAvailablePlansResult {\n const { data, loading, error } = useGetAvailablePlansQuery({\n fetchPolicy: 'cache-and-network',\n });\n\n const plans = useMemo<Plan[]>(() => data?.getAllPlans || [], [data?.getAllPlans]);\n\n const activePlans = useMemo(() => {\n return plans.filter((p: Plan) => p.isActive);\n }, [plans]);\n\n return {\n plans,\n activePlans,\n isLoading: loading,\n error: error as Error | undefined,\n };\n}\n\n/**\n * Hook for dashboard mutations\n */\nexport function useDashboardMutations(): UseDashboardMutationsResult {\n const client = useApolloClient();\n\n // Billing account mutations\n const [createBillingAccountMutation, { loading: isCreatingAccount }] =\n useCreateBillingAccountMutation();\n const [updateBillingAccountMutation, { loading: isUpdatingAccount }] =\n useUpdateBillingAccountMutation();\n const [setDefaultBillingAccountMutation, { loading: isSettingDefaultAccount }] =\n useSetDefaultBillingAccountMutation();\n\n // Payment method mutations\n const [addPaymentMethodMutation, { loading: isAddingPaymentMethod }] =\n useAddPaymentMethodDashboardMutation();\n const [updatePaymentMethodMutation, { loading: isUpdatingPaymentMethod }] =\n useUpdatePaymentMethodDashboardMutation();\n const [deletePaymentMethodMutation, { loading: isDeletingPaymentMethod }] =\n useDeletePaymentMethodDashboardMutation();\n\n // Billing address mutation\n const [setBillingAddressMutation, { loading: isSettingAddress }] = useSetBillingAddressMutation();\n\n // Payment mutations\n const [initiatePaymentMutation, { loading: isInitiatingPayment }] = useInitiatePaymentMutation();\n const [spendCreditsMutation, { loading: isSpendingCredits }] = useSpendCreditsMutation();\n const [verifyPaymentMethodMutation, { loading: isVerifyingPaymentMethod }] =\n useVerifyPaymentMethodMutation();\n\n // Billing account handlers\n const createBillingAccount = useCallback(\n async (input: CreateBillingAccountInput): Promise<BillingAccount> => {\n const { data, error } = await createBillingAccountMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to create billing account');\n }\n if (!data?.createBillingAccount) {\n throw new Error('Failed to create billing account: no data returned');\n }\n await client.refetchQueries({\n include: [GetBillingAccountsByOrgDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.createBillingAccount;\n },\n [createBillingAccountMutation, client]\n );\n\n const updateBillingAccount = useCallback(\n async (input: UpdateBillingAccountInput): Promise<BillingAccount> => {\n const { data, error } = await updateBillingAccountMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to update billing account');\n }\n if (!data?.updateBillingAccount) {\n throw new Error('Failed to update billing account: no data returned');\n }\n // Only refetch the default dashboard - component handles selected account refetch\n await client.refetchQueries({\n include: [GetDefaultBillingAccountDashboardDocument],\n });\n return data.updateBillingAccount;\n },\n [updateBillingAccountMutation, client]\n );\n\n const setDefaultBillingAccount = useCallback(\n async (id: string): Promise<BillingAccount> => {\n const { data, error } = await setDefaultBillingAccountMutation({\n variables: { id },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to set default billing account');\n }\n if (!data?.setDefaultBillingAccount) {\n throw new Error('Failed to set default billing account: no data returned');\n }\n // Refetch all billing accounts and default account to update isDefault flags\n await client.refetchQueries({\n include: [GetBillingAccountsByOrgDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.setDefaultBillingAccount;\n },\n [setDefaultBillingAccountMutation, client]\n );\n\n // Payment method handlers\n // Note: We don't use client.refetchQueries here because it tries to refetch ALL matching queries\n // including those that were skipped (e.g., GET_BILLING_ACCOUNT_DASHBOARD with no id).\n // The calling component should handle refetching the appropriate queries.\n const addPaymentMethod = useCallback(\n async (input: CreatePaymentMethodInput): Promise<PaymentMethod> => {\n const { data, error } = await addPaymentMethodMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to add payment method');\n }\n if (!data?.addPaymentMethod) {\n throw new Error('Failed to add payment method: no data returned');\n }\n return data.addPaymentMethod;\n },\n [addPaymentMethodMutation]\n );\n\n const setDefaultPaymentMethod = useCallback(\n async (id: string, billingAccountId: string): Promise<PaymentMethod> => {\n const { data, error } = await updatePaymentMethodMutation({\n variables: { id, isDefault: true, billingAccountId },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to update payment method');\n }\n if (!data?.updatePaymentMethod) {\n throw new Error('Failed to update payment method: no data returned');\n }\n return data.updatePaymentMethod;\n },\n [updatePaymentMethodMutation]\n );\n\n const deletePaymentMethod = useCallback(\n async (id: string, billingAccountId: string): Promise<boolean> => {\n const { data, error } = await deletePaymentMethodMutation({\n variables: { id, billingAccountId },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to delete payment method');\n }\n if (!data) {\n throw new Error('Failed to delete payment method: no data returned');\n }\n return data.deletePaymentMethod;\n },\n [deletePaymentMethodMutation]\n );\n\n // Billing address handler\n const setBillingAddress = useCallback(\n async (input: SetBillingAddressInput): Promise<BillingAddress> => {\n const { data, error } = await setBillingAddressMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to set billing address');\n }\n if (!data?.setBillingAddress) {\n throw new Error('Failed to set billing address: no data returned');\n }\n // Only refetch queries that don't have conditional required variables\n await client.refetchQueries({\n include: [GetBillingAddressDocument, GetDefaultBillingAccountDashboardDocument],\n });\n return data.setBillingAddress;\n },\n [setBillingAddressMutation, client]\n );\n\n // Payment handlers\n const initiatePayment = useCallback(\n async (input: InitiatePaymentInput): Promise<InitiatePaymentResponse> => {\n const { data, error } = await initiatePaymentMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to initiate payment');\n }\n if (!data?.initiatePayment) {\n throw new Error('Failed to initiate payment: no data returned');\n }\n return data.initiatePayment;\n },\n [initiatePaymentMutation]\n );\n\n const spendCredits = useCallback(\n async (input: SpendCreditsInput): Promise<{ creditTransactionID: string }> => {\n const { data, error } = await spendCreditsMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to spend credits');\n }\n if (!data?.spendCredits) {\n throw new Error('Failed to spend credits: no data returned');\n }\n // Only refetch queries that don't have conditional required variables\n await client.refetchQueries({\n include: [GetDefaultBillingAccountDashboardDocument, GetCreditTransactionsSummaryDocument],\n });\n return data.spendCredits;\n },\n [spendCreditsMutation, client]\n );\n\n // Verify payment method handler\n const verifyPaymentMethod = useCallback(\n async (input: VerifyPaymentMethodInput): Promise<VerifyPaymentMethodResponse> => {\n const { data, error } = await verifyPaymentMethodMutation({\n variables: { input },\n });\n if (error) {\n throw new Error(error.message ?? 'Failed to verify payment method');\n }\n if (!data?.verifyBillingPaymentMethod) {\n throw new Error('Failed to verify payment method: no data returned');\n }\n return data.verifyBillingPaymentMethod;\n },\n [verifyPaymentMethodMutation]\n );\n\n return {\n // Billing account\n createBillingAccount,\n updateBillingAccount,\n setDefaultBillingAccount,\n isCreatingAccount,\n isUpdatingAccount,\n isSettingDefaultAccount,\n\n // Payment methods\n addPaymentMethod,\n setDefaultPaymentMethod,\n deletePaymentMethod,\n isAddingPaymentMethod,\n isUpdatingPaymentMethod,\n isDeletingPaymentMethod,\n\n // Billing address\n setBillingAddress,\n isSettingAddress,\n\n // Payments\n initiatePayment,\n spendCredits,\n verifyPaymentMethod,\n is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ACtB,OAAO,MAAkE;GACvE,IAAM,EAAE,SAAM,aAAU,MAAM,EAAwB,EACpD,WAAW,EAAE,UAAO,EACrB,CAAC;AACF,OAAI,EACF,OAAU,MAAM,EAAM,WAAW,6BAA6B;AAEhE,OAAI,CAAC,GAAM,gBACT,OAAU,MAAM,+CAA+C;AAEjE,UAAO,EAAK;KAEd,CAAC,EAAwB,CAC1B;EA8DC,cA5DmB,EACnB,OAAO,MAAuE;GAC5E,IAAM,EAAE,SAAM,aAAU,MAAM,EAAqB,EACjD,WAAW,EAAE,UAAO,EACrB,CAAC;AACF,OAAI,EACF,OAAU,MAAM,EAAM,WAAW,0BAA0B;AAE7D,OAAI,CAAC,GAAM,aACT,OAAU,MAAM,4CAA4C;AAM9D,UAHA,MAAM,EAAO,eAAe,EAC1B,SAAS,CAAC,GAA2C,EAAqC,EAC3F,CAAC,EACK,EAAK;KAEd,CAAC,GAAsB,EAAO,CAC/B;EA2CC,qBAxC0B,EAC1B,OAAO,MAA0E;GAC/E,IAAM,EAAE,SAAM,aAAU,MAAM,EAA4B,EACxD,WAAW,EAAE,UAAO,EACrB,CAAC;AACF,OAAI,EACF,OAAU,MAAM,EAAM,WAAW,kCAAkC;AAErE,OAAI,CAAC,GAAM,2BACT,OAAU,MAAM,oDAAoD;AAEtE,UAAO,EAAK;KAEd,CAAC,EAA4B,CAC9B;EA2BC;EACA;EACA;EACD"}
@@ -1 +1 @@
1
- {"version":3,"file":"TeamPermissionsPage.d.ts","sourceRoot":"","sources":["../../../../../src/billing/modules/settings/pages/TeamPermissionsPage.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA6C,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAsF3E,eAAO,MAAM,mBAAmB,EAAE,EA4RjC,CAAC"}
1
+ {"version":3,"file":"TeamPermissionsPage.d.ts","sourceRoot":"","sources":["../../../../../src/billing/modules/settings/pages/TeamPermissionsPage.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA6C,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAuF3E,eAAO,MAAM,mBAAmB,EAAE,EAmSjC,CAAC"}