Skip to content

Commit

Permalink
fix: List of stock transfers
Browse files Browse the repository at this point in the history
  • Loading branch information
acasazza committed May 23, 2022
1 parent b5e1954 commit 67dd33e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/StockTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useContext, ReactNode, Fragment } from 'react'
import LineItemChildrenContext from '#context/LineItemChildrenContext'
import { useContext, ReactNode, FunctionComponent } from 'react'
import components from '#config/components'
import ShipmentChildrenContext from '#context/ShipmentChildrenContext'
import StockTransferChildrenContext from '#context/StockTransferChildrenContext'
Expand All @@ -12,19 +11,17 @@ type StockTransferProps = {
children: ReactNode
} & JSX.IntrinsicElements['p']

const StockTransfer: React.FunctionComponent<StockTransferProps> = (props) => {
const StockTransfer: FunctionComponent<StockTransferProps> = (props) => {
const { children } = props
const { lineItem } = useContext(LineItemChildrenContext)
const { stockTransfers } = useContext(ShipmentChildrenContext)
const items = [
...(lineItem ? [lineItem] : []),
...(stockTransfers ? stockTransfers : []),
]
const components = items
?.filter((stock) => stock.sku_code !== lineItem?.sku_code)
const { stockTransfers, lineItems } = useContext(ShipmentChildrenContext)
const components = stockTransfers
?.filter((st) => !!lineItems?.find((l) => l.sku_code !== st.sku_code))
.map((stockTransfer: TStockTransfer, k) => {
const stockTransferProps = {
stockTransfer: stockTransfer?.line_item,
stockTransfer:
stockTransfer.type === 'line_items'
? stockTransfer
: stockTransfer?.line_item,
}
return (
<StockTransferChildrenContext.Provider
Expand All @@ -35,7 +32,7 @@ const StockTransfer: React.FunctionComponent<StockTransferProps> = (props) => {
</StockTransferChildrenContext.Provider>
)
})
return <Fragment>{components}</Fragment>
return <>{components}</>
}

StockTransfer.propTypes = propTypes
Expand Down

0 comments on commit 67dd33e

Please sign in to comment.