Page MenuHomeSealhub

confirm-item-delete.ts
No OneTemporary

confirm-item-delete.ts

import { toKebabCase, toPascalCase } from "js-convert-case";
import { curryImportPath } from "../../utils/import-path.js";
import { formatWithPrettier } from "../../utils/prettier.js";
export async function askItemDeleteTemplate(
ask_delete_action_name: string,
collection_name: string,
newfilefullpath: string,
list_action_name: string,
delete_action_name: string
): Promise<string> {
const importPath = curryImportPath(newfilefullpath);
const result = `import type { Context } from "koa";
import { Page } from "@sealcode/sealgen";
import type { CollectionItem } from "sealious";
import { TempstreamJSX } from "tempstream";
import { ${delete_action_name}URL } from "${importPath(
"src/back/routes/urls.js"
)}";
import html from "${importPath("src/back/html.ts")}";
import { ${toPascalCase(collection_name)} as ${toPascalCase(
collection_name
)}Collection } from "${importPath("src/back/collections/collections.js")}";
export const actionName = "${ask_delete_action_name}";
export default new (class ${ask_delete_action_name}Page extends Page {
canAccess = async (ctx: Context) => {
const policy = ${toPascalCase(
collection_name
)}Collection.getPolicy("edit");
const response = await policy.check(ctx.$context);
return { canAccess: response?.allowed || false, message: response?.reason || "" };
};
getItemTitle(_ctx: Context, item: CollectionItem<typeof ${toPascalCase(
collection_name
)}Collection>){
return item.get("name")
}
async render(ctx: Context) {
const id = ctx.params.id
if(!id){throw new Error("Could not read the id param from the URL")}
const { items: [item] } =
await ctx.$app.collections["${toKebabCase(
collection_name
)}"].list(ctx.$context).ids([id]).fetch();
if (!item) {
throw new Error("Item with given id not found");
}
return html(
ctx,
"Delete?",
<div>
<div class="confirm-delete-page confirm-delete-page--${toKebabCase(
collection_name
)}">
<span>
Are you sure you want to remove: {" "}
<b>{this.getItemTitle(ctx, item)}</b>
</span>
<form action={${delete_action_name}URL(item.id)}>
<button type="submit">
remove
</button>
<input type="hidden" name="id" value={item?.id} />
</form>
</div>
</div>
);
}
})();
`;
return await formatWithPrettier(result);
}

File Metadata

Mime Type
text/x-java
Expires
Wed, May 7, 19:42 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
625580
Default Alt Text
confirm-item-delete.ts (2 KB)

Event Timeline