diff --git a/striker-ui/components/CrudList.tsx b/striker-ui/components/CrudList.tsx index f7f0284b..a020521f 100644 --- a/striker-ui/components/CrudList.tsx +++ b/striker-ui/components/CrudList.tsx @@ -28,6 +28,7 @@ const CrudList = < getAddLoading, getDeleteErrorMessage, getDeleteHeader, + getDeletePromiseChain = (base, ...args) => base(...args), getDeleteSuccessMessage, getEditLoading = (previous?: boolean) => previous, listEmpty, @@ -146,7 +147,11 @@ const CrudList = < setConfirmDialogLoading(true); Promise.all( - checks.map((key) => api.delete(`${entriesUrl}/${key}`)), + getDeletePromiseChain( + (cl, up) => cl.map((key) => api.delete(`${up}/${key}`)), + checks, + entriesUrl, + ), ) .then(() => { finishConfirm('Success', getDeleteSuccessMessage()); diff --git a/striker-ui/types/CrudList.d.ts b/striker-ui/types/CrudList.d.ts index 258c81c3..7526bc63 100644 --- a/striker-ui/types/CrudList.d.ts +++ b/striker-ui/types/CrudList.d.ts @@ -12,8 +12,17 @@ type CrudListItemClickHandler = Exclude< undefined >; +type DeletePromiseChainGetter = ( + checks: ArrayChecklist, + urlPrefix: string, +) => Promise[]; + type CrudListOptionalProps = { getAddLoading?: (previous?: boolean) => boolean; + getDeletePromiseChain?: ( + base: DeletePromiseChainGetter, + ...args: Parameters> + ) => ReturnType>; getEditLoading?: (previous?: boolean) => boolean; listProps?: Partial>; onItemClick?: (