Hey guys!
So, I have this file collection that can contain audio files, and each audio has a title, and I change the audio metadata (like the title or the cover image) based on what the user inputs in the other files.
I am doing this in a beforeChange hook, where I fetch the file from the req and apply the metadata and then append the newly created file to the req object, but when I am saving, if I try to immediatlly make another change, it prompts me with a pop up that tells that the files was change by another user and I need to reload the page. I guess that this happens because the file metadata is apply happening on the server and the client still has the old file and on edit it sees that.
There are 2 possibilites
- add/edit directly in the audio collection
- add/edit in a nested modal
In the 1st case, I have a client side SaveButton that calls router.refresh() and it works perfectly.
However, in the 2nd case, I can't find a good solution to refresh the data. I saw that each time the dialog is opened, the data is being refreshed, so i try to close the dialog after one update on the audio file.
One of the thing that seems to work is something like this to close the dialog programatically:
?.closest('dialog')
?.querySelector<HTMLButtonElement>('.doc-drawer__header-close');
closeButton?.click();```
But this is fragile and it's not an appropriate solution.
I saw that there is a useModal() hook that exports closeModal, but it's not documented in the payloadCMS docs, and I don't really understand how it works.
So, my questions are:
1. How can I close the dialog programatically if the editDepth is > 1?
2. Is there any better wat to approach this issue, with the metadata file change and with the pop-up?