Skip to content

Commit ff7d224

Browse files
committed
feat: DeleteComponent - add delete loading and showError in case of error
1 parent 2273e33 commit ff7d224

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Common/DeleteComponentModal/DeleteComponent.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { ConfirmationDialog, DeleteDialog } from '../Dialogs'
2121
import { ServerErrors } from '../ServerError'
2222
import { DeleteComponentProps } from './types'
2323
import { ToastManager, ToastVariantType } from '@Shared/Services'
24+
import { showError } from '@Common/Helper'
2425

2526
const DeleteComponent = ({
2627
setDeleting,
@@ -36,11 +37,13 @@ const DeleteComponent = ({
3637
configuration = '',
3738
closeCustomComponent,
3839
}: DeleteComponentProps) => {
40+
const [isDeleting, setIsDeleting] = useState(false)
3941
const [showCannotDeleteDialogModal, setCannotDeleteDialogModal] = useState(false)
4042
const { push } = useHistory()
4143

4244
async function handleDelete() {
4345
setDeleting(true)
46+
setIsDeleting(true)
4447
try {
4548
await deleteComponent(payload)
4649
ToastManager.showToast({
@@ -59,9 +62,12 @@ const DeleteComponent = ({
5962
} catch (serverError) {
6063
if (serverError instanceof ServerErrors && serverError.code === 500) {
6164
setCannotDeleteDialogModal(true)
65+
} else {
66+
showError(serverError)
6267
}
6368
} finally {
6469
setDeleting(false)
70+
setIsDeleting(false)
6571
}
6672
}
6773

@@ -92,6 +98,7 @@ const DeleteComponent = ({
9298
delete={handleDelete}
9399
closeDelete={() => toggleConfirmation(false)}
94100
dataTestId="delete-dialog"
101+
apiCallInProgress={isDeleting}
95102
>
96103
<DeleteDialog.Description>
97104
<p>Are you sure you want to delete this {configuration || component}? </p>

0 commit comments

Comments
 (0)