Skip to content

Commit

Permalink
Merge pull request #25 from vtex-apps/bugfix/category-not-loading
Browse files Browse the repository at this point in the history
Fix categories load
  • Loading branch information
wender authored Aug 18, 2020
2 parents d767687 + a3e563c commit e24bbf0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Categories loading
- Default Seller

## [3.0.1] - 2020-08-17

### Changed
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/node": "^12.0.0",
"@types/qs": "^6.5.1",
"@types/ramda": "^0.26.21",
"@vtex/api": "6.36.0",
"@vtex/api": "6.36.1",
"@vtex/test-tools": "^1.2.0",
"@vtex/tsconfig": "^0.2.0",
"eslint": "^6.8.0",
Expand Down
3 changes: 1 addition & 2 deletions node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ export const queries = {
items,
}
},
sellers: async (_: any, args: {}, ctx: Context) => {
console.log(args)
sellers: async (_: any, __: {}, ctx: Context) => {
const {
clients: { search },
} = ctx
Expand Down
10 changes: 5 additions & 5 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1319,10 +1319,10 @@
semver "^6.3.0"
tsutils "^3.17.1"

"@vtex/[email protected].0":
version "6.36.0"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.36.0.tgz#debc0462cae4196a6580ded8ed88359dcb6ce31d"
integrity sha512-kEIHIOA6oXCGq65TpQG6ZBA2r3qQ9SAgoMpjo87dZvbybvxTPI7mz8URKy4jKuArf1mkhzLu9EqsJ+xwljFySg==
"@vtex/[email protected].1":
version "6.36.1"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.36.1.tgz#7de05462227cb9619e93fb38767ae9adb906ead2"
integrity sha512-DwULwOhK8BULNmZFAZXFIK1u+YvGkbl8zPt2f3DkXXI0PSnWPUkTVt1fANgYbeOtiepGNA+ibssCAGUFHFy0zg==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand Down Expand Up @@ -6016,7 +6016,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
33 changes: 20 additions & 13 deletions react/CategoryBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ const messages = defineMessages({
})

const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
any> = ({ text, description, componentOnly, intl, data }) => {
any> = ({ text, description, componentOnly, intl, data: { categories } }) => {
const [state, setState] = useState<any>({
categories: data.categories || [],
categoryItems: {},
quantitySelected: {},
defaultSeller: {},
Expand All @@ -65,7 +64,7 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &

const client = useApolloClient()

const { categories, categoryItems, quantitySelected, defaultSeller } = state
const { categoryItems, quantitySelected, defaultSeller } = state
const [addToCart, { error, loading }] = useMutation<
{ addToCart: OrderFormType },
{ items: [] }
Expand Down Expand Up @@ -205,12 +204,15 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
})
}

const handleSearch = async (categoryId: any) => {
const handleSearch = async (categoryId: number, categoryName: string) => {
const selectedFacets = [{ key: 'c', value: categoryName }]

if (!categoryItems[categoryId]) {
const { data: dataProducts } = await client.query({
query: SearchByCategory,
variables: { categoryId },
variables: { selectedFacets },
})

setOptions(
categoryId,
!!dataProducts &&
Expand Down Expand Up @@ -238,6 +240,7 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
seller: defaultSeller[item],
}
})

onAddToCart(items, skus)
} else {
toastMessage('noneSelection')
Expand Down Expand Up @@ -272,11 +275,15 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
const newQtd = quantitySelected
newQtd[content.itemId] = e.target.value
const newSeller = defaultSeller
newSeller[content.itemId] = content.sellers.find(
(s: any) => {
return s.sellerDefault === true
}
).sellerId
const seller = content.sellers.find((s: any) => {
return s.sellerDefault === true
})
newSeller[content.itemId] =
seller?.sellerId ||
(content.sellers.length
? content.sellers[0].sellerId
: '1')

_setState({
quantitySelected: newQtd,
defaultSeller: newSeller,
Expand All @@ -296,7 +303,7 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
)
}

const openClose = (id: number) => {
const openClose = (id: number, name: string) => {
const findNChange = (source: any) => {
const obj: any = source.map((item: any) => {
const ret = item
Expand All @@ -315,7 +322,7 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
_setState({
categories: newCategories,
})
handleSearch(id)
handleSearch(id, name)
}

const collapsible = (item: any) => {
Expand All @@ -325,7 +332,7 @@ const CategoryBlock: StorefrontFunctionComponent<WrappedComponentProps &
header={<span className="ml5 fw5">{item.name}</span>}
isOpen={item.isOpen}
onClick={() => {
openClose(item.id)
openClose(item.id, item.name)
}}
>
<div className={`${handles.categoriesProductContainer}`}>
Expand Down
6 changes: 1 addition & 5 deletions react/UploadBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ const UploadBlock: StorefrontFunctionComponent<UploadBlockInterface &
doFile(files)
}

const handleReset = (files: any) => {
if (files) {
console.log(files)
}
}
const handleReset = () => {}

const backList = () => {
setState({
Expand Down
3 changes: 1 addition & 2 deletions react/components/QuickOrderAutocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ const QuickOrderAutocomplete = ({ onSelect }: any) => {
setTerm(term)
}
},
// eslint-disable-next-line no-console
onSearch: (...args: any) => console.log('onSearch:', ...args),
onSearch: () => () => {},
onClear: () => setTerm(''),
placeholder: 'Search for a product...',
value: term,
Expand Down
6 changes: 3 additions & 3 deletions react/queries/productsByCategory.gql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
query SearchByCategory($categoryId: String) {
productSearch(category: $categoryId)
@context(provider: "vtex.store-graphql") {
query SearchByCategory($selectedFacets: [SelectedFacetInput]) {
productSearch(selectedFacets: $selectedFacets)
@context(provider: "vtex.search-graphql") {
products {
items {
itemId
Expand Down

0 comments on commit e24bbf0

Please sign in to comment.