1 import { XMarkMini } from "@medusajs/icons"
2 import { IconButton, Text } from "@medusajs/ui"
3 import { useProduct } from "../../../../../hooks/api"
4
5 type TargetItemProps = {
6 index: number
7 onRemove: (index: number) => void
8 label: string
9 value: string
10 }
11
12 export const TargetItem = ({
13 index,
14 label,
15 onRemove,
16 value,
17 }: TargetItemProps) => {
18 const { product } = useProduct(
19 value,
20 {
21 // TODO: Remove exclusion once we avoid including unnecessary relations by default in the query config
22 fields:
23 "id,title,-type,-collection,-options,-tags,-images,-variants,-sales_channels",
24 },
25 { enabled: !label }
26 )
27
28 return (
29 <div className="bg-ui-bg-field-component shadow-borders-base flex items-center justify-between gap-2 rounded-md px-2 py-0.5">
30 <Text size="small" leading="compact">
31 {label || product?.title}
32 </Text>
33 <IconButton
34 size="small"
35 variant="transparent"
36 type="button"
37 onClick={() => onRemove(index)}
38 >
39 <XMarkMini />
40 </IconButton>
41 </div>
42 )
43 }