Skip to content

Commit

Permalink
feat(ui): expose custom errors in delete many (#7439)
Browse files Browse the repository at this point in the history
Exposes any custom errors out to the delete many toast as well.
Closes #7214


![image](https://github.com/user-attachments/assets/e5d1fc92-3f22-4906-b09c-e94caf82eb64)
  • Loading branch information
paulpopus committed Jul 31, 2024
1 parent a308d63 commit 3e780b9
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './index.scss'
const baseClass = 'delete-documents'

const DeleteMany: React.FC<Props> = (props) => {
const { collection: { labels: { plural }, slug } = {}, resetParams } = props
const { collection: { slug, labels: { plural } } = {}, resetParams } = props

const { permissions } = useAuth()
const {
Expand All @@ -41,7 +41,7 @@ const DeleteMany: React.FC<Props> = (props) => {

const handleDelete = useCallback(() => {
setDeleting(true)
requests
void requests
.delete(`${serverURL}${api}/${slug}${getQueryParams()}`, {
headers: {
'Accept-Language': i18n.language,
Expand All @@ -60,7 +60,15 @@ const DeleteMany: React.FC<Props> = (props) => {
}

if (json.errors) {
toast.error(json.message)
let message = json.message

if (json.errors) {
json.errors.forEach((error) => {
message = message + '\n' + error.message
})
}

toast.error(message)
} else {
addDefaultError()
}
Expand Down

0 comments on commit 3e780b9

Please sign in to comment.