diff --git a/src/features/input-create-post/ui/input-create-post.tsx b/src/features/input-create-post/ui/input-create-post.tsx index 0cff517d..6bd243bb 100644 --- a/src/features/input-create-post/ui/input-create-post.tsx +++ b/src/features/input-create-post/ui/input-create-post.tsx @@ -13,14 +13,7 @@ const InputCreatePost: FC = ({ className }) => { const user = useAppSelector(selectUser) const dispatch = useAppDispatch() const handleCreatePost = async (text: string, pictures?: FileList): Promise => { - const formData = new FormData() - formData.append(`text`, text) - if (pictures) - Array.from(pictures).forEach((file, index) => { - formData.append(`file${index}`, file) - }) - - await createPost(formData) + await createPost({ text, pictures }) dispatch(getAllPostsThunk()) } return ( diff --git a/src/shared/api/news/news.ts b/src/shared/api/news/news.ts index 0183ed97..ea4328c1 100644 --- a/src/shared/api/news/news.ts +++ b/src/shared/api/news/news.ts @@ -14,8 +14,17 @@ export const getAllPosts = async (): Promise => { return res.data } -export const createPost = async (form: ICreatePostForm): Promise => { - const res = await apiWithAuth.post('/posts', form) +export const createPost = async ({ + text, + pictures +}: ICreatePostForm): Promise => { + const formData = new FormData() + formData.append(`text`, text) + if (pictures) + Array.from(pictures).forEach((file) => { + formData.append('pictures', file) + }) + const res = await apiWithAuth.post('/posts', formData) return res.data } diff --git a/src/shared/api/user-info/user-info.ts b/src/shared/api/user-info/user-info.ts index 0c20b94b..a451b2e2 100644 --- a/src/shared/api/user-info/user-info.ts +++ b/src/shared/api/user-info/user-info.ts @@ -20,9 +20,12 @@ export const getUserInfo = async (): Promise => { export const editUserInfo = async ( form: IEditUserInfoForm ): Promise => { - const res = await apiWithAuth.patch('/auth/account', form, { - headers: { 'Content-Type': 'multipart/form-data' } - }) + const formData = new FormData() + for (const property in form) { + formData.append(property, form[property as keyof IEditUserInfoForm] as File | string) + } + + const res = await apiWithAuth.patch('/auth/account', formData) return res.data } diff --git a/src/shared/ui/input-send-message.tsx b/src/shared/ui/input-send-message.tsx index 0f081a0e..9406ee1b 100644 --- a/src/shared/ui/input-send-message.tsx +++ b/src/shared/ui/input-send-message.tsx @@ -12,7 +12,7 @@ import send from '@assets/ui/send.svg' interface IInputSendMessageProps extends IInputProps { avatar?: string | null withPicture: boolean - sendMessage: (message: string, pictures?: FileList) => void + sendMessage: (message: string, pictures?: FileList) => Promise } // Todo Переписать в textarea