Hey
@355314072910036993,
Let's walk through this together here
You want a hook to fire on the first publish of a doc. When you say first publish, do you mean when this doc changes status from a draft to publish, or when this doc gets first created?
Or some mix of both?
when it gets first publish
basically a user creates a building trough a form in the application
the admins checks it in payload, maybe fixes, adds some details, and makes the first publish
then the user who created it should get an email that his building was published and it's live
So on that collection, you'd likely want to create a
beforeChangehook.
https://payloadcms.com/docs/hooks/collections#beforechangeIn that hook, you get the doc before its saved, and the originalDoc - this is how you can compare the
_statusof the docs. If the doc is changing from a draft to published, then the originalDoc will have status of draft, and the doc will have a status of published
Does that make sense?
hmmm, it does, but I will have to test it out, thanks for the tip
I looked into it and my issue is that if the document gets published but after it they make any change, save it as draft and publish it again
that is the same thing.
You can also have a check for if the doc was previously published
The website template does this
you mean this?
Yes exactly
yes but this only checks if exactly the previous was published and now it's unpublished. no?
like i want to send an email if this is the ever ever first time publishing, and I guess no clear solution on that
I imagine you could make a request via rest or local api against the versions collection to check if any previous version had a status of published
yes this was an amazing idea. if anyone else needs this, in the beforeChange hook
Woohoo, very nice! I guess we can mark this as solved then?
Yes sir, thank you for the help 😄
My pleasure! Glad we figured it out here
Star
Discord
online
Get dedicated engineering support directly from the Payload team.