Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
chore: enforce sku selection page to hide already selected items
Browse files Browse the repository at this point in the history
  • Loading branch information
pfferrari committed Feb 28, 2024
1 parent 84644d0 commit f3f5946
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
17 changes: 8 additions & 9 deletions packages/app/src/components/SkuListForm/SkuListForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,13 @@ export function SkuListForm({
return watchedFormManual ? 0 : 1
}, [watchedFormManual])

// const selectedItemsCodes = useMemo(() => {
// const excludedCodes = [] as string[]
// watchedFormItems?.forEach((sku) => {
// excludedCodes.push(sku.sku_code)
// })
// return excludedCodes.join(',') ?? ''
// }, [watchedFormItems])
// console.log(selectedItemsCodes)
const selectedItemsCodes = useMemo(() => {
const excludedCodes = [] as string[]
watchedFormItems?.forEach((sku) => {
excludedCodes.push(sku.sku_code)
})
return excludedCodes.join(',') ?? ''
}, [watchedFormItems])

useEffect(() => {
if (resource != null) {
Expand Down Expand Up @@ -164,7 +163,7 @@ export function SkuListForm({
padding='4'
fullWidth
onClick={() => {
showAddItemOverlay('')
showAddItemOverlay(selectedItemsCodes)
}}
/>
</Spacer>
Expand Down
13 changes: 6 additions & 7 deletions packages/app/src/hooks/useAddItemOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import { useState } from 'react'
import { navigate, useSearch } from 'wouter/use-browser-location'

interface OverlayHook {
show: (excludedIds?: string) => void
show: (excludedCodes?: string) => void
Overlay: React.FC<{ onConfirm: (resource: Sku) => void }>
}

export function useAddItemOverlay(): OverlayHook {
const { Overlay: OverlayElement, open, close } = useOverlay()
const [excludedIds, setExcludedIds] = useState<string>('')
const [excludedCodes, setExcludedCodes] = useState<string>('')

const instructions: FiltersInstructions = [
{
Expand All @@ -34,10 +34,9 @@ export function useAddItemOverlay(): OverlayHook {
]

return {
show: (excludedIds) => {
console.log(excludedIds)
if (excludedIds != null) {
setExcludedIds(excludedIds)
show: (excludedCodes) => {
if (excludedCodes != null) {
setExcludedCodes(excludedCodes)
}
open()
},
Expand Down Expand Up @@ -90,7 +89,7 @@ export function useAddItemOverlay(): OverlayHook {
<FilteredList
type='skus'
query={{
filters: { id_eq: excludedIds }
filters: { code_not_in: excludedCodes }
}}
ItemTemplate={(props) => (
<ListItemSku
Expand Down
3 changes: 0 additions & 3 deletions packages/app/src/hooks/useUpdateSkuList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export function useUpdateSkuList(): UpdateSkuListHook {
id: itemNeedsUpdate.id,
quantity: item.quantity
})
console.log('updated sku list item', item)
}
const itemIsAlreadyExisting = updatedSkuList.sku_list_items?.find(
(skuListItem) => skuListItem.sku_code === item.sku_code
Expand All @@ -57,7 +56,6 @@ export function useUpdateSkuList(): UpdateSkuListHook {
sdkClient
)
await sdkClient.sku_list_items.create(skuListItem)
console.log('created sku list item', skuListItem)
}
})
)
Expand All @@ -70,7 +68,6 @@ export function useUpdateSkuList(): UpdateSkuListHook {
)
if (itemIsInNewListItems == null) {
await sdkClient.sku_list_items.delete(oldItem.id)
console.log('deleted sku list item', oldItem.id)
}
})
)
Expand Down

0 comments on commit f3f5946

Please sign in to comment.