Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Improvement: Sharing dialog design, save loading state, and more... (#518)

Ameer Al Ashhabafcd32adc8e8
diff --git a/apps/web/app/dashboard/_components/DashboardInner.tsx b/apps/web/app/dashboard/_components/DashboardInner.tsx
index ba5811c0b..7f36ad5b6 100644
--- a/apps/web/app/dashboard/_components/DashboardInner.tsx
+++ b/apps/web/app/dashboard/_components/DashboardInner.tsx
@@ -72,7 +72,7 @@ export default function DashboardInner({
{/* Content Area */}
<div
className={clsx(
- "flex overflow-auto flex-col flex-1 p-5 pb-5 border border-b-0 bg-gray-1 border-gray-3 lg:rounded-tl-2xl lg:p-8"
+ "flex overflow-y-auto flex-col flex-1 p-5 pb-5 border border-b-0 bg-gray-1 border-gray-3 lg:rounded-tl-2xl lg:p-8"
)}
>
<div className="flex flex-col flex-1 gap-4 h-full">{children}</div>
diff --git a/apps/web/app/dashboard/caps/Caps.tsx b/apps/web/app/dashboard/caps/Caps.tsx
index 7a2086be0..4b8f068c9 100644
--- a/apps/web/app/dashboard/caps/Caps.tsx
+++ b/apps/web/app/dashboard/caps/Caps.tsx
@@ -42,7 +42,6 @@ export const Caps = ({
const totalPages = Math.ceil(count / limit);
const [selectedCaps, setSelectedCaps] = useState<string[]>([]);
const previousCountRef = useRef<number>(0);
- const [, setAnimateDirection] = useState<"up" | "down">("up");
const [isDeleting, setIsDeleting] = useState(false);
const anyCapSelected = selectedCaps.length > 0;
@@ -102,7 +101,6 @@ export const Caps = ({
) {
e.preventDefault();
setSelectedCaps(data.map((cap) => cap.id));
- setAnimateDirection("up");
}
}
};
@@ -142,7 +140,6 @@ export const Caps = ({
: [...prev, capId];
previousCountRef.current = prev.length;
- setAnimateDirection(newSelection.length > prev.length ? "up" : "down");
return newSelection;
});
diff --git a/apps/web/app/dashboard/caps/components/SharingDialog.tsx b/apps/web/app/dashboard/caps/components/SharingDialog.tsx
index 2fca64ce8..f4b9a6742 100644
--- a/apps/web/app/dashboard/caps/components/SharingDialog.tsx
+++ b/apps/web/app/dashboard/caps/components/SharingDialog.tsx
@@ -2,7 +2,8 @@ import { Button, Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle,
import { faShareNodes } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
-import { Plus, Search } from "lucide-react";
+import { motion } from "framer-motion";
+import { Check, Search } from "lucide-react";
import { useEffect, useState } from "react";
import { toast } from "sonner";
@@ -33,6 +34,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
useState<Set<string>>(
new Set(sharedOrganizations.map((organization) => organization.id))
);
+ const [loading, setLoading] = useState(false);
useEffect(() => {
if (isOpen) {
@@ -59,6 +61,7 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
const handleSave = async () => {
try {
+ setLoading(true);
const response = await fetch("/api/caps/share", {
method: "POST",
headers: { "Content-Type": "application/json" },
@@ -118,12 +121,13 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
} else {
toast.success("No changes to sharing settings");
}
-
onSharingUpdated(newSelectedOrganizations);
onClose();
} catch (error) {
console.error("Error updating sharing settings:", error);
toast.error("Failed to update sharing settings");
+ } finally {
+ setLoading(false);
}
};
@@ -156,35 +160,15 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
size={20}
/>
</div>
- <div className="flex overflow-y-auto flex-col gap-2.5 max-h-60">
+ <div className="grid grid-cols-5 gap-3 max-h-60">
{filteredOrganizations && filteredOrganizations.length > 0 ? (
filteredOrganizations.map((organization) => (
- <div
+ <SpaceCard
key={organization.id}
- className={clsx(
- `flex items-center border transition-colors duration-200 border-gray-3 justify-between p-3 rounded-xl cursor-pointer`,
- selectedOrganizations.has(organization.id)
- ? "bg-gray-1"
- : "hover:bg-gray-3 hover:border-gray-4"
- )}
- onClick={() => handleToggleOrganization(organization.id)}
- >
- <div className="flex items-center">
- <div className="flex justify-center items-center mr-3 w-8 h-8 font-semibold rounded-md bg-blue-10 text-gray-12">
- {organization.name.charAt(0).toUpperCase()}
- </div>
- <span className="text-sm transition-colors duration-200 text-gray-12">
- {organization.name}
- </span>
- </div>
- {selectedOrganizations.has(organization.id) ? (
- <span className="text-sm font-medium text-blue-500">
- Added
- </span>
- ) : (
- <Plus className="text-gray-10" size={20} />
- )}
- </div>
+ organization={organization}
+ selectedOrganizations={selectedOrganizations}
+ handleToggleOrganization={handleToggleOrganization}
+ />
))
) : (
<div className="flex gap-2 justify-center items-center pt-2 text-sm">
@@ -197,11 +181,44 @@ export const SharingDialog: React.FC<SharingDialogProps> = ({
<Button size="sm" variant="gray" onClick={onClose}>
Cancel
</Button>
- <Button size="sm" variant="dark" onClick={handleSave}>
- Save
+ <Button spinner={loading} disabled={loading} size="sm" variant="dark" onClick={handleSave}>
+ {loading ? "Saving..." : "Save"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
};
+
+const SpaceCard = ({ organization, selectedOrganizations, handleToggleOrganization }: { organization: { id: string; name: string }, selectedOrganizations: Set<string>, handleToggleOrganization: (organizationId: string) => void }) => {
+ return (
+ <div className={clsx("flex items-center relative flex-col justify-center gap-2 border transition-colors duration-200 border-gray-3 w-full p-3 rounded-xl cursor-pointer", selectedOrganizations.has(organization.id) ? "bg-gray-3 border-gray-4" : "hover:bg-gray-3 hover:border-gray-4")} onClick={() => handleToggleOrganization(organization.id)}>
+ <div className="flex justify-center items-center text-xs font-semibold rounded-full size-6 text-gray-1 bg-gray-12">
+ {organization.name.charAt(0).toUpperCase()}
+ </div>
+ <span className="text-xs truncate transition-colors duration-200 text-gray-10">
+ {organization.name}
+ </span>
+ <motion.div
+ key={organization.id}
+ animate={{
+ scale: selectedOrganizations.has(organization.id) ? 1 : 0
+ }}
+ initial={{
+ scale: 0
+ }}
+ transition={{
+ type: selectedOrganizations.has(organization.id)
+ ? "spring"
+ : "tween",
+ stiffness: selectedOrganizations.has(organization.id) ? 300 : undefined,
+ damping: selectedOrganizations.has(organization.id) ? 20 : undefined,
+ duration: !selectedOrganizations.has(organization.id) ? 0.2 : undefined
+ }}
+ className={clsx("absolute top-[-6px] flex items-center justify-center right-[-5px] bg-gray-4 rounded-full border size-4", selectedOrganizations.has(organization.id) ? "bg-green-500 border-transparent" : "bg-gray-4 border-gray-5")}>
+ <Check className="text-white" size={10} />
+ </motion.div>
+ </div>
+ );
+};
+
\ No newline at end of file
diff --git a/apps/web/app/dashboard/settings/organization/Organization.tsx b/apps/web/app/dashboard/settings/organization/Organization.tsx
index 4be5e3718..9af61ff4b 100644
--- a/apps/web/app/dashboard/settings/organization/Organization.tsx
+++ b/apps/web/app/dashboard/settings/organization/Organization.tsx
@@ -12,7 +12,7 @@ import { useRouter } from "next/navigation";
import { useCallback, useRef, useState } from "react";
import { toast } from "sonner";
import { BillingCard } from "./components/BillingCard";
-import { CustomDomainCard } from "./components/CustomDomainCard";
+import { CustomDomainIconCard } from "./components/CustomDomainIconCard";
import { InviteDialog } from "./components/InviteDialog";
import { MembersCard } from "./components/MembersCard";
import { OrganizationDetailsCard } from "./components/OrganizationDetailsCard";
@@ -106,7 +106,10 @@ export const Organization = () => {
showOwnerToast={showOwnerToast}
organizationName={organizationName}
/>
- <CustomDomainCard />
+ <CustomDomainIconCard
+ isOwner={isOwner}
+ showOwnerToast={showOwnerToast}
+ />
</div>
<MembersCard
diff --git a/apps/web/app/dashboard/settings/organization/components/CustomDomain.tsx b/apps/web/app/dashboard/settings/organization/components/CustomDomain.tsx
index cc29a23e8..ecb7e6a33 100644
--- a/apps/web/app/dashboard/settings/organization/components/CustomDomain.tsx
+++ b/apps/web/app/dashboard/settings/organization/components/CustomDomain.tsx
@@ -227,9 +227,9 @@ export function CustomDomain() {
};
return (
- <div className="space-y-6">
- <div>
- <div className="flex flex-col justify-between items-start mt-2 h-full">
+ <div className="flex flex-wrap space-y-6">
+ <div className="flex-1">
+ <div className="flex flex-col justify-between items-start">
<Input
type="text"
id="customDomain"
diff --git a/apps/web/app/dashboard/settings/organization/components/CustomDomainCard.tsx b/apps/web/app/dashboard/settings/organization/components/CustomDomainIconCard.tsx
similarity index 54%
rename from apps/web/app/dashboard/settings/organization/components/CustomDomainCard.tsx
rename to apps/web/app/dashboard/settings/organization/components/CustomDomainIconCard.tsx
index f8ac85efe..5558edd46 100644
--- a/apps/web/app/dashboard/settings/organization/components/CustomDomainCard.tsx
+++ b/apps/web/app/dashboard/settings/organization/components/CustomDomainIconCard.tsx
@@ -2,16 +2,28 @@
import { Card, CardDescription, Label } from "@cap/ui";
import { CustomDomain } from "./CustomDomain";
+import { OrganizationIcon } from "./OrganizationIcon";
-export const CustomDomainCard = () => {
+interface CustomDomainCardProps {
+ isOwner: boolean;
+ showOwnerToast: () => void;
+}
+
+export const CustomDomainIconCard = ({
+ isOwner,
+ showOwnerToast,
+}: CustomDomainCardProps) => {
return (
<Card className="flex flex-col flex-1 gap-6 w-full lg:flex-row">
- <div className="flex-1">
+ <div className="flex-1 order-first lg:order-last">
+ <OrganizationIcon isOwner={isOwner} showOwnerToast={showOwnerToast} />
+ </div>
+ <div className="flex-1 order-last lg:order-first">
<div className="space-y-1">
<Label htmlFor="customDomain">Custom Domain</Label>
<CardDescription className="w-full max-w-[400px]">
- Set up a custom domain for your organization's shared caps and
- make it unique.
+ Set up a custom domain for your organization's shared caps and make
+ it unique.
</CardDescription>
</div>
<div className="mt-4">
diff --git a/apps/web/app/dashboard/settings/organization/components/OrganizationIcon.tsx b/apps/web/app/dashboard/settings/organization/components/OrganizationIcon.tsx
new file mode 100644
index 000000000..c4547bdf1
--- /dev/null
+++ b/apps/web/app/dashboard/settings/organization/components/OrganizationIcon.tsx
@@ -0,0 +1,195 @@
+"use client";
+
+import { Button, CardDescription, Input, Label } from "@cap/ui";
+import { faCloudUpload } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import clsx from "clsx";
+import Image from "next/image";
+import { useEffect, useRef, useState } from "react";
+
+interface OrganizationIconProps {
+ isOwner: boolean;
+ showOwnerToast: () => void;
+}
+
+export const OrganizationIcon = ({
+ isOwner,
+ showOwnerToast,
+}: OrganizationIconProps) => {
+ const fileInputRef = useRef<HTMLInputElement>(null);
+ const [isDragging, setIsDragging] = useState(false);
+ const [selectedFile, setSelectedFile] = useState<File | null>(null);
+ const [previewUrl, setPreviewUrl] = useState<string | null>(null);
+
+ const handleDragEnter = (e: React.DragEvent<HTMLDivElement>) => {
+ e.preventDefault();
+ e.stopPropagation();
+ if (isOwner) {
+ setIsDragging(true);
+ }
+ };
+
+ const handleDragLeave = (e: React.DragEvent<HTMLDivElement>) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setIsDragging(false);
+ };
+
+ const handleDragOver = (e: React.DragEvent<HTMLDivElement>) => {
+ e.preventDefault();
+ e.stopPropagation();
+ if (isOwner) {
+ e.dataTransfer.dropEffect = "copy";
+ setIsDragging(true);
+ }
+ };
+
+ const handleDrop = (e: React.DragEvent<HTMLDivElement>) => {
+ e.preventDefault();
+ e.stopPropagation();
+ setIsDragging(false);
+
+ if (!isOwner) {
+ showOwnerToast();
+ return;
+ }
+
+ const files = e.dataTransfer.files;
+ if (files && files.length > 0) {
+ // Set the file to the input element
+ const file = files[0];
+
+ if (fileInputRef.current && file) {
+ try {
+ // Create a new DataTransfer instance
+ const dataTransfer = new DataTransfer();
+ dataTransfer.items.add(file);
+ fileInputRef.current.files = dataTransfer.files;
+
+ // Trigger onChange event manually
+ const event = new Event('change', { bubbles: true });
+ fileInputRef.current.dispatchEvent(event);
+ } catch (error) {
+ console.error('Error handling file drop:', error);
+ }
+ }
+ }
+ };
+
+ // Clean up the preview URL when component unmounts
+ useEffect(() => {
+ return () => {
+ if (previewUrl) {
+ URL.revokeObjectURL(previewUrl);
+ }
+ };
+ }, [previewUrl]);
+
+ const handleFileChange = () => {
+ if (!isOwner) {
+ showOwnerToast();
+ return;
+ }
+
+ const file = fileInputRef.current?.files?.[0];
+ if (file) {
+ // Clean up previous preview URL
+ if (previewUrl) {
+ URL.revokeObjectURL(previewUrl);
+ }
+
+ // Create a new preview URL
+ const newPreviewUrl = URL.createObjectURL(file);
+ setPreviewUrl(newPreviewUrl);
+ setSelectedFile(file);
+
+ // Here you would typically upload the file to your server
+ console.log("File selected:", file);
+ }
+ };
+
+ return (
+ <div className="relative flex-1">
+ <div className="space-y-1">
+ <Label htmlFor="icon">Organization Icon</Label>
+ <CardDescription className="w-full max-w-[400px]">
+ Upload a custom logo or icon for your organization and make it
+ unique.
+ </CardDescription>
+ </div>
+ <div className="relative mt-4">
+ <div className="flex absolute top-0 left-0 justify-center items-center w-full h-full rounded-xl backdrop-blur-md bg-gray/50">
+ <p className="text-sm text-gray-11">Coming soon...</p>
+ </div>
+ {selectedFile ? (
+ <div className="flex gap-2 items-center p-1.5 rounded-xl border border-gray-4">
+ <div className="flex flex-1 gap-1.5 items-center">
+ <div className="overflow-hidden relative flex-shrink-0 rounded-md size-6">
+ {previewUrl && (
+ <Image
+ src={previewUrl}
+ alt="Selected file preview"
+ fill
+ className="object-contain"
+ />
+ )}
+ </div>
+ <div className="flex flex-1 gap-1 items-center">
+ <p className="text-xs font-medium w-fit max-w-[150px] truncate text-gray-12">{selectedFile.name}</p>
+ <p className="text-xs text-gray-10 min-w-fit">{(selectedFile.size / 1024).toFixed(1)} KB</p>
+ </div>
+ </div>
+ <Button
+ variant="destructive"
+ style={{
+ "--gradient-border-radius": "8px",
+ } as React.CSSProperties}
+ size="xs"
+ className="min-w-[80px]"
+ onClick={(e) => {
+ e.stopPropagation();
+ setSelectedFile(null);
+ setPreviewUrl(null);
+ if (fileInputRef.current) {
+ fileInputRef.current.value = '';
+ }
+ }}
+ >
+ Remove
+ </Button>
+ </div>
+ ) : (
+ <div
+ onClick={() => fileInputRef.current?.click()}
+ onDragEnter={handleDragEnter}
+ onDragOver={handleDragOver}
+ onDragLeave={handleDragLeave}
+ onDrop={handleDrop}
+ className={clsx(
+ "flex gap-3 justify-center items-center px-4 w-full rounded-xl border border-dashed transition-all duration-300 cursor-pointer py-[12px]",
+ isDragging ? "border-blue-500 bg-gray-5" : "hover:bg-gray-4 border-gray-8"
+ )}
+ >
+ <FontAwesomeIcon
+ className="text-gray-10 size-5"
+ icon={faCloudUpload}
+ />
+ <p className="text-sm truncate text-gray-11">
+ Choose a file or drag & drop it here
+ </p>
+ </div>
+ )}
+ <Input
+ className="hidden"
+ type="file"
+ ref={fileInputRef}
+ id="icon"
+ disabled={!isOwner}
+ accept="image/*"
+ onChange={handleFileChange}
+ name="icon"
+ />
+ </div>
+ </div>
+ );
+};
diff --git a/packages/ui/src/components/Table.tsx b/packages/ui/src/components/Table.tsx
index c76074b30..4a6653971 100644
--- a/packages/ui/src/components/Table.tsx
+++ b/packages/ui/src/components/Table.tsx
@@ -121,5 +121,6 @@ export {
TableFooter,
TableHead,
TableHeader,
- TableRow,
+ TableRow
};
+