Prevent Culture and Hostnames modal close on error (#19133)

* only close modal if update is succesfull

* remove positive notification
This commit is contained in:
Mads Rasmussen
2025-04-25 11:30:47 +02:00
committed by GitHub
parent c2447907ac
commit 3d0ebfd35c
2 changed files with 8 additions and 30 deletions

View File

@@ -56,16 +56,17 @@ export class UmbCultureAndHostnamesModalElement extends UmbModalBaseElement<
this._languageModel = data.items;
}
// Modal
async #handleSave() {
this.value = { defaultIsoCode: this._defaultIsoCode, domains: this._domains };
await this.#documentRepository.updateCultureAndHostnames(this.#unique!, this.value);
this.modalContext?.submit();
const { error } = await this.#documentRepository.updateCultureAndHostnames(this.#unique!, this.value);
if (!error) {
this._submitModal();
}
}
#handleCancel() {
this.modalContext?.reject();
this._rejectModal();
}
// Events

View File

@@ -1,43 +1,20 @@
import { UmbDocumentCultureAndHostnamesServerDataSource } from './culture-and-hostnames.server.data.js';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification';
import type { UmbApi } from '@umbraco-cms/backoffice/extension-api';
import type { UpdateDomainsRequestModel } from '@umbraco-cms/backoffice/external/backend-api';
export class UmbDocumentCultureAndHostnamesRepository extends UmbControllerBase implements UmbApi {
#dataSource = new UmbDocumentCultureAndHostnamesServerDataSource(this);
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
constructor(host: UmbControllerHost) {
super(host);
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (instance) => {
this.#notificationContext = instance;
});
}
async readCultureAndHostnames(unique: string) {
if (!unique) throw new Error('Unique is missing');
const { data, error } = await this.#dataSource.read(unique);
if (!error) {
return { data };
}
return { error };
return this.#dataSource.read(unique);
}
async updateCultureAndHostnames(unique: string, data: UpdateDomainsRequestModel) {
if (!unique) throw new Error('Unique is missing');
if (!data) throw new Error('Data is missing');
const { error } = await this.#dataSource.update(unique, data);
if (!error) {
const notification = { data: { message: `Cultures and hostnames saved` } };
this.#notificationContext?.peek('positive', notification);
}
return { error };
return this.#dataSource.update(unique, data);
}
}