Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Add better disabled state to file upload

Tim Wilsonf5a4bd5c1f02
diff --git a/apps/web/ui/oauth-apps/add-edit-app-form.tsx b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
index fc0fc5ced8..36135de404 100644
--- a/apps/web/ui/oauth-apps/add-edit-app-form.tsx
+++ b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
@@ -369,16 +369,15 @@ export default function AddOAuthAppForm({
))}
</Reorder.Group>
- {canManageApp && screenshots.length < 4 && (
- <FileUpload
- accept="any"
- className="mt-2 aspect-[5/1] w-full rounded-md border border-dashed border-gray-300"
- iconClassName="w-5 h-5"
- variant="plain"
- onChange={async ({ file }) => await handleUpload(file)}
- content="Drag and drop or click to upload screenshots"
- />
- )}
+ <FileUpload
+ accept="any"
+ className="mt-2 aspect-[5/1] w-full rounded-md border border-dashed border-gray-300"
+ iconClassName="w-5 h-5"
+ variant="plain"
+ onChange={async ({ file }) => await handleUpload(file)}
+ content="Drag and drop or click to upload screenshots"
+ disabled={!canManageApp || screenshots.length >= 4}
+ />
</div>
<div>
diff --git a/packages/ui/src/file-upload.tsx b/packages/ui/src/file-upload.tsx
index 9e0ba9a138..0159e5238c 100644
--- a/packages/ui/src/file-upload.tsx
+++ b/packages/ui/src/file-upload.tsx
@@ -156,7 +156,9 @@ export function FileUpload({
<label
className={cn(
imageUploadVariants({ variant }),
- clickToUpload && "cursor-pointer",
+ !disabled
+ ? cn(clickToUpload && "cursor-pointer")
+ : "cursor-not-allowed",
className,
)}
>
@@ -192,22 +194,37 @@ export function FileUpload({
<div
className={cn(
"absolute inset-0 z-[3] flex flex-col items-center justify-center rounded-[inherit] bg-white transition-all",
+ disabled && "bg-gray-50",
dragActive &&
+ !disabled &&
"cursor-copy border-2 border-black bg-gray-50 opacity-100",
imageSrc
- ? cn("opacity-0", showHoverOverlay && "group-hover:opacity-100")
- : "group-hover:bg-gray-50",
+ ? cn(
+ "opacity-0",
+ showHoverOverlay && !disabled && "group-hover:opacity-100",
+ )
+ : cn(!disabled && "group-hover:bg-gray-50"),
)}
>
<UploadCloud
className={cn(
- "h-7 w-7 text-gray-500 transition-all duration-75 group-hover:scale-110 group-active:scale-95",
- dragActive ? "scale-110" : "scale-100",
+ "h-7 w-7 transition-all duration-75",
+ !disabled
+ ? cn(
+ "text-gray-500 group-hover:scale-110 group-active:scale-95",
+ dragActive ? "scale-110" : "scale-100",
+ )
+ : "text-gray-400",
iconClassName,
)}
/>
{content !== null && (
- <div className="mt-2 text-center text-sm text-gray-500">
+ <div
+ className={cn(
+ "mt-2 text-center text-sm text-gray-500",
+ disabled && "text-gray-400",
+ )}
+ >
{content ?? (
<>
<p>Drag and drop {clickToUpload && "or click"} to upload.</p>