fix: Resolved page not saving/not copying contents bug (#3203)

This commit adds a duplicate_page function to the PageDetailsPage component, which allows users to duplicate a page. If the current page does not have a description_html value, it will be set to the default value from the pageDetails object. The formData object is updated with the necessary values for duplication, including the new page name and description. Additionally, the handleSubmit dependency is included in the useEffect hook to ensure proper form submission.
This commit is contained in:
M. Palanikannan 2023-12-20 18:54:16 +05:30 committed by GitHub
parent 40b8b0ac35
commit e141091e99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -246,6 +246,11 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
// ================ Page Menu Actions ================== // ================ Page Menu Actions ==================
const duplicate_page = async () => { const duplicate_page = async () => {
const currentPageValues = getValues(); const currentPageValues = getValues();
if (!currentPageValues?.description_html) {
currentPageValues.description_html = pageDetails?.description_html as string;
}
const formData: Partial<IPage> = { const formData: Partial<IPage> = {
name: "Copy of " + pageDetails?.name, name: "Copy of " + pageDetails?.name,
description_html: currentPageValues.description_html, description_html: currentPageValues.description_html,
@ -336,7 +341,7 @@ const PageDetailsPage: NextPageWithLayout = observer(() => {
debounce(async () => { debounce(async () => {
handleSubmit(updatePage)().finally(() => setIsSubmitting("submitted")); handleSubmit(updatePage)().finally(() => setIsSubmitting("submitted"));
}, 1500), }, 1500),
[handleSubmit] [handleSubmit, pageDetails]
); );
if (error) if (error)