diff --git a/src/data-fetching/useNewDoc/useNewDoc.ts b/src/data-fetching/useNewDoc/useNewDoc.ts index fc8a76a9..198b2109 100644 --- a/src/data-fetching/useNewDoc/useNewDoc.ts +++ b/src/data-fetching/useNewDoc/useNewDoc.ts @@ -1,6 +1,7 @@ import { reactive, unref } from 'vue' import { useCall } from '../useCall/useCall' import { UseCallOptions } from '../useCall/types' +import { docStore } from '../docStore' type UseNewDocOptions = Omit< UseCallOptions, @@ -18,7 +19,11 @@ export function useNewDoc( ) { let doc = reactive>(initialValues) - const out = useCall({ + type DocResponse = T & { + name: string + } + + const out = useCall({ url: `/api/v2/document/${doctype}`, method: 'POST', params() { @@ -34,8 +39,19 @@ export function useNewDoc( ...options, }) + function submit() { + return out + .submit() + .then((doc) => + docStore + .setDoc({ doctype, ...(doc as DocResponse) }) + .then(() => docStore.getDoc(doctype, doc.name.toString()).value as T), + ) + } + return reactive({ ...out, + submit, doc, }) }