diff --git a/assets/js/src/core/modules/user/hooks/use-user-helper.tsx b/assets/js/src/core/modules/user/hooks/use-user-helper.tsx index 4efa41125..0b531ad57 100644 --- a/assets/js/src/core/modules/user/hooks/use-user-helper.tsx +++ b/assets/js/src/core/modules/user/hooks/use-user-helper.tsx @@ -26,7 +26,7 @@ import { type UserGetByIdApiResponse, type UserGetCollectionApiResponse, type PimcoreStudioApiUserSearchApiResponse, type UserDefaultKeyBindingsApiResponse, type UserUploadImageApiResponse -} from '@Pimcore/modules/user/user-api-slice.gen' +} from '@Pimcore/modules/user/user-api-slice-enhanced' import { userOpened, userClosed, userUpdated, changeUser } from '@Pimcore/modules/user/user-slice' import { useNotification } from '@Pimcore/components/notification/useNotification' import { useTranslation } from 'react-i18next' @@ -251,10 +251,7 @@ export const useUserHelper = (): UseUserReturn => { } async function uploadUserAvatar (props): Promise<{ data: UserUploadImageApiResponse, error: Error }> { - const formData = new FormData() - formData.append('userImage', props.file as File) - - const { data, error }: any = await dispatch(api.endpoints.userUploadImage.initiate({ id: props.id, body: formData })) + const { data, error }: any = await dispatch(api.endpoints.userUploadImage.initiate({ id: props.id, body: { userImage: props.file as File } })) if (error !== undefined) { notificationApi.open({ diff --git a/assets/js/src/core/modules/user/user-api-slice-enhanced.ts b/assets/js/src/core/modules/user/user-api-slice-enhanced.ts new file mode 100644 index 000000000..1745553a1 --- /dev/null +++ b/assets/js/src/core/modules/user/user-api-slice-enhanced.ts @@ -0,0 +1,54 @@ +/** +* Pimcore +* +* This source file is available under two different licenses: +* - Pimcore Open Core License (POCL) +* - Pimcore Commercial License (PCL) +* Full copyright and license information is available in +* LICENSE.md which is distributed with this source code. +* +* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) +* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL +*/ + +import { api as baseApi } from './user-api-slice.gen' + +const api = baseApi.enhanceEndpoints({ + endpoints: { + userUploadImage: { + query: (queryArg) => { + const formData = new FormData() + formData.append('userImage', queryArg.body.userImage) + return { + url: `/pimcore-studio/api/user/upload-image/${queryArg.id}`, + method: 'POST', + body: formData + } + } + } + } +}) + +export type * from './user-api-slice.gen' + +export const { + useUserCloneByIdMutation, + useUserCreateMutation, + useUserFolderCreateMutation, + useUserGetCurrentInformationQuery, + useUserGetByIdQuery, + useUserUpdateByIdMutation, + useUserDeleteByIdMutation, + useUserFolderDeleteByIdMutation, + useUserDefaultKeyBindingsQuery, + useUserGetAvailablePermissionsQuery, + useUserGetCollectionQuery, + useUserResetPasswordMutation, + usePimcoreStudioApiUserSearchQuery, + useUserUpdatePasswordByIdMutation, + useUserUploadImageMutation, + useUserGetImageQuery, + useUserGetTreeQuery +} = api + +export { api }