dev #10

Merged
RizqiSyahrendra merged 8 commits from dev into main 2025-03-04 22:43:48 +00:00
4 changed files with 51 additions and 19 deletions
Showing only changes of commit 807e78aa70 - Show all commits

View File

@ -1,4 +1,5 @@
import formatSlug from "@/utils/payload/formatSlug";
import setAuthor from "@/utils/payload/setAuthor";
import { lexicalEditor } from "@payloadcms/richtext-lexical";
import type { CollectionConfig } from "payload";
@ -78,19 +79,23 @@ export const Blogs: CollectionConfig = {
name: "createdBy",
type: "relationship",
relationTo: "users",
hooks: {
beforeChange: [setAuthor],
},
admin: {
hidden: true,
// hooks: {
// beforeChange: [setAuthor],
// },
},
},
{
name: "updatedBy",
type: "relationship",
relationTo: "users",
hooks: {
beforeChange: [setAuthor],
},
admin: {
hidden: true,
// hooks: {
// beforeChange: [setAuthor],
// },
},
},
],
admin: {

View File

@ -8,6 +8,7 @@ import { HorizontalImageContentBlock } from "@/blocks/HorizontalImageContent";
import { ImageSliderBlock } from "@/blocks/ImageSlider";
import { OurTeamBlock } from "@/blocks/OurTeam";
import formatSlug from "@/utils/payload/formatSlug";
import setAuthor from "@/utils/payload/setAuthor";
import { CollectionConfig } from "payload";
export const Pages: CollectionConfig = {
@ -29,9 +30,6 @@ export const Pages: CollectionConfig = {
name: "slug",
label: "Page Slug",
type: "text",
admin: {
position: "sidebar",
},
hooks: {
beforeValidate: [formatSlug("title")],
},
@ -75,6 +73,28 @@ export const Pages: CollectionConfig = {
},
],
},
{
name: "createdBy",
type: "relationship",
relationTo: "users",
hooks: {
beforeChange: [setAuthor],
},
admin: {
hidden: true,
},
},
{
name: "updatedBy",
type: "relationship",
relationTo: "users",
hooks: {
beforeChange: [setAuthor],
},
admin: {
hidden: true,
},
},
],
admin: {
hideAPIURL: true,

View File

@ -306,6 +306,8 @@ export interface Page {
description?: string | null;
cannonical_url?: string | null;
};
createdBy?: (number | null) | User;
updatedBy?: (number | null) | User;
updatedAt: string;
createdAt: string;
}
@ -747,6 +749,8 @@ export interface PagesSelect<T extends boolean = true> {
description?: T;
cannonical_url?: T;
};
createdBy?: T;
updatedBy?: T;
updatedAt?: T;
createdAt?: T;
}

View File

@ -1,14 +1,17 @@
import { FieldHook } from "payload";
const setAuthor: FieldHook = ({ req, operation, data, value }) => {
// if (req.user && !!data) {
// if (operation === "create") {
// data.createdBy = req.user.id;
// }
// data.updatedBy = req.user.id;
// }
const setAuthor: FieldHook = ({ value, req, data, field, operation }) => {
if (req.user && !!data) {
if (operation === "create") {
return req.user.id;
} else {
if (field.name === "updatedBy") {
return req.user.id;
}
}
}
return data;
return value;
};
export default setAuthor;