Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: share links (#715)
Ameer Al Ashhab093521ce3586
diff --git a/apps/web/actions/organization/update-domain.ts b/apps/web/actions/organization/update-domain.tsindex 12111f075..bad2cbbd6 100644--- a/apps/web/actions/organization/update-domain.ts+++ b/apps/web/actions/organization/update-domain.ts@@ -23,6 +23,17 @@ export async function updateDomain(domain: string, organizationId: string) {throw new Error("Only the owner can update the custom domain");}+ // Check if domain is already being used by another organization+ const existingDomain = await db()+ .select()+ .from(organizations)+ .where(eq(organizations.customDomain, domain))+ .limit(1);++ if (existingDomain.length > 0 && existingDomain[0]?.id !== organizationId) {+ throw new Error("This domain is already being used.");+ }+try {const addDomainResponse = await addDomain(domain);diff --git a/apps/web/app/(org)/dashboard/caps/Caps.tsx b/apps/web/app/(org)/dashboard/caps/Caps.tsxindex df70b477d..a8afecc33 100644--- a/apps/web/app/(org)/dashboard/caps/Caps.tsx+++ b/apps/web/app/(org)/dashboard/caps/Caps.tsx@@ -35,10 +35,14 @@ type VideoData = {export const Caps = ({data,count,+ customDomain,+ domainVerified,dubApiKeyEnabled,}: {data: VideoData;count: number;+ customDomain: string | null;+ domainVerified: boolean;dubApiKeyEnabled: boolean;}) => {const { refresh } = useRouter();@@ -286,6 +290,8 @@ export const Caps = ({analytics={analytics[cap.id] || 0}onDelete={deleteCap}userId={user?.id}+ customDomain={customDomain}+ domainVerified={domainVerified}isSelected={selectedCaps.includes(cap.id)}onSelectToggle={() => handleCapSelection(cap.id)}anyCapSelected={anyCapSelected}diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsxindex b69957307..01db839fd 100644--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCard.tsx@@ -56,6 +56,8 @@ export interface CapCardProps extends PropsWithChildren {sharedCapCard?: boolean;isSelected?: boolean;onSelectToggle?: () => void;+ customDomain?: string | null;+ domainVerified?: boolean;hideSharedStatus?: boolean;anyCapSelected?: boolean;}@@ -68,6 +70,8 @@ export const CapCard = ({userId,sharedCapCard = false,hideSharedStatus = false,+ customDomain,+ domainVerified,isSelected = false,onSelectToggle,anyCapSelected = false,@@ -293,6 +297,8 @@ export const CapCard = ({capId={cap.id}copyPressed={copyPressed}isDownloading={isDownloading}+ customDomain={customDomain}+ domainVerified={domainVerified}handleCopy={handleCopy}handleDownload={handleDownload}/>diff --git a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsxindex 5cc99e11d..48cf98494 100644--- a/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx+++ b/apps/web/app/(org)/dashboard/caps/components/CapCard/CapCardButtons.tsx@@ -1,5 +1,5 @@import { Tooltip } from "@/components/Tooltip";-import { buildEnv, NODE_ENV } from "@cap/env";+import { buildEnv } from "@cap/env";import { Button } from "@cap/ui";import { faDownload, faLink } from "@fortawesome/free-solid-svg-icons";import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";@@ -20,6 +20,8 @@ export interface CapCardButtonsProps {isDownloading: boolean;handleCopy: (url: string) => void;handleDownload: () => void;+ customDomain?: string | null;+ domainVerified?: boolean;}export const CapCardButtons: React.FC<CapCardButtonsProps> = ({@@ -28,10 +30,12 @@ export const CapCardButtons: React.FC<CapCardButtonsProps> = ({isDownloading,handleCopy,handleDownload,+ customDomain,+ domainVerified,}) => {return (<>- {buttons(capId, copyPressed, isDownloading, handleCopy, handleDownload).map((button, index) => (+ {buttons(capId, copyPressed, isDownloading, handleCopy, handleDownload, customDomain, domainVerified).map((button, index) => (<Tooltip key={index} content={button.tooltipContent}><ButtononClick={button.onClick}@@ -55,17 +59,26 @@ const buttons = (copyPressed: boolean,isDownloading: boolean,handleCopy: (url: string) => void,- handleDownload: () => void+ handleDownload: () => void,+ customDomain?: string | null,+ domainVerified?: boolean,): ButtonConfig[] => [{tooltipContent: "Copy link",onClick: (e: React.MouseEvent) => {e.stopPropagation();- handleCopy(- buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"- ? `https://cap.link/${capId}`- : `${location.origin}/s/${capId}`- );++ const getVideoLink = () => {+ if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {+ return `https://${customDomain}/s/${capId}`;+ } else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {+ return `https://cap.link/${capId}`;+ } else {+ return `${location.origin}/s/${capId}`;+ }+ };++ handleCopy(getVideoLink());},className: "delay-0",disabled: false,diff --git a/apps/web/app/(org)/dashboard/caps/page.tsx b/apps/web/app/(org)/dashboard/caps/page.tsxindex f2c47b0f8..384fa79ea 100644--- a/apps/web/app/(org)/dashboard/caps/page.tsx+++ b/apps/web/app/(org)/dashboard/caps/page.tsx@@ -1,13 +1,10 @@import { db } from "@cap/database";import { getCurrentUser } from "@cap/database/auth/session";import {- comments,- organizationMembers,- organizations,+ comments, organizations,sharedVideos,users,- videos,- spaces,+ videos} from "@cap/database/schema";import { count, desc, eq, sql } from "drizzle-orm";import { Metadata } from "next";@@ -48,6 +45,30 @@ export default async function CapsPage({const totalCount = totalCountResult[0]?.count || 0;+ // Get custom domain and verification status for the user's organization+ const organizationData = await db()+ .select({+ customDomain: organizations.customDomain,+ domainVerified: organizations.domainVerified,+ })+ .from(organizations)+ .where(eq(organizations.id, user.activeOrganizationId))+ .limit(1);++ let customDomain: string | null = null;+ let domainVerified = false;++ if (+ organizationData.length > 0 &&+ organizationData[0] &&+ organizationData[0].customDomain+ ) {+ customDomain = organizationData[0].customDomain;+ if (organizationData[0].domainVerified !== null) {+ domainVerified = true;+ }+ }+const videoData = await db().select({id: videos.id,@@ -164,9 +185,9 @@ export default async function CapsPage({ownerName: video.ownerName ?? "",metadata: video.metadata as| {- customCreatedAt?: string;- [key: string]: any;- }+ customCreatedAt?: string;+ [key: string]: any;+ }| undefined,hasPassword: video.hasPassword === 1,};@@ -175,6 +196,8 @@ export default async function CapsPage({return (<Capsdata={processedVideoData}+ customDomain={customDomain}+ domainVerified={domainVerified}count={totalCount}dubApiKeyEnabled={!!serverEnv().DUB_API_KEY}/>diff --git a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsxindex 5989d807d..5a8d270a7 100644--- a/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx+++ b/apps/web/app/(org)/dashboard/settings/organization/components/CustomDomain.tsx@@ -195,7 +195,10 @@ export function CustomDomain({ isOwner, showOwnerToast }: CustomDomainProps) {checkVerification(false);}, POLL_INTERVAL);} catch (error) {- toast.error("Failed to update domain settings");+ console.error("Error updating domain:", error);+ toast.error(+ error instanceof Error ? error.message : "Failed to update domain settings"+ );} finally {setLoading(false);}@@ -272,6 +275,7 @@ export function CustomDomain({ isOwner, showOwnerToast }: CustomDomainProps) {type="submit"size="sm"variant="dark"+ className="px-[1.5rem]"onClick={handleSubmit}spinner={loading}disabled={loading}@@ -282,7 +286,7 @@ export function CustomDomain({ isOwner, showOwnerToast }: CustomDomainProps) {{activeOrganization?.organization.customDomain && (<Buttontype="button"- variant="white"+ variant="gray"size="sm"onClick={() => checkVerification(true)}disabled={verifying}@@ -290,11 +294,11 @@ export function CustomDomain({ isOwner, showOwnerToast }: CustomDomainProps) {>{verifying ? (<FontAwesomeIcon- className="animate-spin size-3 mr-0.5"+ className="animate-spin size-4 mr-0.5"icon={faRefresh}/>) : (- <FontAwesomeIcon className="size-3 mr-0.5" icon={faRefresh} />+ <FontAwesomeIcon className="size-4 mr-0.5" icon={faRefresh} />)}Refresh</Button>@@ -303,7 +307,7 @@ export function CustomDomain({ isOwner, showOwnerToast }: CustomDomainProps) {<Buttontype="button"size="sm"- variant="white"+ variant="gray"onClick={handleRemoveDomain}disabled={loading}>diff --git a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx b/apps/web/app/s/[videoId]/_components/ShareHeader.tsxindex 1da094c6b..164d34664 100644--- a/apps/web/app/s/[videoId]/_components/ShareHeader.tsx+++ b/apps/web/app/s/[videoId]/_components/ShareHeader.tsx@@ -10,7 +10,7 @@ import { useRouter } from "next/navigation";import { useState, useEffect } from "react";import { toast } from "sonner";import { Copy, Globe2 } from "lucide-react";-import { buildEnv, NODE_ENV } from "@cap/env";+import { buildEnv } from "@cap/env";import { editTitle } from "@/actions/videos/edit-title";import { usePublicEnv } from "@/utils/public-env";import { isUserOnProPlan } from "@cap/utils";@@ -25,9 +25,7 @@ export const ShareHeader = ({customDomain,domainVerified,sharedOrganizations = [],- userOrganizations = [],sharedSpaces = [],- userSpaces = [],}: {data: typeof videos.$inferSelect;user: typeof userSelectProps | null;@@ -51,12 +49,10 @@ export const ShareHeader = ({const { push, refresh } = useRouter();const [isEditing, setIsEditing] = useState(false);const [title, setTitle] = useState(data.name);- const [isDownloading, setIsDownloading] = useState(false);const [upgradeModalOpen, setUpgradeModalOpen] = useState(false);const [isSharingDialogOpen, setIsSharingDialogOpen] = useState(false);const contextData = useDashboardContext();- const contextSpaces = contextData?.spacesData || null;const contextSharedSpaces = contextData?.sharedSpaces || null;const effectiveSharedSpaces = contextSharedSpaces || sharedSpaces;@@ -91,25 +87,29 @@ export const ShareHeader = ({};const getVideoLink = () => {- return customDomain && domainVerified- ? `https://${customDomain}/s/${data.id}`- : buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"- ? `https://cap.link/${data.id}`- : `${webUrl}/s/${data.id}`;+ if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {+ return `https://${customDomain}/s/${data.id}`;+ } else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {+ return `https://cap.link/${data.id}`;+ } else {+ return `${webUrl}/s/${data.id}`;+ }};const getDisplayLink = () => {- return customDomain && domainVerified- ? `${customDomain}/s/${data.id}`- : buildEnv.NEXT_PUBLIC_IS_CAP && NODE_ENV === "production"- ? `cap.link/${data.id}`- : `${webUrl}/s/${data.id}`;+ if (buildEnv.NEXT_PUBLIC_IS_CAP && customDomain && domainVerified) {+ return `${customDomain}/s/${data.id}`;+ } else if (buildEnv.NEXT_PUBLIC_IS_CAP && !customDomain && !domainVerified) {+ return `cap.link/${data.id}`;+ } else {+ return `${webUrl}/s/${data.id}`;+ }};const isUserPro = user? isUserOnProPlan({- subscriptionStatus: user.stripeSubscriptionStatus,- })+ subscriptionStatus: user.stripeSubscriptionStatus,+ }): false;const handleSharingUpdated = () => {@@ -127,7 +127,7 @@ export const ShareHeader = ({) {return (<p- className={clsx(baseClassName, "hover:text-gray-12 cursor-pointer")}+ className={clsx(baseClassName, "cursor-pointer hover:text-gray-12")}onClick={() => setIsSharingDialogOpen(true)}>Not shared{" "}@@ -137,7 +137,7 @@ export const ShareHeader = ({} else {return (<p- className={clsx(baseClassName, "hover:text-gray-12 cursor-pointer")}+ className={clsx(baseClassName, "cursor-pointer hover:text-gray-12")}onClick={() => setIsSharingDialogOpen(true)}>Shared{" "}@@ -188,7 +188,7 @@ export const ShareHeader = ({)}</div>{user && renderSharedStatus()}- <p className="text-sm text-gray-10 mt-1">+ <p className="mt-1 text-sm text-gray-10">{moment(data.createdAt).fromNow()}</p></div>@@ -196,10 +196,10 @@ export const ShareHeader = ({{user !== null && (<div className="flex space-x-2"><div>- <div className="flex items-center gap-2">+ <div className="flex gap-2 items-center">{data.password && (<FontAwesomeIcon- className="size-4 text-amber-600"+ className="text-amber-600 size-4"icon={faLock}/>)}diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsxindex a8a0f55b1..a5faddf13 100644--- a/apps/web/app/s/[videoId]/page.tsx+++ b/apps/web/app/s/[videoId]/page.tsx@@ -1,5 +1,5 @@import { db } from "@cap/database";-import { eq, desc, sql, count, InferSelectModel } from "drizzle-orm";+import { eq, InferSelectModel } from "drizzle-orm";import { Logo } from "@cap/ui";import {videos,@@ -10,8 +10,8 @@ import {organizations,} from "@cap/database/schema";import { VideoMetadata } from "@cap/database/types";-import { getCurrentUser, userSelectProps } from "@cap/database/auth/session";-import type { Metadata, ResolvingMetadata } from "next";+import { getCurrentUser } from "@cap/database/auth/session";+import type { Metadata } from "next";import { notFound } from "next/navigation";import { buildEnv } from "@cap/env";import { getVideoAnalytics } from "@/actions/videos/get-analytics";@@ -498,14 +498,14 @@ async function AuthorizedContent({const membersListPromise = video.sharedOrganization?.organizationId? db()- .select({ userId: organizationMembers.userId })- .from(organizationMembers)- .where(- eq(- organizationMembers.organizationId,- video.sharedOrganization.organizationId- )+ .select({ userId: organizationMembers.userId })+ .from(organizationMembers)+ .where(+ eq(+ organizationMembers.organizationId,+ video.sharedOrganization.organizationId)+ ): Promise.resolve([]);const commentsPromise = db()diff --git a/apps/web/components/forms/NewOrganization.tsx b/apps/web/components/forms/NewOrganization.tsxindex 94a59022d..4aefadec4 100644--- a/apps/web/components/forms/NewOrganization.tsx+++ b/apps/web/components/forms/NewOrganization.tsx@@ -61,7 +61,7 @@ export const NewOrganization: React.FC<NewOrganizationProps> = (props) => {props.onOrganizationCreated();} catch (error) {console.error("Error creating organization:", error);- toast.error("Failed to create organization");+ error instanceof Error ? toast.error(error.message) : toast.error("Failed to create organization");} finally {setIsUploading(false);props.setCreateLoading?.(false);diff --git a/apps/web/components/forms/server.ts b/apps/web/components/forms/server.tsindex 169c7091c..586207a0f 100644--- a/apps/web/components/forms/server.ts+++ b/apps/web/components/forms/server.ts@@ -22,6 +22,17 @@ export async function createOrganization(formData: FormData) {const name = formData.get("name") as string;if (!name) throw new Error("Organization name is required");+ // Check if organization with the same name already exists+ const existingOrg = await db()+ .select({ id: organizations.id })+ .from(organizations)+ .where(eq(organizations.name, name))+ .limit(1);++ if (existingOrg.length > 0) {+ throw new Error("Organization with this name already exists");+ }+const organizationId = nanoId();// Create the organization firstdiff --git a/packages/ui/src/components/Button.tsx b/packages/ui/src/components/Button.tsxindex 7d4ae3110..e4e5b9b7e 100644--- a/packages/ui/src/components/Button.tsx+++ b/packages/ui/src/components/Button.tsx@@ -17,7 +17,7 @@ const buttonVariants = cva(destructive:"bg-red-500 text-white hover:bg-red-600 disabled:bg-red-200",white: "bg-gray-1 text-gray-12 hover:bg-gray-2 disabled:bg-gray-8",- gray: "bg-gray-4 text-gray-12 hover:bg-gray-5 disabled:bg-gray-1",+ gray: "bg-gray-4 text-gray-12 hover:bg-gray-5 disabled:bg-gray-8",dark: "bg-gray-12 text-gray-1 disabled:cursor-not-allowed hover:bg-gray-11 disabled:text-gray-10 disabled:bg-gray-7 disabled:border-gray-8",darkgradient:"bg-gradient-to-t button-gradient-border from-[#0f0f0f] to-[#404040] shadow-[0_0_0_1px] hover:brightness-110 shadow-[#383838] text-gray-50 hover:bg-[#383838] disabled:bg-[#383838] border-transparent",