fix(marketplace): filter out own store products by 0km distance

- For owners/sellers, exclude products at exactly 0km (own pharmacy)
- This correctly hides own products without needing company_id in JWT
This commit is contained in:
Tiago Yamamoto 2025-12-23 16:29:08 -03:00
parent e7b02f24e7
commit 2bbb715ebb

View file

@ -64,8 +64,15 @@ const ProductSearch = () => {
// Filter out products from the logged-in user's pharmacy and group by name
const groupedProducts = useMemo(() => {
// Filter out own products
const filteredProducts = products.filter(p => p.seller_id !== user?.id)
// Filter out own products - for owners/sellers, products at 0km are from their own store
const isOwnerOrSeller = user?.role === 'owner' || user?.role === 'seller'
const filteredProducts = products.filter(p => {
// Exclude products at exactly 0km distance for owners (own store)
if (isOwnerOrSeller && p.distance_km === 0) {
return false
}
return true
})
// Group by name (case-insensitive)
const groups: Record<string, GroupedProduct> = {}