From 8e3bec37a668c7d61555e9a716072248fa5bd5b8 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Wed, 20 Sep 2023 14:55:44 +0300 Subject: [PATCH] Revert to collection hook --- .../src/payload/collections/Partners.js | 19 +++---------------- .../payload/utils/nestCollectionUnderPage.js | 6 +++--- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/apps/codeforafrica/src/payload/collections/Partners.js b/apps/codeforafrica/src/payload/collections/Partners.js index 338c4faee..1afb94293 100644 --- a/apps/codeforafrica/src/payload/collections/Partners.js +++ b/apps/codeforafrica/src/payload/collections/Partners.js @@ -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; diff --git a/apps/codeforafrica/src/payload/utils/nestCollectionUnderPage.js b/apps/codeforafrica/src/payload/utils/nestCollectionUnderPage.js index 66a83799f..0e5dcd09e 100644 --- a/apps/codeforafrica/src/payload/utils/nestCollectionUnderPage.js +++ b/apps/codeforafrica/src/payload/utils/nestCollectionUnderPage.js @@ -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 } }; }; }