diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/entity-actions/sort-children-of/modal/sort-children-of-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/entity-actions/sort-children-of/modal/sort-children-of-modal.element.ts index ec666a3ad922..e5b315f97501 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/entity-actions/sort-children-of/modal/sort-children-of-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/entity-actions/sort-children-of/modal/sort-children-of-modal.element.ts @@ -8,6 +8,7 @@ import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; import { createExtensionApiByAlias } from '@umbraco-cms/backoffice/extension-registry'; import { UmbPaginationManager } from '@umbraco-cms/backoffice/utils'; import { observeMultiple } from '@umbraco-cms/backoffice/observable-api'; +import type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui'; import type { UmbTableColumn, UmbTableConfig, @@ -46,6 +47,9 @@ export class UmbSortChildrenOfModalElement< @state() private _sortable = false; + @state() + private _submitButtonState?: UUIButtonState; + protected _sortedUniques = new Set(); #pagination = new UmbPaginationManager(); @@ -135,21 +139,32 @@ export class UmbSortChildrenOfModalElement< } async #onSubmit(event: PointerEvent) { + if (this._submitButtonState === 'waiting') return; event?.stopPropagation(); if (!this.data?.sortChildrenOfRepositoryAlias) throw new Error('sortChildrenOfRepositoryAlias is required'); - const sortChildrenOfRepository = await createExtensionApiByAlias( - this, - this.data.sortChildrenOfRepositoryAlias, - ); + this._submitButtonState = 'waiting'; - const { error } = await sortChildrenOfRepository.sortChildrenOf({ - unique: this.data.unique, - sorting: this.#getSortOrderOfSortedItems(), - }); + try { + const sortChildrenOfRepository = await createExtensionApiByAlias( + this, + this.data.sortChildrenOfRepositoryAlias, + ); - if (!error) { - this._submitModal(); + const { error } = await sortChildrenOfRepository.sortChildrenOf({ + unique: this.data.unique, + sorting: this.#getSortOrderOfSortedItems(), + }); + + if (!error) { + this._submitButtonState = 'success'; + this._submitModal(); + } else { + this._submitButtonState = 'failed'; + } + } catch (error) { + this._submitButtonState = 'failed'; + throw error; } } @@ -213,7 +228,13 @@ export class UmbSortChildrenOfModalElement< ${this._children.length === 0 ? this.#renderEmptyState() : this.#renderTable()} - + `; }