Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/api/quickbooks/product/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export class ProductService extends BaseService {
const query = this.db
.update(QBProductSync)
.set(parsedInsertPayload)
.where(conditions)
.where(and(conditions, eq(QBProductSync.portalId, this.user.workspaceId)))

const [product] = returningFields?.length
? await query.returning(
Expand Down Expand Up @@ -397,6 +397,8 @@ export class ProductService extends BaseService {
let itemCount = 0

for (const product of mappedProducts) {
if (product.isExcluded) continue

const qbItemId = z.string().parse(product.qbItemId)
const productId = z.string().parse(product.productId)

Expand Down Expand Up @@ -707,7 +709,7 @@ export class ProductService extends BaseService {
console.info(
`ProductService#updateProductSyncToken. Item not found for Id ${qbItemId} in QuickBooks. Unmapping the product...`,
)
await this.unmapProducts(qbItemId)
// if (updateMappingTable) await this.unmapProducts(qbItemId)
return
} else if (!item.Active) {
console.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import useClickOutside from '@/hook/useClickOutside'
import { useDropdownPosition } from '@/hook/useDropdown'
import {
ProductDataType,
QBItemDataType,
useMapItem,
useProductTableSetting,
} from '@/hook/useSettings'
Expand All @@ -14,12 +15,19 @@ const MapItemComponent = ({
mappingItems,
productId,
priceId,
qbItems,
}: {
mappingItems: ProductMappingItemType[] | undefined
productId: string
priceId: string
qbItems: QBItemDataType[] | undefined
}) => {
const { currentlyMapped } = useMapItem(mappingItems, productId, priceId)
const { currentlyMapped } = useMapItem(
mappingItems,
productId,
priceId,
qbItems,
)
return (
<>
{currentlyMapped ? (
Expand Down Expand Up @@ -148,6 +156,7 @@ export default function ProductMappingTable({
mappingItems={mappingItems}
productId={product.id}
priceId={product.priceId}
qbItems={quickbooksItems}
/>
)}
</div>
Expand Down
27 changes: 24 additions & 3 deletions src/hook/useSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
if (!productSetting || !intialSettingState) return
const showButton = !equal(intialSettingState, productSetting)
setSettingShowConfirm(showButton)
}, [productSetting])

Check warning on line 99 in src/hook/useSettings.ts

View workflow job for this annotation

GitHub Actions / Run linters

React Hook useEffect has a missing dependency: 'intialSettingState'. Either include it or remove the dependency array

useEffect(() => {
if (setting && setting?.setting) {
Expand Down Expand Up @@ -203,7 +203,11 @@
[index]: '',
}))
const fileteredChangedItem = changedItemReference.filter(
(item) => item.id !== products[index].id,
(item) =>
!(
item.id === products[index].id &&
item.priceId === products[index].priceId
),
)
const newVal = [
...fileteredChangedItem,
Expand Down Expand Up @@ -448,6 +452,7 @@
mappingItems: ProductMappingItemType[] | undefined,
productId: string,
priceId: string,
qbItems: QBItemDataType[] | undefined,
) => {
const [currentlyMapped, setCurrentlyMapped] = useState<
ProductMappingItemType | undefined
Expand All @@ -460,8 +465,24 @@
item.qbItemId
)
})
setCurrentlyMapped(currentMapItem)
return currentMapItem
const currentQbItem = qbItems?.find((item) => {
return item.id === currentMapItem?.qbItemId
})

let itemToReturn: { name: string; unitPrice: string } | undefined
const itemName = currentQbItem?.name || currentMapItem?.name
const itemUnitPrice =
currentQbItem?.numericPrice.toFixed(2) || currentMapItem?.unitPrice

if (itemName && itemUnitPrice) {
itemToReturn = {
name: itemName,
unitPrice: itemUnitPrice,
}
}

setCurrentlyMapped(itemToReturn)
return itemToReturn
}

useEffect(() => {
Expand Down
Loading