Skip to content

Commit

Permalink
fix(app-headless-cms): use the passed entry object [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Jul 16, 2024
1 parent d0e9315 commit 3dafa75
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { CmsContentEntry } from "~/types";
import { makeDecoratable } from "@webiny/app-admin";
import { ModelProvider, useModel } from "~/admin/components/ModelProvider";
import { Header } from "~/admin/components/ContentEntryForm/Header";
import { useDefaultValues } from "~/admin/components/ContentEntryForm/useDefaultValues";
import { useFormRenderer } from "~/admin/components/ContentEntryForm/useFormRenderer";
import { ContentEntryFormContext, ContentEntryFormProvider } from "./ContentEntryFormProvider";
import { CustomLayout } from "./CustomLayout";
Expand Down Expand Up @@ -53,16 +52,12 @@ export const ContentEntryForm = makeDecoratable(
const formElementRef = useRef<HTMLDivElement>(null);
const { model } = useModel();
const { goToRevision } = useGoToRevision();
const defaultValues = useDefaultValues(model);
const formRenderer = useFormRenderer(model);

const defaultOnAfterCreate = (entry: CmsContentEntry) => {
goToRevision(entry.id);
};

// Determine initial entry.
const initialData = entry && entry.id ? entry : defaultValues;

// When entry changes, scroll to the top of the form.
useEffect(() => {
if (!formElementRef.current) {
Expand All @@ -72,12 +67,12 @@ export const ContentEntryForm = makeDecoratable(
setTimeout(() => {
formElementRef.current?.scrollTo(0, 0);
}, 20);
}, [initialData.id, formElementRef.current]);
}, [entry.id, formElementRef.current]);

return (
<ContentEntryFormProvider
model={model}
entry={initialData}
entry={entry}
onAfterCreate={onAfterCreate || defaultOnAfterCreate}
setSaveEntry={setSaveEntry}
addItemToListCache={addEntryToListCache}
Expand Down

0 comments on commit 3dafa75

Please sign in to comment.