This commit is contained in:
2024-06-26 10:40:09 +02:00
parent a492bf4ac0
commit de212c367f
5 changed files with 101 additions and 56 deletions
+10 -8
View File
@@ -4,15 +4,17 @@ import { tryFetchPosts } from "@/app/api/post/route";
import { constructAPIUrl } from "@/util/Utils";
import { ReactNode, useEffect } from "react";
import EntityManagementTable from "../../../client/EntityManagementTable";
import PostTable from "@/components/client/admin/PostTable";
import { deletePost, getPostsWithBucketsAndProject, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import PostTable, { PostTableActions } from "@/components/client/admin/PostTable";
import { deletePost, getPostsWithBucketsAndProject, GetPostsAttributes, updatePost } from "@/app/lib/actions/entityManagement/postActions";
import { getProjects } from "@/app/lib/actions/entityManagement/projectActions";
import { Bucket, Project, Post, dbSync, Attachment } from "@/model/Models";
import { tryCreateAttachment } from "@/app/api/attachment/route";
import { handleActionResult } from '../../../../app/lib/actions/clientActionHandler';
type Props = {
children?:ReactNode
}
async function getHeadings(){
let headings:string[] = ['#', 'Title', 'Content', 'Project', 'CreatedAt', 'UpdatedAt']
@@ -24,7 +26,7 @@ export default async function PostView(props:Props){
const headings = await getHeadings();
const actions = {
const actions:PostTableActions = {
deletePost: deletePost,
getPosts:getPostsWithBucketsAndProject,
getProjects:getProjects,
@@ -32,16 +34,16 @@ export default async function PostView(props:Props){
// uploadAttachment:tryCreateAttachment
};
const posts:Post[] = await Post.findAll({include: {model: Bucket, include: {model: Attachment}}}).then(posts=>posts.map((e)=>JSON.parse(JSON.stringify(e))));
const posts:GetPostsAttributes[]| undefined = handleActionResult(await getPostsWithBucketsAndProject());
const projects = await Project.findAll().then(projects=>projects.map((e)=>JSON.parse(JSON.stringify(e))));
return (
<div className="w-[100%] min-h-fit bg-gray-100 overflow-scroll">
<div className="w-[100%] m-auto">
<PostTable data={posts}
projects={projects}
headings={headings}
actions={actions}>
<PostTable data={posts ? posts : []}
projects={projects}
headings={headings}
actions={actions}>
</PostTable>
</div>
</div>