Skip to content

Commit

Permalink
Merge pull request #173 from EmanuelRamos115/feat/add-to-cart-prop
Browse files Browse the repository at this point in the history
Feat/add to cart prop
  • Loading branch information
ataideverton authored Nov 7, 2024
2 parents 0373bff + c039493 commit f631c13
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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

- Changed the checkoutUrl prop to admin app settings

## [3.15.9] - 2024-10-02

Expand Down
6 changes: 1 addition & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ To use these blocks, follow the instructions below.
"componentOnly": false,
"text": "Copy/Paste Skus",
"description": "[SKU Reference ID],[Quantity]",
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -118,7 +117,6 @@ To use these blocks, follow the instructions below.
"description": "Upload a Spreadsheet with two columns (SKU, Quantity) to bulk order",
"downloadText": "Click here to download a spreadsheet model",
"alwaysShowAddToCart:": true,
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -133,7 +131,6 @@ To use these blocks, follow the instructions below.
"componentOnly": false,
"text": "One by One",
"description": "Type the product name, select, enter quantity, add to the cart",
"checkoutUrl:": "/checkout#/cart"
}
},

Expand All @@ -148,7 +145,6 @@ To use these blocks, follow the instructions below.
"componentOnly": false,
"text": "Categories",
"description": "Add products directly from their categories",
"checkoutUrl:": "/checkout#/cart"
}
}
}
Expand All @@ -163,7 +159,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 | `/checkout#/cart` |


Especially, the `quickorder-upload` block also can use the following prop:

Expand Down
18 changes: 15 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"vtex.flex-layout": "0.x",
"vtex.rich-text": "0.x",
"vtex.checkout": "0.x",
"vtex.render-runtime": "7.x",
"vtex.store": "2.x",
"vtex.styleguide": "9.x",
"vtex.store-graphql": "2.x",
Expand All @@ -35,7 +34,8 @@
"vtex.pixel-manager": "1.x",
"vtex.store-resources": "0.x",
"vtex.css-handles": "0.x",
"vtex.store-icons": "0.x"
"vtex.store-icons": "0.x",
"vtex.render-runtime": "8.x"
},
"policies": [
{
Expand Down Expand Up @@ -82,7 +82,19 @@
}
}
],
"settingsSchema": {},
"settingsSchema": {
"title": "Quickorder settings",
"type": "object",
"access": "public",
"properties": {
"checkoutUrl": {
"title": "URL",
"type": "string",
"description": "Checkout redirect href",
"default": "/checkout#/cart"
}
}
},
"billingOptions": {
"termsURL": "https://compliance.vtex.com/gdpr/policies/vtex-privacy-policy",
"support": {
Expand Down
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6071,7 +6071,7 @@ static-extend@^0.1.1:
define-property "^0.2.5"
object-copy "^0.1.0"

stats-lite@vtex/node-stats-lite#dist:
"stats-lite@github:vtex/node-stats-lite#dist":
version "2.2.0"
resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797"
dependencies:
Expand Down
6 changes: 5 additions & 1 deletion react/AutocompleteBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import { useApolloClient, useMutation } from 'react-apollo'
import { autocompleteMessages as messages } from './utils/messages'
import QuickOrderAutocomplete from './components/QuickOrderAutocomplete'
import productQuery from './queries/product.gql'
import getAppSettings from './utils/getAppSettings'

import './global.css'

const AutocompleteBlock: FunctionComponent<any & WrappedComponentProps> = ({
text,
description,
componentOnly,
intl,
checkoutUrl,
}) => {
const client = useApolloClient()
const { showToast } = useContext(ToastContext)
Expand All @@ -34,6 +35,9 @@ const AutocompleteBlock: FunctionComponent<any & WrappedComponentProps> = ({
unitMultiplier: 1,
})

const appSettings = getAppSettings()
const checkoutUrl = appSettings?.checkoutUrl ?? '/checkout#/cart'

const [addToCart, { error, loading }] = useMutation<
{ addToCart: OrderFormType },
{ items: [] }
Expand Down
5 changes: 4 additions & 1 deletion react/CategoryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import { graphql, useApolloClient, useMutation } from 'react-apollo'
import { categoryMessages as messages } from './utils/messages'
import getCategories from './queries/categoriesQuery.gql'
import SearchByCategory from './queries/productsByCategory.gql'
import getAppSettings from './utils/getAppSettings'

const CategoryBlock: FunctionComponent<WrappedComponentProps & any> = ({
text,
description,
componentOnly,
intl,
data: { categories },
checkoutUrl,
}) => {
const [state, setState] = useState<any>({
categoryItems: {},
Expand All @@ -41,6 +41,9 @@ const CategoryBlock: FunctionComponent<WrappedComponentProps & any> = ({
unitMultiplierList: {},
})

const appSettings = getAppSettings()
const checkoutUrl = appSettings?.checkoutUrl ?? '/checkout#/cart'

const { showToast } = useContext(ToastContext)

const client = useApolloClient()
Expand Down
13 changes: 4 additions & 9 deletions react/TextAreaBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { usePixel } from 'vtex.pixel-manager/PixelContext'
import { categoryMessages as messages } from './utils/messages'
import ReviewBlock from './components/ReviewBlock'
import { ParseText, GetText } from './utils'
import getAppSettings from './utils/getAppSettings'

interface ItemType {
id: string
Expand All @@ -24,22 +25,16 @@ interface ItemType {

const TextAreaBlock: FunctionComponent<
TextAreaBlockInterface & WrappedComponentProps
> = ({
intl,
value,
text,
hiddenColumns,
description,
componentOnly,
checkoutUrl,
}: any) => {
> = ({ intl, value, text, hiddenColumns, description, componentOnly }: any) => {
const [state, setState] = useState<any>({
reviewState: false,
showAddToCart: null,
textAreaValue: value || '',
reviewItems: [],
})

const appSettings = getAppSettings()
const checkoutUrl = appSettings?.checkoutUrl ?? '/checkout#/cart'
const [refidLoading, setRefIdLoading] = useState<any>()

const { textAreaValue, reviewItems, reviewState, showAddToCart } = state
Expand Down
5 changes: 4 additions & 1 deletion react/UploadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { categoryMessages as messages } from './utils/messages'
import { ParseText, GetText } from './utils'
import ReviewBlock from './components/ReviewBlock'
import { DropzoneIcon } from './assets/DropZoneIcon'
import getAppSettings from './utils/getAppSettings'

interface ItemType {
id: string
Expand All @@ -34,7 +35,6 @@ const UploadBlock: FunctionComponent<
componentOnly,
intl,
alwaysShowAddToCart = true,
checkoutUrl,
}: any) => {
let productsArray: any = []
const [state, setState] = useState<any>({
Expand All @@ -43,6 +43,9 @@ const UploadBlock: FunctionComponent<
showAddToCart: false,
})

const appSettings = getAppSettings()
const checkoutUrl = appSettings?.checkoutUrl ?? '/checkout#/cart'

const [showValidateButton, setShowValidateButton] = useState<boolean>(false)

const [refidLoading, setRefIdLoading] = useState<any>()
Expand Down
6 changes: 6 additions & 0 deletions react/queries/getSettings.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query getSettings($version: String!) {
publicSettingsForApp(app: "vtex.quickorder", version: $version)
@context(provider: "vtex.apps-graphql") {
message
}
}
41 changes: 41 additions & 0 deletions react/utils/getAppSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { useQuery } from 'react-apollo'
import { useEffect, useState } from 'react'
/* eslint-disable no-restricted-imports */
import { pathOr } from 'ramda'

import AppSettings from '../queries/getSettings.gql'

const useAppSettings = () => {
const { data: appSettingsData } = useQuery(AppSettings, {
variables: {
version: process.env.VTEX_APP_VERSION,
},
ssr: false,
})

const [appSettings, setAppSettings] = useState({
checkoutUrl: '/checkout#/cart',
})

useEffect(() => {
if (appSettingsData) {
const settingsString = pathOr(
`""`,
['publicSettingsForApp', 'message'],
appSettingsData
)

try {
const parsedAppSettings = JSON.parse(settingsString)

setAppSettings(parsedAppSettings)
} catch (error) {
console.error('Error parsing app settings:', error)
}
}
}, [appSettingsData])

return appSettings
}

export default useAppSettings

0 comments on commit f631c13

Please sign in to comment.