Skip to content

Commit

Permalink
Merge pull request #174 from vtex-apps/bugfix/FSEUS-731-autocomplete-…
Browse files Browse the repository at this point in the history
…in-french

[FSEUS-731] Fixing autocomplete for French
  • Loading branch information
ataideverton authored Nov 12, 2024
2 parents 9adf7a6 + 76dc0b6 commit 2756f6e
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 56 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ 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]
### Fixed
- Autocomplete not working with French language

## [3.16.0] - 2024-11-07
### Added

- Changed the checkoutUrl prop to admin app settings
- Changed the checkoutUrl prop to admin app settings

## [3.15.9] - 2024-10-02

Expand Down
6 changes: 2 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"vendor": "vtex",
"name": "quickorder",
"version": "3.16.0",
"version": "3.16.1-beta.0",
"title": "Quickorder",
"description": "Allow users to add multiple products to the cart at once",
"defaultLocale": "en-US",
Expand Down Expand Up @@ -102,9 +102,7 @@
},
"free": true,
"type": "free",
"availableCountries": [
"*"
]
"availableCountries": ["*"]
},
"$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema"
}
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@gocommerce/utils": "^0.7.3",
"@vtex/api": "6.47.0",
"@vtex/api": "6.48.0",
"atob": "^2.1.2",
"axios": "^0.19.0",
"camelcase": "^5.0.0",
Expand Down
8 changes: 4 additions & 4 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1863,10 +1863,10 @@
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.8.0.tgz#8b63ab7f1aa5321248aad5ac890a485656dcea4d"
integrity sha512-te5lMAWii1uEJ4FwLjzdlbw3+n0FZNOvFXHxQDKeT0dilh7HOzdMzV2TrJVUzq8ep7J4Na8OUYPRLSQkJHAlrg==

"@vtex/api@6.47.0":
version "6.47.0"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.47.0.tgz#6910455d593d8bb76f1f4f2b7660023853fda35e"
integrity sha512-t9gt7Q89EMbSj3rLhho+49Fv+/lQgiy8EPVRgtmmXFp1J4v8hIAZF7GPjCPie111KVs4eG0gfZFpmhA5dafKNA==
"@vtex/api@6.48.0":
version "6.48.0"
resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.48.0.tgz#67f9f11d197d543d4f854b057d31a8d6999241e9"
integrity sha512-mAdT7gbV0/BwiuqUkNH1E7KZqTUczT5NbBBZcPJq5kmTr73PUjbR9wh//70ryJo2EAdHlqIgqgwsCVpozenlhg==
dependencies:
"@types/koa" "^2.11.0"
"@types/koa-compose" "^3.2.3"
Expand Down
3 changes: 2 additions & 1 deletion react/AutocompleteBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable react/prop-types */
import type { FunctionComponent } from 'react'
Expand Down Expand Up @@ -179,7 +180,7 @@ const AutocompleteBlock: FunctionComponent<any & WrappedComponentProps> = ({
if (!!product && product.length) {
const query = {
query: productQuery,
variables: { slug: product[0].slug },
variables: { skuId: product[0].value },
}

const { data } = await client.query(query)
Expand Down
82 changes: 39 additions & 43 deletions react/components/ReviewBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable vtex/prefer-early-return */
import type { FunctionComponent } from 'react'
Expand Down Expand Up @@ -53,17 +54,17 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}

const setRestriction = async (data: any) => {
return Promise.all(
data.map(async (item: any) => {
const res: any = await checkRestriction(item.refid)

const promises = data.map((item: any) =>
checkRestriction(item.refid).then((res: any) => {
const foundSku = res?.data?.productSuggestions?.products[0]?.items.find(
(suggestedItem) => suggestedItem.itemId === item.sku
)

return foundSku ? item : null
})
)

return Promise.all(promises)
}

const [state, setReviewState] = useState<any>({
Expand Down Expand Up @@ -177,59 +178,54 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}

const errorMsg = (item: any, sellerWithStock: string) => {
let ret: any = null

/* order of precedence for errors
* 1) Item not found
* 2) Item availability
* 3) Item restriction
*/
const notfound = refIdNotFound.find((curr: any) => {
return curr.refid === item.sku && curr.sku === null
})
const { sku } = item

const found = refIdFound.find((curr: any) => {
return curr.refid === item.sku && curr.sku !== null
})
// Error precedence
const notfound = refIdNotFound.find(
(curr: any) => curr.refid === sku && curr.sku === null
)

const found = refIdFound.find(
(curr: any) => curr.refid === sku && curr.sku !== null
)

if (found?.sku && found.sellers.length === 0) {
return 'store/quickorder.inactive'
}

let selectedSellerHasPartialStock
// Check for stock in the selected seller
let selectedSellerHasPartialStock = false
const foundHasStock =
(found?.sellers?.length &&
found.sellers.filter((seller: any) => {
if (seller?.id === sellerWithStock) {
selectedSellerHasPartialStock =
seller?.availability === 'partiallyAvailable'
}

return (
seller?.availability &&
(seller?.availability === 'available' ||
seller?.availability === 'partiallyAvailable')
)
})?.length) ||
0

const itemRestricted = sellerWithStock
? null
: `store/quickorder.limited`
found?.sellers?.some((seller: any) => {
if (seller?.id === sellerWithStock) {
selectedSellerHasPartialStock =
seller.availability === 'partiallyAvailable'
}

return (
seller?.availability &&
(seller.availability === 'available' ||
seller.availability === 'partiallyAvailable')
)
}) ?? false

// Error handling for availability and restriction
const partialStockError = selectedSellerHasPartialStock
? 'store/quickorder.partiallyAvailable'
: null

const availabilityError = foundHasStock
? partialStockError
: `store/quickorder.withoutStock`
: 'store/quickorder.withoutStock'

if (found?.sku && found?.sellers?.length === 0) {
return 'store/quickorder.inactive'
}
const itemRestricted = !sellerWithStock
? 'store/quickorder.limited'
: null

ret = notfound
// Final return
return notfound
? 'store/quickorder.skuNotFound'
: availabilityError ?? itemRestricted

return ret
}

if (refIdNotFound.length || refNotAvailable.length) {
Expand Down
5 changes: 3 additions & 2 deletions react/queries/product.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query Product($slug: String) {
product(slug: $slug) @context(provider: "vtex.search-graphql") {
query Product($skuId: ID!) {
product(identifier: { field: sku, value: $skuId })
@context(provider: "vtex.search-graphql") {
productName
items {
itemId
Expand Down

0 comments on commit 2756f6e

Please sign in to comment.