Skip to content

Commit

Permalink
Revert to collection hook
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Sep 20, 2023
1 parent 0655057 commit 8e3bec3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
19 changes: 3 additions & 16 deletions apps/codeforafrica/src/payload/collections/Partners.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,9 @@ const Partners = {
label: "Social Media Links",
required: false,
}),
{
name: "link",
type: "group",
admin: {
hidden: true,
},
fields: [
{
name: "href",
type: "text",
hooks: {
beforeValidate: [nestCollectionUnderPage("partners")],
},
},
],
},
],
hooks: {
afterRead: [nestCollectionUnderPage("partners")],
},
};
export default Partners;
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import findAndFormatPagePath from "./findAndFormatPagePath";

function nestCollectionUnderPage(pageSlug) {
return async function nestCollectionItemUnderParentPage({
doc,
req: { payload },
data: { slug },
}) {
let href = null;
try {
const pagePath = await findAndFormatPagePath(payload, pageSlug);
if (pagePath) {
href = `${pagePath}/${slug}`;
href = `${pagePath}/${doc.slug}`;
}
} catch (error) {
// Handle Errors
}
return href;
return { ...doc, link: { href } };
};
}

Expand Down

0 comments on commit 8e3bec3

Please sign in to comment.