Skip to content

Commit

Permalink
Preventing app to re-check a SKU refid if it was already checked; Mer…
Browse files Browse the repository at this point in the history
…ging validated items with the current list
  • Loading branch information
wender committed Feb 20, 2020
1 parent 4e0632b commit d47fca9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"vendor": "vtex",
"name": "quickorder",
"version": "0.5.5",
"version": "0.5.6",
"title": "Quickorder APP",
"description": "Allow users to add multiple products to the cart at once",
"defaultLocale": "pt-BR",
Expand Down
5 changes: 2 additions & 3 deletions react/QuickOrder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ const QuickOrder: StorefrontFunctionComponent<QuickOrderProps &

const onRefidLoading = (refidLoading: any) => {
console.log('onRefidLoading', refidLoading)
console.log('setState #2', reviewItems)
}

const backList = () => {
Expand Down Expand Up @@ -287,13 +286,13 @@ QuickOrder.schema = {
title: 'editor.quickorder.autocomplete.title',
description: 'editor.quickorder.autocomplete.description',
type: 'boolean',
default: null,
default: true,
},
showCopyPaste: {
title: 'editor.quickorder.textarea.title',
description: 'editor.quickorder.textarea.description',
type: 'boolean',
default: null,
default: true,
},
},
}
Expand Down
28 changes: 24 additions & 4 deletions react/components/ReviewBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
error = true
}

console.log('validateRefids', reviewed)

const items = reviewed.map((item: any) => {
return {
...item,
Expand All @@ -78,16 +80,30 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
}
})

onReviewItems(items)
const merge = (original: any) => {
const item = items.find((curr: any) => {
return original.sku === curr.sku
})
console.log('Merge', item)
return item ? item : original
}

const updated = reviewItems.map((item: any) => {
return merge(item)
})

onReviewItems(updated)
console.log('setReviewState #1', updated)
setReviewState({
...state,
reviewItems: items,
reviewItems: updated,
hasError: error,
})
}
}

const getRefIds = async (refids: any, reviewed: any) => {
console.log('getRefIds', reviewed)
onRefidLoading(true)
const query = {
query: getRefIdTranslation,
Expand All @@ -101,6 +117,7 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
}

const convertRefIds = (items: any) => {
console.log('convertRefIds', items)
const refids = items
.filter((item: any) => {
return item.error === null
Expand All @@ -112,8 +129,9 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
}

const checkValidatedItems = () => {
console.log('checkValidatedItems')
const items: [any] = reviewItems.filter((item: any) => {
return item.sku !== null && !item.vtexSku
return item.sku !== null && item.error === null && !item.vtexSku
})
if (items.length) {
convertRefIds(items)
Expand All @@ -133,6 +151,7 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
})

onReviewItems(items)
console.log('setReviewState #2', items)
setReviewState({
...state,
reviewItems: items,
Expand All @@ -142,7 +161,7 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
const updateLineContent = (line: number, content: string) => {
let items = reviewItems
items[line]['content'] = content

console.log('setReviewState #3', items)
setReviewState({
...state,
reviewItems: items,
Expand All @@ -154,6 +173,7 @@ const ReviewBlock: StorefrontFunctionComponent<WrappedComponentProps & any> = ({
let reviewd: any = ParseText(joinLines)

if (reviewd[line].error === null) {
console.log('setReviewState #4', JSON.stringify(reviewd))
setReviewState({
...state,
reviewItems: reviewd,
Expand Down
1 change: 0 additions & 1 deletion react/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,5 @@ export const ParseText = (textAreaValue: string) => {
error: 'quickorder.invalidPattern',
}
})
console.log('Items', items)
return items
}

0 comments on commit d47fca9

Please sign in to comment.