You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { BaseContext } from "koa";
|
|
import { Routes } from "../../collections/collections";
|
|
import { FormHeader, SimpleInput } from "../../forms/controls";
|
|
import { FormField } from "../../forms/field";
|
|
import Form, { FormData } from "../../forms/form";
|
|
import { collectionFieldValidator } from "../../forms/validator";
|
|
import html from "../../html";
|
|
|
|
export const actionName = "AddRoute";
|
|
|
|
export default new (class AddRouteForm extends Form {
|
|
defaultSuccessMessage = "Pomyślnie utworzono użytkownika";
|
|
|
|
fields = [new FormField("name", true, collectionFieldValidator(Routes.fields.name))];
|
|
|
|
controls = [
|
|
new FormHeader("Dodaj nową trasę"),
|
|
new SimpleInput("name", { label: "Nazwa trasy", type: "text" }),
|
|
];
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
async canAccess(_: BaseContext) {
|
|
return { canAccess: true, message: "" };
|
|
}
|
|
|
|
async onSubmit(ctx: BaseContext, values: Record<"name", string>) {
|
|
await ctx.$app.collections.routes.create(ctx.$context, values);
|
|
}
|
|
|
|
async render(ctx: BaseContext, data: FormData, path: string) {
|
|
return html(ctx, "Nowa trasa", await super.render(ctx, data, path));
|
|
}
|
|
})();
|