feat: builds a way for multipart/form-data reqs to retain non-string values

This commit is contained in:
James
2021-12-31 12:55:01 -05:00
parent cd0e172708
commit 4efc2cf71c
5 changed files with 28 additions and 7 deletions

View File

@@ -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;

View File

@@ -288,13 +288,24 @@ const Form: React.FC<Props> = (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]);

View File

@@ -185,10 +185,6 @@ const RichText: React.FC<Props> = (props) => {
if (!valueToRender) valueToRender = defaultValue;
if (path === 'defaultRichText') {
console.log(valueToRender);
}
return (
<div
className={classes}