From 4cc2b0bd759f3f064076bcb751de175da1a9375d Mon Sep 17 00:00:00 2001 From: Daniel Almaguer Date: Mon, 13 May 2024 15:23:55 -0500 Subject: [PATCH] chore: fetch checkout redirect url with gql --- .changeset/thin-scissors-ring.md | 6 +++++ .../cart/_components/checkout-button.tsx | 23 +++++++++++++++-- core/app/[locale]/(default)/cart/page.tsx | 2 +- core/client/management/get-checkout-url.ts | 23 ----------------- packages/client/src/client.ts | 25 ------------------- 5 files changed, 28 insertions(+), 51 deletions(-) create mode 100644 .changeset/thin-scissors-ring.md delete mode 100644 core/client/management/get-checkout-url.ts diff --git a/.changeset/thin-scissors-ring.md b/.changeset/thin-scissors-ring.md new file mode 100644 index 000000000..ee381ba66 --- /dev/null +++ b/.changeset/thin-scissors-ring.md @@ -0,0 +1,6 @@ +--- +"@bigcommerce/catalyst-client": minor +"@bigcommerce/catalyst-core": patch +--- + +removes fetch cart redirect from client and fetch it with gql diff --git a/core/app/[locale]/(default)/cart/_components/checkout-button.tsx b/core/app/[locale]/(default)/cart/_components/checkout-button.tsx index 7db9b54b8..4c430a175 100644 --- a/core/app/[locale]/(default)/cart/_components/checkout-button.tsx +++ b/core/app/[locale]/(default)/cart/_components/checkout-button.tsx @@ -1,8 +1,27 @@ -import { getCheckoutUrl } from '~/client/management/get-checkout-url'; +import { client } from '~/client'; +import { graphql } from '~/client/graphql'; import { Button } from '~/components/ui/button'; +export const CheckoutButtonMutation = graphql(` + mutation CheckoutButtonMutation($cartId: String!) { + cart { + createCartRedirectUrls(input: { cartEntityId: $cartId }) { + redirectUrls { + redirectedCheckoutUrl + } + } + } + } +`); + export const CheckoutButton = async ({ cartId, label }: { cartId: string; label: string }) => { - const checkoutUrl = await getCheckoutUrl(cartId); + const { data } = await client.fetch({ + document: CheckoutButtonMutation, + variables: { cartId }, + fetchOptions: { cache: 'no-store' }, + }); + + const checkoutUrl = data.cart.createCartRedirectUrls.redirectUrls?.redirectedCheckoutUrl; return (