From 5d6778d4211ce13b7e72074272bf70a3fd804b82 Mon Sep 17 00:00:00 2001 From: Emanuel Ramos Date: Tue, 24 Sep 2024 14:44:13 -0300 Subject: [PATCH 1/5] feat: dynamic cart redirect on quickorder --- react/AutocompleteBlock.tsx | 3 ++- react/CategoryBlock.tsx | 3 ++- react/TextAreaBlock.tsx | 4 ++-- react/UploadBlock.tsx | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 19358ffa..52e5a5f7 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -24,6 +24,7 @@ const AutocompleteBlock: FunctionComponent = ({ description, componentOnly, intl, + checkoutUrl }) => { const client = useApolloClient() const { showToast } = useContext(ToastContext) @@ -76,7 +77,7 @@ const AutocompleteBlock: FunctionComponent = ({ action = success ? { label: translateMessage(messages.seeCart), - href: '/checkout/#/cart', + href: checkoutUrl ?? '/checkout/#/cart', } : undefined } diff --git a/react/CategoryBlock.tsx b/react/CategoryBlock.tsx index 42b9d093..547bc2c6 100644 --- a/react/CategoryBlock.tsx +++ b/react/CategoryBlock.tsx @@ -31,6 +31,7 @@ const CategoryBlock: FunctionComponent = ({ componentOnly, intl, data: { categories }, + checkoutUrl }) => { const [state, setState] = useState({ categoryItems: {}, @@ -89,7 +90,7 @@ const CategoryBlock: FunctionComponent = ({ action = success ? { label: intl.formatMessage(messages.seeCart), - href: '/checkout/#/cart', + href: checkoutUrl ?? '/checkout/#/cart', } : undefined } diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 613ecbb8..cb216a64 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -24,7 +24,7 @@ interface ItemType { const TextAreaBlock: FunctionComponent< TextAreaBlockInterface & WrappedComponentProps -> = ({ intl, value, text, hiddenColumns, description, componentOnly }: any) => { +> = ({ intl, value, text, hiddenColumns, description, componentOnly, checkoutUrl }: any) => { const [state, setState] = useState({ reviewState: false, showAddToCart: null, @@ -72,7 +72,7 @@ const TextAreaBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: '/checkout/#/cart', + href: checkoutUrl ?? '/checkout/#/cart', } : undefined diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 9bec6ef0..5370fa6f 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -34,6 +34,7 @@ const UploadBlock: FunctionComponent< componentOnly, intl, alwaysShowAddToCart = true, + checkoutUrl }: any) => { let productsArray: any = [] const [state, setState] = useState({ @@ -84,7 +85,7 @@ const UploadBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: '/checkout/#/cart', + href: checkoutUrl ?? '/checkout/#/cart', } : undefined From f73d98f423d33800e6b114e7a7a9546e615ed6d7 Mon Sep 17 00:00:00 2001 From: EmanuelRamos115 <162623679+EmanuelRamos115@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:51:00 -0300 Subject: [PATCH 2/5] Update README.md --- docs/README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 0f74d0ee..f646c804 100644 --- a/docs/README.md +++ b/docs/README.md @@ -100,7 +100,8 @@ To use these blocks, follow the instructions below. "props": { "componentOnly": false, "text": "Copy/Paste Skus", - "description": "[SKU Reference ID],[Quantity]" + "description": "[SKU Reference ID],[Quantity]", + "checkoutUrl:": "/checkout#/cart" } }, @@ -116,7 +117,8 @@ To use these blocks, follow the instructions below. "text": "Upload", "description": "Upload a Spreadsheet with two columns (SKU, Quantity) to bulk order", "downloadText": "Click here to download a spreadsheet model", - "alwaysShowAddToCart:": true + "alwaysShowAddToCart:": true, + "checkoutUrl:": "/checkout#/cart" } }, @@ -130,7 +132,8 @@ To use these blocks, follow the instructions below. "props": { "componentOnly": false, "text": "One by One", - "description": "Type the product name, select, enter quantity, add to the cart" + "description": "Type the product name, select, enter quantity, add to the cart", + "checkoutUrl:": "/checkout#/cart" } }, @@ -144,7 +147,8 @@ To use these blocks, follow the instructions below. "props": { "componentOnly": false, "text": "Categories", - "description": "Add products directly from their categories" + "description": "Add products directly from their categories", + "checkoutUrl:": "/checkout#/cart" } } } @@ -159,6 +163,7 @@ All blocks exported by the `quickorder` app share the same props: | `text` | `string` | Component title. | `undefined` | | `description` | `string` | Component description. It should be used to explain users how to properly bulk order using the given component. | `undefined` | | `componentOnly` | `boolean` | If `true`, only the component will be loaded, removing the `text` and `description` column. | `false` | +| `checkoutUrl` | `string` | Checkout cart URL for redirect | `false` | Especially, the `quickorder-upload` block also can use the following prop: From dfa306398c989747ab631cf8153afc300ce90ccf Mon Sep 17 00:00:00 2001 From: Emanuel Ramos Date: Wed, 25 Sep 2024 12:10:13 -0300 Subject: [PATCH 3/5] fix: pr review changes --- docs/README.md | 2 +- react/AutocompleteBlock.tsx | 2 +- react/CategoryBlock.tsx | 2 +- react/TextAreaBlock.tsx | 2 +- react/UploadBlock.tsx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index f646c804..5bce353c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -163,7 +163,7 @@ All blocks exported by the `quickorder` app share the same props: | `text` | `string` | Component title. | `undefined` | | `description` | `string` | Component description. It should be used to explain users how to properly bulk order using the given component. | `undefined` | | `componentOnly` | `boolean` | If `true`, only the component will be loaded, removing the `text` and `description` column. | `false` | -| `checkoutUrl` | `string` | Checkout cart URL for redirect | `false` | +| `checkoutUrl` | `string` | Checkout cart URL for redirect | `/checkout#/cart` | Especially, the `quickorder-upload` block also can use the following prop: diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 52e5a5f7..6945f44a 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -77,7 +77,7 @@ const AutocompleteBlock: FunctionComponent = ({ action = success ? { label: translateMessage(messages.seeCart), - href: checkoutUrl ?? '/checkout/#/cart', + href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', } : undefined } diff --git a/react/CategoryBlock.tsx b/react/CategoryBlock.tsx index 547bc2c6..68e345a5 100644 --- a/react/CategoryBlock.tsx +++ b/react/CategoryBlock.tsx @@ -90,7 +90,7 @@ const CategoryBlock: FunctionComponent = ({ action = success ? { label: intl.formatMessage(messages.seeCart), - href: checkoutUrl ?? '/checkout/#/cart', + href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', } : undefined } diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index cb216a64..cee37bf6 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -72,7 +72,7 @@ const TextAreaBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: checkoutUrl ?? '/checkout/#/cart', + href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', } : undefined diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 5370fa6f..0ac88907 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -85,7 +85,7 @@ const UploadBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: checkoutUrl ?? '/checkout/#/cart', + href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', } : undefined From b9559585a7c3a374e14d12b9997504ffc69ac988 Mon Sep 17 00:00:00 2001 From: Everton Ataide Date: Thu, 26 Sep 2024 07:59:12 -0300 Subject: [PATCH 4/5] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f158470f..f9232b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Add a cart url prop so the store can control the redirect via theme ## [3.15.5] - 2024-08-20 From 8a27f9b0ebd6a116e1a141279d7b5db5b08b6c7d Mon Sep 17 00:00:00 2001 From: Everton Ataide Date: Thu, 26 Sep 2024 08:20:13 -0300 Subject: [PATCH 5/5] Update lint --- react/AutocompleteBlock.tsx | 7 +++++-- react/CategoryBlock.tsx | 7 +++++-- react/TextAreaBlock.tsx | 15 +++++++++++++-- react/UploadBlock.tsx | 7 +++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 6945f44a..54d2e4bd 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -24,7 +24,7 @@ const AutocompleteBlock: FunctionComponent = ({ description, componentOnly, intl, - checkoutUrl + checkoutUrl, }) => { const client = useApolloClient() const { showToast } = useContext(ToastContext) @@ -77,7 +77,10 @@ const AutocompleteBlock: FunctionComponent = ({ action = success ? { label: translateMessage(messages.seeCart), - href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', + href: + typeof checkoutUrl === 'string' && checkoutUrl !== '' + ? checkoutUrl + : '/checkout/#/cart', } : undefined } diff --git a/react/CategoryBlock.tsx b/react/CategoryBlock.tsx index 68e345a5..1bbe9506 100644 --- a/react/CategoryBlock.tsx +++ b/react/CategoryBlock.tsx @@ -31,7 +31,7 @@ const CategoryBlock: FunctionComponent = ({ componentOnly, intl, data: { categories }, - checkoutUrl + checkoutUrl, }) => { const [state, setState] = useState({ categoryItems: {}, @@ -90,7 +90,10 @@ const CategoryBlock: FunctionComponent = ({ action = success ? { label: intl.formatMessage(messages.seeCart), - href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', + href: + typeof checkoutUrl === 'string' && checkoutUrl !== '' + ? checkoutUrl + : '/checkout/#/cart', } : undefined } diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index cee37bf6..d992ad4a 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -24,7 +24,15 @@ interface ItemType { const TextAreaBlock: FunctionComponent< TextAreaBlockInterface & WrappedComponentProps -> = ({ intl, value, text, hiddenColumns, description, componentOnly, checkoutUrl }: any) => { +> = ({ + intl, + value, + text, + hiddenColumns, + description, + componentOnly, + checkoutUrl, +}: any) => { const [state, setState] = useState({ reviewState: false, showAddToCart: null, @@ -72,7 +80,10 @@ const TextAreaBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', + href: + typeof checkoutUrl === 'string' && checkoutUrl !== '' + ? checkoutUrl + : '/checkout/#/cart', } : undefined diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 0ac88907..01c4ca31 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -34,7 +34,7 @@ const UploadBlock: FunctionComponent< componentOnly, intl, alwaysShowAddToCart = true, - checkoutUrl + checkoutUrl, }: any) => { let productsArray: any = [] const [state, setState] = useState({ @@ -85,7 +85,10 @@ const UploadBlock: FunctionComponent< const action = success ? { label: translateMessage(messages.seeCart), - href: typeof checkoutUrl === "string" && checkoutUrl !== "" ? checkoutUrl : '/checkout/#/cart', + href: + typeof checkoutUrl === 'string' && checkoutUrl !== '' + ? checkoutUrl + : '/checkout/#/cart', } : undefined