From 8f5af464a242201091dacd4a47352f798791f5f8 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 23 Nov 2021 12:18:39 +0100 Subject: [PATCH] web/admin: fix Forms with file uploads not handling errors correctly Signed-off-by: Jens Langhammer --- web/src/pages/applications/ApplicationForm.ts | 46 +++++++++---------- web/src/pages/flows/FlowForm.ts | 46 +++++++++---------- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/web/src/pages/applications/ApplicationForm.ts b/web/src/pages/applications/ApplicationForm.ts index ebb111464..202b60509 100644 --- a/web/src/pages/applications/ApplicationForm.ts +++ b/web/src/pages/applications/ApplicationForm.ts @@ -53,41 +53,37 @@ export class ApplicationForm extends ModelForm { return super.styles.concat(PFDropdown); } - send = (data: Application): Promise => { - let writeOp: Promise; + send = async (data: Application): Promise => { + let app: Application; if (this.instance) { - writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ + app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ slug: this.instance.slug, applicationRequest: data, }); } else { - writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ + app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ applicationRequest: data, }); } - return config().then((c) => { - if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { - const icon = this.getFormFile(); - if (icon || this.clearIcon) { - return writeOp.then((app) => { - return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({ - slug: app.slug, - file: icon, - clear: this.clearIcon, - }); - }); - } - } else { - return writeOp.then((app) => { - return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({ - slug: app.slug, - filePathRequest: { - url: data.metaIcon || "", - }, - }); + const c = await config(); + if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { + const icon = this.getFormFile(); + if (icon || this.clearIcon) { + await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({ + slug: app.slug, + file: icon, + clear: this.clearIcon, }); } - }); + } else { + await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({ + slug: app.slug, + filePathRequest: { + url: data.metaIcon || "", + }, + }); + } + return app; }; groupProviders(providers: Provider[]): TemplateResult { diff --git a/web/src/pages/flows/FlowForm.ts b/web/src/pages/flows/FlowForm.ts index e033f4344..6ddc87a68 100644 --- a/web/src/pages/flows/FlowForm.ts +++ b/web/src/pages/flows/FlowForm.ts @@ -38,41 +38,37 @@ export class FlowForm extends ModelForm { @property({ type: Boolean }) clearBackground = false; - send = (data: Flow): Promise => { - let writeOp: Promise; + send = async (data: Flow): Promise => { + let flow: Flow; if (this.instance) { - writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({ + flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({ slug: this.instance.slug, flowRequest: data, }); } else { - writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({ + flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({ flowRequest: data, }); } - return config().then((c) => { - if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { - const icon = this.getFormFile(); - if (icon || this.clearBackground) { - return writeOp.then((app) => { - return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({ - slug: app.slug, - file: icon, - clear: this.clearBackground, - }); - }); - } - } else { - return writeOp.then((app) => { - return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ - slug: app.slug, - filePathRequest: { - url: data.background || "", - }, - }); + const c = await config(); + if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { + const icon = this.getFormFile(); + if (icon || this.clearBackground) { + await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({ + slug: flow.slug, + file: icon, + clear: this.clearBackground, }); } - }); + } else { + await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ + slug: flow.slug, + filePathRequest: { + url: data.background || "", + }, + }); + } + return flow; }; renderDesignations(): TemplateResult {