11import { toast } from '@/vdb/components/ui/sonner.js' ;
2- import { ReactNode , useEffect , useMemo , useState } from 'react' ;
2+ import { ReactNode , useEffect , useState } from 'react' ;
33
4+ import { ChannelCodeLabel } from '@/vdb/components/shared/channel-code-label.js' ;
45import { MultiSelect } from '@/vdb/components/shared/multi-select.js' ;
56import { Button } from '@/vdb/components/ui/button.js' ;
67import {
@@ -63,19 +64,13 @@ export function AssignToChannelDialog({
6364 } , [ open ] ) ;
6465
6566 // Filter out the currently selected channel from available options
66- const availableChannels = useMemo (
67- ( ) => channels . filter ( channel => channel . id !== activeChannel ?. id ) ,
68- [ channels , activeChannel ?. id ] ,
69- ) ;
67+ const availableChannels = channels . filter ( channel => channel . id !== activeChannel ?. id ) ;
7068
71- const selectItems = useMemo (
72- ( ) =>
73- availableChannels . map ( ch => ( {
74- value : ch . id ,
75- label : ch . code ,
76- } ) ) ,
77- [ availableChannels ] ,
78- ) ;
69+ const selectItems = availableChannels . map ( ch => ( {
70+ value : ch . id ,
71+ label : ch . code ,
72+ display : < ChannelCodeLabel code = { ch . code } /> ,
73+ } ) ) ;
7974
8075 const handleAssign = async ( ) => {
8176 setIsAssigning ( true ) ;
@@ -86,19 +81,28 @@ export function AssignToChannelDialog({
8681 ) ,
8782 ) ;
8883
89- const rejected = results . filter ( r => r . status === 'rejected' ) ;
90- if ( rejected . length === 0 ) {
84+ const failedChannelIds = results . flatMap ( ( r , i ) =>
85+ r . status === 'rejected' ? [ selectedChannelIds [ i ] ] : [ ] ,
86+ ) ;
87+ const succeededCount = results . length - failedChannelIds . length ;
88+
89+ if ( succeededCount > 0 ) {
90+ onSuccess ?.( ) ;
91+ }
92+
93+ if ( failedChannelIds . length === 0 ) {
9194 toast . success (
9295 t `Successfully assigned ${ entityIdsLength } ${ entityType } to ${ selectedChannelIds . length } channels` ,
9396 ) ;
94- onSuccess ?.( ) ;
9597 onOpenChange ( false ) ;
9698 } else {
97- const firstReason = rejected [ 0 ] ?. status === 'rejected' ? rejected [ 0 ] . reason : undefined ;
99+ const firstRejected = results . find ( r => r . status === 'rejected' ) ;
100+ const firstReason = firstRejected ?. status === 'rejected' ? firstRejected . reason : undefined ;
98101 const description = firstReason instanceof Error ? firstReason . message : undefined ;
102+ setSelectedChannelIds ( failedChannelIds ) ;
99103 toast . error (
100- t `Failed to assign ${ entityIdsLength } ${ entityType } to ${ rejected . length } of ${ selectedChannelIds . length } channels` ,
101- description ? { description } : undefined ,
104+ t `Failed to assign ${ entityIdsLength } ${ entityType } to ${ failedChannelIds . length } of ${ selectedChannelIds . length } channels` ,
105+ { description } ,
102106 ) ;
103107 }
104108 } finally {
0 commit comments