update create

This commit is contained in:
Jesper Møller Jensen
2023-06-12 14:58:35 +12:00
parent 9f8e222f8e
commit 45ec4e0224
4 changed files with 20 additions and 11 deletions

View File

@@ -8,6 +8,7 @@ export interface UmbCreateDictionaryModalData {
export interface UmbCreateDictionaryModalResult {
name?: string;
parentId?: string;
}
export const UMB_CREATE_DICTIONARY_MODAL = new UmbModalToken<

View File

@@ -10,6 +10,7 @@ import {
UMB_CREATE_DICTIONARY_MODAL,
} from '@umbraco-cms/backoffice/modal';
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
import { log } from '@openid/appauth';
@customElement('umb-dashboard-translation-dictionary')
export class UmbDashboardTranslationDictionaryElement extends UmbLitElement {
@@ -136,13 +137,16 @@ export class UmbDashboardTranslationDictionaryElement extends UmbLitElement {
const modalContext = this.#modalContext?.open(UMB_CREATE_DICTIONARY_MODAL, { unique: null });
// TODO: get type from modal result
const { name } = await modalContext.onSubmit();
const { name, parentId } = await modalContext.onSubmit();
if (!name) return;
const { data } = await this.#repo.createScaffold(null);
console.log(data);
// TODO => get location header to route to new item
const { data: url } = await this.#repo.create({ name, parentId });
if (!url) return;
//TODO: Why do we need to extract the id like this?
const id = url.substring(url.lastIndexOf('/') + 1);
history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`);
}
render() {

View File

@@ -36,9 +36,11 @@ export class UmbCreateDictionaryModalElement extends UmbModalBaseElement<
if (!form || !form.checkValidity()) return;
const formData = new FormData(form);
const name = formData.get('name') as string;
this.modalContext?.submit({
name: formData.get('name') as string,
name,
parentId: this.data?.unique ?? undefined,
});
}

View File

@@ -44,13 +44,15 @@ export default class UmbCreateDictionaryEntityAction extends UmbEntityActionBase
parentName: this.#sectionSidebarContext.headline,
});
// TODO: get type from modal result
const { name } = await modalContext.onSubmit();
const { name, parentId } = await modalContext.onSubmit();
if (!name) return;
const { data } = await this.repository.createScaffold(this.unique, { name });
const { data: url } = await this.repository.create({ name, parentId });
if (!url) return;
// TODO => get location header to route to new item
console.log(data);
//TODO: Why do we need to extract the id like this?
const id = url.substring(url.lastIndexOf('/') + 1);
history.pushState({}, '', `/section/translation/workspace/dictionary-item/edit/${id}`);
}
}