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.

Final fixes & touch ups

Steven Tey0e59723a473a
diff --git a/app/api/cron/import/bitly/utils.ts b/app/api/cron/import/bitly/utils.ts
index 422c63cf2a..09c97c3170 100644
--- a/app/api/cron/import/bitly/utils.ts
+++ b/app/api/cron/import/bitly/utils.ts
@@ -36,7 +36,7 @@ export const importLinksFromBitly = async ({
const { links, pagination } = data;
const nextSearchAfter = pagination.search_after;
- // const pipeline = redis.pipeline();
+ const pipeline = redis.pipeline();
// convert links to format that can be imported into database
const importedLinks = links
@@ -47,12 +47,9 @@ export const importLinksFromBitly = async ({
if (!domains.includes(domain)) {
return null;
}
- // pipeline.set(
- // `${domain}:${key}`,
- // {
- // url: encodeURIComponent(url),
- // },
- // );
+ pipeline.set(`${domain}:${key}`, {
+ url: encodeURIComponent(url),
+ });
const createdAt = new Date(created_at).toISOString();
const tagId = tagsToId ? tagsToId[tags[0]] : null;
return {
@@ -74,7 +71,7 @@ export const importLinksFromBitly = async ({
data: importedLinks,
skipDuplicates: true,
}),
- // pipeline.exec(),
+ pipeline.exec(),
]);
count += importedLinks.length;
diff --git a/app/api/cron/import/short/utils.ts b/app/api/cron/import/short/utils.ts
index 589ec570d3..e490bf5614 100644
--- a/app/api/cron/import/short/utils.ts
+++ b/app/api/cron/import/short/utils.ts
@@ -32,7 +32,7 @@ export const importLinksFromShort = async ({
).then((res) => res.json());
const { links, nextPageToken } = data;
- // const pipeline = redis.pipeline();
+ const pipeline = redis.pipeline();
// convert links to format that can be imported into database
const importedLinks = links
@@ -51,14 +51,11 @@ export const importLinksFromShort = async ({
if (path.length === 0) {
return null;
}
- // pipeline.set(
- // `${domain}:${path}`,
- // {
- // url: encodeURIComponent(originalURL),
- // ...(iphoneURL && { ios: encodeURIComponent(iphoneURL) }),
- // ...(androidURL && { android: encodeURIComponent(androidURL) }),
- // },
- // );
+ pipeline.set(`${domain}:${path}`, {
+ url: encodeURIComponent(originalURL),
+ ...(iphoneURL && { ios: encodeURIComponent(iphoneURL) }),
+ ...(androidURL && { android: encodeURIComponent(androidURL) }),
+ });
return {
projectId,
domain,
@@ -81,7 +78,7 @@ export const importLinksFromShort = async ({
data: importedLinks,
skipDuplicates: true,
}),
- // pipeline.exec(),
+ pipeline.exec(),
]);
count += importedLinks.length;
diff --git a/app/ui/popover.tsx b/app/ui/popover.tsx
index 312ce458c9..4d6d0ee9ed 100644
--- a/app/ui/popover.tsx
+++ b/app/ui/popover.tsx
@@ -46,7 +46,7 @@ export default function Popover({
{children}
</PopoverPrimitive.Trigger>
<PopoverPrimitive.Content
- sideOffset={4}
+ sideOffset={8}
align={align}
className="z-50 hidden animate-slide-up-fade items-center rounded-md border border-gray-200 bg-white drop-shadow-lg md:block"
>
diff --git a/components/app/modals/import-bitly-modal.tsx b/components/app/modals/import-bitly-modal.tsx
index 19090fe1a2..a4f455cce5 100644
--- a/components/app/modals/import-bitly-modal.tsx
+++ b/components/app/modals/import-bitly-modal.tsx
@@ -35,7 +35,7 @@ function ImportBitlyModal({
const [redirecting, setRedirecting] = useState(false);
const { data: groups, isLoading } = useSWR<BitlyGroupProps[]>(
- slug && `/api/projects/${slug}/import/bitly`,
+ slug && showImportBitlyModal && `/api/projects/${slug}/import/bitly`,
fetcher,
{
revalidateOnFocus: false,
diff --git a/components/app/modals/import-short-modal.tsx b/components/app/modals/import-short-modal.tsx
index 7758660cab..e4ab74e49f 100644
--- a/components/app/modals/import-short-modal.tsx
+++ b/components/app/modals/import-short-modal.tsx
@@ -32,12 +32,15 @@ function ImportShortModal({
const { slug, import: importSource } = router.query;
const { data: domains, isLoading } = useSWR<ShortioDomainProps[]>(
- slug && `/api/projects/${slug}/import/short`,
+ slug && showImportShortModal && `/api/projects/${slug}/import/short`,
fetcher,
{
revalidateOnFocus: false,
revalidateOnReconnect: false,
refreshInterval: 0,
+ onError: (err) => {
+ toast.error(err.message);
+ },
},
);
@@ -252,7 +255,7 @@ function ImportShortModal({
className="mt-1 block w-full appearance-none rounded-md border border-gray-300 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-black focus:outline-none focus:ring-black sm:text-sm"
/>
</div>
- <Button text="Submit API Key" loading={submitting} />
+ <Button text="Confirm API Key" loading={submitting} />
</form>
)}
</div>
diff --git a/lib/utils.ts b/lib/utils.ts
index 96c79f4d9b..31b3123ef6 100644
--- a/lib/utils.ts
+++ b/lib/utils.ts
@@ -12,6 +12,7 @@ import {
HOME_HOSTNAMES,
HOME_DOMAIN,
} from "./constants";
+import { toast } from "sonner";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
diff --git a/pages/api/projects/[slug]/import/short.ts b/pages/api/projects/[slug]/import/short.ts
index cd39bf8820..628d9e6727 100644
--- a/pages/api/projects/[slug]/import/short.ts
+++ b/pages/api/projects/[slug]/import/short.ts
@@ -20,7 +20,7 @@ export default withProjectAuth(async (req, res, project) => {
},
});
const data = await response.json();
- if (data.message === "FORBIDDEN") {
+ if (data.error === "Unauthorized") {
return res.status(403).end("Invalid Short.io access token");
}
diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsx
index 92f52c75ff..e9f9d10ba6 100644
--- a/pages/app/[slug]/index.tsx
+++ b/pages/app/[slug]/index.tsx
@@ -5,17 +5,15 @@ import AppLayout from "components/layout/app";
import useProject from "#/lib/swr/use-project";
import { useState } from "react";
import Popover from "#/ui/popover";
-import { ChevronDown, FilePlus2, Import } from "lucide-react";
-import { useRouter } from "next/router";
+import { ChevronDown, FilePlus2, Sheet } from "lucide-react";
+import IconMenu from "@/components/shared/icon-menu";
+import Tooltip from "#/ui/tooltip";
export default function ProjectLinks() {
- const router = useRouter();
const { slug } = useProject();
const { AddEditLinkModal, AddEditLinkButton } = useAddEditLinkModal();
- const [openPopover, setOpenPopover] = useState(false);
-
return (
<AppLayout>
{slug && <AddEditLinkModal />}
@@ -25,81 +23,7 @@ export default function ProjectLinks() {
<h1 className="text-2xl text-gray-600">Links</h1>
<div className="flex">
<AddEditLinkButton />
- <Popover
- content={
- <div className="w-full p-2 md:w-44">
- {/* <button
- onClick={() => {}}
- className="flex w-full items-center justify-between space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
- >
- <IconMenu
- text="Bulk create links"
- icon={<FilePlus2 className="h-4 w-4" />}
- />
- </button> */}
- <div>
- <div className="flex items-center space-x-2 p-2">
- <Import className="h-4 w-4" />
- <p className="text-xs font-medium uppercase text-gray-500">
- Import Links
- </p>
- </div>
- <button
- onClick={() => {
- setOpenPopover(false);
- router.push({
- pathname: `/${slug}`,
- query: {
- import: "bitly",
- },
- });
- }}
- className="flex w-full items-center space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
- >
- <img
- src="/_static/icons/bitly.svg"
- alt="Bitly logo"
- className="h-4 w-4 rounded-full"
- />
- <p className="text-sm text-gray-600">Bitly</p>
- </button>
- <button
- onClick={() => {
- setOpenPopover(false);
- router.push({
- pathname: `/${slug}`,
- query: {
- import: "short",
- },
- });
- }}
- className="flex w-full items-center space-x-2 rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
- >
- <img
- src="/_static/icons/short.svg"
- alt="Short.io logo"
- className="h-4 w-4"
- />
- <p className="text-sm text-gray-600">Short.io</p>
- </button>
- </div>
- </div>
- }
- openPopover={openPopover}
- setOpenPopover={setOpenPopover}
- align="end"
- >
- <button
- onClick={() => setOpenPopover(!openPopover)}
- className="group ml-2 flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white p-2.5 shadow transition-all duration-75 active:scale-95"
- >
- <ChevronDown
- className={`h-4 w-4 shrink-0 ${
- openPopover ? "rotate-180 text-gray-700" : "text-gray-400"
- } transition-all group-hover:text-gray-700`}
- />
- </button>
- </Popover>
+ {/* <AddLinkOptions /> */}
</div>
</div>
</MaxWidthWrapper>
@@ -108,3 +32,97 @@ export default function ProjectLinks() {
</AppLayout>
);
}
+
+const AddLinkOptions = () => {
+ const { slug } = useProject();
+ const [openPopover, setOpenPopover] = useState(false);
+
+ return (
+ <Popover
+ content={
+ <div className="w-full divide-y divide-gray-200 md:w-52">
+ <div className="p-2">
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ router.push({
+ pathname: `/${slug}`,
+ query: {
+ import: "bitly",
+ },
+ });
+ }}
+ className="w-full rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <IconMenu
+ text="Import from Bitly"
+ icon={
+ <img
+ src="/_static/icons/bitly.svg"
+ alt="Bitly logo"
+ className="h-4 w-4 rounded-full grayscale"
+ />
+ }
+ />
+ </button>
+ <button
+ onClick={() => {
+ setOpenPopover(false);
+ router.push({
+ pathname: `/${slug}`,
+ query: {
+ import: "short",
+ },
+ });
+ }}
+ className="w-full rounded-md p-2 hover:bg-gray-100 active:bg-gray-200"
+ >
+ <IconMenu
+ text="Import from Short.io"
+ icon={
+ <img
+ src="/_static/icons/short.svg"
+ alt="Short.io logo"
+ className="h-4 w-4 grayscale"
+ />
+ }
+ />
+ </button>
+ <Tooltip content="This feature is still in development – we'll let you know when it's ready!">
+ <div className="flex w-full cursor-not-allowed items-center justify-between space-x-2 rounded-md p-2 text-sm text-gray-400">
+ <IconMenu
+ text="Import from CSV"
+ icon={<Sheet className="h-4 w-4" />}
+ />
+ </div>
+ </Tooltip>
+ </div>
+ <div className="p-2">
+ <Tooltip content="This feature is still in development – we'll let you know when it's ready!">
+ <div className="flex w-full cursor-not-allowed items-center justify-between space-x-2 rounded-md p-2 text-sm text-gray-400">
+ <IconMenu
+ text="Bulk create links"
+ icon={<FilePlus2 className="h-4 w-4" />}
+ />
+ </div>
+ </Tooltip>
+ </div>
+ </div>
+ }
+ openPopover={openPopover}
+ setOpenPopover={setOpenPopover}
+ align="end"
+ >
+ <button
+ onClick={() => setOpenPopover(!openPopover)}
+ className="group ml-2 flex items-center justify-between space-x-2 rounded-md border border-gray-200 bg-white p-2.5 shadow transition-all duration-75 active:scale-95"
+ >
+ <ChevronDown
+ className={`h-4 w-4 shrink-0 ${
+ openPopover ? "rotate-180 text-gray-700" : "text-gray-400"
+ } transition-all group-hover:text-gray-700`}
+ />
+ </button>
+ </Popover>
+ );
+};