From 1e857f03f1c8a2e47d73a86e824d53b44724dcbf Mon Sep 17 00:00:00 2001 From: Michael Matloka Date: Mon, 30 Sep 2024 16:44:42 +0200 Subject: [PATCH] fix(settings): Fix edge case crashing org logo selection (#25275) Co-authored-by: Zach Waterfield --- frontend/src/lib/hooks/useUploadFiles.ts | 2 +- .../src/lib/lemon-ui/LemonFileInput/LemonFileInput.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/hooks/useUploadFiles.ts b/frontend/src/lib/hooks/useUploadFiles.ts index 095494d5d1738..f486c50649580 100644 --- a/frontend/src/lib/hooks/useUploadFiles.ts +++ b/frontend/src/lib/hooks/useUploadFiles.ts @@ -68,7 +68,7 @@ export function useUploadFiles({ } } uploadFiles().catch(console.error) - }, [filesToUpload]) + }, [filesToUpload, onUpload, onError]) return { setFilesToUpload, filesToUpload, uploading } } diff --git a/frontend/src/lib/lemon-ui/LemonFileInput/LemonFileInput.tsx b/frontend/src/lib/lemon-ui/LemonFileInput/LemonFileInput.tsx index 4aa9366f6ddea..04a13056a7b45 100644 --- a/frontend/src/lib/lemon-ui/LemonFileInput/LemonFileInput.tsx +++ b/frontend/src/lib/lemon-ui/LemonFileInput/LemonFileInput.tsx @@ -61,9 +61,11 @@ export const LemonFileInput = ({ const eventFiles = e.target.files const filesArr = Array.prototype.slice.call(eventFiles) - const localFiles = multiple ? [...files, ...filesArr] : [filesArr[0]] - setFiles(localFiles) - onChange?.(localFiles) + if (filesArr.length > 0) { + const localFiles = multiple ? [...files, ...filesArr] : filesArr.slice(0, 1) + setFiles(localFiles) + onChange?.(localFiles) + } } const handleDrag = (e: DragEvent): void => { @@ -141,7 +143,7 @@ export const LemonFileInput = ({ !alternativeDropTargetRef?.current && drag && 'FileDropTarget--active' )} > -