Skip to content

Commit

Permalink
Merge pull request #605 from mfts/feat/link-creation
Browse files Browse the repository at this point in the history
feat: improve link creation
  • Loading branch information
mfts authored Sep 19, 2024
2 parents e654d50 + f2dc7a9 commit 361a8f5
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 53 deletions.
25 changes: 4 additions & 21 deletions components/documents/add-document-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ export function AddDocumentModal({
}

if (!newVersion) {
// copy the link to the clipboard
copyToClipboard(
`${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${document.links[0].id}`,
"Document uploaded and link copied to clipboard. Redirecting to document page...",
);
toast.success("Document uploaded. Redirecting to document page...");

// track the event
plausible("documentUploaded");
Expand All @@ -156,12 +152,6 @@ export function AddDocumentModal({
type: document.type,
teamId: teamId,
});
analytics.capture("Link Added", {
linkId: document.links[0].id,
documentId: document.id,
customDomain: null,
teamId: teamId,
});

// redirect to the document page
router.push("/documents/" + document.id);
Expand Down Expand Up @@ -283,6 +273,7 @@ export function AddDocumentModal({
url: notionLink,
numPages: 1,
type: "notion",
createLink: false,
}),
},
);
Expand Down Expand Up @@ -312,10 +303,8 @@ export function AddDocumentModal({
}

if (!newVersion) {
// copy the link to the clipboard
copyToClipboard(
`${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${document.links[0].id}`,
"Notion Page processed and link copied to clipboard. Redirecting to document page...",
toast.success(
"Notion Page processed. Redirecting to document page...",
);

// track the event
Expand All @@ -329,12 +318,6 @@ export function AddDocumentModal({
type: "notion",
teamId: teamId,
});
analytics.capture("Link Added", {
linkId: document.links[0].id,
documentId: document.id,
customDomain: null,
teamId: teamId,
});

// redirect to the document page
router.push("/documents/" + document.id);
Expand Down
2 changes: 1 addition & 1 deletion components/documents/document-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ export default function DocumentHeader({
};

return (
<header className="!mb-16 flex items-center justify-between gap-x-8">
<header className="flex items-center justify-between gap-x-8">
<div className="flex items-center space-x-2">
{fileIcon({
fileType: prismaDocument.type ?? "",
Expand Down
2 changes: 0 additions & 2 deletions components/links/link-sheet/domain-section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ export default function DomainSection({
};

useEffect(() => {
console.log("data.domain", data.domain);
if (domains && !editLink) {
console.log("data.domain", data.domain);
const defaultDomain = domains.find((domain) => domain.isDefault);
setData({
...data,
Expand Down
33 changes: 19 additions & 14 deletions components/links/links-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useState } from "react";

import { useTeam } from "@/context/team-context";
import { DocumentVersion } from "@prisma/client";
import { EyeIcon, Settings2Icon } from "lucide-react";
import { EyeIcon, LinkIcon, Settings2Icon } from "lucide-react";
import { toast } from "sonner";
import { mutate } from "swr";

Expand Down Expand Up @@ -237,7 +237,7 @@ export default function LinksTable({
</TableRow>
</TableHeader>
<TableBody>
{links ? (
{links && links.length > 0 ? (
links
.filter((link) => !link.isArchived)
.map((link) => (
Expand Down Expand Up @@ -414,17 +414,22 @@ export default function LinksTable({
))
) : (
<TableRow>
<TableCell className="min-w-[100px]">
<Skeleton className="h-6 w-full" />
</TableCell>
<TableCell className="min-w-[450px]">
<Skeleton className="h-6 w-full" />
</TableCell>
<TableCell>
<Skeleton className="h-6 w-24" />
</TableCell>
<TableCell>
<Skeleton className="h-6 w-24" />
<TableCell colSpan={5}>
<div className="flex w-full flex-col items-center justify-center gap-4 rounded-xl py-4">
<div className="hidden rounded-full sm:block">
<div
className={cn(
"rounded-full border border-white bg-gradient-to-t from-gray-100 p-1 md:p-3",
)}
>
<LinkIcon className="size-6" />
</div>
</div>
<p>No links found for this {targetType.toLowerCase()}</p>
<Button onClick={() => setIsLinkSheetVisible(true)}>
Create link to share
</Button>
</div>
</TableCell>
</TableRow>
)}
Expand All @@ -436,7 +441,7 @@ export default function LinksTable({
isOpen={isLinkSheetVisible}
setIsOpen={setIsLinkSheetVisible}
linkType={`${targetType}_LINK`}
currentLink={selectedLink}
currentLink={selectedLink.id ? selectedLink : undefined}
existingLinks={links}
/>

Expand Down
2 changes: 1 addition & 1 deletion components/welcome/dataroom-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export default function DataroomUpload({ dataroomId }: DataroomUploadProps) {
...linkData,
metaImage: blobUrl,
targetId: dataroomId,
linkType: "DATAROOM_LINK",
linkType: LinkType.DATAROOM_LINK,
}),
});

Expand Down
4 changes: 3 additions & 1 deletion components/welcome/notion-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default function NotionForm() {
url: notionLink,
numPages: 1,
type: "notion",
createLink: true,
}),
},
);
Expand Down Expand Up @@ -165,7 +166,8 @@ export default function NotionForm() {
body: JSON.stringify({
...linkData,
metaImage: blobUrl,
documentId: currentDocId,
targetId: currentDocId,
linkType: LinkType.DOCUMENT_LINK,
}),
});

Expand Down
9 changes: 7 additions & 2 deletions components/welcome/special-upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ export default function DeckGeneratorUpload() {
supportedFileType: supportedFileType,
};
// create a document in the database
const response = await createDocument({ documentData, teamId, numPages });
const response = await createDocument({
documentData,
teamId,
numPages,
createLink: true,
});

if (response) {
const document = await response.json();
Expand Down Expand Up @@ -171,7 +176,7 @@ export default function DeckGeneratorUpload() {
...linkData,
metaImage: blobUrl,
targetId: currentDocId,
linkType: "DOCUMENT_LINK",
linkType: LinkType.DOCUMENT_LINK,
}),
});

Expand Down
9 changes: 7 additions & 2 deletions components/welcome/upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ export default function Upload() {
supportedFileType: supportedFileType,
};
// create a document in the database
const response = await createDocument({ documentData, teamId, numPages });
const response = await createDocument({
documentData,
teamId,
numPages,
createLink: true,
});

if (response) {
const document = await response.json();
Expand Down Expand Up @@ -152,7 +157,7 @@ export default function Upload() {
...linkData,
metaImage: blobUrl,
targetId: currentDocId,
linkType: "DOCUMENT_LINK",
linkType: LinkType.DOCUMENT_LINK,
}),
});

Expand Down
3 changes: 3 additions & 0 deletions lib/documents/create-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ export const createDocument = async ({
teamId,
numPages,
folderPathName,
createLink = false,
}: {
documentData: DocumentData;
teamId: string;
numPages?: number;
folderPathName?: string;
createLink?: boolean;
}) => {
// create a document in the database with the blob url
const response = await fetch(`/api/teams/${teamId}/documents`, {
Expand All @@ -33,6 +35,7 @@ export const createDocument = async ({
folderPathName: folderPathName,
type: documentData.supportedFileType,
contentType: documentData.contentType,
createLink: createLink,
}),
});

Expand Down
2 changes: 0 additions & 2 deletions pages/api/links/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ export default async function handler(
views: [],
};

console.log("linkWithView", linkWithView);

if (!linkWithView) {
return res.status(404).json({ error: "Link not found" });
}
Expand Down
3 changes: 0 additions & 3 deletions pages/api/teams/[teamId]/datarooms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ export default async function handle(
name: name,
teamId: teamId,
pId: pId,
links: {
create: { linkType: "DATAROOM_LINK" },
},
},
});

Expand Down
2 changes: 1 addition & 1 deletion pages/api/teams/[teamId]/datarooms/trial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default async function handle(
/** Emails
*
* 1. Send welcome email
* 2. Send dataroom info email after 3 days
* 2. Send dataroom info email after 1 day
* 3. Send expired trial email after 7 days
*/
waitUntil(sendDataroomTrialWelcome({ fullName, to: email! }));
Expand Down
10 changes: 7 additions & 3 deletions pages/api/teams/[teamId]/documents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export default async function handle(
type: fileType,
folderPathName,
contentType,
createLink,
} = req.body as {
name: string;
url: string;
Expand All @@ -87,6 +88,7 @@ export default async function handle(
type?: string;
folderPathName?: string;
contentType: string;
createLink?: boolean;
};

try {
Expand Down Expand Up @@ -135,9 +137,11 @@ export default async function handle(
storageType,
ownerId: (session.user as CustomUser).id,
teamId: teamId,
links: {
create: {},
},
...(createLink && {
links: {
create: {},
},
}),
versions: {
create: {
file: fileUrl,
Expand Down

0 comments on commit 361a8f5

Please sign in to comment.