diff --git a/src/admin/components/elements/SaveDraft/index.tsx b/src/admin/components/elements/SaveDraft/index.tsx index a91a97e6041..0c8af5f30e3 100644 --- a/src/admin/components/elements/SaveDraft/index.tsx +++ b/src/admin/components/elements/SaveDraft/index.tsx @@ -18,8 +18,6 @@ const SaveDraft: React.FC = () => { const canSaveDraft = modified; - console.log({ modified }); - const saveDraft = useCallback(() => { const search = `?locale=${locale}&depth=0&fallback-locale=null&draft=true`; let action; diff --git a/src/admin/components/forms/Form/index.tsx b/src/admin/components/forms/Form/index.tsx index 91edfb8772b..ff13c18bee3 100644 --- a/src/admin/components/forms/Form/index.tsx +++ b/src/admin/components/forms/Form/index.tsx @@ -288,13 +288,24 @@ const Form: React.FC = (props) => { const createFormData = useCallback((overrides: any = {}) => { const data = reduceFieldsToValues(contextRef.current.fields); + const file = data?.file; + + if (file) { + delete data.file; + } + const dataWithOverrides = { ...data, ...overrides, }; + const dataToSerialize = { + _payload: JSON.stringify(dataWithOverrides), + file, + }; + // nullAsUndefineds is important to allow uploads and relationship fields to clear themselves - const formData = serialize(dataWithOverrides, { indices: true, nullsAsUndefineds: false }); + const formData = serialize(dataToSerialize, { indices: true, nullsAsUndefineds: false }); return formData; }, [contextRef]); diff --git a/src/admin/components/forms/field-types/RichText/RichText.tsx b/src/admin/components/forms/field-types/RichText/RichText.tsx index eec529f32ac..0d01ad5001d 100644 --- a/src/admin/components/forms/field-types/RichText/RichText.tsx +++ b/src/admin/components/forms/field-types/RichText/RichText.tsx @@ -185,10 +185,6 @@ const RichText: React.FC = (props) => { if (!valueToRender) valueToRender = defaultValue; - if (path === 'defaultRichText') { - console.log(valueToRender); - } - return (
{ + if (req.body?._payload) { + const payloadJSON = JSON.parse(req.body._payload); + + req.body = { + ...req.body, + ...payloadJSON, + }; + } + + next(); +}; diff --git a/src/express/middleware/index.ts b/src/express/middleware/index.ts index 58fa5781df8..0c2b5c1c6cd 100644 --- a/src/express/middleware/index.ts +++ b/src/express/middleware/index.ts @@ -12,6 +12,7 @@ import identifyAPI from './identifyAPI'; import { Payload } from '../..'; import { PayloadRequest } from '../types'; import corsHeaders from './corsHeaders'; +import convertPayload from './convertPayload'; const middleware = (payload: Payload): any => { const rateLimitOptions: { @@ -39,6 +40,7 @@ const middleware = (payload: Payload): any => { parseNested: true, ...payload.config.upload, }), + convertPayload, corsHeaders(payload.config), authenticate(payload.config), ...(payload.config.express.middleware || []),