Skip to content

Commit 0e1b3a0

Browse files
waleedlatif1claude
andcommitted
fix: add WebP support and use refs pattern in useProfilePictureUpload
- Add image/webp to ACCEPTED_IMAGE_TYPES in useProfilePictureUpload - Add image/webp to file input accept attributes in whitelabeling settings - Refactor useProfilePictureUpload to use refs for onUpload, onError, and currentImage callbacks, matching the established codebase pattern Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9b89181 commit 0e1b3a0

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

apps/sim/app/workspace/[workspaceId]/settings/hooks/use-profile-picture-upload.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { StorageContext } from '@/lib/uploads/shared/types'
44

55
const logger = createLogger('ProfilePictureUpload')
66
const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
7-
const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/jpg', 'image/svg+xml']
7+
const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/jpg', 'image/svg+xml', 'image/webp']
88

99
interface UseProfilePictureUploadProps {
1010
onUpload?: (url: string | null) => void
@@ -27,10 +27,19 @@ export function useProfilePictureUpload({
2727
}: UseProfilePictureUploadProps = {}) {
2828
const previewRef = useRef<string | null>(null)
2929
const fileInputRef = useRef<HTMLInputElement>(null)
30+
const onUploadRef = useRef(onUpload)
31+
const onErrorRef = useRef(onError)
32+
const currentImageRef = useRef(currentImage)
3033
const [previewUrl, setPreviewUrl] = useState<string | null>(currentImage || null)
3134
const [fileName, setFileName] = useState<string | null>(null)
3235
const [isUploading, setIsUploading] = useState(false)
3336

37+
useEffect(() => {
38+
onUploadRef.current = onUpload
39+
onErrorRef.current = onError
40+
currentImageRef.current = currentImage
41+
}, [onUpload, onError, currentImage])
42+
3443
useEffect(() => {
3544
if (previewRef.current && previewRef.current !== currentImage) {
3645
URL.revokeObjectURL(previewRef.current)
@@ -44,7 +53,7 @@ export function useProfilePictureUpload({
4453
return `File "${file.name}" is too large. Maximum size is 5MB.`
4554
}
4655
if (!ACCEPTED_IMAGE_TYPES.includes(file.type)) {
47-
return `File "${file.name}" is not a supported image format. Please use PNG, JPEG, or SVG.`
56+
return `File "${file.name}" is not a supported image format. Please use PNG, JPEG, SVG, or WebP.`
4857
}
4958
return null
5059
}, [])
@@ -88,7 +97,7 @@ export function useProfilePictureUpload({
8897
async (file: File) => {
8998
const validationError = validateFile(file)
9099
if (validationError) {
91-
onError?.(validationError)
100+
onErrorRef.current?.(validationError)
92101
return
93102
}
94103

@@ -105,19 +114,19 @@ export function useProfilePictureUpload({
105114
URL.revokeObjectURL(newPreviewUrl)
106115
previewRef.current = null
107116
setPreviewUrl(serverUrl)
108-
onUpload?.(serverUrl)
117+
onUploadRef.current?.(serverUrl)
109118
} catch (error) {
110119
const errorMessage =
111120
error instanceof Error ? error.message : 'Failed to upload profile picture'
112-
onError?.(errorMessage)
121+
onErrorRef.current?.(errorMessage)
113122
URL.revokeObjectURL(newPreviewUrl)
114123
previewRef.current = null
115-
setPreviewUrl(currentImage || null)
124+
setPreviewUrl(currentImageRef.current || null)
116125
} finally {
117126
setIsUploading(false)
118127
}
119128
},
120-
[onUpload, onError, uploadFileToServer, validateFile, currentImage]
129+
[uploadFileToServer, validateFile]
121130
)
122131

123132
const handleFileChange = useCallback(
@@ -147,8 +156,8 @@ export function useProfilePictureUpload({
147156
if (fileInputRef.current) {
148157
fileInputRef.current.value = ''
149158
}
150-
onUpload?.(null)
151-
}, [onUpload])
159+
onUploadRef.current?.(null)
160+
}, [])
152161

153162
useEffect(() => {
154163
return () => {

apps/sim/ee/whitelabeling/components/whitelabeling-settings.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ export function WhitelabelingSettings() {
364364
<input
365365
ref={logoUpload.fileInputRef}
366366
type='file'
367-
accept='image/png,image/jpeg,image/jpg,image/svg+xml'
367+
accept='image/png,image/jpeg,image/jpg,image/svg+xml,image/webp'
368368
onChange={logoUpload.handleFileChange}
369369
className='hidden'
370370
/>
@@ -420,7 +420,7 @@ export function WhitelabelingSettings() {
420420
<input
421421
ref={wordmarkUpload.fileInputRef}
422422
type='file'
423-
accept='image/png,image/jpeg,image/jpg,image/svg+xml'
423+
accept='image/png,image/jpeg,image/jpg,image/svg+xml,image/webp'
424424
onChange={wordmarkUpload.handleFileChange}
425425
className='hidden'
426426
/>

0 commit comments

Comments
 (0)