Skip to content

Commit 529a371

Browse files
ggazzosampaiodiego
authored andcommitted
[FIX] File upload (Avatars, Emoji, Sounds) (#18841)
1 parent 9caf130 commit 529a371

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

client/contexts/ServerContext.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type ServerContextValue = {
1010
absoluteUrl: (path: string) => string;
1111
callMethod: (methodName: string, ...args: any[]) => Promise<any>;
1212
callEndpoint: (httpMethod: 'GET' | 'POST' | 'DELETE', endpoint: string, ...args: any[]) => Promise<any>;
13-
uploadToEndpoint: (endpoint: string) => Promise<void>;
13+
uploadToEndpoint: (endpoint: string, params: any, formData: any) => Promise<void>;
1414
getStream: (streamName: string, options?: {}) => IServerStream;
1515
};
1616

@@ -40,9 +40,9 @@ export const useEndpoint = (httpMethod: 'GET' | 'POST' | 'DELETE', endpoint: str
4040
return useCallback((...args: any[]) => callEndpoint(httpMethod, endpoint, ...args), [callEndpoint, httpMethod, endpoint]);
4141
};
4242

43-
export const useUpload = (endpoint: string): () => Promise<void> => {
43+
export const useUpload = (endpoint: string): (params: any, formData: any) => Promise<void> => {
4444
const { uploadToEndpoint } = useContext(ServerContext);
45-
return useCallback(() => uploadToEndpoint(endpoint), [endpoint, uploadToEndpoint]);
45+
return useCallback((params, formData: any) => uploadToEndpoint(endpoint, params, formData), [endpoint, uploadToEndpoint]);
4646
};
4747

4848
export const useStream = (streamName: string, options?: {}): IServerStream => {

client/hooks/useFileInput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
22
import { useRef, useEffect } from 'react';
33

4-
export const useFileInput = (onSetFile, fileType = 'image/*') => {
4+
export const useFileInput = (onSetFile, fileType = 'image/*', fileField = 'image') => {
55
const ref = useRef();
66

77
useEffect(() => {
@@ -14,7 +14,7 @@ export const useFileInput = (onSetFile, fileType = 'image/*') => {
1414

1515
ref.current = fileInput;
1616
const handleFiles = () => {
17-
formData.append(fileType, fileInput.files[0]);
17+
formData.append(fileField, fileInput.files[0]);
1818
onSetFile(fileInput.files[0], formData);
1919
};
2020
fileInput.addEventListener('change', handleFiles, false);

client/hooks/useUpdateAvatar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const useUpdateAvatar = (avatarObj, userId) => {
1717

1818
const saveAvatarQuery = useMemo(() => ({
1919
userId,
20-
avatarUrl,
20+
...avatarUrl && { avatarUrl },
2121
}), [avatarUrl, userId]);
2222

2323
const resetAvatarQuery = useMemo(() => ({

0 commit comments

Comments
 (0)