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);
}
send = (data: Application): Promise<Application | void> => {
let writeOp: Promise<Application>;
send = async (data: Application): Promise<Application | void> => {
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 {

View File

@ -38,41 +38,37 @@ export class FlowForm extends ModelForm<Flow, string> {
@property({ type: Boolean })
clearBackground = false;
send = (data: Flow): Promise<void | Flow> => {
let writeOp: Promise<Flow>;
send = async (data: Flow): Promise<void | Flow> => {
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 {