push work
This commit is contained in:
parent
7312ab632c
commit
d8d0aaa90e
@ -1,11 +1,14 @@
|
|||||||
'use server';
|
"use server";
|
||||||
import { Project } from "@/models";
|
import { Project } from "@/models";
|
||||||
import { ActionResult } from "../../ActionResult";
|
import { ActionResult } from "../../ActionResult";
|
||||||
import { Attributes } from "@sequelize/core";
|
import { Attributes } from "@sequelize/core";
|
||||||
import { userIsAdmin } from "../../actions";
|
import { userIsAdmin } from "../../actions";
|
||||||
|
|
||||||
export async function getProjects(): Promise<ActionResult<Attributes<Project>[]>> {
|
export async function getProjects(): Promise<
|
||||||
if (! await userIsAdmin()) return { error: 'Unauthorized, not fetching Projects' }
|
ActionResult<Attributes<Project>[]>
|
||||||
|
> {
|
||||||
|
if (!(await userIsAdmin()))
|
||||||
|
return { error: "Unauthorized, not fetching Projects" };
|
||||||
const posts = await Project.findAll();
|
const posts = await Project.findAll();
|
||||||
return { result: JSON.parse(JSON.stringify(posts)) };
|
return { result: JSON.parse(JSON.stringify(posts)) };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,12 +12,10 @@ import {
|
|||||||
PostAttributesWithBuckets,
|
PostAttributesWithBuckets,
|
||||||
} from "@/models";
|
} from "@/models";
|
||||||
import { handleActionResult } from "@/app/lib/actions/clientActionHandler";
|
import { handleActionResult } from "@/app/lib/actions/clientActionHandler";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getPostsWithBucketsAndProject,
|
getPostsWithBucketsAndProject,
|
||||||
GetPostsAttributes,
|
GetPostsAttributes,
|
||||||
} from "@/app/lib/actions/entitymanagement/post/postActions";
|
} from "@/app/lib/actions/entitymanagement/post/postActions";
|
||||||
|
|
||||||
import { PostViewProps } from "@/components/views/admin/post";
|
import { PostViewProps } from "@/components/views/admin/post";
|
||||||
import { StateHook } from "@/util/";
|
import { StateHook } from "@/util/";
|
||||||
|
|
||||||
@ -67,9 +65,7 @@ export default function PostTable({
|
|||||||
.getPosts() // Get Posts From Server
|
.getPosts() // Get Posts From Server
|
||||||
.then((getPostsServerActionResult) => {
|
.then((getPostsServerActionResult) => {
|
||||||
// Handle Result and toast error on failure
|
// Handle Result and toast error on failure
|
||||||
const result = handleActionResult(
|
const result = handleActionResult(getPostsServerActionResult);
|
||||||
getPostsServerActionResult
|
|
||||||
);
|
|
||||||
// Set Posts state
|
// Set Posts state
|
||||||
if (result) state.posts.setState(result);
|
if (result) state.posts.setState(result);
|
||||||
});
|
});
|
||||||
@ -123,9 +119,7 @@ export default function PostTable({
|
|||||||
key="editbutton"
|
key="editbutton"
|
||||||
type="button"
|
type="button"
|
||||||
className="btn btn-primary"
|
className="btn btn-primary"
|
||||||
onClick={() =>
|
onClick={() => editorControls.showEditor(post)}
|
||||||
editorControls.showEditor(post)
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import PostTable, {
|
import PostTable, {
|
||||||
PostTableStateProps,
|
PostTableStateProps,
|
||||||
} from "@/components/client/admin/PostTable";
|
} from "@/components/client/admin/PostTable";
|
||||||
|
|||||||
@ -48,7 +48,7 @@ export async function PostView(props: Props) {
|
|||||||
deletePost: deletePost,
|
deletePost: deletePost,
|
||||||
getPosts: getPostsWithBucketsAndProject,
|
getPosts: getPostsWithBucketsAndProject,
|
||||||
getProjects: getProjects,
|
getProjects: getProjects,
|
||||||
savePost: updatePost
|
savePost: updatePost,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user