web/admin: fix Forms with file uploads not handling errors correctly

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-23 12:18:39 +01:00
parent fb70769358
commit 8f5af464a2
2 changed files with 42 additions and 50 deletions

View file

@ -53,41 +53,37 @@ export class ApplicationForm extends ModelForm<Application, string> {
return super.styles.concat(PFDropdown); return super.styles.concat(PFDropdown);
} }
send = (data: Application): Promise<Application | void> => { send = async (data: Application): Promise<Application | void> => {
let writeOp: Promise<Application>; let app: Application;
if (this.instance) { if (this.instance) {
writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({ app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsUpdate({
slug: this.instance.slug, slug: this.instance.slug,
applicationRequest: data, applicationRequest: data,
}); });
} else { } else {
writeOp = new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({ app = await new CoreApi(DEFAULT_CONFIG).coreApplicationsCreate({
applicationRequest: data, applicationRequest: data,
}); });
} }
return config().then((c) => { const c = await config();
if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) {
const icon = this.getFormFile(); const icon = this.getFormFile();
if (icon || this.clearIcon) { if (icon || this.clearIcon) {
return writeOp.then((app) => { await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconCreate({
slug: app.slug, slug: app.slug,
file: icon, file: icon,
clear: this.clearIcon, clear: this.clearIcon,
}); });
});
} }
} else { } else {
return writeOp.then((app) => { await new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({
return new CoreApi(DEFAULT_CONFIG).coreApplicationsSetIconUrlCreate({
slug: app.slug, slug: app.slug,
filePathRequest: { filePathRequest: {
url: data.metaIcon || "", url: data.metaIcon || "",
}, },
}); });
});
} }
}); return app;
}; };
groupProviders(providers: Provider[]): TemplateResult { groupProviders(providers: Provider[]): TemplateResult {

View file

@ -38,41 +38,37 @@ export class FlowForm extends ModelForm<Flow, string> {
@property({ type: Boolean }) @property({ type: Boolean })
clearBackground = false; clearBackground = false;
send = (data: Flow): Promise<void | Flow> => { send = async (data: Flow): Promise<void | Flow> => {
let writeOp: Promise<Flow>; let flow: Flow;
if (this.instance) { if (this.instance) {
writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({ flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesUpdate({
slug: this.instance.slug, slug: this.instance.slug,
flowRequest: data, flowRequest: data,
}); });
} else { } else {
writeOp = new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({ flow = await new FlowsApi(DEFAULT_CONFIG).flowsInstancesCreate({
flowRequest: data, flowRequest: data,
}); });
} }
return config().then((c) => { const c = await config();
if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) { if (c.capabilities.includes(CapabilitiesEnum.SaveMedia)) {
const icon = this.getFormFile(); const icon = this.getFormFile();
if (icon || this.clearBackground) { if (icon || this.clearBackground) {
return writeOp.then((app) => { await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundCreate({ slug: flow.slug,
slug: app.slug,
file: icon, file: icon,
clear: this.clearBackground, clear: this.clearBackground,
}); });
});
} }
} else { } else {
return writeOp.then((app) => { await new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesSetBackgroundUrlCreate({ slug: flow.slug,
slug: app.slug,
filePathRequest: { filePathRequest: {
url: data.background || "", url: data.background || "",
}, },
}); });
});
} }
}); return flow;
}; };
renderDesignations(): TemplateResult { renderDesignations(): TemplateResult {