reload collection after user creation

This commit is contained in:
Mads Rasmussen
2024-09-05 15:42:27 +02:00
parent fb782d46a6
commit 57f6cd64e5

View File

@@ -4,6 +4,7 @@ import { UmbUserKind } from '../../utils/index.js';
import { html, customElement, state } from '@umbraco-cms/backoffice/external/lit';
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal';
import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity';
import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity';
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
import { UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action';
@@ -32,17 +33,27 @@ export class UmbCollectionActionButtonElement extends UmbLitElement {
},
},
});
modalContext?.onSubmit().catch(async () => {
// modal is closed after creation instead of navigating to the new user.
// We therefore need to reload the children of the entity
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadChildrenOfEntityEvent({
entityType,
unique,
});
eventContext.dispatchEvent(event);
modalContext
?.onSubmit()
.then(() => {
this.#requestReloadChildrenOfEntity({ entityType, unique });
})
.catch(async () => {
// modal is closed after creation instead of navigating to the new user.
// We therefore need to reload the children of the entity
this.#requestReloadChildrenOfEntity({ entityType, unique });
});
}
async #requestReloadChildrenOfEntity({ entityType, unique }: UmbEntityModel) {
const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT);
const event = new UmbRequestReloadChildrenOfEntityEvent({
entityType,
unique,
});
eventContext.dispatchEvent(event);
}
#onPopoverToggle(event: ToggleEvent) {