@@ -21,15 +21,19 @@ export function RewardPartnersTable({
21
21
const [ search , setSearch ] = useState ( "" ) ;
22
22
const [ debouncedSearch ] = useDebounce ( search , 500 ) ;
23
23
24
- const { data : partners } = usePartners ( {
24
+ // Get all partners for the table
25
+ const { data : allPartners } = usePartners ( { } ) ;
26
+
27
+ // Get filtered partners for the combobox
28
+ const { data : searchPartners } = usePartners ( {
25
29
query : {
26
30
search : debouncedSearch ,
27
31
} ,
28
32
} ) ;
29
33
30
34
const options = useMemo (
31
35
( ) =>
32
- partners ?. map ( ( partner ) => ( {
36
+ searchPartners ?. map ( ( partner ) => ( {
33
37
icon : (
34
38
< img
35
39
alt = { partner . name }
@@ -40,7 +44,7 @@ export function RewardPartnersTable({
40
44
value : partner . id ,
41
45
label : partner . name ,
42
46
} ) ) ,
43
- [ partners ] ,
47
+ [ searchPartners ] ,
44
48
) ;
45
49
46
50
const selectedPartnersOptions = useMemo (
@@ -54,21 +58,30 @@ export function RewardPartnersTable({
54
58
const selectedPartners = useMemo (
55
59
( ) =>
56
60
partnerIds
57
- . map ( ( id ) => partners ?. find ( ( partner ) => partner . id === id ) )
61
+ . map ( ( id ) => allPartners ?. find ( ( partner ) => partner . id === id ) )
58
62
. filter ( ( p ) : p is NonNullable < typeof p > => p != null )
59
63
. map ( ( partner ) => ( {
60
64
id : partner . id ,
61
65
name : partner . name ,
62
66
email : partner . email ,
63
67
image : partner . image ,
64
68
} ) ) ,
65
- [ partnerIds , partners ] ,
69
+ [ partnerIds , allPartners ] ,
66
70
) ;
67
71
68
72
const handlePartnerSelection = (
69
73
selectedOptions : typeof selectedPartnersOptions ,
70
74
) => {
71
- const newSelectedIds = selectedOptions . map ( ( { value } ) => value ) ;
75
+ // Get all currently selected IDs
76
+ const currentIds = new Set ( partnerIds ) ;
77
+
78
+ // Add new selections
79
+ selectedOptions . forEach ( ( { value } ) => {
80
+ currentIds . add ( value ) ;
81
+ } ) ;
82
+
83
+ // Convert back to array
84
+ const newSelectedIds = Array . from ( currentIds ) ;
72
85
setPartners ( newSelectedIds ) ;
73
86
} ;
74
87
@@ -115,6 +128,7 @@ export function RewardPartnersTable({
115
128
resourceName : ( p ) => `eligible partner${ p ? "s" : "" } ` ,
116
129
getRowId : ( row : EnrolledPartnerProps ) => row . id ,
117
130
loading,
131
+ rowCount : selectedPartners . length ,
118
132
} ) ;
119
133
120
134
return (
0 commit comments