Skip to content

Commit

Permalink
Merge pull request #92 from vtex-apps/bugfix/QUICKORDER-10
Browse files Browse the repository at this point in the history
[QUICKORDER-10] fixed a bug where changing sellers would not change item status
  • Loading branch information
whc105 authored Feb 10, 2022
2 parents e1f783d + 5c2b423 commit 8f817d7
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Fixed a bug where changing seller would not update specific status for that seller
- Fixed a bug where the copy/paste and upload blocks would not show updated results

## [3.6.2] - 2022-02-09

### Added
Expand Down
10 changes: 7 additions & 3 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
type Query {
skuFromRefIds(refids: [String], orderFormId: String): Refids
@cacheControl(scope: SEGMENT, maxAge: MEDIUM)
@withSegment
skuFromRefIds(
refids: [String]
orderFormId: String
refIdSellerMap: RefIdSellerMap
): Refids @cacheControl(scope: SEGMENT, maxAge: MEDIUM) @withSegment
sellers: SellersType
@cacheControl(scope: SEGMENT, maxAge: MEDIUM)
@withSegment
}

scalar RefIdSellerMap
22 changes: 18 additions & 4 deletions node/clients/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import { InstanceOptions, IOContext, JanusClient } from '@vtex/api'
interface RefIdArgs {
refids: any
orderFormId: string
refIdSellerMap: RefIdSellerMap
}
interface Items {
id: string
quantity: number
seller: string
}

interface RefIdSellerMap {
[key: string]: string
}

export class Search extends JanusClient {
constructor(context: IOContext, options?: InstanceOptions) {
super(context, {
Expand All @@ -33,6 +38,7 @@ export class Search extends JanusClient {
public skuFromRefIds = async ({
refids,
orderFormId,
refIdSellerMap,
}: RefIdArgs): Promise<any> => {
this.sellersList = await this.sellers()

Expand Down Expand Up @@ -70,7 +76,11 @@ export class Search extends JanusClient {

const orderForm = await this.getOrderForm(orderFormId)

const { items }: any = await this.simulate(result, orderForm)
const { items }: any = await this.simulate(
result,
orderForm,
refIdSellerMap
)
items.forEach((item: any) => {
items[item.id] = item
})
Expand All @@ -83,6 +93,7 @@ export class Search extends JanusClient {
}
})
}

return result
}

Expand All @@ -95,7 +106,11 @@ export class Search extends JanusClient {
})
}

private simulate = async (refids: [Items], orderForm: any) => {
private simulate = async (
refids: [Items],
orderForm: any,
refIdSellerMap: RefIdSellerMap
) => {
const {
salesChannel,
storePreferencesData: { countryCode },
Expand All @@ -106,11 +121,10 @@ export class Search extends JanusClient {
return !!item.sku
})
.map((item: any) => {
const [seller] = item.sellers
return {
id: item.sku,
quantity: 1,
seller: seller?.id,
seller: refIdSellerMap[item.refid],
}
})

Expand Down
3 changes: 2 additions & 1 deletion node/resolvers/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const fieldResolvers = {
export const queries = {
skuFromRefIds: async (
_: any,
args: { refids: string; orderFormId: string },
args: { refids: string; orderFormId: string; refIdSellerMap: any },
ctx: Context
): Promise<any> => {
const {
Expand All @@ -25,6 +25,7 @@ export const queries = {
const items = await search.skuFromRefIds({
refids: args.refids,
orderFormId: args.orderFormId,
refIdSellerMap: args.refIdSellerMap,
})

return {
Expand Down
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6037,7 +6037,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:
Expand Down
48 changes: 24 additions & 24 deletions react/components/ReviewBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable vtex/prefer-early-return */
import React, { useState, FunctionComponent } from 'react'
import React, { useState, FunctionComponent, useEffect } from 'react'
import {
Table,
Input,
Expand All @@ -19,7 +19,6 @@ import getRefIdTranslation from '../queries/refids.gql'
import OrderFormQuery from '../queries/orderForm.gql'

const remove = <IconDelete />
let initialLoad = ''

const messages = defineMessages({
valid: {
Expand Down Expand Up @@ -258,12 +257,10 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}

const items = reviewed.map((item: any) => {
const sellers = item.sku ? mappedRefId[item.sku]?.sellers : '1'

return {
...item,
sellers: item.sku ? mappedRefId[item.sku]?.sellers : '1',
seller: sellers?.length ? sellers[0].id : '1',
seller: item.seller ? item.seller : '1',
vtexSku: item.sku ? mappedRefId[item.sku]?.sku : '1',
unitMultiplier: item.sku
? mappedRefId[item.sku]?.unitMultiplier
Expand Down Expand Up @@ -296,20 +293,17 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}
}

const getRefIds = async (_refids: any, reviewed: any) => {
const getRefIds = async (
_refids: any,
reviewed: any,
refIdSellerMap: any
) => {
onRefidLoading(true)
let refids = {}

if (_refids.length) {
_refids.forEach(refid => {
refids[refid] = true
})
refids = Object.getOwnPropertyNames(refids)
}
const refids = _refids.length ? Array.from(new Set(_refids)) : []

const query = {
query: getRefIdTranslation,
variables: { refids, orderFormId },
variables: { refids, orderFormId, refIdSellerMap },
}

const { data } = await client.query(query)
Expand All @@ -319,15 +313,18 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}

const convertRefIds = (items: any) => {
const refIdSellerMap = {}
const refids = items
.filter((item: any) => {
return item.error === null
})
.map((item: any) => {
refIdSellerMap[item.sku] = '1'

return item.sku
})

getRefIds(refids, items)
getRefIds(refids, items, refIdSellerMap)
}

const checkValidatedItems = () => {
Expand All @@ -340,10 +337,9 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}
}

if (initialLoad !== GetText(reviewItems)) {
useEffect(() => {
checkValidatedItems()
initialLoad = GetText(reviewItems)
}
})

const removeLine = (i: number) => {
const items: [any] = reviewItems
Expand Down Expand Up @@ -382,6 +378,7 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}

const updateLineSeller = (index: number, seller: string) => {
const refIdSellerMap = {}
const items = reviewItems.map((item: any) => {
return item.index === index
? {
Expand All @@ -391,10 +388,13 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
: item
})

setReviewState({
...state,
reviewItems: items,
const refids = items.map((item: any) => {
refIdSellerMap[item.sku] = item.seller

return item.sku
})

getRefIds(refids, items, refIdSellerMap)
}

const onBlurField = (line: number) => {
Expand Down Expand Up @@ -491,9 +491,9 @@ const ReviewBlock: FunctionComponent<WrappedComponentProps & any> = ({
}
})}
value={rowData.seller}
onChange={(_: any, v: any) =>
onChange={(_: any, v: any) => {
updateLineSeller(rowData.index, v)
}
}}
/>
</div>
)
Expand Down
12 changes: 10 additions & 2 deletions react/queries/refids.gql
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
query getSkuFromRefIds($refids: [String], $orderFormId: String) {
skuFromRefIds(refids: $refids, orderFormId: $orderFormId) {
query getSkuFromRefIds(
$refids: [String]
$orderFormId: String
$refIdSellerMap: RefIdSellerMap
) {
skuFromRefIds(
refids: $refids
orderFormId: $orderFormId
refIdSellerMap: $refIdSellerMap
) {
items {
sku
refid
Expand Down

0 comments on commit 8f817d7

Please sign in to comment.