#Using Sonner in hooks
7 messages · Page 1 of 1 (latest)
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
You should be able to import toast from payload ui package, no need to install sonner in your project.
I tried that without luck. Isn't a hook server-side and I can't use toast directly? There must be a different mechanism to inform a user about errors happening in a hook.
Is it possible to make a thrown error shown to the user? Like this:
export const afterChangeHook: CollectionAfterChangeHook<Material> = async ({
doc,
req,
}) => {
throw new APIError("Failed in hook");
...
But this shows just a toast saying: "Something went wrong" but not my custom message.
found the solution. In the thrown Error the HttpStatus code must be a client one (4xx). Then the message shows up in the Admin UI.
export class HookAPIError extends APIError {
constructor(message: string) {
super(message, 400, undefined, true)
}
}
This thread is already marked as unanswered.