Skip to content

Commit

Permalink
Fix problem with RTK query code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-moser committed Dec 9, 2024
1 parent 3e2a0e5 commit 890fa7b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
7 changes: 2 additions & 5 deletions assets/js/src/core/modules/user/hooks/use-user-helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down
54 changes: 54 additions & 0 deletions assets/js/src/core/modules/user/user-api-slice-enhanced.ts
Original file line number Diff line number Diff line change
@@ -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 }

0 comments on commit 890fa7b

Please sign in to comment.