Skip to content

Commit

Permalink
fix useStripeCustomerFetch nonNilAssertion error
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvdm committed Jul 16, 2024
1 parent 83df11d commit c8b47a6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion web/src/hooks/useStripeCustomerFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
} from "../generated/graphql.js";
import { nonNilAssertionError } from "../lib/nonNilAssertionError.js";
import type { StripeCustomerBase } from "../types.js";
import { isEmptyString } from "../lib/index.js"

const STRIPE_CUSTOMER_SEARCH = gql`
query stripeCustomerSearch(
Expand Down Expand Up @@ -116,13 +117,15 @@ export const useStripeCustomerFetch = (
setCustomer: (customer: StripeCustomerBase) => unknown,
) => {
const client = useApolloClient();

useEffect(() => {
const doFetch = async () => {
const context = {
id,
client,
searchString,
};

const stripeCustomer = await fetchCustomer(context);

if (stripeCustomer == null) {
Expand All @@ -135,6 +138,11 @@ export const useStripeCustomerFetch = (
setCustomer(stripeCustomer);
};

doFetch();
if(!isEmptyString(id) || !isEmptyString(searchString)) {
doFetch();
}


}, [searchString, id]);
};

1 change: 1 addition & 0 deletions web/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./logger.js";
export * from "./isEmptyObj.js";
export * from "./isEmptyString.js"
3 changes: 3 additions & 0 deletions web/src/lib/isEmptyString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isEmptyString = (value: unknown) => {
return (value == null || (typeof value === "string" && value.trim().length === 0));
}

0 comments on commit c8b47a6

Please sign in to comment.