11"use client" ;
22
3- import { Button , Input } from "@cap/ui" ;
3+ import { Button , Input , LoadingSpinner } from "@cap/ui" ;
44import {
55 faCloudUpload ,
66 faSpinner ,
@@ -12,6 +12,7 @@ import type React from "react";
1212import { useEffect , useRef , useState } from "react" ;
1313import { toast } from "sonner" ;
1414import { useSignedImageUrl } from "@/lib/use-signed-image-url" ;
15+ import { SignedImageUrl } from "./SignedImageUrl" ;
1516import { Tooltip } from "./Tooltip" ;
1617
1718const ALLOWED_IMAGE_TYPES = new Set ( [ "image/jpeg" , "image/png" ] ) ;
@@ -61,13 +62,6 @@ export const FileInput: React.FC<FileInputProps> = ({
6162 // Get signed URL for S3 keys
6263 const { data : signedUrl } = useSignedImageUrl ( previewUrl , type ) ;
6364
64- function isS3Key ( imageKeyOrUrl : string | null | undefined ) : boolean {
65- if ( ! imageKeyOrUrl ) return false ;
66- return (
67- imageKeyOrUrl . startsWith ( "users/" ) ||
68- imageKeyOrUrl . startsWith ( "organizations/" )
69- ) ;
70- }
7165 const previousPreviewRef = useRef < {
7266 url : string | null ;
7367 isLocal : boolean ;
@@ -235,7 +229,12 @@ export const FileInput: React.FC<FileInputProps> = ({
235229 } }
236230 >
237231 { /* Fixed height container to prevent resizing */ }
238- { previewUrl ? (
232+ { isLoading ? (
233+ < div className = "flex h-full items-center gap-2 rounded-xl border border-dashed border-gray-4 bg-gray-1 px-4 py-1.5" >
234+ < LoadingSpinner themeColors size = { 16 } />
235+ < p className = "truncate text-[13px] text-gray-11" > Uploading...</ p >
236+ </ div >
237+ ) : previewUrl ? (
239238 < div className = "flex h-full items-center gap-2 rounded-xl border border-dashed border-gray-4 bg-gray-1 px-4 py-1.5" >
240239 < div className = "flex flex-1 items-center gap-1.5" >
241240 < div className = "flex flex-1 gap-1 items-center" >
@@ -250,19 +249,13 @@ export const FileInput: React.FC<FileInputProps> = ({
250249 } }
251250 className = "flex overflow-hidden relative flex-shrink-0 justify-center items-center rounded-full"
252251 >
253- { previewUrl && (
254- < img
255- src = {
256- isS3Key ( previewUrl ) ? ( signedUrl ?? "" ) : previewUrl
257- }
258- alt = "File preview"
259- width = { 32 }
260- height = { 32 }
261- loading = "eager"
262- referrerPolicy = "no-referrer"
263- className = "object-cover rounded-full size-8"
264- />
265- ) }
252+ < SignedImageUrl
253+ image = { previewUrl }
254+ name = "File preview"
255+ type = { type }
256+ letterClass = "text-lg"
257+ className = "size-full"
258+ />
266259 </ div >
267260 </ div >
268261 </ div >
0 commit comments