diff --git a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/course-picker.tsx b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/course-picker.tsx index 425966c..4e9df98 100644 --- a/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/course-picker.tsx +++ b/apps/admin.saladeaula.digital/app/routes/_.$orgid.enrollments.add/course-picker.tsx @@ -62,27 +62,29 @@ export const CoursePicker = forwardRef( const [open, { set }] = useToggle() const [sort, { toggle }] = useToggle('a-z', 'z-a') const fuse = useMemo(() => { - const hits_ = hits.map((item) => ({ - ...item, - _name: normalize(item.name) - })) - - return new Fuse(hits_, { - keys: ['_name'], + return new Fuse(hits, { + keys: ['name'], threshold: 0.3, - includeMatches: true + includeMatches: true, + getFn: (obj, path) => { + const value = obj[path as keyof typeof obj] + return typeof value === 'string' ? normalize(value) : value + } }) }, [hits]) const filtered = useMemo(() => { - const results = !search - ? hits - : fuse.search(normalize(search)).map(({ item }) => item) + if (!search) { + return [...hits].sort((a, b) => { + const comparison = a.name.localeCompare(b.name) + return sort === 'a-z' ? comparison : -comparison + }) + } - return results.sort((a, b) => { - const comparison = a.name.localeCompare(b.name) - return sort === 'a-z' ? comparison : -comparison - }) + return fuse.search(search).map(({ item, matches }) => ({ + ...item, + matches + })) }, [search, fuse, hits, sort]) return ( @@ -124,6 +126,7 @@ export const CoursePicker = forwardRef( tabIndex={-1} className="cursor-pointer text-muted-foreground hover:text-accent-foreground" onClick={toggle} + disabled={search.length > 0} > {sort == 'a-z' ? : } @@ -143,31 +146,34 @@ export const CoursePicker = forwardRef( id, name, access_period, - metadata__unit_price: unit_price - }) => ( - { - onChange?.({ - id, - name, - access_period: Number(access_period), - unit_price: Number(unit_price) - }) - set(false) - }} - > - {name} - - - ) + metadata__unit_price: unit_price, + matches + }) => { + return ( + { + onChange?.({ + id, + name, + access_period: Number(access_period), + unit_price: Number(unit_price) + }) + set(false) + }} + > + {name} + + + ) + } )}