From 9c5c6c6972bbe541321526dd65b437787224ecb6 Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 11:40:12 +0200 Subject: [PATCH 1/7] Checkout link provided by organization config --- .../src/components/orders/CheckoutLink.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/packages/react-components/src/components/orders/CheckoutLink.tsx b/packages/react-components/src/components/orders/CheckoutLink.tsx index 6f5c2cfe..df07e3de 100644 --- a/packages/react-components/src/components/orders/CheckoutLink.tsx +++ b/packages/react-components/src/components/orders/CheckoutLink.tsx @@ -5,6 +5,7 @@ import { type ChildrenFunction } from '#typings/index' import CommerceLayerContext from '#context/CommerceLayerContext' import { getApplicationLink } from '#utils/getApplicationLink' import { getDomain } from '#utils/getDomain' +import { getOrganizationConfig } from '#utils/organization' interface ChildrenProps extends Omit { checkoutUrl: string @@ -33,7 +34,7 @@ interface Props extends Omit { * found in the `order` object. */ export function CheckoutLink(props: Props): JSX.Element { - const { label, hostedCheckout = true, children, ...p } = props + const { label, hostedCheckout = true, children, onClick, ...p } = props const { order } = useContext(OrderContext) const { accessToken, endpoint } = useContext(CommerceLayerContext) if (accessToken == null || endpoint == null) @@ -56,10 +57,29 @@ export function CheckoutLink(props: Props): JSX.Element { href, ...p } + function handleClick( + e: React.MouseEvent + ): void { + e.preventDefault() + if (accessToken && endpoint) { + void getOrganizationConfig({ + accessToken, + endpoint, + params: { + accessToken + } + }).then((config) => { + if (config?.links?.checkout) { + e.preventDefault() + location.href = config.links.checkout + } + }) + } + } return children ? ( {children} ) : ( - + {label} ) From eddbf0198cfa5c90ca4eddb36edc8422ee16c4ab Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 11:41:23 +0200 Subject: [PATCH 2/7] v4.15.3-beta.0 --- lerna.json | 2 +- packages/react-components/package.json | 2 +- .../react-components/src/components/customers/MyAccountLink.tsx | 1 - .../react-components/src/components/orders/CheckoutLink.tsx | 1 - 4 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 201df52a..5f5e32d1 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useNx": false, "npmClient": "pnpm", - "version": "4.15.2", + "version": "4.15.3-beta.0", "command": { "version": { "preid": "beta" diff --git a/packages/react-components/package.json b/packages/react-components/package.json index 1ca58819..e9e68fcf 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@commercelayer/react-components", - "version": "4.15.2", + "version": "4.15.3-beta.0", "description": "The Official Commerce Layer React Components", "main": "lib/cjs/index.js", "module": "lib/esm/index.js", diff --git a/packages/react-components/src/components/customers/MyAccountLink.tsx b/packages/react-components/src/components/customers/MyAccountLink.tsx index b9f93508..6f1738a3 100644 --- a/packages/react-components/src/components/customers/MyAccountLink.tsx +++ b/packages/react-components/src/components/customers/MyAccountLink.tsx @@ -66,7 +66,6 @@ export function MyAccountLink(props: Props): JSX.Element { function handleClick( e: React.MouseEvent ): void { - e.preventDefault() if (!disabled && accessToken && endpoint) { void getOrganizationConfig({ accessToken, diff --git a/packages/react-components/src/components/orders/CheckoutLink.tsx b/packages/react-components/src/components/orders/CheckoutLink.tsx index df07e3de..184dfb40 100644 --- a/packages/react-components/src/components/orders/CheckoutLink.tsx +++ b/packages/react-components/src/components/orders/CheckoutLink.tsx @@ -60,7 +60,6 @@ export function CheckoutLink(props: Props): JSX.Element { function handleClick( e: React.MouseEvent ): void { - e.preventDefault() if (accessToken && endpoint) { void getOrganizationConfig({ accessToken, From 058fe9020da8f0ad9ed62007ebcb722ad44c32e5 Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 12:12:42 +0200 Subject: [PATCH 3/7] v4.15.3-beta.1 --- lerna.json | 2 +- packages/react-components/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 5f5e32d1..4d393424 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useNx": false, "npmClient": "pnpm", - "version": "4.15.3-beta.0", + "version": "4.15.3-beta.1", "command": { "version": { "preid": "beta" diff --git a/packages/react-components/package.json b/packages/react-components/package.json index e9e68fcf..eadd553b 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@commercelayer/react-components", - "version": "4.15.3-beta.0", + "version": "4.15.3-beta.1", "description": "The Official Commerce Layer React Components", "main": "lib/cjs/index.js", "module": "lib/esm/index.js", From 4f8afdfdc81f9be8153ee4385b755e14908a609f Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 17:27:37 +0200 Subject: [PATCH 4/7] Checkout link provided by organization config --- .../src/components/orders/CheckoutLink.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-components/src/components/orders/CheckoutLink.tsx b/packages/react-components/src/components/orders/CheckoutLink.tsx index 184dfb40..198abe17 100644 --- a/packages/react-components/src/components/orders/CheckoutLink.tsx +++ b/packages/react-components/src/components/orders/CheckoutLink.tsx @@ -60,19 +60,25 @@ export function CheckoutLink(props: Props): JSX.Element { function handleClick( e: React.MouseEvent ): void { - if (accessToken && endpoint) { + e.preventDefault() + e.stopPropagation() + if (accessToken && endpoint && order?.id) { void getOrganizationConfig({ accessToken, endpoint, params: { - accessToken + accessToken, + orderId: order?.id } }).then((config) => { if (config?.links?.checkout) { - e.preventDefault() location.href = config.links.checkout + } else { + location.href = e.currentTarget.href } }) + } else { + location.href = e.currentTarget.href } } return children ? ( From a8992ec45a3186b771962b49af986ef15d27f1f3 Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 17:28:08 +0200 Subject: [PATCH 5/7] v4.15.3-beta.2 --- lerna.json | 2 +- packages/react-components/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 4d393424..8a34fc12 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useNx": false, "npmClient": "pnpm", - "version": "4.15.3-beta.1", + "version": "4.15.3-beta.2", "command": { "version": { "preid": "beta" diff --git a/packages/react-components/package.json b/packages/react-components/package.json index eadd553b..06b72abd 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@commercelayer/react-components", - "version": "4.15.3-beta.1", + "version": "4.15.3-beta.2", "description": "The Official Commerce Layer React Components", "main": "lib/cjs/index.js", "module": "lib/esm/index.js", From 9028bc182ccd48ca9fb286b4ab841736b14249cd Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 17:58:58 +0200 Subject: [PATCH 6/7] Redirect to hosted checkout --- .../react-components/src/components/orders/CheckoutLink.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/react-components/src/components/orders/CheckoutLink.tsx b/packages/react-components/src/components/orders/CheckoutLink.tsx index 198abe17..7f954b95 100644 --- a/packages/react-components/src/components/orders/CheckoutLink.tsx +++ b/packages/react-components/src/components/orders/CheckoutLink.tsx @@ -62,6 +62,8 @@ export function CheckoutLink(props: Props): JSX.Element { ): void { e.preventDefault() e.stopPropagation() + console.log('e.currentTarget.href', e.currentTarget.href) + const currentHref = e.currentTarget.href if (accessToken && endpoint && order?.id) { void getOrganizationConfig({ accessToken, @@ -74,11 +76,11 @@ export function CheckoutLink(props: Props): JSX.Element { if (config?.links?.checkout) { location.href = config.links.checkout } else { - location.href = e.currentTarget.href + location.href = currentHref } }) } else { - location.href = e.currentTarget.href + location.href = currentHref } } return children ? ( From 11724e077376deb7193717aefecab354c35c67bb Mon Sep 17 00:00:00 2001 From: Alessandro Casazza Date: Tue, 30 Jul 2024 18:00:06 +0200 Subject: [PATCH 7/7] v4.15.3-beta.3 --- lerna.json | 2 +- packages/react-components/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lerna.json b/lerna.json index 8a34fc12..1dc20eea 100644 --- a/lerna.json +++ b/lerna.json @@ -2,7 +2,7 @@ "$schema": "node_modules/lerna/schemas/lerna-schema.json", "useNx": false, "npmClient": "pnpm", - "version": "4.15.3-beta.2", + "version": "4.15.3-beta.3", "command": { "version": { "preid": "beta" diff --git a/packages/react-components/package.json b/packages/react-components/package.json index 06b72abd..35c8897b 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@commercelayer/react-components", - "version": "4.15.3-beta.2", + "version": "4.15.3-beta.3", "description": "The Official Commerce Layer React Components", "main": "lib/cjs/index.js", "module": "lib/esm/index.js",