Display improvements
This commit is contained in:
parent
cca8d03988
commit
39cfada3e8
9 changed files with 98 additions and 24 deletions
|
|
@ -3,6 +3,15 @@
|
|||
import { revalidatePath } from "next/cache";
|
||||
import { db, Database } from "@/app/_lib/database";
|
||||
import { FieldDescription, Entity } from "@/app/_lib/service";
|
||||
import crypto from "crypto";
|
||||
|
||||
const generateToken = () => {
|
||||
const length = 20;
|
||||
const randomBytes = crypto.randomBytes(length);
|
||||
const randomString = randomBytes.toString("hex").slice(0, length);
|
||||
|
||||
return randomString;
|
||||
};
|
||||
|
||||
type CreateActionArgs = {
|
||||
entity: Entity;
|
||||
|
|
@ -20,8 +29,12 @@ export const createAction = async ({
|
|||
formData,
|
||||
}: CreateActionArgs) => {
|
||||
const newRecord = fields.reduce(
|
||||
(acc: Record<string, string>, field: FieldDescription) => {
|
||||
// @ts-expect-error
|
||||
(acc: Record<string, any>, field: FieldDescription) => {
|
||||
if (field.autogenerated === "token") {
|
||||
acc[field.name] = generateToken();
|
||||
return acc;
|
||||
}
|
||||
|
||||
acc[field.name] = formData.get(field.name)?.toString() ?? null;
|
||||
return acc;
|
||||
},
|
||||
|
|
@ -56,8 +69,7 @@ export const updateAction = async ({
|
|||
}: UpdateActionArgs) => {
|
||||
const id = currentState.values.id;
|
||||
const updatedRecord = fields.reduce(
|
||||
(acc: Record<string, string>, field: FieldDescription) => {
|
||||
// @ts-expect-error
|
||||
(acc: Record<string, any>, field: FieldDescription) => {
|
||||
acc[field.name] = formData.get(field.name)?.toString() ?? null;
|
||||
return acc;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue