Skip to content

Commit

Permalink
fix(admin-ui): Update channel switcher after deleting channel
Browse files Browse the repository at this point in the history
Fixes #2511
  • Loading branch information
michaelbromley committed Nov 14, 2023
1 parent fedd554 commit 32f592d
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import {
createBulkDeleteAction,
GetChannelsQuery,
GetCustomerListQuery,
ItemOf,
Permission,
} from '@vendure/admin-ui/core';
import { map } from 'rxjs/operators';
import { createBulkDeleteAction, GetChannelsQuery, ItemOf, Permission } from '@vendure/admin-ui/core';
import { map, mergeMap } from 'rxjs/operators';

export const deleteChannelsBulkAction = createBulkDeleteAction<ItemOf<GetChannelsQuery, 'channels'>>({
location: 'channel-list',
requiresPermission: userPermissions =>
userPermissions.includes(Permission.SuperAdmin) || userPermissions.includes(Permission.DeleteChannel),
getItemName: item => item.code,
bulkDelete: (dataService, ids) =>
dataService.settings.deleteChannels(ids).pipe(map(res => res.deleteChannels)),
bulkDelete: (dataService, ids) => {
return dataService.settings.deleteChannels(ids).pipe(
mergeMap(({ deleteChannels }) =>
dataService.auth.currentUser().single$.pipe(
map(({ me }) => ({
me,
deleteChannels,
})),
),
),
mergeMap(({ me, deleteChannels }) =>
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dataService.client.updateUserChannels(me!.channels).pipe(map(() => deleteChannels)),
),
);
},
});

0 comments on commit 32f592d

Please sign in to comment.