Fix FormData

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-05-12 19:43:57 +02:00
parent 47b01ca078
commit ec918d497d
5 changed files with 16 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import { serialize } from 'object-to-formdata';
import { selectAccount } from 'soapbox/selectors';
import { setSentryAccount } from 'soapbox/sentry';
import KVStore from 'soapbox/storage/kv-store';
@ -70,14 +72,11 @@ const patchMe = (params: Record<string, any>, isFormData = false) =>
(dispatch: AppDispatch, getState: () => RootState) => {
dispatch(patchMeRequest());
const headers: HeadersInit = isFormData ? {
'Content-Type': 'multipart/form-data',
} : {};
const headers: HeadersInit = isFormData ? { 'Content-Type': '' } : {};
let body: FormData | string;
if (isFormData) {
body = new FormData();
Object.entries(params).forEach(([key, value]) => (body as FormData).append(key, value));
body = serialize(params, { indices: true });
} else {
body = JSON.stringify(params);
}

View File

@ -1,3 +1,5 @@
import { serialize } from 'object-to-formdata';
import { Entities } from 'soapbox/entity-store/entities';
import { useCreateEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks/useApi';
@ -17,9 +19,7 @@ function useCreateGroup() {
const api = useApi();
const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS, 'search', ''], (params: CreateGroupParams) => {
const formData = new FormData();
Object.entries(params).forEach(([key, value]) => formData.append(key, value));
const formData = serialize(params, { indices: true });
return api('/api/v1/groups', {
method: 'POST',

View File

@ -1,3 +1,5 @@
import { serialize } from 'object-to-formdata';
import { Entities } from 'soapbox/entity-store/entities';
import { useCreateEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks/useApi';
@ -16,7 +18,7 @@ function useUpdateGroup(groupId: string) {
const api = useApi();
const { createEntity, ...rest } = useCreateEntity([Entities.GROUPS], (params: UpdateGroupParams) => {
const formData = new FormData();
const formData = serialize(params, { indices: true });
Object.entries(params).forEach(([key, value]) => formData.append(key, value));