diff --git a/manifest.json b/manifest.json index 29bcff08..fde3dc00 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/react/QuickOrder.tsx b/react/QuickOrder.tsx index 6abb64c7..41c968d2 100644 --- a/react/QuickOrder.tsx +++ b/react/QuickOrder.tsx @@ -167,7 +167,6 @@ const QuickOrder: StorefrontFunctionComponent { console.log('onRefidLoading', refidLoading) - console.log('setState #2', reviewItems) } const backList = () => { @@ -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, }, }, } diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index 8e179f7e..7fa842f4 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -70,6 +70,8 @@ const ReviewBlock: StorefrontFunctionComponent = ({ error = true } + console.log('validateRefids', reviewed) + const items = reviewed.map((item: any) => { return { ...item, @@ -78,16 +80,30 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } }) - 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, @@ -101,6 +117,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } const convertRefIds = (items: any) => { + console.log('convertRefIds', items) const refids = items .filter((item: any) => { return item.error === null @@ -112,8 +129,9 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } 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) @@ -133,6 +151,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ }) onReviewItems(items) + console.log('setReviewState #2', items) setReviewState({ ...state, reviewItems: items, @@ -142,7 +161,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ const updateLineContent = (line: number, content: string) => { let items = reviewItems items[line]['content'] = content - + console.log('setReviewState #3', items) setReviewState({ ...state, reviewItems: items, @@ -154,6 +173,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ let reviewd: any = ParseText(joinLines) if (reviewd[line].error === null) { + console.log('setReviewState #4', JSON.stringify(reviewd)) setReviewState({ ...state, reviewItems: reviewd, diff --git a/react/utils/index.ts b/react/utils/index.ts index 160d1b32..e18f3b97 100644 --- a/react/utils/index.ts +++ b/react/utils/index.ts @@ -40,6 +40,5 @@ export const ParseText = (textAreaValue: string) => { error: 'quickorder.invalidPattern', } }) - console.log('Items', items) return items }