add quantity to combobox
This commit is contained in:
@@ -36,6 +36,8 @@ import {
|
|||||||
} from '@repo/ui/components/ui/popover'
|
} from '@repo/ui/components/ui/popover'
|
||||||
import { cn } from '@repo/ui/lib/utils'
|
import { cn } from '@repo/ui/lib/utils'
|
||||||
|
|
||||||
|
import { Abbr } from '@repo/ui/components/abbr'
|
||||||
|
import { Kbd } from '@repo/ui/components/ui/kbd'
|
||||||
import { type Course } from './data'
|
import { type Course } from './data'
|
||||||
|
|
||||||
interface CoursePickerProps extends Omit<
|
interface CoursePickerProps extends Omit<
|
||||||
@@ -146,7 +148,8 @@ export const CoursePicker = forwardRef<HTMLInputElement, CoursePickerProps>(
|
|||||||
id,
|
id,
|
||||||
name,
|
name,
|
||||||
access_period,
|
access_period,
|
||||||
metadata__unit_price: unit_price
|
metadata__unit_price: unit_price,
|
||||||
|
quantity = null
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<CommandItem
|
<CommandItem
|
||||||
@@ -163,13 +166,15 @@ export const CoursePicker = forwardRef<HTMLInputElement, CoursePickerProps>(
|
|||||||
set(false)
|
set(false)
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{name}
|
|
||||||
<CheckIcon
|
<CheckIcon
|
||||||
className={cn(
|
className={cn(
|
||||||
'ml-auto',
|
|
||||||
value?.id === id ? 'opacity-100' : 'opacity-0'
|
value?.id === id ? 'opacity-100' : 'opacity-0'
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Abbr>{name}</Abbr>
|
||||||
|
{quantity && (
|
||||||
|
<Kbd className="ml-auto border">{quantity}x</Kbd>
|
||||||
|
)}
|
||||||
</CommandItem>
|
</CommandItem>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,15 +90,23 @@ export default function Route({ loaderData: { seats } }: Route.ComponentProps) {
|
|||||||
() =>
|
() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
hits: Array.from(
|
hits: Array.from(
|
||||||
new Map(
|
seats
|
||||||
seats.map(({ course }) => [
|
.reduce((map, { course }) => {
|
||||||
course.id,
|
const existing = map.get(course.id)
|
||||||
{
|
|
||||||
|
if (existing) {
|
||||||
|
existing.quantity += 1
|
||||||
|
} else {
|
||||||
|
map.set(course.id, {
|
||||||
...course,
|
...course,
|
||||||
metadata__unit_price: 1
|
metadata__unit_price: 1,
|
||||||
|
quantity: 1
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]) ?? []
|
|
||||||
).values()
|
return map
|
||||||
|
}, new Map())
|
||||||
|
.values()
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
[seats]
|
[seats]
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ function SeatsMenu({ seats: seats_ }: { seats: Seat[] }) {
|
|||||||
<Fragment key={idx}>
|
<Fragment key={idx}>
|
||||||
<Abbr>{course.name}</Abbr>
|
<Abbr>{course.name}</Abbr>
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<Kbd>{quantity}x</Kbd>
|
<Kbd className="border">{quantity}x</Kbd>
|
||||||
</div>
|
</div>
|
||||||
</Fragment>
|
</Fragment>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user