@@ -124,7 +124,7 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
124124 isArchivedTab
125125 ) ,
126126 } ,
127- { } ,
127+ { sortField : 'sort_order' , sortDirection : PaginationSortDirection . ASC } ,
128128 CallsDataQuantity . EXTENDED
129129 ) ;
130130
@@ -348,24 +348,38 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
348348
349349 const onDragEnd = ( result : DropResult ) : void => {
350350 if ( ! result . destination ) return ;
351- const callsWithUpdatedOrder = reorder (
351+ const reorderedCalls = reorder (
352352 calls ,
353353 result . source . index ,
354354 result . destination . index
355355 ) ;
356- setCalls (
357- callsWithUpdatedOrder . sort ( ( a , b ) =>
358- a . sort_order > b . sort_order ? - 1 : 1
359- )
360- ) ;
361- const callOrderList = callsWithUpdatedOrder . map ( ( item , index ) => ( {
362- callId : item . id ,
356+
357+ const updatedCalls = reorderedCalls . map ( ( item , index ) => ( {
358+ ...item ,
363359 sort_order : index ,
364360 } ) ) ;
365361
366- api ( ) . updateCallOrder ( {
367- data : callOrderList ,
368- } ) ;
362+ setCalls ( updatedCalls ) ;
363+
364+ const callOrderList = updatedCalls . map ( ( item ) => ( {
365+ callId : item . id ,
366+ sort_order : item . sort_order ,
367+ } ) ) ;
368+
369+ api ( )
370+ . updateCallOrder ( {
371+ data : callOrderList ,
372+ } )
373+ . then ( ( ) => {
374+ setCallsQueryParams ( ( prev ) => ( {
375+ ...prev ,
376+ sortField : 'sort_order' ,
377+ sortDirection : PaginationSortDirection . ASC ,
378+ } ) ) ;
379+ } )
380+ . catch ( ( ) => {
381+ throw new Error ( 'Failed to update call order' ) ;
382+ } ) ;
369383 } ;
370384
371385 const getCallOrder = ( ) : void => {
0 commit comments