The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Final changes
Steven Tey1ac2aaa5de7b
diff --git a/app/dub.sh/changelog/page.tsx b/app/dub.sh/changelog/page.tsxindex e1ec10692e..ff03ebb7c3 100644--- a/app/dub.sh/changelog/page.tsx+++ b/app/dub.sh/changelog/page.tsx@@ -1,7 +1,6 @@import BlurImage from "#/ui/blur-image";import { getBlurDataURL } from "@/lib/images";import { allChangelogPosts } from "contentlayer/generated";-import { Metadata } from "next";import { constructMetadata, formatDate } from "@/lib/utils";import Link from "next/link";import { MDX } from "#/ui/blog/mdx";diff --git a/app/lib/twitter/index.ts b/app/lib/twitter/index.tsindex fc0b5b006c..e0ab4d064f 100644--- a/app/lib/twitter/index.ts+++ b/app/lib/twitter/index.ts@@ -1,6 +1,6 @@import { getTweet } from "./get-tweet";-export default function getTweetsMetadata(ids: string[]) {+export default function getTweets(ids: string[]) {return Promise.all(ids.map((id) => getTweet(id)));}diff --git a/app/ui/blog/mdx.tsx b/app/ui/blog/mdx.tsxindex 8fa7f9fbda..39bbca2014 100644--- a/app/ui/blog/mdx.tsx+++ b/app/ui/blog/mdx.tsx@@ -2,7 +2,7 @@import Link from "next/link";import { useMDXComponent } from "next-contentlayer/hooks";-import Tweet from "../tweet";+import Tweet from "#/ui/tweet";import GithubRepo, { GithubRepoProps } from "@/components/shared/github-repo";import BlurImage from "#/ui/blur-image";diff --git a/app/ui/home/testimonials.tsx b/app/ui/home/testimonials.tsxindex 6e15c09ce8..cfc87cfb6f 100644--- a/app/ui/home/testimonials.tsx+++ b/app/ui/home/testimonials.tsx@@ -1,7 +1,7 @@import { unstable_cache } from "next/cache";import prisma from "@/lib/prisma";import { nFormatter } from "@/lib/utils";-import getTweetsMetadata, { homepageTweets } from "#/lib/twitter";+import getTweets, { homepageTweets } from "#/lib/twitter";import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import Tweet from "#/ui/tweet";import TestimonialsMobile from "./testimonials-mobile";@@ -16,7 +16,7 @@ export default async function Testimonials() {revalidate: 300,},)();- const tweets = await getTweetsMetadata(homepageTweets);+ const tweets = await getTweets(homepageTweets);return (<MaxWidthWrapper className="pt-20">diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsxindex d0c81679a1..7b78f2bf26 100644--- a/app/ui/modal-provider.tsx+++ b/app/ui/modal-provider.tsx@@ -10,11 +10,17 @@ import {import { useAddProjectModal } from "@/components/app/modals/add-project-modal";import { useAcceptInviteModal } from "@/components/app/modals/accept-invite-modal";import useProject from "@/lib/swr/use-project";+import { useTagLinkModal } from "@/components/app/modals/tag-link-modal";+import { useAddEditDomainModal } from "@/components/app/modals/add-edit-domain-modal";export const ModalContext = createContext<{setShowAddProjectModal: Dispatch<SetStateAction<boolean>>;+ setShowAddEditDomainModal: Dispatch<SetStateAction<boolean>>;+ setShowTagLinkModal: Dispatch<SetStateAction<boolean>>;}>({setShowAddProjectModal: () => {},+ setShowAddEditDomainModal: () => {},+ setShowTagLinkModal: () => {},});export default function ModalProvider({ children }: { children: ReactNode }) {@@ -23,6 +29,9 @@ export default function ModalProvider({ children }: { children: ReactNode }) {const { AddProjectModal, setShowAddProjectModal } = useAddProjectModal();const { AcceptInviteModal, setShowAcceptInviteModal } =useAcceptInviteModal();+ const { setShowAddEditDomainModal, AddEditDomainModal } =+ useAddEditDomainModal({});+ const { setShowTagLinkModal, TagLinkModal } = useTagLinkModal({});// handle errorsuseEffect(() => {@@ -32,11 +41,19 @@ export default function ModalProvider({ children }: { children: ReactNode }) {}, [error]);return (- <ModalContext.Provider value={{ setShowAddProjectModal }}>+ <ModalContext.Provider+ value={{+ setShowAddProjectModal,+ setShowAddEditDomainModal,+ setShowTagLinkModal,+ }}+ ><AddProjectModal />{error && (error.status === 409 || error.status === 410) && (<AcceptInviteModal />)}+ <AddEditDomainModal />+ <TagLinkModal />{children}</ModalContext.Provider>);diff --git a/components/app/links/link-filters.tsx b/components/app/links/link-filters.tsxindex 09392d145c..96b8bd9757 100644--- a/components/app/links/link-filters.tsx+++ b/components/app/links/link-filters.tsx@@ -1,6 +1,5 @@import { useRouter } from "next/router";import {- ReactNode,useCallback,useContext,useEffect,@@ -14,7 +13,6 @@ import useDomains from "@/lib/swr/use-domains";import { AnimatePresence, motion } from "framer-motion";import { SWIPE_REVEAL_ANIMATION_SETTINGS } from "@/lib/constants";import { useDebouncedCallback } from "use-debounce";-import Link from "next/link";import useLinks from "@/lib/swr/use-links";import { LoadingSpinner } from "#/ui/icons";import useLinksCount from "@/lib/swr/use-links-count";@@ -25,6 +23,7 @@ import { toast } from "sonner";import { ModalContext } from "#/ui/modal-provider";import useTags from "@/lib/swr/use-tags";import Badge from "@/components/shared/badge";+import { TagProps } from "@/lib/types";export default function LinkFilters() {const { primaryDomain } = useDomains();@@ -44,7 +43,7 @@ export default function LinkFilters() {};const searchInputRef = useRef(); // this is a hack to clear the search input when the clear button is clicked- return domains ? (+ return domains && tags && tagsCount ? (<div className="grid w-full rounded-md bg-white px-5 lg:divide-y lg:divide-gray-300"><div className="grid gap-3 py-6"><div className="flex items-center justify-between">@@ -56,12 +55,8 @@ export default function LinkFilters() {<SearchBox searchInputRef={searchInputRef} /></div><DomainsFilter domains={domains} primaryDomain={primaryDomain} />- {slug && (- <>- {tagsCount && <TagsFilter tags={tags} tagsCount={tagsCount} />}- <MyLinksFilter />- </>- )}+ <TagsFilter tags={tags} tagsCount={tagsCount} />+ {slug && <MyLinksFilter />}<ArchiveFilter /></div>) : (@@ -81,7 +76,7 @@ const ClearButton = ({ searchInputRef }) => {searchInputRef.current.value = "";});}}- className="group flex items-center justify-center space-x-1 rounded-md border border-gray-500 px-2 py-1 transition-all hover:border-black"+ className="group flex items-center justify-center space-x-1 rounded-md border border-gray-400 px-2 py-1 transition-all hover:border-gray-600 active:bg-gray-100"><XCircle className="h-4 w-4 text-gray-500 transition-all group-hover:text-black" /><p className="text-sm text-gray-500 transition-all group-hover:text-black">@@ -162,7 +157,8 @@ const DomainsFilter = ({ domains, primaryDomain }) => {count: _count,}));- const { setShowAddProjectModal } = useContext(ModalContext);+ const { setShowAddEditDomainModal, setShowAddProjectModal } =+ useContext(ModalContext);return (<fieldset className="overflow-hidden py-6">@@ -178,6 +174,21 @@ const DomainsFilter = ({ domains, primaryDomain }) => {/><h4 className="font-medium text-gray-900">Domains</h4></button>+ <button+ onClick={() => {+ if (slug) {+ setShowAddEditDomainModal(true);+ } else {+ setShowAddProjectModal(true);+ toast.error(+ "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",+ );+ }+ }}+ className="mr-2 rounded-md border border-gray-200 px-3 py-1 transition-all hover:border-gray-600 active:bg-gray-100"+ >+ <p className="text-sm text-gray-500">Add</p>+ </button></div><AnimatePresence initial={false}>{!collapsed && (@@ -209,26 +220,6 @@ const DomainsFilter = ({ domains, primaryDomain }) => {</label></div>))}- {slug ? (- <Link- href={`/${slug}/domains`}- className="rounded-md border border-gray-300 p-1 text-center text-sm"- >- Add a domain- </Link>- ) : (- <button- onClick={() => {- setShowAddProjectModal(true);- toast.error(- "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",- );- }}- className="rounded-md border border-gray-300 p-1 text-center text-sm"- >- Add a domain- </button>- )}</motion.div>)}</AnimatePresence>@@ -236,19 +227,26 @@ const DomainsFilter = ({ domains, primaryDomain }) => {);};-const TagsFilter = ({ tags, tagsCount }) => {+const TagsFilter = ({+ tags,+ tagsCount,+}: {+ tags: TagProps[];+ tagsCount: { tagId: string; _count: number }[];+}) => {const router = useRouter();- const [collapsed, setCollapsed] = useState(tagsCount.length === 0);+ const { slug } = router.query as { slug?: string };+ const [collapsed, setCollapsed] = useState(false);const [search, setSearch] = useState("");const [showMore, setShowMore] = useState(false);const options = useMemo(() => {- const initialOptions = tagsCount.map(({ tagId, _count }) => ({- id: tagId,- name: tags?.find((tag) => tag.id === tagId)?.name || "",- color: tags?.find((tag) => tag.id === tagId)?.color || "blue",- count: _count,- }));+ const initialOptions = tags+ .map((tag) => ({+ ...tag,+ count: tagsCount.find(({ tagId }) => tagId === tag.id)?._count || 0,+ }))+ .sort((a, b) => b.count - a.count);// filter options based on searchreturn search.length > 0? initialOptions.filter(({ name }) =>@@ -257,6 +255,20 @@ const TagsFilter = ({ tags, tagsCount }) => {: initialOptions;}, [tagsCount, tags, search]);+ const { setShowTagLinkModal, setShowAddProjectModal } =+ useContext(ModalContext);++ const addTag = useCallback(() => {+ if (slug) {+ setShowTagLinkModal(true);+ } else {+ setShowAddProjectModal(true);+ toast.error(+ "You can only add a domain to a custom project. Please create a new project or navigate to an existing one.",+ );+ }+ }, [setShowTagLinkModal, setShowAddProjectModal, slug]);+return (<fieldset className="overflow-hidden py-6"><div className="flex h-8 items-center justify-between">@@ -271,6 +283,12 @@ const TagsFilter = ({ tags, tagsCount }) => {/><h4 className="font-medium text-gray-900">Tags</h4></button>+ <button+ onClick={addTag}+ className="mr-2 rounded-md border border-gray-200 px-3 py-1 transition-all hover:border-gray-600 active:bg-gray-100"+ >+ <p className="text-sm text-gray-500">Add</p>+ </button></div><AnimatePresence initial={false}>{!collapsed && (@@ -281,14 +299,12 @@ const TagsFilter = ({ tags, tagsCount }) => {{tags?.length === 0 ? ( // if the project has no tags<p className="text-center text-sm text-gray-500">No tags yet.{" "}- <a+ <buttonclassName="font-medium underline underline-offset-4 transition-colors hover:text-black"- href="https://dub.sh/guides/how-to-use-tags"- target="_blank"- rel="noopener noreferrer"+ onClick={addTag}>Add one.- </a>+ </button></p>) : (<>@@ -305,7 +321,7 @@ const TagsFilter = ({ tags, tagsCount }) => {/></div>{options.length === 0 && (- <p className="text-center text-sm text-gray-500">+ <p className="mt-1 text-center text-sm text-gray-500">No tags match your search.</p>)}diff --git a/components/app/modals/add-edit-domain-modal.tsx b/components/app/modals/add-edit-domain-modal.tsxindex cbae1ff287..a76b667eb6 100644--- a/components/app/modals/add-edit-domain-modal.tsx+++ b/components/app/modals/add-edit-domain-modal.tsx@@ -89,7 +89,7 @@ function AddEditDomainModal({}, [showAddEditDomainModal, saving, domainError, props, data]);const endpoint = useMemo(() => {- if (props?.slug) {+ if (props) {return {method: "PUT",url: `/api/projects/${slug}/domains/${domain}`,@@ -128,7 +128,7 @@ function AddEditDomainModal({<div className="inline-block w-full transform overflow-hidden bg-white align-middle shadow-xl transition-all sm:max-w-md sm:rounded-2xl sm:border sm:border-gray-200"><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16"><BlurImage- src={logo || `https://avatar.vercel.sh/${slug}`}+ src={logo || "/_static/logo.png"}alt={`Logo for ${slug}`}className="h-10 w-10 rounded-full border border-gray-200"width={20}@@ -155,6 +155,9 @@ function AddEditDomainModal({mutate(`/api/projects/${slug}/domains`);setShowAddEditDomainModal(false);toast.success(endpoint.successMessage);+ if (!props) {+ router.push(`/${slug}/domains`);+ }} else if (res.status === 422) {const { domainError: domainErrorResponse } = await res.json();if (domainErrorResponse) {diff --git a/components/app/modals/archive-link-modal.tsx b/components/app/modals/archive-link-modal.tsxindex 493896376b..b3f61db576 100644--- a/components/app/modals/archive-link-modal.tsx+++ b/components/app/modals/archive-link-modal.tsx@@ -8,7 +8,6 @@ import {} from "react";import { mutate } from "swr";import BlurImage from "#/ui/blur-image";-import { LoadingDots } from "#/ui/icons";import Modal from "@/components/shared/modal";import { LinkProps } from "@/lib/types";import { getApexDomain, getQueryString, linkConstructor } from "@/lib/utils";diff --git a/components/app/modals/tag-link-modal.tsx b/components/app/modals/tag-link-modal.tsxindex 2a2b553fb3..66bd007d9e 100644--- a/components/app/modals/tag-link-modal.tsx+++ b/components/app/modals/tag-link-modal.tsx@@ -34,14 +34,14 @@ function TagLinkModal({}: {showTagLinkModal: boolean;setShowTagLinkModal: Dispatch<SetStateAction<boolean>>;- props: LinkProps;+ props?: LinkProps;}) {const router = useRouter();const { slug } = router.query;const [tagging, setTagging] = useState(false);- const apexDomain = getApexDomain(props.url);+ const apexDomain = props?.url ? getApexDomain(props.url) : "dub.sh";- const { key, domain, tagId } = props;+ const { domain, tagId } = props || {};const { tags } = useTags();const [tagValue, setTagValue] = useState(@@ -56,44 +56,61 @@ function TagLinkModal({: false;}, [tagging, tagId, tags, tagValue]);- const shortlink = useMemo(() => {- return linkConstructor({- key,- domain,- pretty: true,- });- }, [key, domain]);+ const type = useMemo(() => {+ if (props) {+ return {+ title: `Tag ${linkConstructor({+ key: props.key,+ domain,+ pretty: true,+ })}`,+ description: "Assign a tag to your short link",+ endpoint: `/api/links/${encodeURIComponent(+ props.key,+ )}/tag?slug=${slug}&domain=${domain}`,+ method: tagValue.length > 0 ? "POST" : "DELETE",+ };+ } else {+ return {+ title: "Add a Tag",+ description: "Tags can be used to group short links together.",+ endpoint: `/api/projects/${slug}/tags`,+ method: "POST",+ };+ }+ }, [props, slug, domain, tagValue]);const handleSubmit = useCallback(async (e?: SyntheticEvent) => {e?.preventDefault();setTagging(true);- fetch(- `/api/links/${encodeURIComponent(- props.key,- )}/tag?slug=${slug}&domain=${domain}`,- {- method: tagValue.length > 0 ? "POST" : "DELETE",- headers: {- "Content-Type": "application/json",- },- ...(tagValue.length > 0 && {- body: JSON.stringify({ tag: tagValue }),- }),+ fetch(type.endpoint, {+ method: type.method,+ headers: {+ "Content-Type": "application/json",},- ).then(async (res) => {+ ...(tagValue.length > 0 && {+ body: JSON.stringify({ tag: tagValue }),+ }),+ }).then(async (res) => {setTagging(false);if (res.status === 200) {- mutate(`/api/links${getQueryString(router)}`);mutate(`/api/projects/${slug}/tags`);- mutate(- `/api/links/_count${getQueryString(router, {- groupBy: "tagId",- })}`,- );- setShowTagLinkModal(false);- toast.success(`Successfully updated shortlink!`);- tagValue.length > 0 && va.track("Tagged Link");+ if (props) {+ mutate(`/api/links${getQueryString(router)}`);+ mutate(+ `/api/links/_count${getQueryString(router, {+ groupBy: "tagId",+ })}`,+ );+ setShowTagLinkModal(false);+ toast.success(`Successfully updated shortlink!`);+ tagValue.length > 0 && va.track("Tagged Link");+ } else {+ toast.success(`Successfully added tag!`);+ setOpenCommandList(true);+ va.track("Added Tag");+ }} else {const error = await res.text();toast.error(error);@@ -104,7 +121,7 @@ function TagLinkModal({);const commandRef = useRef<HTMLDivElement | null>(null);- const [open, setOpen] = useState(false);+ const [openCommandList, setOpenCommandList] = useState(false);useEffect(() => {const handleClickOutside = (e) => {@@ -115,21 +132,17 @@ function TagLinkModal({// the data-exclude-click attributee.target.closest("[data-exclude-click]") === null) {- setOpen(false);+ setOpenCommandList(false);}};- if (showTagLinkModal && open) {+ if (showTagLinkModal && openCommandList) {document.addEventListener("click", handleClickOutside);return () => document.removeEventListener("click", handleClickOutside);}- }, [commandRef, showTagLinkModal, open]);+ }, [commandRef, showTagLinkModal, openCommandList]);return (- <Modal- showModal={showTagLinkModal}- setShowModal={setShowTagLinkModal}- pauseTrap={open}- >+ <Modal showModal={showTagLinkModal} setShowModal={setShowTagLinkModal}><div className="inline-block w-full bg-white align-middle shadow-xl transition-all sm:max-w-md sm:rounded-2xl sm:border sm:border-gray-200"><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 text-center sm:px-16"><BlurImage@@ -139,10 +152,8 @@ function TagLinkModal({width={20}height={20}/>- <h3 className="text-lg font-medium">Tag {shortlink}</h3>- <p className="text-sm text-gray-500">- Assign a tag to your short link- </p>+ <h3 className="text-lg font-medium">{type.title}</h3>+ <p className="text-sm text-gray-500">{type.description}</p></div><form@@ -160,26 +171,29 @@ function TagLinkModal({<div className="relative mt-1 w-full rounded-md"><Search className="absolute inset-y-0 left-0 my-auto h-7 w-7 pl-3 text-gray-400" /><Command.Input- placeholder="Choose tag"+ placeholder={props ? "Choose tag" : "Add a tag"}+ required={!props}// only show the dropdown if there are tags and the tagValue is not empty- onFocus={() => tags && tags.length > 0 && setOpen(true)}+ onFocus={() =>+ tags && tags.length > 0 && setOpenCommandList(true)+ }value={tagValue}onValueChange={setTagValue}onKeyDown={(e) => {if (e.key === "Escape") {e.stopPropagation();- setOpen(false);+ setOpenCommandList(false);} else if (e.key === "Enter") {- if (open) {- // if dropdown is open, close it- setOpen(false);+ if (openCommandList) {+ // if dropdown is openCommandList, close it+ setOpenCommandList(false);} else {// if dropdown is already closed, submit formhandleSubmit();}- // if it's a letter or a number and there's no meta key pressed, open dropdown+ // if it's a letter or a number and there's no meta key pressed, openCommandList dropdown} else if (e.key.match(/^[a-z0-9]$/i) && !e.metaKey) {- setOpen(true);+ setOpenCommandList(true);}}}className="block w-full rounded-md border-gray-300 px-10 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500"@@ -189,7 +203,7 @@ function TagLinkModal({onClick={(e) => {e.stopPropagation();setTagValue("");- setOpen(true);+ setOpenCommandList(true);}}className="absolute inset-y-0 right-0 my-auto">@@ -199,7 +213,7 @@ function TagLinkModal({<ChevronDown className="absolute inset-y-0 right-0 my-auto h-7 w-7 pr-3 text-gray-400" />)}</div>- {open && (+ {openCommandList && (<Command.Listdata-exclude-clickstyle={{@@ -210,7 +224,7 @@ function TagLinkModal({<Command.Empty><buttontype="button"- onClick={() => setOpen(false)}+ onClick={() => setOpenCommandList(false)}className="flex w-full cursor-pointer items-center rounded-md bg-gray-100 px-4 py-2 text-sm text-gray-900 hover:text-gray-900 aria-selected:bg-gray-100 aria-selected:text-gray-900">{tagValue.length > 0 ? (@@ -231,7 +245,7 @@ function TagLinkModal({value={tag.name}onSelect={() => {setTagValue(tag.name);- setOpen(false);+ setOpenCommandList(false);}}className="group flex cursor-pointer items-center justify-between rounded-md px-4 py-2 text-sm text-gray-900 hover:bg-gray-100 hover:text-gray-900 active:bg-gray-200 aria-selected:bg-gray-100 aria-selected:text-gray-900">@@ -346,7 +360,8 @@ const TagPopover = ({ tag }: { tag: TagProps }) => {</div><div className="p-2"><button- onClick={() => {+ onClick={(e) => {+ e.stopPropagation();confirm("Are you sure you want to delete this tag? All tagged links will be untagged, but they won't be deleted.",) && handleDelete();@@ -384,17 +399,17 @@ const TagPopover = ({ tag }: { tag: TagProps }) => {);};-export function useTagLinkModal({ props }: { props: LinkProps }) {+export function useTagLinkModal({ props }: { props?: LinkProps }) {const [showTagLinkModal, setShowTagLinkModal] = useState(false);const TagLinkModalCallback = useCallback(() => {- return props ? (+ return (<TagLinkModalshowTagLinkModal={showTagLinkModal}setShowTagLinkModal={setShowTagLinkModal}props={props}/>- ) : null;+ );}, [showTagLinkModal, setShowTagLinkModal]);return useMemo(diff --git a/components/shared/modal.tsx b/components/shared/modal.tsxindex 6d7aabaf38..0b9f247788 100644--- a/components/shared/modal.tsx+++ b/components/shared/modal.tsx@@ -16,7 +16,6 @@ export default function Modal({bgColor = "bg-white",closeWithX,mobileOnly,- pauseTrap,}: {children: React.ReactNode;showModal: boolean;@@ -24,7 +23,6 @@ export default function Modal({bgColor?: string;closeWithX?: boolean;mobileOnly?: boolean;- pauseTrap?: boolean;}) {const router = useRouter();const { key } = router.query;@@ -80,9 +78,9 @@ export default function Modal({<AnimatePresence>{showModal && (<FocusTrap- active={!pauseTrap}focusTrapOptions={{initialFocus: false,+ clickOutsideDeactivates: true,onActivate: () => {// prevent scroll outside of modal when modal is opendocument.body.style.overflow = "hidden";diff --git a/components/shared/popover.tsx b/components/shared/popover.tsxindex 97a92e21ff..2119e895d3 100644--- a/components/shared/popover.tsx+++ b/components/shared/popover.tsx@@ -91,7 +91,7 @@ export default function Popover({</AnimatePresence></>)}- <PopoverPrimitive.Root modal>+ <PopoverPrimitive.Root open={openPopover} onOpenChange={setOpenPopover}><PopoverPrimitive.Trigger{...(!desktopOnly && {className: "hidden md:inline-flex",diff --git a/emails/IntroducingTags.tsx b/emails/IntroducingTags.tsxnew file mode 100644index 0000000000..e69de29bb2diff --git a/lib/swr/use-tags.ts b/lib/swr/use-tags.tsindex 1a33b636ed..1faf2e8c4d 100644--- a/lib/swr/use-tags.ts+++ b/lib/swr/use-tags.ts@@ -16,7 +16,7 @@ export default function useTags() {);return {- tags,+ tags: slug ? tags : [],loading: tags ? false : true,isValidating,};diff --git a/package.json b/package.jsonindex 9ad97d7ee6..fc42a4ca41 100644--- a/package.json+++ b/package.json@@ -55,7 +55,7 @@"lucide-react": "^0.192.0","mailing-core": "^0.9.1","ms": "^2.1.3",- "next": "^13.4.4-canary.3",+ "next": "^13.4.4-canary.4","next-auth": "^4.22.1","next-contentlayer": "^0.3.2","node-html-parser": "^6.1.4",diff --git a/pages/api/links/[key]/tag.ts b/pages/api/links/[key]/tag.tsindex c7ebc3bb35..4881160a52 100644--- a/pages/api/links/[key]/tag.ts+++ b/pages/api/links/[key]/tag.ts@@ -1,19 +1,38 @@import { randomBadgeColor } from "@/components/shared/badge";import { withLinksAuth } from "@/lib/auth";-import { DUB_PROJECT_ID } from "@/lib/constants";import prisma from "@/lib/prisma";export default withLinksAuth(async (req, res, _session, project, domain) => {const { key } = req.query as { key: string };const { tag } = req.body as { tag: string };if (!key) {- return res.status(400).json({ error: "Missing key" });+ return res.status(400).end("Missing key");+ }+ if (!project || !domain) {+ return res.status(400).end("Missing project or domain");}if (req.method === "POST") {+ const tags = await prisma.tag.findMany({+ where: {+ projectId: project.id,+ },+ });+ // if on a free plan and trying to create more than 3 tags+ if (+ project.plan === "free" &&+ tags.length >= 3 &&+ !tags.find((t) => t.name === tag)+ ) {+ return res+ .status(403)+ .end(+ "You can only create 3 tags in the Free plan. Upgrade to Pro to create unlimited tags.",+ );+ }const response = await prisma.link.update({where: {domain_key: {- domain: domain || "dub.sh",+ domain,key,},},@@ -23,13 +42,13 @@ export default withLinksAuth(async (req, res, _session, project, domain) => {where: {name_projectId: {name: tag,- projectId: project?.id || DUB_PROJECT_ID,+ projectId: project.id,},},create: {name: tag,color: randomBadgeColor(),- projectId: project?.id || DUB_PROJECT_ID,+ projectId: project.id,},},},@@ -40,7 +59,7 @@ export default withLinksAuth(async (req, res, _session, project, domain) => {const response = await prisma.link.update({where: {domain_key: {- domain: domain || "dub.sh",+ domain,key,},},diff --git a/pages/api/projects/[slug]/tags/index.ts b/pages/api/projects/[slug]/tags/index.tsindex 5648430f9a..d4288ce341 100644--- a/pages/api/projects/[slug]/tags/index.ts+++ b/pages/api/projects/[slug]/tags/index.ts@@ -1,3 +1,4 @@+import { randomBadgeColor } from "@/components/shared/badge";import { withProjectAuth } from "@/lib/auth";import prisma from "@/lib/prisma";@@ -18,8 +19,30 @@ export default withProjectAuth(async (req, res, project) => {},});return res.status(200).json(tags);+ } else if (req.method === "POST") {+ const tagsCount = await prisma.tag.count({+ where: {+ projectId: project.id,+ },+ });+ if (project.plan === "free" && tagsCount >= 3) {+ return res+ .status(403)+ .end(+ "You can only create 3 tags in the Free plan. Upgrade to Pro to create unlimited tags.",+ );+ }+ const { tag } = req.body;+ const response = await prisma.tag.create({+ data: {+ name: tag,+ color: randomBadgeColor(),+ projectId: project.id,+ },+ });+ return res.status(200).json(response);} else {- res.setHeader("Allow", ["GET"]);+ res.setHeader("Allow", ["GET", "POST"]);return res.status(405).json({ error: `Method ${req.method} Not Allowed` });}});diff --git a/posts/changelog/introducing-tags.mdx b/posts/changelog/introducing-tags.mdxindex 70992886a0..62fcc1fbb3 100644--- a/posts/changelog/introducing-tags.mdx+++ b/posts/changelog/introducing-tags.mdx@@ -1,9 +1,17 @@---title: Introducing TagspublishedAt: 2023-05-21-summary: "Introducing Tags on Dub. With tags, you can now organize your links into categories, and filter your links by tags."-image: "https://media.cleanshot.cloud/media/42580/ZotuXjFHBaeAcsTIP3j8cYNJi51F7k841VTxihnn.jpeg?Expires=1684728914&Signature=TTIm5To2eQxfdGexRMd4caUlpoY9859zfRjBX~l518OJmfQojXsPYyRm8Lu-y9Zlc-vvAff~mZAlBvPJuO1w9fui327LGf0QJ8ounnSh0S1ptYkyroMNKSp0QqzMo6mpHLflr3FoOCMylSKdtjr-lLpXNhl4nicy2yx8sm1cYczyQfWJ0lhYf3p3NKQq-TvCmI0d9NbMN2SQ6r0pBgqNnG8tLdf7oytSGytIPYr41PbnHU62mCt3uWgGVqZOvtkVTGmafeuYGUeAAlSPnMg2QvO2abo24cWP7ZsT6YFyYdHzloK4fXFSp~dyNl3sfV8WehkF~fDxYx98FZ8hrfpKYg__&Key-Pair-Id=K269JMAT9ZF4GZ"+summary: "Introducing Tags – a smarter way to manage your links on Dub."+image: "https://d2vwwcvoksz7ty.cloudfront.net/changelog/introducing-tags.png"author: "steventey"----Introducing Tags on Dub. With tags, you can now organize your links into categories, and filter your links by tags.+Introducing Tags – a smarter way to manage your links on Dub.++With tags, you can now:++1. Organize your links by campaigns, clients, or any other categories you can think of.+2. Filter your links by tags and get a shareable link to the filtered results.+3. Easily edit/delete your tags with a Notion-style dropdown interface.++This has been a [highly](https://github.com/steven-tey/dub/issues/101) [requested](https://github.com/steven-tey/dub/issues/124) feature, and we're excited to finally ship it!diff --git a/yarn.lock b/yarn.lockindex 9a4cff62ef..82ae19d77b 100644--- a/yarn.lock+++ b/yarn.lock@@ -699,10 +699,10 @@resolved "https://registry.yarnpkg.com/@next/env/-/env-13.1.6.tgz#c4925609f16142ded1a5cb833359ab17359b7a93"integrity sha512-s+W9Fdqh5MFk6ECrbnVmmAOwxKQuhGMT7xXHrkYIBMBcTiOqNWhv5KbJIboKR5STXxNXl32hllnvKaffzFaWQg==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/env/-/env-13.4.4-canary.3.tgz#0e7f4465e32fa8a4bca310c99b7c2f4115dc10b4"- integrity sha512-JxJhwQ9XRR558jlgoJYPccM6XgfPwOmZwtJ4Ie+n6Irhc6pJyATTAjgZFJHL85TWuCia5CI9nVAxlt/LPNc8RA==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/env/-/env-13.4.4-canary.4.tgz#e3515db6c0013c622fb381686efaa7c1fae1359f"+ integrity sha512-awPflttJPZ7SzbnlE+LBECmhDiFZfR6QB7j4U2llZEELS3tgKkJaRUoifkE+PDN67C6g35GUN0EYUBgu2wIdUg=="@next/[email protected]":version "13.1.6"@@ -719,20 +719,20 @@resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.1.6.tgz#ec1b90fd9bf809d8b81004c5182e254dced4ad96"integrity sha512-KKRQH4DDE4kONXCvFMNBZGDb499Hs+xcFAwvj+rfSUssIDrZOlyfJNy55rH5t2Qxed1e4K80KEJgsxKQN1/fyw==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.4-canary.3.tgz#b287e9042c020e7e8c140abda702bbb29158adc0"- integrity sha512-LANaPyvgv+Rb+0PuCqC5ga+IQvcg5VXp/IGL64RPHhDmc1lSPlNh6tse3DTjtLtHo1wbFA5sc3BuAkM/URwrsg==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.4-canary.4.tgz#23de5a9367c9140ddea0412d72295fac74041b76"+ integrity sha512-VReD6MptefpNR2YFbto9Jm8uBJavomr2HnQGLlEZJONyHwePDUQjm6pGkkr9sxk3G1SeeFMS1duYgrek+QLQjA=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.1.6.tgz#e869ac75d16995eee733a7d1550322d9051c1eb4"integrity sha512-/uOky5PaZDoaU99ohjtNcDTJ6ks/gZ5ykTQDvNZDjIoCxFe3+t06bxsTPY6tAO6uEAw5f6vVFX5H5KLwhrkZCA==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.4-canary.3.tgz#ba99f8a121d86c9d75dec0e8fde05c931a3bfb8c"- integrity sha512-Z0CxnvU3MZVawExMqBBSyiLO+rqAGFeqEuTkHBmNATyuPLnknVPJxZtPcGx0uVqmX4GYfA1+PtsZnfhYfKCGfQ==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.4-canary.4.tgz#c7dc4bab04b05674c89a36c0aec531644678e051"+ integrity sha512-06P7ISzj1MGxwvi4TMlJck/Eb0K14zExFSiE+bKRU901+yV6NHM92e6jR93nW2Dt9BF3l5oW4Bt2Y4c5en4Rqg=="@next/[email protected]":version "13.1.6"@@ -749,70 +749,70 @@resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.1.6.tgz#87a71db21cded3f7c63d1d19079845c59813c53d"integrity sha512-yCH+yDr7/4FDuWv6+GiYrPI9kcTAO3y48UmaIbrKy8ZJpi7RehJe3vIBRUmLrLaNDH3rY1rwoHi471NvR5J5NQ==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.4-canary.3.tgz#7285ef9e9acad22c7fa8d262175a49672ed70aad"- integrity sha512-fmLaBf0BYVsapLQsUtTPjKNukFIPACEJuqjdjAW+RPaoUP6EOeu5Y62qFz8Biy6x06RHez6aOZ/VQvCdo0RbdA==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.4-canary.4.tgz#1eba1e80ba9fd3e64a33cf1cdec40abe54b02314"+ integrity sha512-WWAuRoXZkhrzH2MmB2i1/diVRxqW+jSpdfPA7fkLENmQkc5p0mgGq1jUJyzbJVWC+fbCCa0z+efqPbqbFshpEg=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.1.6.tgz#c5aac8619331b9fd030603bbe2b36052011e11de"integrity sha512-ECagB8LGX25P9Mrmlc7Q/TQBb9rGScxHbv/kLqqIWs2fIXy6Y/EiBBiM72NTwuXUFCNrWR4sjUPSooVBJJ3ESQ==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.4-canary.3.tgz#54099dea03f5c309720681c36d69beb53048991b"- integrity sha512-sy/nagNqorb/TF/LmSalIsbLP3PvHkTU12I3123GNI9Vb7TV6E9MaEIFlYueDmfV+sAQD4B4x7JLqxNqr2dThQ==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.4-canary.4.tgz#206342427481d488f7760c1b1462cfeb98935ef8"+ integrity sha512-k+ygS5l3VhsBd4MTlxghm8DyNfdfEdC/jKbhA8FnPQrP20NT7uDgBn0zcRpYyHnklZsspGwhlfyWt4K69G+upA=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.1.6.tgz#9513d36d540bbfea575576746736054c31aacdea"integrity sha512-GT5w2mruk90V/I5g6ScuueE7fqj/d8Bui2qxdw6lFxmuTgMeol5rnzAv4uAoVQgClOUO/MULilzlODg9Ib3Y4Q==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.4-canary.3.tgz#3894b8b1182fc1b31fca92714ee9040f40913014"- integrity sha512-I60UpiaoOxLLDDBVH6n4pCTXg+kqRFQj5uFJ2VIFyG2WZTwj5D6R7qSe8U+kVLnDTtV/EmvBCfGJY6KUqB6BSw==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.4-canary.4.tgz#5065e26404290c15bfcf2ce13774ca394e24b568"+ integrity sha512-naPxuq/7342qZsIh7+IHpB+njuvo++yTTbar1pebEY9vCcFiK0MkICIDgULY1X0eqN5lbMEhCfBWgoIigt8A4Q=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.1.6.tgz#d61fc6884899f5957251f4ce3f522e34a2c479b7"integrity sha512-keFD6KvwOPzmat4TCnlnuxJCQepPN+8j3Nw876FtULxo8005Y9Ghcl7ACcR8GoiKoddAq8gxNBrpjoxjQRHeAQ==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.4-canary.3.tgz#b5dc388eb51b483f1480feff702c899d492b0ee7"- integrity sha512-FASYC/TgQdlgNhHiJjiuqMSx4LRqm85V0R1hAxesXVsGxpMIPiJNdduiErnINzid9W/ixryqHizop+92p7TIcg==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.4-canary.4.tgz#6e312fb36d2c5ad3643ca361688b03f637f69d3b"+ integrity sha512-bVXKIXUqBR6acZ8dg0ZSnBkjhkwU4Ddxi4Zd9HPJBp7qgzOIhDMvu/pB/BiTlyZo/v7XuoR8Dx3thLx9u+byXg=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.1.6.tgz#fac2077a8ae9768e31444c9ae90807e64117cda7"integrity sha512-OwertslIiGQluFvHyRDzBCIB07qJjqabAmINlXUYt7/sY7Q7QPE8xVi5beBxX/rxTGPIbtyIe3faBE6Z2KywhQ==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.4-canary.3.tgz#a628b177c7d8e587e10f5f89c365673316a7c083"- integrity sha512-unpD/F42HEWlubjnaOS+FKXcuytfIbSJMxv7sLzwVURcQaUpSE4/hdCmqk+5zeh9RJhDoVUyW+yKJqkBzsygtw==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.4-canary.4.tgz#6b60f413c68aaea3ddbd29cf5dddc03cef76d88f"+ integrity sha512-lx0TStzwDspJF8g/YrcTxHuKw9kCWJq6p37q+9f+D/O/HrPRZD+blHs/vxkM5ZgjvUo8N+0Tp4kcn7p59F4pSA=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.1.6.tgz#498bc11c91b4c482a625bf4b978f98ae91111e46"integrity sha512-g8zowiuP8FxUR9zslPmlju7qYbs2XBtTLVSxVikPtUDQedhcls39uKYLvOOd1JZg0ehyhopobRoH1q+MHlIN/w==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.4-canary.3.tgz#1f7a8f2a1f87a6a8a8bd6532faed7381742abbbe"- integrity sha512-7iEppmgbpFORfecsiQLOtt+x7uqNv8m43vSDj0C7ICaFgU9XzpOwE2Ckk0akDit+dZ6o39mYrDQwKEW0PaR0Mw==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.4-canary.4.tgz#d671b11b4b277dfa9c5253480f708ff7441ba124"+ integrity sha512-Gf5QSCqPP0c7RZaAqpOay230O2QZuB3W0LWf7WHMVyVZdNCKe6UKRcaXNdZmTl5yNI3DEJ2qYNP9zGSoKBkIPg=="@next/[email protected]":version "13.1.6"resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.1.6.tgz#17ed919c723426b7d0ce1cd73d40ce3dcd342089"integrity sha512-Ls2OL9hi3YlJKGNdKv8k3X/lLgc3VmLG3a/DeTkAd+lAituJp8ZHmRmm9f9SL84fT3CotlzcgbdaCDfFwFA6bA==-"@next/[email protected]":- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.4-canary.3.tgz#629d5cb8f17db1f8dd51b39f870838db85442c15"- integrity sha512-Z/J5EZDOe+SfXtpt5CCc3YGhYpm0pM9Fx9Ea1v4mZU4qdWb3a05Q5INN7JWIzPumJGD30QRq+11jR08wqMsZ8A==+"@next/[email protected]":+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.4-canary.4.tgz#b4518f76cb75cc33f0fef7aee05c0b04d4556fb6"+ integrity sha512-p6pZKe3I1VGbH+RzaxUW4zOYb3HbHD7iUree7ZBBJxpUDn5OQIdUjXKjjHgHxfFN/pOkhGhEvBmW49tCoq3GzQ=="@nodelib/[email protected]":version "2.1.5"@@ -6840,12 +6840,12 @@ [email protected]:"@next/swc-win32-ia32-msvc" "13.1.6""@next/swc-win32-x64-msvc" "13.1.6"-next@^13.4.4-canary.3:- version "13.4.4-canary.3"- resolved "https://registry.yarnpkg.com/next/-/next-13.4.4-canary.3.tgz#5a57c9e9ca9a8a759b3b14c0c254c25ebe07636f"- integrity sha512-gC0fKmS3HNW4OLc88hjXy3OxeBgiKcfT9MqmOJ98sLGhJSfF/UKTJy/dZ7gDHU6X7B+YyjQyVEKR9KqPInLryA==+next@^13.4.4-canary.4:+ version "13.4.4-canary.4"+ resolved "https://registry.yarnpkg.com/next/-/next-13.4.4-canary.4.tgz#6d6a7c46bca8a554735794305888f438d8effd8c"+ integrity sha512-YixaBwR33UsfGZIekE/MxcZMfIQRrZ1zub6vnB3cVijoxgUk03KPCi0yblpOaEJW1jefhOnf9iCCa8Xdnkvjbg==dependencies:- "@next/env" "13.4.4-canary.3"+ "@next/env" "13.4.4-canary.4""@swc/helpers" "0.5.1"busboy "1.6.0"caniuse-lite "^1.0.30001406"@@ -6853,15 +6853,15 @@ next@^13.4.4-canary.3:styled-jsx "5.1.1"zod "3.21.4"optionalDependencies:- "@next/swc-darwin-arm64" "13.4.4-canary.3"- "@next/swc-darwin-x64" "13.4.4-canary.3"- "@next/swc-linux-arm64-gnu" "13.4.4-canary.3"- "@next/swc-linux-arm64-musl" "13.4.4-canary.3"- "@next/swc-linux-x64-gnu" "13.4.4-canary.3"- "@next/swc-linux-x64-musl" "13.4.4-canary.3"- "@next/swc-win32-arm64-msvc" "13.4.4-canary.3"- "@next/swc-win32-ia32-msvc" "13.4.4-canary.3"- "@next/swc-win32-x64-msvc" "13.4.4-canary.3"+ "@next/swc-darwin-arm64" "13.4.4-canary.4"+ "@next/swc-darwin-x64" "13.4.4-canary.4"+ "@next/swc-linux-arm64-gnu" "13.4.4-canary.4"+ "@next/swc-linux-arm64-musl" "13.4.4-canary.4"+ "@next/swc-linux-x64-gnu" "13.4.4-canary.4"+ "@next/swc-linux-x64-musl" "13.4.4-canary.4"+ "@next/swc-win32-arm64-msvc" "13.4.4-canary.4"+ "@next/swc-win32-ia32-msvc" "13.4.4-canary.4"+ "@next/swc-win32-x64-msvc" "13.4.4-canary.4"no-case@^2.2.0:version "2.3.2"