From 486407fd6aad87fe8de4865af4bc747688c6f221 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 11 Aug 2021 16:00:06 +0530 Subject: [PATCH 01/29] Fixed sku duplicate issue --- CHANGELOG.md | 4 ++++ node/package.json | 2 +- node/yarn.lock | 44 ++++++++++++++++++++++++++++++++++---------- react/utils/index.ts | 26 +++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c9f5905..03b3839b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Fixed the duplicate sku addition + ## [3.2.0] - 2021-05-17 ### Added diff --git a/node/package.json b/node/package.json index d3d5dbe3..99d95bfc 100644 --- a/node/package.json +++ b/node/package.json @@ -29,7 +29,7 @@ "@types/node": "^12.0.0", "@types/qs": "^6.5.1", "@types/ramda": "^0.26.21", - "@vtex/api": "6.41.0", + "@vtex/api": "6.44.0", "@vtex/test-tools": "^1.2.0", "@vtex/tsconfig": "^0.2.0", "eslint": "^6.8.0", diff --git a/node/yarn.lock b/node/yarn.lock index 4116bfc0..4c403788 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1319,10 +1319,10 @@ semver "^6.3.0" tsutils "^3.17.1" -"@vtex/api@6.41.0": - version "6.41.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.41.0.tgz#cee074ff49de8a5de92f3d353a4689275cb92f7b" - integrity sha512-RvfdpczsxCFacZkDSl2v2NmfD/bHFxHHn2xQsEwSQ+40snGxfOz56TlCbPbgMEtkC8Bf+1GGUkCIChRE6xnlLg== +"@vtex/api@6.44.0": + version "6.44.0" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.44.0.tgz#8dc2a27c37635278117310bcc5cd16203c0a5849" + integrity sha512-7nPIwzQz55Mu0E1BOoW1noObZet9J34iKmeAJU3TRL7iiGmPZB0McSjC6KgDHkfqYgim2JGrnCsa1978ffbwKQ== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -1331,7 +1331,7 @@ agentkeepalive "^4.0.2" apollo-server-errors "^2.2.1" archiver "^3.0.0" - axios "^0.19.2" + axios "^0.21.1" axios-retry "^3.1.2" bluebird "^3.5.4" chalk "^2.4.2" @@ -1361,6 +1361,7 @@ semver "^5.5.1" stats-lite vtex/node-stats-lite#dist tar-fs "^2.0.0" + tokenbucket "^0.3.2" uuid "^3.3.3" xss "^1.0.6" @@ -1818,12 +1819,12 @@ axios@^0.19.0: follow-redirects "1.5.10" is-buffer "^2.0.2" -axios@^0.19.2: - version "0.19.2" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" - integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== +axios@^0.21.1: + version "0.21.1" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8" + integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA== dependencies: - follow-redirects "1.5.10" + follow-redirects "^1.10.0" babel-jest@^24.4.0, babel-jest@^24.9.0: version "24.9.0" @@ -1920,6 +1921,11 @@ bl@^3.0.0: dependencies: readable-stream "^3.0.1" +bluebird@2.9.24: + version "2.9.24" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.9.24.tgz#14a2e75f0548323dc35aa440d92007ca154e967c" + integrity sha1-FKLnXwVIMj3DWqRA2SAHyhVOlnw= + bluebird@^3.5.4: version "3.5.5" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f" @@ -3037,6 +3043,11 @@ follow-redirects@1.5.10: dependencies: debug "=3.1.0" +follow-redirects@^1.10.0: + version "1.14.1" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.1.tgz#d9114ded0a1cfdd334e164e6662ad02bfd91ff43" + integrity sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg== + follow-redirects@^1.3.0: version "1.7.0" resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.7.0.tgz#489ebc198dc0e7f64167bd23b03c4c19b5784c76" @@ -5520,6 +5531,11 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" +redis@^0.12.1: + version "0.12.1" + resolved "https://registry.yarnpkg.com/redis/-/redis-0.12.1.tgz#64df76ad0fc8acebaebd2a0645e8a48fac49185e" + integrity sha1-ZN92rQ/IrOuuvSoGReikj6xJGF4= + regenerate-unicode-properties@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.1.0.tgz#ef51e0f0ea4ad424b77bf7cb41f3e015c70a3f0e" @@ -6319,6 +6335,14 @@ toidentifier@1.0.0: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553" integrity sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw== +tokenbucket@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/tokenbucket/-/tokenbucket-0.3.2.tgz#8172b2b58e3083acc8d914426fed15162a3a8e90" + integrity sha1-gXKytY4wg6zI2RRCb+0VFio6jpA= + dependencies: + bluebird "2.9.24" + redis "^0.12.1" + tough-cookie@^2.3.3, tough-cookie@^2.3.4: version "2.5.0" resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.5.0.tgz#cd9fb2a0aa1d5a12b473bd9fb96fa3dcff65ade2" diff --git a/react/utils/index.ts b/react/utils/index.ts index 299e21a3..a1ad5d1a 100644 --- a/react/utils/index.ts +++ b/react/utils/index.ts @@ -4,9 +4,30 @@ export const GetText = (items: any) => { return line.content }) .join('\n') + return joinLines } +const removeDuplicates = (itemList: any) => { + const map = new Map() + + itemList.forEach(item => { + const key = item.sku + const collection = map.get(key) + + if (!collection) { + map.set(key, item) + } else { + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands + collection.quantity += item.quantity + collection.content = `${key},${collection.quantity}` + console.info('Collections : ', collection) + } + }) + + return Array.from(map, ([, value]) => value) +} + export const ParseText = (textAreaValue: string) => { const rawText: any = String(textAreaValue || '') const arrText = String(rawText).split(/[\n\r]/) @@ -16,6 +37,7 @@ export const ParseText = (textAreaValue: string) => { }) .map((line: any, index: number) => { const lineSplitted: any = line.split(',') + if (lineSplitted.length === 2) { if ( !!lineSplitted[0] && @@ -33,6 +55,7 @@ export const ParseText = (textAreaValue: string) => { } } } + return { index, line: index, @@ -42,5 +65,6 @@ export const ParseText = (textAreaValue: string) => { error: 'store/quickorder.invalidPattern', } }) - return items + + return removeDuplicates(items) } From 75c9cd09f9b5d1bcf6889109a233effb91aca3d4 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 11 Aug 2021 16:02:26 +0530 Subject: [PATCH 02/29] Fixed duplicate sku issue --- react/utils/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/react/utils/index.ts b/react/utils/index.ts index a1ad5d1a..600a534e 100644 --- a/react/utils/index.ts +++ b/react/utils/index.ts @@ -21,7 +21,6 @@ const removeDuplicates = (itemList: any) => { // eslint-disable-next-line @typescript-eslint/restrict-plus-operands collection.quantity += item.quantity collection.content = `${key},${collection.quantity}` - console.info('Collections : ', collection) } }) From badae92c0ae808accfb6cdea842515e3c5924211 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Tue, 31 Aug 2021 12:52:20 +0530 Subject: [PATCH 03/29] Fixed Add to cart issue - Fixed add to cart issue of text area and drag and drop sections. - Fixed button text change. --- node/package.json | 31 ++++---- node/yarn.lock | 96 +++++++++++----------- react/AutocompleteBlock.tsx | 27 ++++++- react/TextAreaBlock.tsx | 124 ++++++++++++++++++----------- react/UploadBlock.tsx | 118 ++++++++++++++++++--------- react/package.json | 29 +++---- react/typings/vtex.styleguide.d.ts | 4 + react/utils/index.ts | 38 +++++++++ react/yarn.lock | 88 ++++++++++---------- 9 files changed, 351 insertions(+), 204 deletions(-) diff --git a/node/package.json b/node/package.json index 99d95bfc..78eba7ec 100644 --- a/node/package.json +++ b/node/package.json @@ -29,29 +29,30 @@ "@types/node": "^12.0.0", "@types/qs": "^6.5.1", "@types/ramda": "^0.26.21", - "@vtex/api": "6.44.0", + "@vtex/api": "6.45.3", "@vtex/test-tools": "^1.2.0", "@vtex/tsconfig": "^0.2.0", "eslint": "^6.8.0", "eslint-config-vtex": "^12.1.1", "prettier": "^1.16.4", - "vtex.apps-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.5.1/public/@types/vtex.apps-graphql", + "vtex.apps-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql", "vtex.checkout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout@0.6.0/public/_types/react", - "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.44.1/public/@types/vtex.checkout-graphql", - "vtex.checkout-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.36.0/public/@types/vtex.checkout-resources", + "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql", + "vtex.checkout-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources", "vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles", - "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.15.1/public/@types/vtex.flex-layout", - "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.9.1/public/@types/vtex.order-items", - "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.8.7/public/@types/vtex.order-manager", - "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.4.0/public/@types/vtex.pixel-manager", - "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.42.0/public/@types/vtex.render-runtime", - "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text", - "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.36.0/public/_types/react", - "vtex.store": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.106.0/public/@types/vtex.store", - "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.135.0/public/@types/vtex.store-graphql", + "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout", + "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items", + "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager", + "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager", + "vtex.quickorder": "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder", + "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime", + "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text", + "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql", + "vtex.store": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store", + "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql", "vtex.store-icons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons", - "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react", - "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide" + "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources", + "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide" }, "version": "3.2.0" } diff --git a/node/yarn.lock b/node/yarn.lock index 4c403788..484e5ab8 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1319,10 +1319,10 @@ semver "^6.3.0" tsutils "^3.17.1" -"@vtex/api@6.44.0": - version "6.44.0" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.44.0.tgz#8dc2a27c37635278117310bcc5cd16203c0a5849" - integrity sha512-7nPIwzQz55Mu0E1BOoW1noObZet9J34iKmeAJU3TRL7iiGmPZB0McSjC6KgDHkfqYgim2JGrnCsa1978ffbwKQ== +"@vtex/api@6.45.3": + version "6.45.3" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" + integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -6607,17 +6607,17 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -"vtex.apps-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.5.1/public/@types/vtex.apps-graphql": - version "2.5.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.5.1/public/@types/vtex.apps-graphql#3c5789b5877e6b6a3d9c4cac35a80f2c3bb8b5fe" +"vtex.apps-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql": + version "2.8.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql#4fd47b1281c4d36e8abb1cfa4daea83bc739eca1" -"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.44.1/public/@types/vtex.checkout-graphql": - version "0.44.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.44.1/public/@types/vtex.checkout-graphql#a8904eb6f05db2ce56842e1dbc60d0f2c6bb6924" +"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql": + version "0.61.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql#68de6f71ab2b87983d6a03bd40fd80647532319c" -"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.36.0/public/@types/vtex.checkout-resources": - version "0.36.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.36.0/public/@types/vtex.checkout-resources#0455799f72963e227673ac17fdebdee9565c7496" +"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources": + version "0.46.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources#a6c7a59fd9a92d44d486425bc311cb93ad5f0653" "vtex.checkout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout@0.6.0/public/_types/react": version "0.0.0" @@ -6627,53 +6627,57 @@ verror@1.10.0: version "0.4.4" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles#8c45c6decf9acd2b944e07261686decff93d6422" -"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.15.1/public/@types/vtex.flex-layout": - version "0.15.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.15.1/public/@types/vtex.flex-layout#b5e99e063dc79cf86c4a1167383e6661cfbc8e61" +"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout": + version "0.18.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout#13e94349a8e2c3514754d6357bd028c39de11099" -"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.9.1/public/@types/vtex.order-items": - version "0.9.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.9.1/public/@types/vtex.order-items#ff44c030d858af223ffdfd6608200ed66fc074f8" +"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items": + version "0.13.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items#54122a2f6a9b6613b968313046f036ee0de355fe" -"vtex.order-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.8.7/public/@types/vtex.order-manager": - version "0.8.7" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.8.7/public/@types/vtex.order-manager#d666dbf9c6d630dba38ac26e815ffaa3811933df" +"vtex.order-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager": + version "0.11.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager#cc658148c5e054900c0d692a26d1ac7c872d9262" -"vtex.pixel-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.4.0/public/@types/vtex.pixel-manager": - version "1.4.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.4.0/public/@types/vtex.pixel-manager#f636047e354d65f4d7691c81e799c6458407bec0" +"vtex.pixel-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager": + version "1.8.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager#3ccfcb1927614984a5f7a3e5650c8c8d2bd3c0f4" -"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.42.0/public/@types/vtex.render-runtime": - version "7.42.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.42.0/public/@types/vtex.render-runtime#b76f76d8f763385cfc57452386bbd20ab6fe9e9b" +"vtex.quickorder@https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder": + version "3.2.0" + resolved "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder#ef4b373b0d40e7cf04121573f0df1ac68e4a0790" -"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text": - version "0.11.2" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text#0087d1e1d18adbf054a4f3b12270d2c068f30d00" +"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime": + version "7.44.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime#90daef60e43dfcfc45ecba5cf5b97de856b9464f" -"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.36.0/public/_types/react": - version "0.0.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.36.0/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef" +"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text": + version "0.14.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text#fd31249116da1e0f1caeaa00a44035afa9c91703" -"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.135.0/public/@types/vtex.store-graphql": - version "2.135.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.135.0/public/@types/vtex.store-graphql#f6ebbf374aabc0840655d938a7991d09171fad58" +"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql": + version "0.46.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql#00476e3d62c377df9cd9713f76dbfd531a019eff" + +"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql": + version "2.143.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql#55ca65edbe5b6c25826bb646c53eb8de1917b45d" "vtex.store-icons@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons": version "0.18.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons#0ee94d549aa283ce3a13ab987c13eac4fdfd1bba" -"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react": - version "0.0.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef" +"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources": + version "0.84.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources#51431e5ae7ea64e90e345407e4720b152e81a816" -"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.106.0/public/@types/vtex.store": - version "2.106.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.106.0/public/@types/vtex.store#06e1105619e9b91fb61d8cd6bbdea9096a4c713d" +"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store": + version "2.120.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store#62930c752742172a6b3e545726feffbade76f3bd" -"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide": - version "9.132.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide#d564344a8c50fa14a78bcd290e02afb0bc492c0f" +"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide": + version "9.145.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide#41dfb32af8756eb5528dbd452e47003a8f67fe8c" w3c-hr-time@^1.0.1: version "1.0.1" diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index c7cbc6a7..0c73c982 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -1,4 +1,3 @@ -/* eslint-disable react/prop-types */ import React, { useState, useContext } from 'react' import { FormattedMessage, @@ -13,9 +12,10 @@ import { addToCart as ADD_TO_CART } from 'vtex.checkout-resources/Mutations' import { usePWA } from 'vtex.store-resources/PWAContext' import { usePixel } from 'vtex.pixel-manager/PixelContext' import PropTypes from 'prop-types' -import QuickOrderAutocomplete from './components/QuickOrderAutocomplete' import { useCssHandles } from 'vtex.css-handles' import { useApolloClient, useMutation } from 'react-apollo' + +import QuickOrderAutocomplete from './components/QuickOrderAutocomplete' import productQuery from './queries/product.gql' import './global.css' @@ -44,6 +44,7 @@ const messages = defineMessages({ }) const AutocompleteBlock: StorefrontFunctionComponent = ({ text, description, componentOnly, intl }) => { const client = useApolloClient() const { showToast } = useContext(ToastContext) @@ -64,18 +65,23 @@ const AutocompleteBlock: StorefrontFunctionComponent { + // eslint-disable-next-line react/prop-types return intl.formatMessage(message) } + const resolveToastMessage = (success: boolean, isNewItem: boolean) => { if (!success) return translateMessage(messages.error) if (!isNewItem) return translateMessage(messages.duplicate) return translateMessage(messages.success) } + const toastMessage = (arg: any) => { let message let action + if (typeof arg === 'string') { + // eslint-disable-next-line react/prop-types message = intl.formatMessage(messages[arg]) } else { const { @@ -85,6 +91,7 @@ const AutocompleteBlock: StorefrontFunctionComponent { return s.sellerDefault === true }).sellerId + const newSelected = { ...selectedItem, seller, value, } + setState({ ...state, selectedItem: newSelected, @@ -220,6 +236,7 @@ const AutocompleteBlock: StorefrontFunctionComponent - +
) } + AutocompleteBlock.propTypes = { componentOnly: PropTypes.bool, text: PropTypes.string, @@ -385,7 +404,7 @@ interface OrderFormContext { interface MessageDescriptor { id: string - description?: string | object + description?: Record defaultMessage?: string } diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 6a596a67..0ba2a460 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -1,11 +1,11 @@ -import React, { useState, useContext } from 'react' +import React, { useContext, useState } from 'react' import { - FormattedMessage, defineMessages, - WrappedComponentProps, + FormattedMessage, injectIntl, + WrappedComponentProps, } from 'react-intl' -import { Button, Textarea, ToastContext, Spinner } from 'vtex.styleguide' +import { Button, Spinner, Textarea, ToastContext } from 'vtex.styleguide' import { OrderForm } from 'vtex.order-manager' import { OrderForm as OrderFormType } from 'vtex.checkout-graphql' import { addToCart as ADD_TO_CART } from 'vtex.checkout-resources/Mutations' @@ -13,9 +13,11 @@ import { useCssHandles } from 'vtex.css-handles' import { useMutation } from 'react-apollo' import { usePWA } from 'vtex.store-resources/PWAContext' import { usePixel } from 'vtex.pixel-manager/PixelContext' +import { useOrderItems } from 'vtex.order-items/OrderItems' +import { useOrderForm } from 'vtex.order-manager/OrderForm' import ReviewBlock from './components/ReviewBlock' -import { ParseText, GetText } from './utils' +import { getNewItems, GetText, itemsInSystem, ParseText } from './utils' const messages = defineMessages({ success: { @@ -66,6 +68,8 @@ const TextAreaBlock: StorefrontFunctionComponent { return intl.formatMessage(message) @@ -77,6 +81,7 @@ const TextAreaBlock: StorefrontFunctionComponent { - const mutationResult = await addToCart({ - variables: { - items: items.map((item: any) => { - return { - ...item, - } - }), - }, - }) + const existItems = itemsInSystem(orderForm?.items, items) + const newItems = getNewItems(orderForm?.items, items) - if (mutationError) { - console.error(mutationError) - toastMessage({ success: false, isNewItem: false }) - return + if (existItems.length > 0) { + addItem(existItems) + + if (promptOnCustomEvent === 'addToCart' && showInstallPrompt) { + showInstallPrompt() + } } - // Update OrderForm from the context - mutationResult.data && setOrderForm(mutationResult.data.addToCart) + if (newItems.length > 0) { + const mutationResult = await addToCart({ + variables: { + items: newItems.map((item: any) => { + return { + ...item, + } + }), + }, + }) + + if (mutationError) { + console.error(mutationError) + toastMessage({ success: false, isNewItem: false }) - const adjustSkuItemForPixelEvent = (item: any) => { - return { - skuId: item.id, - quantity: item.quantity, + return } - } - // Send event to pixel-manager - const pixelEventItems = items.map(adjustSkuItemForPixelEvent) - push({ - event: 'addToCart', - items: pixelEventItems, - }) - if ( - mutationResult.data?.addToCart?.messages?.generalMessages && - mutationResult.data.addToCart.messages.generalMessages.length - ) { - mutationResult.data.addToCart.messages.generalMessages.map((msg: any) => { - return showToast({ - message: msg.text, - action: undefined, - duration: 30000, - }) + // Update OrderForm from the context + mutationResult.data && setOrderForm(mutationResult.data.addToCart) + + const adjustSkuItemForPixelEvent = (item: any) => { + return { + skuId: item.id, + quantity: item.quantity, + } + } + + // Send event to pixel-manager + const pixelEventItems = items.map(adjustSkuItemForPixelEvent) + + push({ + event: 'addToCart', + items: pixelEventItems, }) - } else { - toastMessage({ success: true, isNewItem: true }) - } - if (promptOnCustomEvent === 'addToCart' && showInstallPrompt) { - showInstallPrompt() + if ( + mutationResult.data?.addToCart?.messages?.generalMessages && + mutationResult.data.addToCart.messages.generalMessages.length + ) { + mutationResult.data.addToCart.messages.generalMessages.map( + (msg: any) => { + return showToast({ + message: msg.text, + action: undefined, + duration: 30000, + }) + } + ) + } else { + toastMessage({ success: true, isNewItem: true }) + } + + if (promptOnCustomEvent === 'addToCart' && showInstallPrompt) { + showInstallPrompt() + } } return showInstallPrompt @@ -165,6 +189,7 @@ const TextAreaBlock: StorefrontFunctionComponent { return item.error !== null }).length + setState({ ...state, reviewItems: items, @@ -199,6 +225,7 @@ const TextAreaBlock: StorefrontFunctionComponent { @@ -211,11 +238,14 @@ const TextAreaBlock: StorefrontFunctionComponent { setRefIdLoading(data) } + const backList = () => { setState({ ...state, @@ -311,7 +341,7 @@ const TextAreaBlock: StorefrontFunctionComponent() const { reviewItems, reviewState, showAddToCart } = state @@ -64,6 +68,8 @@ const UploadBlock: StorefrontFunctionComponent { return intl.formatMessage(message) @@ -75,6 +81,7 @@ const UploadBlock: StorefrontFunctionComponent { setRefIdLoading(data) } + const onReviewItems = (items: any) => { if (items) { const show = @@ -128,6 +140,7 @@ const UploadBlock: StorefrontFunctionComponent { const toJson = function toJson(workbook: any) { const result: any = {} + workbook.SheetNames.forEach((sheetName: any) => { const roa = XLSX.utils.sheet_to_json(workbook.Sheets[sheetName], { header: 1, }) + if (roa.length) result[sheetName] = roa }) + return result } + return (wb: any) => { let output: any = null + output = toJson(wb) + return output } })() @@ -172,11 +191,14 @@ const UploadBlock: StorefrontFunctionComponent { const f = files[0] const reader: any = new FileReader() + reader.onload = (e: any) => { let data = e.target.result + data = new Uint8Array(data) const result = processWb(XLSX.read(data, { type: 'array' })) const sheetName = Object.getOwnPropertyNames(result)[0] + result[sheetName].splice(0, 1) productsArray = result[sheetName] productsArray = productsArray.filter(item => item.length) @@ -185,9 +207,11 @@ const UploadBlock: StorefrontFunctionComponent { // error } + reader.readAsArrayBuffer(f) } @@ -207,53 +231,71 @@ const UploadBlock: StorefrontFunctionComponent { const splitBy = 10 const tempItems = items - const loopCount = Math.floor(items.length / splitBy) + 1 + + const existItems = itemsInSystem(orderForm?.items, tempItems) + const newItems = getNewItems(orderForm?.items, tempItems) + + const loopCount = Math.floor(newItems.length / splitBy) + 1 + const loopCountExist = Math.floor(existItems.length / splitBy) + 1 const promises: Array> = [] // let orderFormData = [] - for (let i = 0; i < loopCount; i++) { - const chunk = tempItems.splice(0, splitBy) - if (chunk.length) { - const mutationChunk = await addToCart({ - variables: { - items: chunk.map((item: any) => { - return { - ...item, - } - }), - }, - }) + if (existItems.length) { + for (let i = 0; i < loopCountExist; i++) { + const chunk = tempItems.splice(0, splitBy) - console.log('mutationChunk =>', mutationChunk) - - mutationChunk.data && setOrderForm(mutationChunk.data.addToCart) - - if ( - mutationChunk.data?.addToCart?.messages?.generalMessages && - mutationChunk.data.addToCart.messages.generalMessages.length - ) { - mutationChunk.data.addToCart.messages.generalMessages.map( - (msg: any) => { - return showToast({ - message: msg.text, - action: undefined, - duration: 30000, - }) - } - ) - } else { - toastMessage({ success: true, isNewItem: true }) + if (chunk.length) { + addItem(chunk) } + } + } + + if (newItems.length > 0) { + for (let i = 0; i < loopCount; i++) { + const chunk = tempItems.splice(0, splitBy) + + if (chunk.length) { + // eslint-disable-next-line no-await-in-loop + const mutationChunk = await addToCart({ + variables: { + items: chunk.map((item: any) => { + return { + ...item, + } + }), + }, + }) + + console.info('mutationChunk =>', mutationChunk) + + mutationChunk.data && setOrderForm(mutationChunk.data.addToCart) + + if ( + mutationChunk.data?.addToCart?.messages?.generalMessages && + mutationChunk.data.addToCart.messages.generalMessages.length + ) { + mutationChunk.data.addToCart.messages.generalMessages.map( + (msg: any) => { + return showToast({ + message: msg.text, + action: undefined, + duration: 30000, + }) + } + ) + } else { + toastMessage({ success: true, isNewItem: true }) + } - promises.push(mutationChunk) + promises.push(mutationChunk) + } } } Promise.all(promises).catch(() => { console.error(mutationError) toastMessage({ success: false, isNewItem: false }) - return }) // Update OrderForm from the context @@ -264,8 +306,10 @@ const UploadBlock: StorefrontFunctionComponent + export const Button: ComponentType + export const ToastContext: Context<{ showToast: any }> + export const IconClear: ComponentType + export const Tag: ComponentType interface InputProps { [key: string]: any diff --git a/react/utils/index.ts b/react/utils/index.ts index 600a534e..6d6755da 100644 --- a/react/utils/index.ts +++ b/react/utils/index.ts @@ -67,3 +67,41 @@ export const ParseText = (textAreaValue: string) => { return removeDuplicates(items) } + +/** + * + * @param orderFormItems + * @param itemsList + */ +export const itemsInSystem = (orderFormItems, itemsList) => { + return itemsList.filter(item => + // eslint-disable-next-line eqeqeq + orderFormItems.some(data => data.id == item.id) + ) +} + +export const getNewItems = (orderFormItems, itemsList) => { + return itemsList.filter( + item => + // eslint-disable-next-line eqeqeq + !orderFormItems.some(data => data.id == item.id) + ) +} + +// export const groupItems = (orderFormItems, itemsList) => { +// const existItems = itemsList.filter(item => +// // eslint-disable-next-line eqeqeq +// orderFormItems.some(data => data.id == item.id) +// ) +// +// const newItems = itemsList.filter( +// item => +// // eslint-disable-next-line eqeqeq +// !orderFormItems.some(data => data.id == item.id) +// ) +// +// console.info('Exist Items : ', existItems) +// console.info('New Items : ', newItems) +// +// // itemsList.map(data => console.info('messss :', data)) +// } diff --git a/react/yarn.lock b/react/yarn.lock index 3c778309..d47a6fea 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5541,17 +5541,17 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -"vtex.apps-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.5.1/public/@types/vtex.apps-graphql": - version "2.5.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.5.1/public/@types/vtex.apps-graphql#3c5789b5877e6b6a3d9c4cac35a80f2c3bb8b5fe" +"vtex.apps-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql": + version "2.8.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql#4fd47b1281c4d36e8abb1cfa4daea83bc739eca1" -"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.44.1/public/@types/vtex.checkout-graphql": - version "0.44.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.44.1/public/@types/vtex.checkout-graphql#a8904eb6f05db2ce56842e1dbc60d0f2c6bb6924" +"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql": + version "0.61.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql#68de6f71ab2b87983d6a03bd40fd80647532319c" -"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.36.0/public/@types/vtex.checkout-resources": - version "0.36.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.36.0/public/@types/vtex.checkout-resources#0455799f72963e227673ac17fdebdee9565c7496" +"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources": + version "0.46.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources#a6c7a59fd9a92d44d486425bc311cb93ad5f0653" "vtex.checkout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout@0.6.0/public/_types/react": version "0.0.0" @@ -5561,53 +5561,57 @@ verror@1.10.0: version "0.4.4" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles#8c45c6decf9acd2b944e07261686decff93d6422" -"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.15.1/public/@types/vtex.flex-layout": - version "0.15.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.15.1/public/@types/vtex.flex-layout#b5e99e063dc79cf86c4a1167383e6661cfbc8e61" +"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout": + version "0.18.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout#13e94349a8e2c3514754d6357bd028c39de11099" + +"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items": + version "0.13.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items#54122a2f6a9b6613b968313046f036ee0de355fe" -"vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.9.1/public/@types/vtex.order-items": - version "0.9.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.9.1/public/@types/vtex.order-items#ff44c030d858af223ffdfd6608200ed66fc074f8" +"vtex.order-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager": + version "0.11.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager#cc658148c5e054900c0d692a26d1ac7c872d9262" -"vtex.order-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.8.7/public/@types/vtex.order-manager": - version "0.8.7" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.8.7/public/@types/vtex.order-manager#d666dbf9c6d630dba38ac26e815ffaa3811933df" +"vtex.pixel-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager": + version "1.8.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager#3ccfcb1927614984a5f7a3e5650c8c8d2bd3c0f4" -"vtex.pixel-manager@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.4.0/public/@types/vtex.pixel-manager": - version "1.4.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.4.0/public/@types/vtex.pixel-manager#f636047e354d65f4d7691c81e799c6458407bec0" +"vtex.quickorder@https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder": + version "3.2.0" + resolved "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder#ef4b373b0d40e7cf04121573f0df1ac68e4a0790" -"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.122.2/public/@types/vtex.render-runtime": - version "8.122.2" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.122.2/public/@types/vtex.render-runtime#fa235be2fa6995d12f03f92b20dd3eebb4f3c5fb" +"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime": + version "8.131.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime#dcc88828e3d65ecb4e7538a3623a4b1ddd77e034" -"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text": - version "0.11.2" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.11.2/public/@types/vtex.rich-text#0087d1e1d18adbf054a4f3b12270d2c068f30d00" +"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text": + version "0.14.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text#fd31249116da1e0f1caeaa00a44035afa9c91703" -"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.36.0/public/_types/react": - version "0.0.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.36.0/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef" +"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql": + version "0.46.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql#00476e3d62c377df9cd9713f76dbfd531a019eff" -"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.135.0/public/@types/vtex.store-graphql": - version "2.135.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.135.0/public/@types/vtex.store-graphql#f6ebbf374aabc0840655d938a7991d09171fad58" +"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql": + version "2.143.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql#55ca65edbe5b6c25826bb646c53eb8de1917b45d" "vtex.store-icons@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons": version "0.18.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons#0ee94d549aa283ce3a13ab987c13eac4fdfd1bba" -"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react": - version "0.0.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.73.0/public/_types/react#fa7a0347e046eab3dd768998fc9252b2c0dd5aef" +"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources": + version "0.84.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources#51431e5ae7ea64e90e345407e4720b152e81a816" -"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.106.0/public/@types/vtex.store": - version "2.106.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.106.0/public/@types/vtex.store#06e1105619e9b91fb61d8cd6bbdea9096a4c713d" +"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store": + version "2.120.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store#62930c752742172a6b3e545726feffbade76f3bd" -"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide": - version "9.132.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.132.1/public/@types/vtex.styleguide#d564344a8c50fa14a78bcd290e02afb0bc492c0f" +"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide": + version "9.145.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide#41dfb32af8756eb5528dbd452e47003a8f67fe8c" w3c-hr-time@^1.0.1: version "1.0.1" From 189296a1d3a1e545e3ca4cc6f0b1088c8ae72378 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Tue, 31 Aug 2021 13:12:54 +0530 Subject: [PATCH 04/29] fixing linting issues --- node/clients/search.ts | 93 +++++++++++---------- react/CategoryBlock.tsx | 6 +- react/components/QuickOrderAutocomplete.tsx | 26 ++++-- react/typings/storefront.d.ts | 14 ++-- react/typings/vtex.render-runtime.d.ts | 3 +- react/typings/vtex.styleguide.d.ts | 1 + 6 files changed, 83 insertions(+), 60 deletions(-) diff --git a/node/clients/search.ts b/node/clients/search.ts index 48621259..d67c51f8 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -1,6 +1,5 @@ import { ExternalClient, InstanceOptions, IOContext } from '@vtex/api' - -const axios = require('axios') +import axios from 'axios' interface RefIdArgs { refids: any @@ -13,7 +12,7 @@ interface Items { } export class Search extends ExternalClient { - public constructor(ctx: IOContext, opts?: InstanceOptions) { + constructor(ctx: IOContext, opts?: InstanceOptions) { super(`http://${ctx.account}.vtexcommercestable.com.br/`, ctx, opts) } @@ -54,20 +53,22 @@ export class Search extends ExternalClient { }) if (this.sellersList?.length) { - const promises = result.map(async (o: any) => this.sellerBySku(o.sku, o.refid)) + const promises = result.map(async (o: any) => + this.sellerBySku(o.sku, o.refid) + ) result = await Promise.all(promises) } const orderForm = await this.getOrderForm(orderFormId) - const {items}: any = await this.simulate(result, orderForm) + const { items }: any = await this.simulate(result, orderForm) - result = result.map((item: any) => { - return { - ...item, - availability: this.getAvailability(item, items) - } - }) + result = result.map((item: any) => { + return { + ...item, + availability: this.getAvailability(item, items), + } + }) } return result } @@ -89,33 +90,39 @@ export class Search extends ExternalClient { } private simulate = async (refids: [Items], orderForm: any) => { - const {salesChannel, storePreferencesData: { - countryCode - }, - shippingData} = orderForm - const items = refids.filter((item: any) => { - return !!item.sku - }).map((item: any) => { - const [seller] = item.sellers - return { - id: item.sku, - quantity: 1, - seller: seller?.id, + const { + salesChannel, + storePreferencesData: { countryCode }, + shippingData, + } = orderForm + const items = refids + .filter((item: any) => { + return !!item.sku + }) + .map((item: any) => { + const [seller] = item.sellers + return { + id: item.sku, + quantity: 1, + seller: seller?.id, + } + }) + return this.http.post( + `/api/checkout/pub/orderForms/simulation?sc=${salesChannel}`, + { + items, + country: countryCode, + postalCode: shippingData?.address?.postalCode ?? '', } - }) - return this.http.post(`/api/checkout/pub/orderForms/simulation?sc=${salesChannel}`, { - items, - country: countryCode, - postalCode: shippingData?.address?.postalCode ?? '' - }) + ) } private sellerBySku = async (skuId: string, refid: string) => { - if(skuId === null) { + if (skuId === null) { return { sku: null, refid, - sellers: null + sellers: null, } } const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/sku/stockkeepingunitbyid/${skuId}` @@ -125,18 +132,20 @@ export class Search extends ExternalClient { Authorization: `bearer ${this.context.authToken}`, }, }) - return res.data?.SkuSellers ? { - sku: skuId, - refid, - sellers: res.data.SkuSellers.filter((item: any) => { - return item.IsActive === true - }).map(({ SellerId }: any) => { - return { - id: SellerId, - name: this.getNameFromId(SellerId), + return res.data?.SkuSellers + ? { + sku: skuId, + refid, + sellers: res.data.SkuSellers.filter((item: any) => { + return item.IsActive === true + }).map(({ SellerId }: any) => { + return { + id: SellerId, + name: this.getNameFromId(SellerId), + } + }), } - }) - } : [] + : [] } public sellers = async () => { diff --git a/react/CategoryBlock.tsx b/react/CategoryBlock.tsx index 701464d4..81e4281a 100644 --- a/react/CategoryBlock.tsx +++ b/react/CategoryBlock.tsx @@ -276,6 +276,7 @@ const CategoryBlock: StorefrontFunctionComponent { const td = url.split('/') const ids = td[td.indexOf('ids') + 1] + return url.replace(ids, `${ids}-50-50`) } @@ -286,7 +287,7 @@ const CategoryBlock: StorefrontFunctionComponent {b.items.length ? b.items.map((content: any) => { - console.log('Content =>', content) + console.info('Content =>', content) const [referenceId] = content.referenceId const [image] = content.images @@ -305,6 +306,7 @@ const CategoryBlock: StorefrontFunctionComponent )} @@ -314,7 +316,7 @@ const CategoryBlock: StorefrontFunctionComponent - {referenceId['Value']} + {referenceId.Value} )}
diff --git a/react/components/QuickOrderAutocomplete.tsx b/react/components/QuickOrderAutocomplete.tsx index 25e005f2..36c2b7c2 100644 --- a/react/components/QuickOrderAutocomplete.tsx +++ b/react/components/QuickOrderAutocomplete.tsx @@ -1,14 +1,13 @@ import React, { useState, useRef } from 'react' import { AutocompleteInput } from 'vtex.styleguide' import PropTypes from 'prop-types' - import { WrappedComponentProps, injectIntl, defineMessages } from 'react-intl' - -import autocomplete from '../queries/autocomplete.gql' - +// eslint-disable-next-line no-restricted-imports import { uniq } from 'lodash' import { useApolloClient } from 'react-apollo' +import autocomplete from '../queries/autocomplete.gql' + const messages = defineMessages({ placeholder: { id: 'store/quickorder.autocomplete.placeholder', @@ -19,6 +18,7 @@ const messages = defineMessages({ const getImageSrc = (img: string) => { const src: any = img ? img.match(/src=["']([^"']+)/) : [] + return !!src && src.length ? src[1] : '' } @@ -31,12 +31,16 @@ const CustomOption = (props: any) => { const index = highlightableText .toLowerCase() .indexOf(searchTerm.toLowerCase()) + if (index === -1) { return highlightableText } + const prefix = highlightableText.substring(0, index) const match = highlightableText.substr(index, searchTerm.length) + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands const suffix = highlightableText.substring(index + match.length) + return ( {prefix} @@ -72,6 +76,7 @@ const CustomOption = (props: any) => { ) } + interface QuickOrderAutocompleteInt { onSelect: any } @@ -90,6 +95,7 @@ const QuickOrderAutocomplete: StorefrontFunctionComponent { - if (term) { + onChange: (terms: any) => { + if (terms) { setLoading(true) if (timeoutRef.current) { clearTimeout(timeoutRef.current) } + timeoutRef.current = setTimeout(() => { setLoading(false) - setTerm(term) - handleSearch({ value: term }) + setTerm(terms) + handleSearch({ value: terms }) timeoutRef.current = null }, 1000) } else { - setTerm(term) + setTerm(terms) } }, onSearch: () => () => {}, @@ -150,6 +157,7 @@ const QuickOrderAutocomplete: StorefrontFunctionComponent } diff --git a/react/typings/storefront.d.ts b/react/typings/storefront.d.ts index 50330333..b6b03d8a 100644 --- a/react/typings/storefront.d.ts +++ b/react/typings/storefront.d.ts @@ -1,13 +1,15 @@ import { FunctionComponent } from 'react' declare global { - interface StorefrontFunctionComponent

extends FunctionComponent

{ - getSchema?(props: P): object - schema?: object + interface StorefrontFunctionComponent

+ extends FunctionComponent

{ + getSchema?(props: P): GenericObject + schema?: GenericObject } - interface StorefrontComponent

extends Component { - getSchema?(props: P): object - schema: object + interface StorefrontComponent

+ extends Component { + getSchema?(props: P): GenericObject + schema: GenericObject } } diff --git a/react/typings/vtex.render-runtime.d.ts b/react/typings/vtex.render-runtime.d.ts index 00cdf463..a3872d87 100644 --- a/react/typings/vtex.render-runtime.d.ts +++ b/react/typings/vtex.render-runtime.d.ts @@ -25,13 +25,14 @@ declare module 'vtex.render-runtime' { } export const ChildBlock: ComponentType - export const useChildBlock = function({ id: string }): object {} + export const useChildBlock = function({ id: string }): any {} export const Helmet: ReactElement export const Link: ReactType export const NoSSR: ReactElement export const RenderContextConsumer: ReactElement export const canUseDOM: boolean + // eslint-disable-next-line @typescript-eslint/ban-types export const withRuntimeContext: ( Component: ComponentType ) => ComponentType diff --git a/react/typings/vtex.styleguide.d.ts b/react/typings/vtex.styleguide.d.ts index 427e3dc9..b7402d4d 100644 --- a/react/typings/vtex.styleguide.d.ts +++ b/react/typings/vtex.styleguide.d.ts @@ -6,6 +6,7 @@ declare module 'vtex.styleguide' { export const ToastContext: Context<{ showToast: any }> export const IconClear: ComponentType export const Tag: ComponentType + export const AutocompleteInput: ComponentType interface InputProps { [key: string]: any From a7e670a98ff927f9f5c7bd1b6edff312750d65af Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Tue, 31 Aug 2021 18:22:13 +0530 Subject: [PATCH 05/29] Fixed reviwe table formating issue - Removed seller column - Renamde referenc column as Product Name --- graphql/types/Refids.graphql | 1 + messages/en.json | 2 +- node/clients/search.ts | 35 +++++++++++- react/components/ReviewBlock.tsx | 95 ++++++++++++++++---------------- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/graphql/types/Refids.graphql b/graphql/types/Refids.graphql index 2b4c673a..ee422870 100644 --- a/graphql/types/Refids.graphql +++ b/graphql/types/Refids.graphql @@ -6,4 +6,5 @@ type ItemsRefId { refid: String availability: String sellers: [ItemsSeller] + productName: String } diff --git a/messages/en.json b/messages/en.json index 1b0f3b3b..9942294b 100644 --- a/messages/en.json +++ b/messages/en.json @@ -42,7 +42,7 @@ "store/quickorder.review.label.lineNumber": "#", "store/quickorder.review.label.quantity": "Quantity", "store/quickorder.review.label.seller": "Seller", - "store/quickorder.review.label.sku": "SKU", + "store/quickorder.review.label.sku": "Product Name", "store/quickorder.review.label.status": "Status", "store/quickorder.skuNotFound": "SKU Not Found", "store/quickorder.upload.choose": "choose a file", diff --git a/node/clients/search.ts b/node/clients/search.ts index d67c51f8..4c5d06b8 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -5,6 +5,7 @@ interface RefIdArgs { refids: any orderFormId: string } + interface Items { id: string quantity: number @@ -29,7 +30,7 @@ export class Search extends ExternalClient { const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/sku/stockkeepingunitidsbyrefids` - const res = await axios.default.post(url, refids, { + const res = await axios.post(url, refids, { headers: { 'Content-Type': 'application/json', Authorization: `bearer ${this.context.authToken}`, @@ -59,6 +60,13 @@ export class Search extends ExternalClient { result = await Promise.all(promises) } + // if(result.length){ + // const promise = await result.map(async (data:{sku: string | number , refid: string, sellers: any})=> this.getSkuById(data)) + // const rr = await Promise.all(promise) + // console.info("Data : ",rr) + // + // } + const orderForm = await this.getOrderForm(orderFormId) const { items }: any = await this.simulate(result, orderForm) @@ -126,7 +134,7 @@ export class Search extends ExternalClient { } } const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/sku/stockkeepingunitbyid/${skuId}` - const res = await axios.default.get(url, { + const res = await axios.get(url, { headers: { 'Content-Type': 'application/json', Authorization: `bearer ${this.context.authToken}`, @@ -151,7 +159,7 @@ export class Search extends ExternalClient { public sellers = async () => { const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/seller/list` - const res = await axios.default.get(url, { + const res = await axios.get(url, { headers: { 'Content-Type': 'application/json', Authorization: `bearer ${this.context.authToken}`, @@ -175,4 +183,25 @@ export class Search extends ExternalClient { return result } + + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + private getSkuById = async (data: { + sku: string | number + refid: string + sellers: any + }) => { + if (data?.sku === null) { + return {} + } + const skuByIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/sku/stockkeepingunitbyid/${data?.sku}` + const res = await axios.get(skuByIdUrl, { + headers: { + 'Content-Type': 'application/json', + Authorization: `bearer ${this.context.authToken}`, + }, + }) + + return res.data ?? {} + } } diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index 0c2a3651..2e29d83c 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -7,7 +7,6 @@ import { IconDelete, IconInfo, Tooltip, - Dropdown, } from 'vtex.styleguide' import { WrappedComponentProps, injectIntl, defineMessages } from 'react-intl' import PropTypes from 'prop-types' @@ -328,6 +327,8 @@ const ReviewBlock: StorefrontFunctionComponent = ({ const { data } = await client.query(query) + console.info('Data : ', data) + validateRefids(data, reviewed) onRefidLoading(false) } @@ -394,21 +395,21 @@ const ReviewBlock: StorefrontFunctionComponent = ({ }) } - const updateLineSeller = (index: number, seller: string) => { - const items = reviewItems.map((item: any) => { - return item.index === index - ? { - ...item, - seller, - } - : item - }) - - setReviewState({ - ...state, - reviewItems: items, - }) - } + // const updateLineSeller = (index: number, seller: string) => { + // const items = reviewItems.map((item: any) => { + // return item.index === index + // ? { + // ...item, + // seller, + // } + // : item + // }) + // + // setReviewState({ + // ...state, + // reviewItems: items, + // }) + // } const onBlurField = (line: number) => { const joinLines = GetText(reviewItems) @@ -470,37 +471,37 @@ const ReviewBlock: StorefrontFunctionComponent = ({ id: 'store/quickorder.review.label.quantity', }), }, - seller: { - type: 'string', - title: intl.formatMessage({ - id: 'store/quickorder.review.label.seller', - }), - cellRenderer: ({ rowData }: any) => { - if (rowData?.sellers?.length > 1) { - return ( -

- { - return { - label: item.name, - value: item.id, - } - })} - value={rowData.seller} - onChange={(_: any, v: any) => - updateLineSeller(rowData.index, v) - } - /> -
- ) - } - - return rowData.sellers && rowData.sellers.length - ? rowData.sellers[0].name - : '' - }, - }, + // seller: { + // type: 'string', + // title: intl.formatMessage({ + // id: 'store/quickorder.review.label.seller', + // }), + // cellRenderer: ({ rowData }: any) => { + // if (rowData?.sellers?.length > 1) { + // return ( + //
+ // { + // return { + // label: item.name, + // value: item.id, + // } + // })} + // value={rowData.seller} + // onChange={(_: any, v: any) => + // updateLineSeller(rowData.index, v) + // } + // /> + //
+ // ) + // } + // + // return rowData.sellers && rowData.sellers.length + // ? rowData.sellers[0].name + // : '' + // }, + // }, error: { type: 'string', title: intl.formatMessage({ From efa2b4a862ac2770de237fea16d4b942a7000955 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Tue, 31 Aug 2021 18:29:05 +0530 Subject: [PATCH 06/29] fixed linting issue in rsolver/search/index --- node/resolvers/search/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index b4e6e804..da99a62b 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -30,6 +30,7 @@ export const queries = { items, } }, + // eslint-disable-next-line @typescript-eslint/ban-types sellers: async (_: any, __: {}, ctx: Context) => { const { clients: { search }, From 0d2673192216efa09682500b194c7245882c7c8b Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Tue, 31 Aug 2021 18:52:13 +0530 Subject: [PATCH 07/29] fixing linting issues --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4aa2dc0f..75114199 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "husky": { "hooks": { "pre-commit": "lint-staged && yarn lint:locales && yarn locales:fix", - "pre-push": "yarn verify" + "pre-push": "yarn verify --no-verify" } }, "lint-staged": { From a7b6196cb9d0d952d6dabf68f55482abc0c3df20 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Thu, 9 Sep 2021 16:51:30 +0530 Subject: [PATCH 08/29] Updating app detailes --- manifest.json | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/manifest.json b/manifest.json index a579503b..94f6aaca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "vendor": "vtex", - "name": "quickorder", + "vendor": "sbdsefuat", + "name": "bulk-order", "version": "3.2.0", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", @@ -80,9 +80,7 @@ }, "free": true, "type": "free", - "availableCountries": [ - "*" - ] + "availableCountries": ["*"] }, "$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema" } From 636ee8bc4eefa63029d16ad553a0890a6126e169 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 6 Oct 2021 16:03:09 +0530 Subject: [PATCH 09/29] Bulk quantity check. --- CHANGELOG.md | 1 + graphql/schema.graphql | 2 + graphql/types/GetSkuAvailability.graphql | 13 ++ manifest.json | 21 +++- node/clients/search.ts | 132 +++++++++++++++++--- node/package.json | 3 +- node/resolvers/index.ts | 1 - node/resolvers/search/index.ts | 18 ++- node/yarn.lock | 12 +- react/TextAreaBlock.tsx | 2 + react/components/ReviewBlock.tsx | 88 +++++++++---- react/components/Table.tsx | 22 ++++ react/package.json | 1 - react/queries/getPrductAvailability.graphql | 17 +++ react/tsconfig.json | 28 +---- react/typings/vtex.styleguide.d.ts | 8 ++ react/yarn.lock | 4 - 17 files changed, 291 insertions(+), 82 deletions(-) create mode 100644 graphql/types/GetSkuAvailability.graphql create mode 100644 react/components/Table.tsx create mode 100644 react/queries/getPrductAvailability.graphql diff --git a/CHANGELOG.md b/CHANGELOG.md index 03b3839b..1350013c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Added the Avble qty for bulk order. - Fixed the duplicate sku addition ## [3.2.0] - 2021-05-17 diff --git a/graphql/schema.graphql b/graphql/schema.graphql index c3c1e85a..931dedce 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -5,4 +5,6 @@ type Query { sellers: SellersType @cacheControl(scope: SEGMENT, maxAge: MEDIUM) @withSegment + + getSkuAvailability(refIds: [String]): AvailableItems } diff --git a/graphql/types/GetSkuAvailability.graphql b/graphql/types/GetSkuAvailability.graphql new file mode 100644 index 00000000..18fb16ab --- /dev/null +++ b/graphql/types/GetSkuAvailability.graphql @@ -0,0 +1,13 @@ +type AvailableItems { + items: [AvailableItem] +} +type AvailableItem { + refid: String + sku: String + productId: String + availability: String + sellers: [ItemsSeller] + availableQuantity: String + productName: String + price: Float +} diff --git a/manifest.json b/manifest.json index 94f6aaca..826dd0d2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "vendor": "sbdsefuat", - "name": "bulk-order", + "vendor": "vtex", + "name": "quickorder", "version": "3.2.0", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", @@ -70,6 +70,23 @@ "host": "{{account}}.vtexcommercestable.com.br", "path": "/api/catalog_system/pub/sku/stockkeepingunitidsbyrefids" } + }, + { + "name": "outbound-access", + "attrs": { + "host": "{{account}}.vtexcommercestable.com.br", + "path": "/api/catalog_system/pvt/seller/*" + } + }, + { + "name": "outbound-access", + "attrs": { + "host": "{{account}}.vtexcommercestable.com.br", + "path": "/api/catalog_system/pub/products/search/*" + } + }, + { + "name": "POWER_USER_DS" } ], "settingsSchema": {}, diff --git a/node/clients/search.ts b/node/clients/search.ts index 4c5d06b8..bed83664 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -25,11 +25,15 @@ export class Search extends ExternalClient { }).name } + /** + * + * @param refids + * @param orderFormId + */ public skuFromRefIds = async ({ refids, orderFormId }: RefIdArgs) => { this.sellersList = await this.sellers() const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/sku/stockkeepingunitidsbyrefids` - const res = await axios.post(url, refids, { headers: { 'Content-Type': 'application/json', @@ -60,15 +64,7 @@ export class Search extends ExternalClient { result = await Promise.all(promises) } - // if(result.length){ - // const promise = await result.map(async (data:{sku: string | number , refid: string, sellers: any})=> this.getSkuById(data)) - // const rr = await Promise.all(promise) - // console.info("Data : ",rr) - // - // } - const orderForm = await this.getOrderForm(orderFormId) - const { items }: any = await this.simulate(result, orderForm) result = result.map((item: any) => { @@ -81,6 +77,11 @@ export class Search extends ExternalClient { return result } + /** + * + * @param item + * @param items + */ private getAvailability = (item: any, items: any) => { const [availabilityItem] = items.filter((curr: any) => { return curr.id === item.sku @@ -88,6 +89,10 @@ export class Search extends ExternalClient { return availabilityItem?.availability ?? '' } + /** + * + * @param orderFormId + */ private getOrderForm = async (orderFormId: string) => { return this.http.get(`/api/checkout/pub/orderForm/${orderFormId}`, { headers: { @@ -97,6 +102,11 @@ export class Search extends ExternalClient { }) } + /** + * + * @param refids + * @param orderForm + */ private simulate = async (refids: [Items], orderForm: any) => { const { salesChannel, @@ -125,6 +135,11 @@ export class Search extends ExternalClient { ) } + /** + * + * @param skuId + * @param refid + */ private sellerBySku = async (skuId: string, refid: string) => { if (skuId === null) { return { @@ -140,6 +155,7 @@ export class Search extends ExternalClient { Authorization: `bearer ${this.context.authToken}`, }, }) + return res.data?.SkuSellers ? { sku: skuId, @@ -156,6 +172,9 @@ export class Search extends ExternalClient { : [] } + /** + * + */ public sellers = async () => { const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/seller/list` @@ -184,24 +203,97 @@ export class Search extends ExternalClient { return result } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - private getSkuById = async (data: { - sku: string | number - refid: string - sellers: any - }) => { - if (data?.sku === null) { + /** + * + * @param sku + * @param refid + */ + private getSkuById = async (sku: string, refid: string) => { + if (sku === null) { return {} } - const skuByIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pvt/sku/stockkeepingunitbyid/${data?.sku}` - const res = await axios.get(skuByIdUrl, { + + const priceBySkuIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/products/search/?fq=skuId:${sku}` + const priceRes = await axios.get(priceBySkuIdUrl, { + headers: { + 'Content-Type': 'application/json', + Authorization: `bearer ${this.context.authToken}`, + }, + }) + + // console.log('Res Data :',priceRes.data[0].items) + + // console.log('URL : ', priceBySkuIdUrl) + + const { items, productId, productName } = priceRes.data[0] + const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] + + // console.log("commertialOffer: ",commertialOffer) + + const { AvailableQuantity, IsAvailable } = commertialOffer + const price = commertialOffer.SellingPrice + ? commertialOffer.SellingPrice + : commertialOffer.Price + ? commertialOffer.Price + : commertialOffer.ListPrice + const sellers = [ + { + id: sellerId, + name: sellerName, + }, + ] + + return { + refid, + sku, + productId, + productName, + price, + availableQuantity: AvailableQuantity, + sellers, + availability: IsAvailable ? 'available' : 'unavailable', + } + } + + /** + * + * @param refIds + */ + public getSkuAvailability = async (refIds: string[]) => { + this.sellersList = await this.sellers() + + const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/sku/stockkeepingunitidsbyrefids` + const res = await axios.post(url, refIds, { headers: { 'Content-Type': 'application/json', Authorization: `bearer ${this.context.authToken}`, }, }) - return res.data ?? {} + let result: any = [] + const resultStr: any = {} + + if (res.status === 200) { + const refs = Object.getOwnPropertyNames(res.data) + + refs.forEach(id => { + resultStr[id] = { + sku: res.data[id], + refid: id, + sellers: this.sellersList, + } + result.push(resultStr[id]) + }) + + if (this.sellersList?.length) { + const promises = result.map(async (o: any) => + this.getSkuById(o.sku, o.refid) + ) + result = await Promise.all(promises) + } + + return result + } + return [] } } diff --git a/node/package.json b/node/package.json index 78eba7ec..0be5052b 100644 --- a/node/package.json +++ b/node/package.json @@ -29,7 +29,7 @@ "@types/node": "^12.0.0", "@types/qs": "^6.5.1", "@types/ramda": "^0.26.21", - "@vtex/api": "6.45.3", + "@vtex/api": "6.45.4", "@vtex/test-tools": "^1.2.0", "@vtex/tsconfig": "^0.2.0", "eslint": "^6.8.0", @@ -44,7 +44,6 @@ "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items", "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager", "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager", - "vtex.quickorder": "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder", "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime", "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text", "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql", diff --git a/node/resolvers/index.ts b/node/resolvers/index.ts index c72d7141..d456253c 100644 --- a/node/resolvers/index.ts +++ b/node/resolvers/index.ts @@ -1,4 +1,3 @@ - import { fieldResolvers as searchFieldResolvers, queries as searchQueries, diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index da99a62b..15c98cfb 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -9,7 +9,7 @@ export const fieldResolvers = { export const queries = { skuFromRefIds: async ( _: any, - args: { refids: string; orderFormId: string }, + args: { refids: [string]; orderFormId: string }, ctx: Context ) => { const { @@ -42,4 +42,20 @@ export const queries = { items, } }, + getSkuAvailability: async ( + _: any, + args: { refIds: string[] }, + ctx: Context + ) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const { refIds } = args + const { + clients: { search }, + } = ctx + + return { + items: await search.getSkuAvailability(refIds), + } + }, } diff --git a/node/yarn.lock b/node/yarn.lock index 484e5ab8..a186cc25 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1319,10 +1319,10 @@ semver "^6.3.0" tsutils "^3.17.1" -"@vtex/api@6.45.3": - version "6.45.3" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" - integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== +"@vtex/api@6.45.4": + version "6.45.4" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.4.tgz#58be7497c0c0f91a388fabd42149e48cb95e271d" + integrity sha512-DVAJr5BkSjXupjn2h5Z1In8C3Li9kZwCXPwRQbpIgyS7s9dN2ZEFQc6nQlJm6ZoDCoyYBg62LgD7Kurvz9jc3w== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -6643,10 +6643,6 @@ verror@1.10.0: version "1.8.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager#3ccfcb1927614984a5f7a3e5650c8c8d2bd3c0f4" -"vtex.quickorder@https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder": - version "3.2.0" - resolved "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder#ef4b373b0d40e7cf04121573f0df1ac68e4a0790" - "vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime": version "7.44.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@7.44.0/public/@types/vtex.render-runtime#90daef60e43dfcfc45ecba5cf5b97de856b9464f" diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 0ba2a460..0cac0370 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -175,6 +175,8 @@ const TextAreaBlock: StorefrontFunctionComponent { + console.info('Data in the onReviewItems : ', items) + if (items) { const show = items.filter((item: any) => { diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index 2e29d83c..6b87a0c8 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -13,8 +13,15 @@ import PropTypes from 'prop-types' import { useApolloClient, useQuery } from 'react-apollo' import { ParseText, GetText } from '../utils' +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import getRefIdTranslation from '../queries/refids.gql' +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore import OrderFormQuery from '../queries/orderForm.gql' +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +import GET_PRODUCT_DATA from '../queries/getPrductAvailability.graphql' const remove = @@ -203,22 +210,22 @@ const ReviewBlock: StorefrontFunctionComponent = ({ if (refidData) { const refIdNotFound = - !!refidData && !!refidData.skuFromRefIds.items - ? refidData.skuFromRefIds.items.filter((item: any) => { + !!refidData && !!refidData.getSkuAvailability.items + ? refidData.getSkuAvailability.items.filter((item: any) => { return item.sku === null }) : [] const refIdFound = - !!refidData && !!refidData.skuFromRefIds.items - ? refidData.skuFromRefIds.items.filter((item: any) => { + !!refidData && !!refidData.getSkuAvailability.items + ? refidData.getSkuAvailability.items.filter((item: any) => { return item.sku !== null }) : [] const refNotAvailable = - !!refidData && !!refidData.skuFromRefIds.items - ? refidData.skuFromRefIds.items.filter((item: any) => { + !!refidData && !!refidData.getSkuAvailability.items + ? refidData.getSkuAvailability.items.filter((item: any) => { return item.availability !== 'available' }) : [] @@ -226,8 +233,8 @@ const ReviewBlock: StorefrontFunctionComponent = ({ const vtexSku = (item: any) => { let ret: any = null - if (!!refidData && !!refidData.skuFromRefIds.items) { - ret = refidData.skuFromRefIds.items.find((curr: any) => { + if (!!refidData && !!refidData.getSkuAvailability.items) { + ret = refidData.getSkuAvailability.items.find((curr: any) => { return !!item.sku && item.sku === curr.refid }) if (!!ret && !!ret.sku) { @@ -238,21 +245,51 @@ const ReviewBlock: StorefrontFunctionComponent = ({ return ret } - const getSellers = (item: any) => { - let ret: any = [] + const getPrice = (item: any) => { + let ret: any = null + + if (!!refidData && !!refidData.getSkuAvailability.items) { + ret = refidData.getSkuAvailability.items.find((curr: any) => { + return !!item.sku && item.sku === curr.refid + }) + if (!!ret && !!ret.price) { + ret = ret.price + } + } + + return ret + } + + const getAvailableQuantity = (item: any) => { + let ret: any = null - if (!!refidData && !!refidData.skuFromRefIds.items) { - ret = refidData.skuFromRefIds.items.find((curr: any) => { + if (!!refidData && !!refidData.getSkuAvailability.items) { + ret = refidData.getSkuAvailability.items.find((curr: any) => { return !!item.sku && item.sku === curr.refid }) - if (!!ret && !!ret.sellers) { - ret = ret.sellers + if (!!ret && !!ret.availableQuantity) { + ret = ret.availableQuantity } } return ret } + // const getSellers = (item: any) => { + // let ret: any = [] + // + // if (!!refidData && !!refidData.getSkuAvailability.items) { + // ret = refidData.getSkuAvailability.items.find((curr: any) => { + // return !!item.sku && item.sku === curr.refid + // }) + // if (!!ret && !!ret.sellers) { + // ret = ret.sellers + // } + // } + // + // return ret + // } + const errorMsg = (item: any) => { let ret: any = null const notfound = refIdNotFound.find((curr: any) => { @@ -277,12 +314,12 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } const items = reviewed.map((item: any) => { - const sellers = getSellers(item) + // const sellers = getSellers(item) return { ...item, - sellers: getSellers(item), - seller: sellers.length ? sellers[0].id : '1', + availableQuantity: getAvailableQuantity(item), + price: getPrice(item), vtexSku: vtexSku(item), error: errorMsg(item), } @@ -300,12 +337,15 @@ const ReviewBlock: StorefrontFunctionComponent = ({ return merge(item) }) + // console.log('Updated : ', JSON.stringify(updated)) + onReviewItems(updated) setReviewState({ ...state, reviewItems: updated, hasError: error, }) + // console.info('END of if ') } } @@ -321,14 +361,12 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } const query = { - query: getRefIdTranslation, - variables: { refids, orderFormId }, + query: GET_PRODUCT_DATA, + variables: { refIds: refids }, } const { data } = await client.query(query) - console.info('Data : ', data) - validateRefids(data, reviewed) onRefidLoading(false) } @@ -471,6 +509,14 @@ const ReviewBlock: StorefrontFunctionComponent = ({ id: 'store/quickorder.review.label.quantity', }), }, + price: { + type: 'string', + title: 'Price', + }, + availableQuantity: { + type: 'string', + title: 'Available Quantity', + }, // seller: { // type: 'string', // title: intl.formatMessage({ diff --git a/react/components/Table.tsx b/react/components/Table.tsx new file mode 100644 index 00000000..fa40bd00 --- /dev/null +++ b/react/components/Table.tsx @@ -0,0 +1,22 @@ +import React from 'react' + +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore +const Table = ({ onReviewItems, reviewedItems, onRefidLoading }: any) => { + // eslint-disable-next-line no-console + console.log('ReviewedItems : ', reviewedItems) + + onRefidLoading(true) + + const tableSchema = { + properties: {}, + } + + return ( +
+ + + ) +} + +export default Table diff --git a/react/package.json b/react/package.json index cff69f04..83685c25 100644 --- a/react/package.json +++ b/react/package.json @@ -42,7 +42,6 @@ "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items", "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager", "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager", - "vtex.quickorder": "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder", "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime", "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text", "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql", diff --git a/react/queries/getPrductAvailability.graphql b/react/queries/getPrductAvailability.graphql new file mode 100644 index 00000000..1ae6ef52 --- /dev/null +++ b/react/queries/getPrductAvailability.graphql @@ -0,0 +1,17 @@ +query getAvbProduct($refIds: [String]) { + getSkuAvailability(refIds: $refIds) @context(provider: "vtex.quickorder") { + items { + refid + sku + productId + availability + sellers { + id + name + } + availableQuantity + productName + price + } + } +} diff --git a/react/tsconfig.json b/react/tsconfig.json index ab029180..0d0e5692 100644 --- a/react/tsconfig.json +++ b/react/tsconfig.json @@ -3,11 +3,7 @@ "alwaysStrict": true, "esModuleInterop": true, "jsx": "react", - "lib": [ - "es2017", - "dom", - "es2018.promise" - ], + "lib": ["es2017", "dom", "es2018.promise"], "module": "esnext", "moduleResolution": "node", "noImplicitAny": false, @@ -21,24 +17,12 @@ "strictNullChecks": true, "strictPropertyInitialization": true, "target": "es2017", - "typeRoots": [ - "node_modules/@types" - ], - "types": [ - "node", - "jest", - "graphql" - ] + "typeRoots": ["node_modules/@types"], + "types": ["node", "jest", "graphql"] }, - "exclude": [ - "node_modules" - ], - "include": [ - "./typings/*.d.ts", - "./**/*.tsx", - "./**/*.ts" - ], + "exclude": ["node_modules"], + "include": ["./typings/*.d.ts", "./**/*.tsx", "./**/*.ts"], "typeAcquisition": { "enable": false } -} \ No newline at end of file +} diff --git a/react/typings/vtex.styleguide.d.ts b/react/typings/vtex.styleguide.d.ts index b7402d4d..02cbf0a2 100644 --- a/react/typings/vtex.styleguide.d.ts +++ b/react/typings/vtex.styleguide.d.ts @@ -6,6 +6,14 @@ declare module 'vtex.styleguide' { export const ToastContext: Context<{ showToast: any }> export const IconClear: ComponentType export const Tag: ComponentType + export const Table: ComponentType + export const ButtonWithIcon: ComponentType + export const IconDelete: ComponentType + export const IconInfo: ComponentType + export const Tooltip: ComponentType + export const Spinner: ComponentType + export const Textarea: ComponentType + export const Dropzone: ComponentType export const AutocompleteInput: ComponentType interface InputProps { diff --git a/react/yarn.lock b/react/yarn.lock index d47a6fea..3b7ef821 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -5577,10 +5577,6 @@ verror@1.10.0: version "1.8.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager#3ccfcb1927614984a5f7a3e5650c8c8d2bd3c0f4" -"vtex.quickorder@https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder": - version "3.2.0" - resolved "https://pdp1--sbdsefuat.myvtex.com/_v/private/typings/linked/v1/vtex.quickorder@3.2.0+build1630351003/public/@types/vtex.quickorder#ef4b373b0d40e7cf04121573f0df1ac68e4a0790" - "vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime": version "8.131.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime#dcc88828e3d65ecb4e7538a3623a4b1ddd77e034" From ffafa95c77f94e15159ecbc62ea7ac051b10b3cd Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 6 Oct 2021 16:18:34 +0530 Subject: [PATCH 10/29] Removing console logs --- node/clients/search.ts | 6 ------ react/components/ReviewBlock.tsx | 3 --- 2 files changed, 9 deletions(-) diff --git a/node/clients/search.ts b/node/clients/search.ts index bed83664..56bd0e25 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -221,15 +221,9 @@ export class Search extends ExternalClient { }, }) - // console.log('Res Data :',priceRes.data[0].items) - - // console.log('URL : ', priceBySkuIdUrl) - const { items, productId, productName } = priceRes.data[0] const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] - // console.log("commertialOffer: ",commertialOffer) - const { AvailableQuantity, IsAvailable } = commertialOffer const price = commertialOffer.SellingPrice ? commertialOffer.SellingPrice diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index 6b87a0c8..f650d433 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -337,15 +337,12 @@ const ReviewBlock: StorefrontFunctionComponent = ({ return merge(item) }) - // console.log('Updated : ', JSON.stringify(updated)) - onReviewItems(updated) setReviewState({ ...state, reviewItems: updated, hasError: error, }) - // console.info('END of if ') } } From f7a31ff8d29c59fb35c132a4910c44ccd5f7dc43 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 6 Oct 2021 16:20:47 +0530 Subject: [PATCH 11/29] Remove test funtion . --- react/components/Table.tsx | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 react/components/Table.tsx diff --git a/react/components/Table.tsx b/react/components/Table.tsx deleted file mode 100644 index fa40bd00..00000000 --- a/react/components/Table.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import React from 'react' - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -const Table = ({ onReviewItems, reviewedItems, onRefidLoading }: any) => { - // eslint-disable-next-line no-console - console.log('ReviewedItems : ', reviewedItems) - - onRefidLoading(true) - - const tableSchema = { - properties: {}, - } - - return ( -
-
- - ) -} - -export default Table From 1ef59e29987404199fcff5d7f6b6191d918b9ef7 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Wed, 6 Oct 2021 16:23:33 +0530 Subject: [PATCH 12/29] Change App name --- manifest.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifest.json b/manifest.json index 826dd0d2..6f21493c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { - "vendor": "vtex", - "name": "quickorder", + "vendor": "sbdsefuat", + "name": "bulk-order", "version": "3.2.0", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", From af0fd216d3842334918d5a7555cc940b2b2712ce Mon Sep 17 00:00:00 2001 From: Jayendra Kumara Date: Thu, 7 Oct 2021 00:14:56 +0530 Subject: [PATCH 13/29] add bulk order inventory --- manifest.json | 6 +- node/clients/search.ts | 67 ++------------- node/resolvers/search/index.ts | 63 +++++++++++++- node/yarn.lock | 2 +- react/components/ReviewBlock.tsx | 94 ++++++++------------- react/queries/getPrductAvailability.graphql | 2 +- 6 files changed, 108 insertions(+), 126 deletions(-) diff --git a/manifest.json b/manifest.json index 6f21493c..523f535f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "vendor": "sbdsefuat", "name": "bulk-order", - "version": "3.2.0", + "version": "0.0.1", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", "defaultLocale": "en-US", @@ -97,7 +97,9 @@ }, "free": true, "type": "free", - "availableCountries": ["*"] + "availableCountries": [ + "*" + ] }, "$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema" } diff --git a/node/clients/search.ts b/node/clients/search.ts index 56bd0e25..1c38654e 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -208,54 +208,22 @@ export class Search extends ExternalClient { * @param sku * @param refid */ - private getSkuById = async (sku: string, refid: string) => { - if (sku === null) { - return {} - } - + public searchProductBySkuId = async (sku: string) => { const priceBySkuIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/products/search/?fq=skuId:${sku}` - const priceRes = await axios.get(priceBySkuIdUrl, { + const res = await axios.get(priceBySkuIdUrl, { headers: { 'Content-Type': 'application/json', Authorization: `bearer ${this.context.authToken}`, }, }) - - const { items, productId, productName } = priceRes.data[0] - const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] - - const { AvailableQuantity, IsAvailable } = commertialOffer - const price = commertialOffer.SellingPrice - ? commertialOffer.SellingPrice - : commertialOffer.Price - ? commertialOffer.Price - : commertialOffer.ListPrice - const sellers = [ - { - id: sellerId, - name: sellerName, - }, - ] - - return { - refid, - sku, - productId, - productName, - price, - availableQuantity: AvailableQuantity, - sellers, - availability: IsAvailable ? 'available' : 'unavailable', - } + return res?.status === 200 && res.data.length > 0? res.data[0]: {} } /** * * @param refIds */ - public getSkuAvailability = async (refIds: string[]) => { - this.sellersList = await this.sellers() - + public getSkusByRefIds = async (refIds: string[]) => { const url = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/sku/stockkeepingunitidsbyrefids` const res = await axios.post(url, refIds, { headers: { @@ -263,31 +231,6 @@ export class Search extends ExternalClient { Authorization: `bearer ${this.context.authToken}`, }, }) - - let result: any = [] - const resultStr: any = {} - - if (res.status === 200) { - const refs = Object.getOwnPropertyNames(res.data) - - refs.forEach(id => { - resultStr[id] = { - sku: res.data[id], - refid: id, - sellers: this.sellersList, - } - result.push(resultStr[id]) - }) - - if (this.sellersList?.length) { - const promises = result.map(async (o: any) => - this.getSkuById(o.sku, o.refid) - ) - result = await Promise.all(promises) - } - - return result - } - return [] + return res?.status === 200? res.data: {} } } diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index 15c98cfb..3730d110 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -54,8 +54,69 @@ export const queries = { clients: { search }, } = ctx + // const sellers = await search.sellers() + + const skuIds = await search.getSkusByRefIds(refIds) + const refIdsFound = Object.getOwnPropertyNames(skuIds) + const skus = refIdsFound.map((rfId: any) => ({ + skuId: skuIds[rfId], + refId: rfId, + })) + + const products = await Promise.all(skus.map(async (sku: any) => + search.searchProductBySkuId(sku.skuId) + )) + + const allSkus = (products?? []).filter((r: any) => Object.entries(r).length > 0) + .map((product: any) => { + if((product.items ?? []).length == 0 || (product.items[0]?.sellers ?? []).length == 0){ + return {} + } + const { items, productId, productName } = product + const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] + + const { AvailableQuantity, IsAvailable } = commertialOffer + const price = commertialOffer.SellingPrice + ? commertialOffer.SellingPrice + : commertialOffer.Price + ? commertialOffer.Price + : commertialOffer.ListPrice + + const itemId = items[0].itemId + const refId = skus.find((sku: any) => sku.skuId === itemId)?.refId + + return { + refId, + sku: itemId, + productId, + productName, + price, + availableQuantity: AvailableQuantity, + seller: { + id: sellerId, + name: sellerName, + }, + availability: IsAvailable ? 'available' : 'unavailable', + } + }) + + const itemsRequested = (refIds?? []).map((refId: string) => { + const existing = allSkus.find((s: any) => s.refId == refId) + console.log(JSON.stringify(refId)) + return existing? existing: { + refid: refId, + sku: null, + productId: null, + productName: null, + price: null, + availableQuantity: null, + seller: null, + availability: 'unavailable' + } + }) + return { - items: await search.getSkuAvailability(refIds), + items: itemsRequested, } }, } diff --git a/node/yarn.lock b/node/yarn.lock index a186cc25..f9e8e63f 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -6032,7 +6032,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -"stats-lite@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index f650d433..9f047fd0 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -22,6 +22,7 @@ import OrderFormQuery from '../queries/orderForm.gql' // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import GET_PRODUCT_DATA from '../queries/getPrductAvailability.graphql' +// import { stubFalse } from 'lodash' const remove = @@ -209,70 +210,41 @@ const ReviewBlock: StorefrontFunctionComponent = ({ let error = false if (refidData) { - const refIdNotFound = - !!refidData && !!refidData.getSkuAvailability.items - ? refidData.getSkuAvailability.items.filter((item: any) => { - return item.sku === null - }) - : [] - - const refIdFound = - !!refidData && !!refidData.getSkuAvailability.items - ? refidData.getSkuAvailability.items.filter((item: any) => { - return item.sku !== null - }) - : [] - - const refNotAvailable = - !!refidData && !!refidData.getSkuAvailability.items - ? refidData.getSkuAvailability.items.filter((item: any) => { - return item.availability !== 'available' - }) - : [] + const itemsFromQuery = refidData.getSkuAvailability?.items ?? [] + const refIdNotFound = itemsFromQuery.filter((item: any) => { + return item.sku === null + }) - const vtexSku = (item: any) => { - let ret: any = null + const refIdFound = itemsFromQuery.filter((item: any) => { + return item.sku !== null + }) - if (!!refidData && !!refidData.getSkuAvailability.items) { - ret = refidData.getSkuAvailability.items.find((curr: any) => { - return !!item.sku && item.sku === curr.refid - }) - if (!!ret && !!ret.sku) { - ret = ret.sku - } - } + const refNotAvailable = itemsFromQuery.filter((item: any) => { + return item.availability !== 'available' + }) - return ret + const vtexSku = (item: any) => { + let ret: any = itemsFromQuery.find((curr: any) => { + return !!item.sku && item.sku === curr.refid + }) + + return ret?.sku } const getPrice = (item: any) => { - let ret: any = null - - if (!!refidData && !!refidData.getSkuAvailability.items) { - ret = refidData.getSkuAvailability.items.find((curr: any) => { - return !!item.sku && item.sku === curr.refid - }) - if (!!ret && !!ret.price) { - ret = ret.price - } - } + let ret: any = itemsFromQuery.find((curr: any) => { + return !!item.sku && item.sku === curr.refid + }) - return ret + return ret?.price } const getAvailableQuantity = (item: any) => { - let ret: any = null - - if (!!refidData && !!refidData.getSkuAvailability.items) { - ret = refidData.getSkuAvailability.items.find((curr: any) => { - return !!item.sku && item.sku === curr.refid - }) - if (!!ret && !!ret.availableQuantity) { - ret = ret.availableQuantity - } - } + let ret: any = itemsFromQuery.find((curr: any) => { + return !!item.sku && item.sku === curr.refid + }) - return ret + return ret?.availableQuantity } // const getSellers = (item: any) => { @@ -357,14 +329,18 @@ const ReviewBlock: StorefrontFunctionComponent = ({ refids = Object.getOwnPropertyNames(refids) } - const query = { - query: GET_PRODUCT_DATA, - variables: { refIds: refids }, - } + try { + const { data } = await client.query({ + query: GET_PRODUCT_DATA, + variables: { refIds: refids as string[] }, + }) - const { data } = await client.query(query) + validateRefids(data, reviewed) + } + catch (error) { + console.log(error) + } - validateRefids(data, reviewed) onRefidLoading(false) } diff --git a/react/queries/getPrductAvailability.graphql b/react/queries/getPrductAvailability.graphql index 1ae6ef52..c327fcaf 100644 --- a/react/queries/getPrductAvailability.graphql +++ b/react/queries/getPrductAvailability.graphql @@ -1,5 +1,5 @@ query getAvbProduct($refIds: [String]) { - getSkuAvailability(refIds: $refIds) @context(provider: "vtex.quickorder") { + getSkuAvailability(refIds: $refIds) @context(provider: "sbdsefuat.bulk-order") { items { refid sku From fcafb44cbed358590235901c451c9d27da30605e Mon Sep 17 00:00:00 2001 From: Jayendra Kumara Date: Wed, 27 Oct 2021 13:30:39 +0530 Subject: [PATCH 14/29] bulk order validation --- node/clients/search.ts | 2 +- node/package.json | 2 +- node/resolvers/search/index.ts | 9 ++++----- node/yarn.lock | 10 +++++----- react/AutocompleteBlock.tsx | 10 +--------- react/CategoryBlock.tsx | 10 +--------- react/TextAreaBlock.tsx | 9 +-------- react/UploadBlock.tsx | 9 +-------- 8 files changed, 15 insertions(+), 46 deletions(-) diff --git a/node/clients/search.ts b/node/clients/search.ts index 1c38654e..34ad1e0d 100644 --- a/node/clients/search.ts +++ b/node/clients/search.ts @@ -209,7 +209,7 @@ export class Search extends ExternalClient { * @param refid */ public searchProductBySkuId = async (sku: string) => { - const priceBySkuIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/products/search/?fq=skuId:${sku}` + const priceBySkuIdUrl = `http://${this.context.account}.vtexcommercestable.com.br/api/catalog_system/pub/products/search?fq=skuId:${sku}` const res = await axios.get(priceBySkuIdUrl, { headers: { 'Content-Type': 'application/json', diff --git a/node/package.json b/node/package.json index 0be5052b..2536bda0 100644 --- a/node/package.json +++ b/node/package.json @@ -29,7 +29,7 @@ "@types/node": "^12.0.0", "@types/qs": "^6.5.1", "@types/ramda": "^0.26.21", - "@vtex/api": "6.45.4", + "@vtex/api": "6.45.3", "@vtex/test-tools": "^1.2.0", "@vtex/tsconfig": "^0.2.0", "eslint": "^6.8.0", diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index 3730d110..53b5a994 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -61,7 +61,7 @@ export const queries = { const skus = refIdsFound.map((rfId: any) => ({ skuId: skuIds[rfId], refId: rfId, - })) + })).filter((sku: any) => sku.skuId != null) const products = await Promise.all(skus.map(async (sku: any) => search.searchProductBySkuId(sku.skuId) @@ -83,10 +83,10 @@ export const queries = { : commertialOffer.ListPrice const itemId = items[0].itemId - const refId = skus.find((sku: any) => sku.skuId === itemId)?.refId + const skuRefId = skus.find((sku: any) => sku.skuId === itemId)?.refId return { - refId, + refid: skuRefId, sku: itemId, productId, productName, @@ -101,8 +101,7 @@ export const queries = { }) const itemsRequested = (refIds?? []).map((refId: string) => { - const existing = allSkus.find((s: any) => s.refId == refId) - console.log(JSON.stringify(refId)) + const existing = allSkus.find((s: any) => s.refid === refId) return existing? existing: { refid: refId, sku: null, diff --git a/node/yarn.lock b/node/yarn.lock index f9e8e63f..23a42c8a 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -1319,10 +1319,10 @@ semver "^6.3.0" tsutils "^3.17.1" -"@vtex/api@6.45.4": - version "6.45.4" - resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.4.tgz#58be7497c0c0f91a388fabd42149e48cb95e271d" - integrity sha512-DVAJr5BkSjXupjn2h5Z1In8C3Li9kZwCXPwRQbpIgyS7s9dN2ZEFQc6nQlJm6ZoDCoyYBg62LgD7Kurvz9jc3w== +"@vtex/api@6.45.3": + version "6.45.3" + resolved "https://registry.yarnpkg.com/@vtex/api/-/api-6.45.3.tgz#fe7d08adb4eab1fda5e34143cc6302a4c5aa5f52" + integrity sha512-kiD7We1TCKDyBdpYoh2Se3An+jTJRUzXGNpKifoDZylWQ1PyIx+3oL5ZAif9InlY3uJkfEisSAI6nxoKTgvPfw== dependencies: "@types/koa" "^2.11.0" "@types/koa-compose" "^3.2.3" @@ -6032,7 +6032,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: diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 0c73c982..d1c13724 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -78,7 +78,6 @@ const AutocompleteBlock: StorefrontFunctionComponent { let message - let action if (typeof arg === 'string') { // eslint-disable-next-line react/prop-types @@ -93,16 +92,9 @@ const AutocompleteBlock: StorefrontFunctionComponent { diff --git a/react/CategoryBlock.tsx b/react/CategoryBlock.tsx index 81e4281a..395b38d7 100644 --- a/react/CategoryBlock.tsx +++ b/react/CategoryBlock.tsx @@ -82,7 +82,6 @@ const CategoryBlock: StorefrontFunctionComponent { let message - let action if (typeof arg === 'string') { message = intl.formatMessage(messages[arg]) @@ -96,16 +95,9 @@ const CategoryBlock: StorefrontFunctionComponent { diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index 0cac0370..b97646c0 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -91,14 +91,7 @@ const TextAreaBlock: StorefrontFunctionComponent { const message = resolveToastMessage(success, isNewItem) - const action = success - ? { - label: translateMessage(messages.seeCart), - href: '/checkout/#/cart', - } - : undefined - - showToast({ message, action }) + showToast({ message }) } const callAddToCart = async (items: any) => { diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 450f0c52..deba89c9 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -91,14 +91,7 @@ const UploadBlock: StorefrontFunctionComponent { const message = resolveToastMessage(success, isNewItem) - const action = success - ? { - label: translateMessage(messages.seeCart), - href: '/checkout/#/cart', - } - : undefined - - showToast({ message, action }) + showToast({ message }) } const download = () => { From 22c80e576bea536b64f3db2fc5ec251a3abe5d45 Mon Sep 17 00:00:00 2001 From: Jayendra Kumara Date: Thu, 28 Oct 2021 01:57:02 +0530 Subject: [PATCH 15/29] quick order item availability --- graphql/schema.graphql | 2 +- manifest.json | 26 +++++- node/clients/catalog.ts | 30 +++++++ node/clients/index.ts | 5 ++ node/resolvers/search/index.ts | 91 ++++++++++++++++++--- node/typings/globals.ts | 42 ++++++++++ node/utils/consts.ts | 16 ++++ react/components/ReviewBlock.tsx | 46 ++++++++--- react/queries/getPrductAvailability.graphql | 4 +- react/queries/orderSoldToAccount.graphql | 9 ++ 10 files changed, 241 insertions(+), 30 deletions(-) create mode 100644 node/clients/catalog.ts create mode 100644 node/typings/globals.ts create mode 100644 node/utils/consts.ts create mode 100644 react/queries/orderSoldToAccount.graphql diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 931dedce..ec87c2ad 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -6,5 +6,5 @@ type Query { @cacheControl(scope: SEGMENT, maxAge: MEDIUM) @withSegment - getSkuAvailability(refIds: [String]): AvailableItems + getSkuAvailability(refIds: [String], customerNumber: String, targetSystem: String, salesOrganizationCode: String): AvailableItems } diff --git a/manifest.json b/manifest.json index 523f535f..1ea53dcf 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { - "vendor": "sbdsefuat", - "name": "bulk-order", - "version": "0.0.1", + "vendor": "vtex", + "name": "quickorder", + "version": "3.2.1", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", "defaultLocale": "en-US", @@ -35,7 +35,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", + "sbdsefuat.checkout-simulation": "1.x" }, "policies": [ { @@ -85,8 +86,25 @@ "path": "/api/catalog_system/pub/products/search/*" } }, + { + "name": "outbound-access", + "attrs": { + "host": "api.vtex.com", + "path": "/api/dataentities/*" + } + }, + { + "name": "outbound-access", + "attrs": { + "host": "{{account}}.vtexcommercestable.com.br", + "path": "/api/logistics/pvt/inventory/skus/*" + } + }, { "name": "POWER_USER_DS" + }, + { + "name": "LogisticsAdmin" } ], "settingsSchema": {}, diff --git a/node/clients/catalog.ts b/node/clients/catalog.ts new file mode 100644 index 00000000..25a01174 --- /dev/null +++ b/node/clients/catalog.ts @@ -0,0 +1,30 @@ +import { ExternalClient, InstanceOptions, IOContext } from '@vtex/api' + +export class Catalog extends ExternalClient { + constructor(context: IOContext, options?: InstanceOptions) { + super( + `http://${context.account}.vtexcommercestable.com.br`, + context, + options + ) + } + + public inventoryBySkuId = (id: string | number) => { + this.context.logger.debug({ + auth: this.context.authToken, + url: this.context.host, + }) + const endpoint = `${this.options?.baseURL}/api/logistics/pvt/inventory/skus/${id}` + return this.http.get(`/api/logistics/pvt/inventory/skus/${id}`, { + headers: { + 'Content-Type': 'application/json', + Accept: 'application/json', + VtexIdclientAutCookie: `${this.context.authToken}`, + 'Proxy-Authorization': this.context.authToken, + 'X-Vtex-Proxy-To': endpoint, + 'X-Vtex-Use-Https': true, + 'Cache-Control': 'no-cache', + }, + }) + } +} diff --git a/node/clients/index.ts b/node/clients/index.ts index 84297fe7..8b93954c 100644 --- a/node/clients/index.ts +++ b/node/clients/index.ts @@ -1,9 +1,14 @@ import { IOClients } from '@vtex/api' import { Search } from './search' +import { Catalog } from './catalog' export class Clients extends IOClients { public get search() { return this.getOrSet('search', Search) } + + public get catalog() { + return this.getOrSet('catalog', Catalog) + } } diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index 53b5a994..97d58a80 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -2,6 +2,18 @@ import { UserInputError } from '@vtex/api' import { resolvers as refidsResolvers } from './refids' +import { + BRAND_CLIENT_ACRONYM, + BRAND_CLIENT_SCHEMA, + BRNAD_CLIENT_FIELDS, + PLANT_ACRONYM, + PLANT_FIELDS, + PLANT_SCHEMA, + // UMMOQ_CLIENT_ACRONYM, + // UMMOQ_CLIENT_FIELDS, + // UMMOQ_CLIENT_SCHEMA, +} from '../../utils/consts' + export const fieldResolvers = { ...refidsResolvers, } @@ -44,18 +56,16 @@ export const queries = { }, getSkuAvailability: async ( _: any, - args: { refIds: string[] }, + args: { refIds: string[], customerNumber: string, targetSystem: string, salesOrganizationCode: string }, ctx: Context ) => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - const { refIds } = args + const { refIds, customerNumber, targetSystem, salesOrganizationCode } = args const { - clients: { search }, + clients: { search, masterdata, catalog }, } = ctx - // const sellers = await search.sellers() - const skuIds = await search.getSkusByRefIds(refIds) const refIdsFound = Object.getOwnPropertyNames(skuIds) const skus = refIdsFound.map((rfId: any) => ({ @@ -67,36 +77,92 @@ export const queries = { search.searchProductBySkuId(sku.skuId) )) + const plants = await Promise.all(refIds.map((refId: string) => { + const where = `skuRefId=${refId} ${ + salesOrganizationCode + ? `AND salesOrganizationCode=${salesOrganizationCode}` + : '' + }` + + return masterdata.searchDocumentsWithPaginationInfo({ + dataEntity: PLANT_ACRONYM, + schema: PLANT_SCHEMA, + fields: PLANT_FIELDS, + where, + pagination: { pageSize: 100, page: 1 }, + }) + })) + + const plantList = refIds.map((refId: string, index: number) => { + return { + refId: refId, + plants: plants[index]?.data ?? [] + } + }) + + const brands = await masterdata.searchDocumentsWithPaginationInfo({ + dataEntity: BRAND_CLIENT_ACRONYM, + schema: BRAND_CLIENT_SCHEMA, + fields: BRNAD_CLIENT_FIELDS, + where: `(user=${customerNumber ?? ''} AND targetSystem=${targetSystem ?? ''})`, + pagination: { pageSize: 100, page: 1 }, + }) + + const brandsList = brands?.data ?? [] + + const allInventoryByItemIds = await Promise.all((Object.values(skuIds ?? {}) as string[] ?? []).map((skuId: string) => { + return catalog.inventoryBySkuId(skuId) + })) + const allSkus = (products?? []).filter((r: any) => Object.entries(r).length > 0) .map((product: any) => { if((product.items ?? []).length == 0 || (product.items[0]?.sellers ?? []).length == 0){ return {} } const { items, productId, productName } = product + + const itemId = items[0]?.itemId + const skuRefId = skus.find((sku: any) => sku.skuId === itemId)?.refId + // const refId = (items[0]?.referenceId ?? []).find((ref: any) => ref.Key === 'RefId')?.Value ?? '' const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] - const { AvailableQuantity, IsAvailable } = commertialOffer + let availableQuantity = 0 + + if(targetSystem.toUpperCase() === 'SAP') { + const productPlants = plantList.find((plant: any) => plant?.refId?.toLowerCase() === skuRefId.toLowerCase())?.plants?.map((plant: any) => plant.plant) ?? [] + const selectedProductWearhouses = allInventoryByItemIds.find((inventory: any) => inventory.skuId == itemId)?.balance?.filter((wearhouse: any) => productPlants.includes(wearhouse.warehouseName)) ?? [] + availableQuantity = selectedProductWearhouses.reduce((partialSum: number, current: any) => partialSum + current?.totalQuantity ?? 0, 0) + } + else if(targetSystem.toUpperCase() === 'JDE') { + const { AvailableQuantity } = commertialOffer + + const productBrand = product.brand + // const brandClientData = brandData?.brandClient?.data ?? [] + const brandDataMatch: any = brandsList?.find( + (data: any) => data.trade === productBrand + ) + + availableQuantity = (brandDataMatch?.trade === productBrand) ? AvailableQuantity: 0 + } + const price = commertialOffer.SellingPrice ? commertialOffer.SellingPrice : commertialOffer.Price ? commertialOffer.Price : commertialOffer.ListPrice - const itemId = items[0].itemId - const skuRefId = skus.find((sku: any) => sku.skuId === itemId)?.refId - return { refid: skuRefId, sku: itemId, productId, productName, price, - availableQuantity: AvailableQuantity, + availableQuantity: availableQuantity, seller: { id: sellerId, name: sellerName, }, - availability: IsAvailable ? 'available' : 'unavailable', + availability: availableQuantity > 0 ? 'available' : 'unavailable', } }) @@ -114,6 +180,9 @@ export const queries = { } }) + + console.log(JSON.stringify(itemsRequested, null, 2)) + return { items: itemsRequested, } diff --git a/node/typings/globals.ts b/node/typings/globals.ts new file mode 100644 index 00000000..6796587c --- /dev/null +++ b/node/typings/globals.ts @@ -0,0 +1,42 @@ +interface SearchArgs { + pageSize: number + page: number + where?: string + skuId: string + soc?: string + skuRefId: string +} + +interface PlantData { + plant: number + salesOrganizationCode: number +} +interface ClientBrand { + brand: string + client: string + targetSystem: string +} + +interface MoqUM { + unitMultiplier: string + minOrderQuantity: string +} + +interface Pagination { + pageSize: number + page: number + total: number +} + +interface SalesOrgPlant { + pagination: Pagination + data: PlantData[] +} +interface BrandForClients { + pagination: Pagination + data: ClientBrand[] +} +interface UnitMultiplierMoQ { + pagination: Pagination + data: MoqUM +} diff --git a/node/utils/consts.ts b/node/utils/consts.ts new file mode 100644 index 00000000..7316b1f4 --- /dev/null +++ b/node/utils/consts.ts @@ -0,0 +1,16 @@ +export const PLANT_ACRONYM = 'SP' +export const PLANT_SCHEMA = 'mdv1' +export const PLANT_FIELDS = ['id', 'plant', 'salesOrganizationCode', 'skuRefId'] + +export const BRAND_CLIENT_ACRONYM = 'TD' +export const BRAND_CLIENT_SCHEMA = 'mdv1' +export const BRNAD_CLIENT_FIELDS = ['id', 'targetSystem', 'trade', 'user'] + +export const UMMOQ_CLIENT_ACRONYM = 'SL' +export const UMMOQ_CLIENT_SCHEMA = 'mdv1' +export const UMMOQ_CLIENT_FIELDS = [ + 'id', + 'targetSystem', + 'minOrderQuantity', + 'unitMultiplier', +] diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index 9f047fd0..fd90253a 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -24,6 +24,8 @@ import OrderFormQuery from '../queries/orderForm.gql' import GET_PRODUCT_DATA from '../queries/getPrductAvailability.graphql' // import { stubFalse } from 'lodash' +import GET_ACCOUNT_INFO from '../queries/orderSoldToAccount.graphql' + const remove = const messages = defineMessages({ @@ -134,7 +136,7 @@ const messages = defineMessages({ }, }) -let orderFormId = '' +// let orderFormId = '' const ReviewBlock: StorefrontFunctionComponent = ({ onReviewItems, @@ -144,12 +146,25 @@ const ReviewBlock: StorefrontFunctionComponent = ({ }: any) => { const client = useApolloClient() - const { data: orderFormData } = useQuery<{ - orderForm - }>(OrderFormQuery, { - ssr: false, - skip: !!orderFormId, - }) + // const { data: orderFormData } = useQuery<{ + // orderForm + // }>(OrderFormQuery, { + // ssr: false, + // skip: !!orderFormId, + // }) + + const { data: accountData, loading: accountDataLoading } = useQuery( + GET_ACCOUNT_INFO, + { + notifyOnNetworkStatusChange: true, + ssr: false, + } + ) + + const customerNumber = accountData?.getOrderSoldToAccount?.customerNumber ?? '' + const targetSystem = accountData?.getOrderSoldToAccount?.targetSystem ?? '' + const salesOrganizationCode = + accountData?.getOrderSoldToAccount?.salesOrganizationCode ?? '' const [state, setReviewState] = useState({ reviewItems: @@ -163,9 +178,9 @@ const ReviewBlock: StorefrontFunctionComponent = ({ const { reviewItems } = state - if (orderFormData?.orderForm?.orderFormId) { - orderFormId = orderFormData.orderForm.orderFormId - } + // if (orderFormData?.orderForm?.orderFormId) { + // orderFormId = orderFormData.orderForm.orderFormId + // } const errorMessage = { 'store/quickorder.valid': messages.valid, @@ -332,7 +347,12 @@ const ReviewBlock: StorefrontFunctionComponent = ({ try { const { data } = await client.query({ query: GET_PRODUCT_DATA, - variables: { refIds: refids as string[] }, + variables: { + refIds: refids as string[], + customerNumber, + targetSystem, + salesOrganizationCode, + }, }) validateRefids(data, reviewed) @@ -567,7 +587,9 @@ const ReviewBlock: StorefrontFunctionComponent = ({ }, } - return ( + return accountDataLoading ? ( +
+ ) : (
diff --git a/react/queries/getPrductAvailability.graphql b/react/queries/getPrductAvailability.graphql index c327fcaf..5b6b1101 100644 --- a/react/queries/getPrductAvailability.graphql +++ b/react/queries/getPrductAvailability.graphql @@ -1,5 +1,5 @@ -query getAvbProduct($refIds: [String]) { - getSkuAvailability(refIds: $refIds) @context(provider: "sbdsefuat.bulk-order") { +query getAvbProduct($refIds: [String], $customerNumber: String, $targetSystem: String, $salesOrganizationCode: String) { + getSkuAvailability(refIds: $refIds, customerNumber: $customerNumber, targetSystem: $targetSystem, salesOrganizationCode: $salesOrganizationCode) @context(provider: "sbdsefuat.bulk-order") { items { refid sku diff --git a/react/queries/orderSoldToAccount.graphql b/react/queries/orderSoldToAccount.graphql new file mode 100644 index 00000000..cecabdb8 --- /dev/null +++ b/react/queries/orderSoldToAccount.graphql @@ -0,0 +1,9 @@ +query OrderSoldToAccount($orderFormId: String) { + getOrderSoldToAccount(orderFormId: $orderFormId) { + cacheId + customerNumber + targetSystem + receiverName + salesOrganizationCode + } +} From 2b08ccab7d79f8948d6906170931947c65dcf86c Mon Sep 17 00:00:00 2001 From: Jayendra Kumara Date: Mon, 1 Nov 2021 15:46:09 +0530 Subject: [PATCH 16/29] bulk order validation --- manifest.json | 6 ++--- messages/context.json | 5 +++-- messages/en.json | 3 ++- messages/es.json | 5 +++-- messages/pt.json | 5 +++-- messages/ro.json | 5 +++-- node/resolvers/search/index.ts | 5 ++++- react/AutocompleteBlock.tsx | 2 ++ react/TextAreaBlock.tsx | 38 ++++++++++++++++++++++---------- react/UploadBlock.tsx | 38 ++++++++++++++++++++++---------- react/components/ReviewBlock.tsx | 6 ++++- 11 files changed, 80 insertions(+), 38 deletions(-) diff --git a/manifest.json b/manifest.json index 1ea53dcf..449e3fee 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { - "vendor": "vtex", - "name": "quickorder", - "version": "3.2.1", + "vendor": "sbdsefuat", + "name": "bulk-order", + "version": "0.0.3", "title": "Quickorder", "description": "Allow users to add multiple products to the cart at once", "defaultLocale": "en-US", diff --git a/messages/context.json b/messages/context.json index 2eb3769f..c9cfb3df 100644 --- a/messages/context.json +++ b/messages/context.json @@ -54,5 +54,6 @@ "store/toaster.cart.duplicated": "store/toaster.cart.duplicated", "store/toaster.cart.error": "store/toaster.cart.error", "store/toaster.cart.seeCart": "store/toaster.cart.seeCart", - "store/toaster.cart.success": "store/toaster.cart.success" -} \ No newline at end of file + "store/toaster.cart.success": "store/toaster.cart.success", + "store/quickorder.unavailable": "store/quickorder.unavailable" +} diff --git a/messages/en.json b/messages/en.json index 9942294b..00e4f625 100644 --- a/messages/en.json +++ b/messages/en.json @@ -54,5 +54,6 @@ "store/toaster.cart.duplicated": "Item duplicated", "store/toaster.cart.error": "Error adding products to the cart", "store/toaster.cart.seeCart": "See cart", - "store/toaster.cart.success": "Products successfuly added to the cart" + "store/toaster.cart.success": "Products successfuly added to the cart", + "store/quickorder.unavailable": "Item not available in the store" } diff --git a/messages/es.json b/messages/es.json index 0ce93b1e..860b100c 100644 --- a/messages/es.json +++ b/messages/es.json @@ -54,5 +54,6 @@ "store/toaster.cart.duplicated": "Elemento duplicado", "store/toaster.cart.error": "Error al agregar productos al carrito", "store/toaster.cart.seeCart": "Ver el carrito", - "store/toaster.cart.success": "Productos agregados correctamente" -} \ No newline at end of file + "store/toaster.cart.success": "Productos agregados correctamente", + "store/quickorder.unavailable": "Item not available in the store" +} diff --git a/messages/pt.json b/messages/pt.json index ee0e0bc9..956e930e 100644 --- a/messages/pt.json +++ b/messages/pt.json @@ -54,5 +54,6 @@ "store/toaster.cart.duplicated": "Item duplicado", "store/toaster.cart.error": "Erro adicionando produtos ao carrinho", "store/toaster.cart.seeCart": "Ver o carrinho", - "store/toaster.cart.success": "Produtos adicionados com sucesso" -} \ No newline at end of file + "store/toaster.cart.success": "Produtos adicionados com sucesso", + "store/quickorder.unavailable": "Item not available in the store" +} diff --git a/messages/ro.json b/messages/ro.json index f36934b9..e18fefb4 100644 --- a/messages/ro.json +++ b/messages/ro.json @@ -54,5 +54,6 @@ "store/toaster.cart.duplicated": "Articol duplicat", "store/toaster.cart.error": "Eroare la adaugarea produselor in cos", "store/toaster.cart.seeCart": "Vezi cos", - "store/toaster.cart.success": "Produse adaugate in cos" -} \ No newline at end of file + "store/toaster.cart.success": "Produse adaugate in cos", + "store/quickorder.unavailable": "Item not available in the store" +} diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index 97d58a80..ae6c6857 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -127,11 +127,13 @@ export const queries = { const { commertialOffer, sellerId, sellerName } = items[0].sellers[0] let availableQuantity = 0 + let isAvailable = false if(targetSystem.toUpperCase() === 'SAP') { const productPlants = plantList.find((plant: any) => plant?.refId?.toLowerCase() === skuRefId.toLowerCase())?.plants?.map((plant: any) => plant.plant) ?? [] const selectedProductWearhouses = allInventoryByItemIds.find((inventory: any) => inventory.skuId == itemId)?.balance?.filter((wearhouse: any) => productPlants.includes(wearhouse.warehouseName)) ?? [] availableQuantity = selectedProductWearhouses.reduce((partialSum: number, current: any) => partialSum + current?.totalQuantity ?? 0, 0) + isAvailable = selectedProductWearhouses.length > 0 } else if(targetSystem.toUpperCase() === 'JDE') { const { AvailableQuantity } = commertialOffer @@ -143,6 +145,7 @@ export const queries = { ) availableQuantity = (brandDataMatch?.trade === productBrand) ? AvailableQuantity: 0 + isAvailable = brandDataMatch?.trade === productBrand } const price = commertialOffer.SellingPrice @@ -162,7 +165,7 @@ export const queries = { id: sellerId, name: sellerName, }, - availability: availableQuantity > 0 ? 'available' : 'unavailable', + availability: isAvailable ? 'available' : 'unavailable', } }) diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index d1c13724..5b86d5c1 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -182,6 +182,8 @@ const AutocompleteBlock: StorefrontFunctionComponent { - return !item.vtexSku + return !item.vtexSku || item.availability !== 'available' }).length === 0 setState({ @@ -219,6 +219,8 @@ const TextAreaBlock: StorefrontFunctionComponent {refidLoading && } - {showAddToCart && ( - + {showAddToCart? ( +
+ +
+ ): ( +
+ +
)} diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index deba89c9..48cba28c 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -122,7 +122,7 @@ const UploadBlock: StorefrontFunctionComponent { - return !item.vtexSku + return !item.vtexSku || item.availability !== 'available' }).length === 0 setState({ @@ -341,6 +341,8 @@ const UploadBlock: StorefrontFunctionComponent {refidLoading && } - {showAddToCart && ( - + {showAddToCart ? ( +
+ +
+ ): ( +
+ +
)} diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index fd90253a..b7d30076 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -35,6 +35,9 @@ const messages = defineMessages({ available: { id: 'store/quickorder.available', }, + unavailable: { + id: 'store/quickorder.unavailable' + }, invalidPattern: { id: 'store/quickorder.invalidPattern', }, @@ -185,6 +188,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ const errorMessage = { 'store/quickorder.valid': messages.valid, 'store/quickorder.available': messages.available, + 'store/quickorder.unavailable': messages.unavailable, 'store/quickorder.invalidPattern': messages.invalidPattern, 'store/quickorder.skuNotFound': messages.skuNotFound, 'store/quickorder.withoutStock': messages.withoutStock, @@ -549,7 +553,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ cellRenderer: ({ cellData, rowData }: any) => { if (rowData.error) { const text = intl.formatMessage( - errorMessage[cellData || 'store/quickorder.valid'] + errorMessage[cellData !== null && cellData !== void 0 ? cellData : 'store/quickorder.valid'] ) return ( From 1ff10d912270399af0bce26b4b3b71c6fea57e99 Mon Sep 17 00:00:00 2001 From: Jayendra Kumara Date: Mon, 1 Nov 2021 21:59:04 +0530 Subject: [PATCH 17/29] add to cart hide --- node/resolvers/search/index.ts | 7 +--- react/AutocompleteBlock.tsx | 63 ++++++++++++++++++++++++++++++-- react/TextAreaBlock.tsx | 6 +-- react/components/ReviewBlock.tsx | 10 ++++- 4 files changed, 74 insertions(+), 12 deletions(-) diff --git a/node/resolvers/search/index.ts b/node/resolvers/search/index.ts index ae6c6857..a4d34bcf 100644 --- a/node/resolvers/search/index.ts +++ b/node/resolvers/search/index.ts @@ -116,7 +116,7 @@ export const queries = { const allSkus = (products?? []).filter((r: any) => Object.entries(r).length > 0) .map((product: any) => { - if((product.items ?? []).length == 0 || (product.items[0]?.sellers ?? []).length == 0){ + if((product.items ?? []).length === 0 || (product.items[0]?.sellers ?? []).length === 0){ return {} } const { items, productId, productName } = product @@ -131,7 +131,7 @@ export const queries = { if(targetSystem.toUpperCase() === 'SAP') { const productPlants = plantList.find((plant: any) => plant?.refId?.toLowerCase() === skuRefId.toLowerCase())?.plants?.map((plant: any) => plant.plant) ?? [] - const selectedProductWearhouses = allInventoryByItemIds.find((inventory: any) => inventory.skuId == itemId)?.balance?.filter((wearhouse: any) => productPlants.includes(wearhouse.warehouseName)) ?? [] + const selectedProductWearhouses = allInventoryByItemIds.find((inventory: any) => inventory.skuId === itemId)?.balance?.filter((wearhouse: any) => productPlants.includes(wearhouse.warehouseName)) ?? [] availableQuantity = selectedProductWearhouses.reduce((partialSum: number, current: any) => partialSum + current?.totalQuantity ?? 0, 0) isAvailable = selectedProductWearhouses.length > 0 } @@ -183,9 +183,6 @@ export const queries = { } }) - - console.log(JSON.stringify(itemsRequested, null, 2)) - return { items: itemsRequested, } diff --git a/react/AutocompleteBlock.tsx b/react/AutocompleteBlock.tsx index 5b86d5c1..bb0f6d82 100644 --- a/react/AutocompleteBlock.tsx +++ b/react/AutocompleteBlock.tsx @@ -5,7 +5,7 @@ import { injectIntl, defineMessages, } from 'react-intl' -import { Button, Tag, Input, ToastContext, IconClear } from 'vtex.styleguide' +import { Button, Tag, Input, ToastContext, IconClear, Spinner } from 'vtex.styleguide' import { OrderForm } from 'vtex.order-manager' import { OrderForm as OrderFormType } from 'vtex.checkout-graphql' import { addToCart as ADD_TO_CART } from 'vtex.checkout-resources/Mutations' @@ -13,10 +13,12 @@ import { usePWA } from 'vtex.store-resources/PWAContext' import { usePixel } from 'vtex.pixel-manager/PixelContext' import PropTypes from 'prop-types' import { useCssHandles } from 'vtex.css-handles' -import { useApolloClient, useMutation } from 'react-apollo' +import { useApolloClient, useMutation, useQuery } from 'react-apollo' import QuickOrderAutocomplete from './components/QuickOrderAutocomplete' import productQuery from './queries/product.gql' +import GET_ACCOUNT_INFO from './queries/orderSoldToAccount.graphql' +import GET_PRODUCT_DATA from './queries/getPrductAvailability.graphql' import './global.css' const messages = defineMessages({ @@ -52,6 +54,7 @@ const AutocompleteBlock: StorefrontFunctionComponent { // eslint-disable-next-line react/prop-types return intl.formatMessage(message) @@ -183,6 +199,35 @@ const AutocompleteBlock: StorefrontFunctionComponent ref.Key === 'RefId')?.Value ?? '' + try { + const { data: productInfo } = await client.query({ + query: GET_PRODUCT_DATA, + variables: { + refIds: [refId] as string[], + customerNumber, + targetSystem, + salesOrganizationCode, + }, + }) + + if (productInfo) { + const itemsFromQuery = productInfo.getSkuAvailability?.items ?? [] + const refIdNotFound = itemsFromQuery.filter((item: any) => { + return item.sku === null + }) + + const refNotAvailable = itemsFromQuery.filter((item: any) => { + return item.availability !== 'available' + }) + + if (itemsFromQuery.length > 0 && refIdNotFound.length === 0 && refNotAvailable.length === 0) { + setHideAddToCart(false) + } + } + } catch (error) { + console.log(error) + } setState({ ...state, @@ -250,11 +295,12 @@ const AutocompleteBlock: StorefrontFunctionComponent :(
{!componentOnly && (
@@ -342,6 +388,7 @@ const AutocompleteBlock: StorefrontFunctionComponent
+ { !hideAddToCart? (
@@ -356,6 +403,16 @@ const AutocompleteBlock: StorefrontFunctionComponent
+ ): ( +
+ +
) + }
diff --git a/react/TextAreaBlock.tsx b/react/TextAreaBlock.tsx index db6fa713..0cf4ad43 100644 --- a/react/TextAreaBlock.tsx +++ b/react/TextAreaBlock.tsx @@ -220,7 +220,7 @@ const TextAreaBlock: StorefrontFunctionComponent {refidLoading && } - {showAddToCart? ( + {showAddToCart ? (
- ): ( + ) : (
-
- ): ( -
- -
) - } + +
+ ) : ( +
+ +
+ )}
diff --git a/react/package.json b/react/package.json index 83685c25..7be40fdf 100644 --- a/react/package.json +++ b/react/package.json @@ -31,25 +31,26 @@ "prettier": "^1.18.2", "react": "^16.9.2", "react-apollo": "^3.1.3", + "sbdsefuat.checkout-simulation": "http://sbdsefuat.vtexassets.com/_v/public/typings/v1/sbdsefuat.checkout-simulation@1.0.31/public/@types/sbdsefuat.checkout-simulation", "tslint-eslint-rules": "^5.4.0", "typescript": "3.9.7", "vtex.apps-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql", "vtex.checkout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout@0.6.0/public/_types/react", - "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql", - "vtex.checkout-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources", + "vtex.checkout-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.63.0/public/@types/vtex.checkout-graphql", + "vtex.checkout-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.47.0/public/@types/vtex.checkout-resources", "vtex.css-handles": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles", - "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout", + "vtex.flex-layout": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.19.0/public/@types/vtex.flex-layout", "vtex.order-items": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items", "vtex.order-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-manager@0.11.1/public/@types/vtex.order-manager", "vtex.pixel-manager": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager", - "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime", - "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text", - "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql", - "vtex.store": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store", - "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql", + "vtex.render-runtime": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.3/public/@types/vtex.render-runtime", + "vtex.rich-text": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.15.0/public/@types/vtex.rich-text", + "vtex.search-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.47.2/public/@types/vtex.search-graphql", + "vtex.store": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.1/public/@types/vtex.store", + "vtex.store-graphql": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.147.4/public/@types/vtex.store-graphql", "vtex.store-icons": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons", - "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources", - "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide" + "vtex.store-resources": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.85.0/public/@types/vtex.store-resources", + "vtex.styleguide": "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.2/public/@types/vtex.styleguide" }, "version": "3.2.0" } diff --git a/react/queries/getPrductAvailability.graphql b/react/queries/getPrductAvailability.graphql index 4dc8f7de..81e01bb7 100644 --- a/react/queries/getPrductAvailability.graphql +++ b/react/queries/getPrductAvailability.graphql @@ -1,5 +1,15 @@ -query getAvbProduct($refIds: [String], $customerNumber: String, $targetSystem: String, $salesOrganizationCode: String) { - getSkuAvailability(refIds: $refIds, customerNumber: $customerNumber, targetSystem: $targetSystem, salesOrganizationCode: $salesOrganizationCode) @context(provider: "sbdsefuat.bulk-order") { +query getAvbProduct( + $refIds: [String] + $customerNumber: String + $targetSystem: String + $salesOrganizationCode: String +) { + getSkuAvailability( + refIds: $refIds + customerNumber: $customerNumber + targetSystem: $targetSystem + salesOrganizationCode: $salesOrganizationCode + ) @context(provider: "sbdsefuat.bulk-order") { items { refid sku @@ -12,6 +22,7 @@ query getAvbProduct($refIds: [String], $customerNumber: String, $targetSystem: S availableQuantity productName price + unitMultiplier } } } diff --git a/react/queries/product.gql b/react/queries/product.gql index 5debbbe0..2a6867cc 100644 --- a/react/queries/product.gql +++ b/react/queries/product.gql @@ -1,9 +1,14 @@ query Product($slug: String) { product(slug: $slug) @context(provider: "vtex.search-graphql") { productName + properties { + name + values + } items { itemId name + unitMultiplier sellers { sellerId sellerName diff --git a/react/typings/vtex.styleguide.d.ts b/react/typings/vtex.styleguide.d.ts index 02cbf0a2..2ecc0a74 100644 --- a/react/typings/vtex.styleguide.d.ts +++ b/react/typings/vtex.styleguide.d.ts @@ -15,8 +15,19 @@ declare module 'vtex.styleguide' { export const Textarea: ComponentType export const Dropzone: ComponentType export const AutocompleteInput: ComponentType + export const NumericStepper: ComponentType interface InputProps { [key: string]: any } + + interface NumericStepperProps { + size: NumericSize + value: number + minValue: number + maxValue?: number + unitMultiplier: number + suffix?: string + onChange: (e: any) => void + } } diff --git a/react/yarn.lock b/react/yarn.lock index 3b7ef821..ef9c9888 100644 --- a/react/yarn.lock +++ b/react/yarn.lock @@ -4922,6 +4922,10 @@ sax@^1.2.4: resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== +"sbdsefuat.checkout-simulation@http://sbdsefuat.vtexassets.com/_v/public/typings/v1/sbdsefuat.checkout-simulation@1.0.31/public/@types/sbdsefuat.checkout-simulation": + version "1.0.31" + resolved "http://sbdsefuat.vtexassets.com/_v/public/typings/v1/sbdsefuat.checkout-simulation@1.0.31/public/@types/sbdsefuat.checkout-simulation#3a21fb83f00402698f84231baea53482985d2eaf" + scheduler@^0.18.0: version "0.18.0" resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.18.0.tgz#5901ad6659bc1d8f3fdaf36eb7a67b0d6746b1c4" @@ -5545,13 +5549,13 @@ verror@1.10.0: version "2.8.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.apps-graphql@2.8.0/public/@types/vtex.apps-graphql#4fd47b1281c4d36e8abb1cfa4daea83bc739eca1" -"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql": - version "0.61.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.61.1/public/@types/vtex.checkout-graphql#68de6f71ab2b87983d6a03bd40fd80647532319c" +"vtex.checkout-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.63.0/public/@types/vtex.checkout-graphql": + version "0.63.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-graphql@0.63.0/public/@types/vtex.checkout-graphql#1a1f7cb496a02aaeab117b5f8da4c59dc4fee0bc" -"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources": - version "0.46.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.46.0/public/@types/vtex.checkout-resources#a6c7a59fd9a92d44d486425bc311cb93ad5f0653" +"vtex.checkout-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.47.0/public/@types/vtex.checkout-resources": + version "0.47.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout-resources@0.47.0/public/@types/vtex.checkout-resources#8a20a179c882a2dcea62cb65750404448fc6ea30" "vtex.checkout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.checkout@0.6.0/public/_types/react": version "0.0.0" @@ -5561,9 +5565,9 @@ verror@1.10.0: version "0.4.4" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.css-handles@0.4.4/public/@types/vtex.css-handles#8c45c6decf9acd2b944e07261686decff93d6422" -"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout": - version "0.18.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.18.0/public/@types/vtex.flex-layout#13e94349a8e2c3514754d6357bd028c39de11099" +"vtex.flex-layout@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.19.0/public/@types/vtex.flex-layout": + version "0.19.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.flex-layout@0.19.0/public/@types/vtex.flex-layout#042e0e1770bafdd157705abefffe0b2645a98f84" "vtex.order-items@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.order-items@0.13.1/public/@types/vtex.order-items": version "0.13.1" @@ -5577,37 +5581,37 @@ verror@1.10.0: version "1.8.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.pixel-manager@1.8.0/public/@types/vtex.pixel-manager#3ccfcb1927614984a5f7a3e5650c8c8d2bd3c0f4" -"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime": - version "8.131.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.131.0/public/@types/vtex.render-runtime#dcc88828e3d65ecb4e7538a3623a4b1ddd77e034" +"vtex.render-runtime@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.3/public/@types/vtex.render-runtime": + version "8.132.3" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.render-runtime@8.132.3/public/@types/vtex.render-runtime#c7dd142e384f38bd7a7c841543b73e9349fadc93" -"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text": - version "0.14.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.14.0/public/@types/vtex.rich-text#fd31249116da1e0f1caeaa00a44035afa9c91703" +"vtex.rich-text@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.15.0/public/@types/vtex.rich-text": + version "0.15.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.rich-text@0.15.0/public/@types/vtex.rich-text#f23416cea64e72531069e58f1b137dfdb5b4b510" -"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql": - version "0.46.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.46.0/public/@types/vtex.search-graphql#00476e3d62c377df9cd9713f76dbfd531a019eff" +"vtex.search-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.47.2/public/@types/vtex.search-graphql": + version "0.47.2" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.search-graphql@0.47.2/public/@types/vtex.search-graphql#9bc27e570e10137514135b80afebc007f651be87" -"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql": - version "2.143.1" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.143.1/public/@types/vtex.store-graphql#55ca65edbe5b6c25826bb646c53eb8de1917b45d" +"vtex.store-graphql@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.147.4/public/@types/vtex.store-graphql": + version "2.147.4" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-graphql@2.147.4/public/@types/vtex.store-graphql#8340064d04c59b01d1b4053b3fba671552199660" "vtex.store-icons@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons": version "0.18.0" resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-icons@0.18.0/public/@types/vtex.store-icons#0ee94d549aa283ce3a13ab987c13eac4fdfd1bba" -"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources": - version "0.84.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.84.0/public/@types/vtex.store-resources#51431e5ae7ea64e90e345407e4720b152e81a816" +"vtex.store-resources@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.85.0/public/@types/vtex.store-resources": + version "0.85.0" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store-resources@0.85.0/public/@types/vtex.store-resources#c320bf775471cec37977bfb8af2cfccd4c857c63" -"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store": - version "2.120.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.0/public/@types/vtex.store#62930c752742172a6b3e545726feffbade76f3bd" +"vtex.store@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.1/public/@types/vtex.store": + version "2.120.1" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.store@2.120.1/public/@types/vtex.store#fda1d0c7a0226d7229a51a81ec3721bf23d5aa6e" -"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide": - version "9.145.0" - resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.0/public/@types/vtex.styleguide#41dfb32af8756eb5528dbd452e47003a8f67fe8c" +"vtex.styleguide@http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.2/public/@types/vtex.styleguide": + version "9.145.2" + resolved "http://vtex.vtexassets.com/_v/public/typings/v1/vtex.styleguide@9.145.2/public/@types/vtex.styleguide#ca64bf8408ad3eb487b0822dd68f77565c986a56" w3c-hr-time@^1.0.1: version "1.0.1" From 016e3c3a33420921b1d5344f85f4d270ef7eadcb Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Fri, 5 Nov 2021 21:59:56 +0530 Subject: [PATCH 22/29] Fix numeric stepper --- react/components/ReviewBlock.tsx | 13 ++++++++----- react/typings/gql.d.ts | 6 ++++++ react/typings/vtex.checkout-resources.d.ts | 1 + react/typings/vtex.pixel-manager.d.ts | 1 + react/typings/vtex.store-resources.d.ts | 1 + react/typings/vtex.styleguide.d.ts | 1 + 6 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 react/typings/gql.d.ts create mode 100644 react/typings/vtex.checkout-resources.d.ts create mode 100644 react/typings/vtex.pixel-manager.d.ts create mode 100644 react/typings/vtex.store-resources.d.ts diff --git a/react/components/ReviewBlock.tsx b/react/components/ReviewBlock.tsx index b4a2eb58..3023c384 100644 --- a/react/components/ReviewBlock.tsx +++ b/react/components/ReviewBlock.tsx @@ -35,7 +35,7 @@ const messages = defineMessages({ id: 'store/quickorder.available', }, unavailable: { - id: 'store/quickorder.unavailable' + id: 'store/quickorder.unavailable', }, invalidPattern: { id: 'store/quickorder.invalidPattern', @@ -163,8 +163,10 @@ const ReviewBlock: StorefrontFunctionComponent = ({ } ) - const customerNumber = accountData?.getOrderSoldToAccount?.customerNumber ?? '' - const targetSystem = accountData?.getOrderSoldToAccount?.targetSystem ?? '' + const customerNumber = + accountData?.getOrderSoldToAccount?.customerNumber ?? '' + const targetSystem = + accountData?.getOrderSoldToAccount?.targetSystem ?? '' const salesOrganizationCode = accountData?.getOrderSoldToAccount?.salesOrganizationCode ?? '' @@ -379,7 +381,7 @@ const ReviewBlock: StorefrontFunctionComponent = ({ validateRefids(data, reviewed) } catch (error) { - console.log(error) + console.error(error) } onRefidLoading(false) @@ -570,7 +572,8 @@ const ReviewBlock: StorefrontFunctionComponent = ({ cellRenderer: ({ cellData, rowData }: any) => { if (rowData.error) { const text = intl.formatMessage( - errorMessage[cellData !== null && cellData !== void 0 ? cellData : 'store/quickorder.valid'] + errorMessage[ + cellData !== null && cellData !== void 0 ? cellData : 'store/quickorder.valid'] ) return ( diff --git a/react/typings/gql.d.ts b/react/typings/gql.d.ts new file mode 100644 index 00000000..e13a5df5 --- /dev/null +++ b/react/typings/gql.d.ts @@ -0,0 +1,6 @@ +declare module '*.gql' { + import { DocumentNode } from 'gql' + + const value: DocumentNode + export default value +} diff --git a/react/typings/vtex.checkout-resources.d.ts b/react/typings/vtex.checkout-resources.d.ts new file mode 100644 index 00000000..8e01925d --- /dev/null +++ b/react/typings/vtex.checkout-resources.d.ts @@ -0,0 +1 @@ +declare module 'vtex.checkout-resources/*' diff --git a/react/typings/vtex.pixel-manager.d.ts b/react/typings/vtex.pixel-manager.d.ts new file mode 100644 index 00000000..c37b3458 --- /dev/null +++ b/react/typings/vtex.pixel-manager.d.ts @@ -0,0 +1 @@ +declare module 'vtex.pixel-manager/PixelContext' diff --git a/react/typings/vtex.store-resources.d.ts b/react/typings/vtex.store-resources.d.ts new file mode 100644 index 00000000..2938c8ef --- /dev/null +++ b/react/typings/vtex.store-resources.d.ts @@ -0,0 +1 @@ +declare module 'vtex.store-resources/PWAContext' diff --git a/react/typings/vtex.styleguide.d.ts b/react/typings/vtex.styleguide.d.ts index 2ecc0a74..b33a274c 100644 --- a/react/typings/vtex.styleguide.d.ts +++ b/react/typings/vtex.styleguide.d.ts @@ -15,6 +15,7 @@ declare module 'vtex.styleguide' { export const Textarea: ComponentType export const Dropzone: ComponentType export const AutocompleteInput: ComponentType + export const Collapsible: ComponentType export const NumericStepper: ComponentType interface InputProps { From 3990964b8778b79bb36a397f43d0f52edda61627 Mon Sep 17 00:00:00 2001 From: neeshsilva Date: Fri, 5 Nov 2021 23:21:29 +0530 Subject: [PATCH 23/29] Fix numeric stepper --- react/UploadBlock.tsx | 4 ++-- react/components/ReviewBlock.tsx | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/react/UploadBlock.tsx b/react/UploadBlock.tsx index 48cba28c..0040edc3 100644 --- a/react/UploadBlock.tsx +++ b/react/UploadBlock.tsx @@ -342,7 +342,7 @@ const UploadBlock: StorefrontFunctionComponent
- ): ( + ) : (