Prevent Culture and Hostnames modal close on error (#19133)
* only close modal if update is succesfull * remove positive notification
This commit is contained in:
@@ -56,16 +56,17 @@ export class UmbCultureAndHostnamesModalElement extends UmbModalBaseElement<
|
|||||||
this._languageModel = data.items;
|
this._languageModel = data.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modal
|
|
||||||
|
|
||||||
async #handleSave() {
|
async #handleSave() {
|
||||||
this.value = { defaultIsoCode: this._defaultIsoCode, domains: this._domains };
|
this.value = { defaultIsoCode: this._defaultIsoCode, domains: this._domains };
|
||||||
await this.#documentRepository.updateCultureAndHostnames(this.#unique!, this.value);
|
const { error } = await this.#documentRepository.updateCultureAndHostnames(this.#unique!, this.value);
|
||||||
this.modalContext?.submit();
|
|
||||||
|
if (!error) {
|
||||||
|
this._submitModal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#handleCancel() {
|
#handleCancel() {
|
||||||
this.modalContext?.reject();
|
this._rejectModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|||||||
@@ -1,43 +1,20 @@
|
|||||||
import { UmbDocumentCultureAndHostnamesServerDataSource } from './culture-and-hostnames.server.data.js';
|
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 { 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 { UmbApi } from '@umbraco-cms/backoffice/extension-api';
|
||||||
import type { UpdateDomainsRequestModel } from '@umbraco-cms/backoffice/external/backend-api';
|
import type { UpdateDomainsRequestModel } from '@umbraco-cms/backoffice/external/backend-api';
|
||||||
|
|
||||||
export class UmbDocumentCultureAndHostnamesRepository extends UmbControllerBase implements UmbApi {
|
export class UmbDocumentCultureAndHostnamesRepository extends UmbControllerBase implements UmbApi {
|
||||||
#dataSource = new UmbDocumentCultureAndHostnamesServerDataSource(this);
|
#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) {
|
async readCultureAndHostnames(unique: string) {
|
||||||
if (!unique) throw new Error('Unique is missing');
|
if (!unique) throw new Error('Unique is missing');
|
||||||
|
return this.#dataSource.read(unique);
|
||||||
const { data, error } = await this.#dataSource.read(unique);
|
|
||||||
if (!error) {
|
|
||||||
return { data };
|
|
||||||
}
|
|
||||||
return { error };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateCultureAndHostnames(unique: string, data: UpdateDomainsRequestModel) {
|
async updateCultureAndHostnames(unique: string, data: UpdateDomainsRequestModel) {
|
||||||
if (!unique) throw new Error('Unique is missing');
|
if (!unique) throw new Error('Unique is missing');
|
||||||
if (!data) throw new Error('Data is missing');
|
if (!data) throw new Error('Data is missing');
|
||||||
|
return this.#dataSource.update(unique, data);
|
||||||
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 };
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user