Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preview link as #849

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions components/links/links-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import LinkSheet, {
} from "./link-sheet";
import LinksVisitors from "./links-visitors";

export type PreviewType = "QUICK_PREVIEW" | "COMPLETE_PREVIEW";

export default function LinksTable({
targetType,
links,
Expand Down Expand Up @@ -114,7 +116,10 @@ export default function LinksTable({
}, 0);
};

const handlePreviewLink = async (link: LinkWithViews) => {
const handlePreviewLink = async (
link: LinkWithViews,
viewAs: PreviewType,
) => {
if (link.domainId && plan === "free") {
toast.error("You need to upgrade to preview this link");
return;
Expand All @@ -133,7 +138,7 @@ export default function LinksTable({
}

const { previewToken } = await response.json();
const previewLink = `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}?previewToken=${previewToken}`;
const previewLink = `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}?previewToken=${previewToken}&viewAs=${viewAs}`;

window.open(previewLink, "_blank");
};
Expand Down Expand Up @@ -313,15 +318,38 @@ export default function LinksTable({
)}
</div>
<ButtonTooltip content="Preview link">
<Button
variant={"link"}
size={"icon"}
className="group h-7 w-8"
onClick={() => handlePreviewLink(link)}
>
<span className="sr-only">Preview link</span>
<EyeIcon className="h-5 w-5 text-gray-400 group-hover:text-gray-500" />
</Button>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
className="h-8 w-8 p-0 group-hover/row:ring-1 group-hover/row:ring-gray-200 group-hover/row:dark:ring-gray-700"
>
<span className="sr-only">Open menu</span>
<EyeIcon className="h-5 w-5 text-gray-400 group-hover:text-gray-500" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>View As</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={() =>
handlePreviewLink(link, "QUICK_PREVIEW")
}
>
Quick Preview
</DropdownMenuItem>
<DropdownMenuItem
onClick={() =>
handlePreviewLink(
link,
"COMPLETE_PREVIEW",
)
}
>
Complete Preview
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</ButtonTooltip>
<ButtonTooltip content="Edit link">
<Button
Expand Down
15 changes: 13 additions & 2 deletions pages/view/[linkId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useSession } from "next-auth/react";
import { ExtendedRecordMap } from "notion-types";
import { parsePageId } from "notion-utils";

import { PreviewType } from "@/components/links/links-table";
import LoadingSpinner from "@/components/ui/loading-spinner";
import CustomMetaTag from "@/components/view/custom-metatag";
import DataroomView from "@/components/view/dataroom/dataroom-view";
Expand Down Expand Up @@ -230,10 +231,12 @@ export default function ViewPage({
email: verifiedEmail,
d: disableEditEmail,
previewToken,
viewAs,
} = router.query as {
email: string;
d: string;
previewToken?: string;
viewAs?: PreviewType;
};
const { linkType, link, brand } = linkData;

Expand Down Expand Up @@ -304,7 +307,11 @@ export default function ViewPage({
link={link}
userEmail={verifiedEmail ?? storedEmail ?? userEmail}
userId={userId}
isProtected={!!(emailProtected || linkPassword || enableAgreement)}
isProtected={
viewAs === "QUICK_PREVIEW"
? false
: !!(emailProtected || linkPassword || enableAgreement)
}
notionData={notionData}
brand={brand}
showPoweredByBanner={showPoweredByBanner}
Expand Down Expand Up @@ -387,7 +394,11 @@ export default function ViewPage({
link={link}
userEmail={verifiedEmail ?? storedEmail ?? userEmail}
userId={userId}
isProtected={!!(emailProtected || linkPassword || enableAgreement)}
isProtected={
viewAs === "QUICK_PREVIEW"
? false
: !!(emailProtected || linkPassword || enableAgreement)
}
brand={brand}
useAdvancedExcelViewer={useAdvancedExcelViewer}
previewToken={previewToken}
Expand Down
Loading