The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add Google OAuth
Steven Tey58f5fe11eb9e
diff --git a/app/ui/button.tsx b/app/ui/button.tsxindex 7078ee2b16..ec4175923a 100644--- a/app/ui/button.tsx+++ b/app/ui/button.tsx@@ -11,6 +11,7 @@ export default function Button({onClick,disabled,loading,+ icon,disabledTooltip,}: {text: string;@@ -18,6 +19,7 @@ export default function Button({onClick?: any;disabled?: boolean;loading?: boolean;+ icon?: ReactNode;disabledTooltip?: string | ReactNode;}) {if (disabledTooltip) {@@ -34,7 +36,7 @@ export default function Button({// if onClick is passed, it's a "button" type, otherwise it's being used in a form, hence "submit"type={onClick ? "button" : "submit"}className={clsx(- "flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none",+ "flex h-10 w-full items-center justify-center space-x-2 rounded-md border text-sm transition-all focus:outline-none",disabled || loading? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400": {@@ -49,7 +51,14 @@ export default function Button({{...(onClick ? { onClick } : {})}disabled={disabled || loading}>- {loading ? <LoadingDots color="#808080" /> : <p>{text}</p>}+ {loading ? (+ <LoadingDots color="#808080" />+ ) : (+ <>+ {icon}+ <p>{text}</p>+ </>+ )}</button>);}diff --git a/app/ui/form.tsx b/app/ui/form.tsxnew file mode 100644index 0000000000..bbcd9ba844--- /dev/null+++ b/app/ui/form.tsx@@ -0,0 +1,66 @@+import { useState, useMemo, InputHTMLAttributes } from "react";+import Button from "#/ui/button";++export default function Form({+ title,+ description,+ inputData,+ helpText,+ handleSubmit,+}: {+ title: string;+ description: string;+ inputData: InputHTMLAttributes<HTMLInputElement>;+ helpText?: string;+ handleSubmit: (data) => Promise<any>;+}) {+ const [value, setValue] = useState(inputData.defaultValue);+ const [saving, setSaving] = useState(false);+ const saveDisabled = useMemo(() => {+ return saving || !value || value === inputData.defaultValue;+ }, [saving, value, inputData.defaultValue]);++ return (+ <form+ onSubmit={async (e) => {+ e.preventDefault();+ setSaving(true);+ await handleSubmit({+ [inputData.name as string]: value,+ });+ setSaving(false);+ }}+ className="rounded-lg border border-gray-200 bg-white"+ >+ <div className="relative flex flex-col space-y-3 p-5 sm:p-10">+ <h2 className="text-xl font-medium">{title}</h2>+ <div className="flex items-center space-x-1">+ <p className="text-sm text-gray-500">{description}</p>+ </div>+ <div />+ {inputData.defaultValue ? (+ <input+ {...inputData}+ type="text"+ required+ onChange={(e) => setValue(e.target.value)}+ className="w-full max-w-md rounded-md border border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"+ />+ ) : (+ <div className="h-[2.35rem] w-full max-w-md animate-pulse rounded-md bg-gray-200" />+ )}+ </div>++ <div className="flex items-center justify-between rounded-b-lg border-t border-gray-200 bg-gray-50 p-3 sm:px-10">+ <p className="text-sm text-gray-500">{helpText}</p>+ <div className="w-32">+ <Button+ text="Save Changes"+ loading={saving}+ disabled={saveDisabled}+ />+ </div>+ </div>+ </form>+ );+}diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsxindex 7b78f2bf26..6aae881076 100644--- a/app/ui/modal-provider.tsx+++ b/app/ui/modal-provider.tsx@@ -7,11 +7,15 @@ import {createContext,useEffect,} from "react";+import { useSession } from "next-auth/react";+import ErrorPage from "next/error";+import useProject from "@/lib/swr/use-project";+import Cookies from "js-cookie";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";+import { useGoogleOauthModal } from "@/components/app/modals/google-oauth-modal";export const ModalContext = createContext<{setShowAddProjectModal: Dispatch<SetStateAction<boolean>>;@@ -24,8 +28,7 @@ export const ModalContext = createContext<{});export default function ModalProvider({ children }: { children: ReactNode }) {- const { error } = useProject();-+ const { GoogleOauthModal, setShowGoogleOauthModal } = useGoogleOauthModal();const { AddProjectModal, setShowAddProjectModal } = useAddProjectModal();const { AcceptInviteModal, setShowAcceptInviteModal } =useAcceptInviteModal();@@ -33,6 +36,19 @@ export default function ModalProvider({ children }: { children: ReactNode }) {useAddEditDomainModal({});const { setShowTagLinkModal, TagLinkModal } = useTagLinkModal({});+ const { data: session } = useSession();+ useEffect(() => {+ if (+ session?.user?.email &&+ !session.user?.name &&+ !Cookies.get("hideGoogleOauthModal")+ ) {+ console.log(session);+ setShowGoogleOauthModal(true);+ }+ }, [session]);++ const { error } = useProject();// handle errorsuseEffect(() => {if (error && (error.status === 409 || error.status === 410)) {@@ -40,6 +56,9 @@ export default function ModalProvider({ children }: { children: ReactNode }) {}}, [error]);+ if (error && error.status === 404) {+ return <ErrorPage statusCode={404} />;+ }return (<ModalContext.Providervalue={{@@ -48,6 +67,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {setShowTagLinkModal,}}>+ <GoogleOauthModal /><AddProjectModal />{error && (error.status === 409 || error.status === 410) && (<AcceptInviteModal />diff --git a/components/app/modals/add-edit-link-modal/index.tsx b/components/app/modals/add-edit-link-modal/index.tsxindex a1f2fbf702..ab0735ee02 100644--- a/components/app/modals/add-edit-link-modal/index.tsx+++ b/components/app/modals/add-edit-link-modal/index.tsx@@ -316,25 +316,24 @@ function AddEditLinkModal({router.push("/links").then(() => {setShowAddEditLinkModal(false);});+ }+ // copy shortlink to clipboard when adding a new link+ if (!props) {+ navigator.clipboard+ .writeText(+ linkConstructor({+ // remove leading and trailing slashes+ key: data.key.replace(/^\/|\/$/g, ""),+ domain,+ }),+ )+ .then(() => {+ toast.success("Copied shortlink to clipboard!");+ });} else {- // copy shortlink to clipboard when adding a new link- if (!props) {- navigator.clipboard- .writeText(- linkConstructor({- // remove leading and trailing slashes- key: data.key.replace(/^\/|\/$/g, ""),- domain,- }),- )- .then(() => {- toast.success("Copied shortlink to clipboard!");- });- } else {- toast.success("Successfully updated shortlink!");- }- setShowAddEditLinkModal(false);+ toast.success("Successfully updated shortlink!");}+ setShowAddEditLinkModal(false);} else {const error = await res.text();if (error) {diff --git a/components/app/modals/add-project-modal.tsx b/components/app/modals/add-project-modal.tsxindex 8e874ccecd..fdfd54407d 100644--- a/components/app/modals/add-project-modal.tsx+++ b/components/app/modals/add-project-modal.tsx@@ -116,6 +116,7 @@ function AddProjectModalHelper({mutate("/api/projects");router.push(`/${slug}`);toast.success("Successfully created project!");+ setShowAddProjectModal(false);} else if (res.status === 422) {const {slugError: slugErrorResponse,diff --git a/components/app/modals/delete-project-modal.tsx b/components/app/modals/delete-project-modal.tsxindex cd93678eac..c59be723f0 100644--- a/components/app/modals/delete-project-modal.tsx+++ b/components/app/modals/delete-project-modal.tsx@@ -22,7 +22,7 @@ function DeleteProjectModal({}) {const router = useRouter();const { slug } = router.query as { slug: string };- const { logo } = useProject();+ const { id, logo } = useProject();const [deleting, setDeleting] = useState(false);async function deleteProject() {@@ -54,8 +54,8 @@ function DeleteProjectModal({<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}`}- alt={`Logo for ${slug}`}+ src={logo || `https://avatar.vercel.sh/${id}`}+ alt={id || "Delete Project"}className="h-10 w-10 rounded-full border border-gray-200"width={20}height={20}diff --git a/components/app/modals/google-oauth-modal.tsx b/components/app/modals/google-oauth-modal.tsxnew file mode 100644index 0000000000..0b18c0471f--- /dev/null+++ b/components/app/modals/google-oauth-modal.tsx@@ -0,0 +1,89 @@+import { signIn } from "next-auth/react";+import {+ Dispatch,+ SetStateAction,+ useCallback,+ useMemo,+ useState,+} from "react";+import BlurImage from "#/ui/blur-image";+import Modal from "@/components/shared/modal";+import Button from "#/ui/button";+import { Google } from "@/components/shared/icons";+import Cookies from "js-cookie";++function GoogleOauthModal({+ showGoogleOauthModal,+ setShowGoogleOauthModal,+}: {+ showGoogleOauthModal: boolean;+ setShowGoogleOauthModal: Dispatch<SetStateAction<boolean>>;+}) {+ const [clickedGoogle, setClickedGoogle] = useState(false);++ return (+ <Modal+ showModal={showGoogleOauthModal}+ setShowModal={setShowGoogleOauthModal}+ >+ <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={`/_static/logo.png`}+ alt={"Invite Teammate"}+ className="h-10 w-10 rounded-full"+ width={20}+ height={20}+ />+ <h3 className="text-lg font-medium">Connect your Google Account</h3>+ <p className="text-center text-sm text-gray-500">+ This allows you to sign in to your Dub account with Google.+ </p>+ </div>+ <div className="flex flex-col space-y-3 bg-gray-50 px-4 py-8 text-left sm:px-16">+ <Button+ text="Connect Google Account"+ onClick={() => {+ setClickedGoogle(true);+ signIn("google", {+ callbackUrl: "/settings",+ });+ }}+ loading={clickedGoogle}+ icon={<Google className="h-4 w-4" />}+ />+ <button+ onClick={() => {+ setShowGoogleOauthModal(false);+ Cookies.set("hideGoogleOauthModal", true, { expires: 14 });+ }}+ className="text-sm text-gray-400 underline underline-offset-4 transition-colors hover:text-gray-800 active:text-gray-400"+ >+ Don't show this again+ </button>+ </div>+ </div>+ </Modal>+ );+}++export function useGoogleOauthModal() {+ const [showGoogleOauthModal, setShowGoogleOauthModal] = useState(false);++ const GoogleOauthModalCallback = useCallback(() => {+ return (+ <GoogleOauthModal+ showGoogleOauthModal={showGoogleOauthModal}+ setShowGoogleOauthModal={setShowGoogleOauthModal}+ />+ );+ }, [showGoogleOauthModal, setShowGoogleOauthModal]);++ return useMemo(+ () => ({+ setShowGoogleOauthModal,+ GoogleOauthModal: GoogleOauthModalCallback,+ }),+ [setShowGoogleOauthModal, GoogleOauthModalCallback],+ );+}diff --git a/components/app/projects/project-card.tsx b/components/app/projects/project-card.tsxindex ffbf212543..3887e333c1 100644--- a/components/app/projects/project-card.tsx+++ b/components/app/projects/project-card.tsx@@ -6,10 +6,11 @@ import Tooltip, { TooltipContent } from "#/ui/tooltip";import { ProjectWithDomainProps } from "@/lib/types";import { fetcher, nFormatter } from "@/lib/utils";import { BarChart2, Globe, Link2 } from "lucide-react";-import PlanBadge from "../settings/plan-badge";+import PlanBadge from "./settings/plan-badge";import { GOOGLE_FAVICON_URL } from "@/lib/constants";export default function ProjectCard({+ id,name,slug,logo,@@ -32,7 +33,7 @@ export default function ProjectCard({<div className="flex items-center space-x-3"><BlurImagesrc={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}- alt={slug}+ alt={id}className="h-10 w-10 flex-shrink-0 overflow-hidden rounded-full"width={48}height={48}diff --git a/components/app/settings/delete-project.tsx b/components/app/projects/settings/delete-project.tsxsimilarity index 100%rename from components/app/settings/delete-project.tsxrename to components/app/projects/settings/delete-project.tsxdiff --git a/components/app/settings/plan-badge.tsx b/components/app/projects/settings/plan-badge.tsxsimilarity index 100%rename from components/app/settings/plan-badge.tsxrename to components/app/projects/settings/plan-badge.tsxdiff --git a/components/app/settings/plan-usage.tsx b/components/app/projects/settings/plan-usage.tsxsimilarity index 100%rename from components/app/settings/plan-usage.tsxrename to components/app/projects/settings/plan-usage.tsxdiff --git a/components/app/settings/project-name.tsx b/components/app/settings/project-name.tsxdeleted file mode 100644index 452bea3d4e..0000000000--- a/components/app/settings/project-name.tsx+++ /dev/null@@ -1,86 +0,0 @@-import { useRouter } from "next/router";-import { useEffect, useMemo, useState } from "react";-import { toast } from "sonner";-import { LoadingDots } from "#/ui/icons";-import useProject from "@/lib/swr/use-project";-import { mutate } from "swr";--export default function ProjectName() {- const router = useRouter();- const { slug } = router.query as { slug: string };-- const { name } = useProject();- const [newName, setNewName] = useState<string | undefined | null>(null);- useEffect(() => {- setNewName(name);- }, [name]);- const [saving, setSaving] = useState(false);- const saveDisabled = useMemo(() => {- return saving || !newName || newName === name;- }, [saving, newName, name]);-- return (- <form- onSubmit={(e) => {- e.preventDefault();- setSaving(true);- fetch(`/api/projects/${slug}`, {- method: "PUT",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- name: newName,- }),- }).then(async (res) => {- setSaving(false);- if (res.status === 200) {- mutate("/api/projects");- mutate(`/api/projects/${slug}`);- toast.success("Successfully updated project name!");- }- });- }}- className="rounded-lg border border-gray-200 bg-white"- >- <div className="relative flex flex-col space-y-3 p-5 sm:p-10">- <h2 className="text-xl font-medium">Project Name</h2>- <div className="flex items-center space-x-1">- <p className="text-sm text-gray-500">- This is the name of your project on Dub.- </p>- </div>- <div />- {newName ? (- <input- type="text"- name="project-name"- id="project-name"- placeholder="Dub"- required- value={newName}- onChange={(e) => setNewName(e.target.value)}- className="w-full max-w-md rounded-md border border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"- />- ) : (- <div className="h-[2.35rem] w-full max-w-md animate-pulse rounded-md bg-gray-200" />- )}- </div>-- <div className="border-b border-gray-200" />-- <div className="px-5 py-4 sm:flex sm:items-center sm:justify-end sm:px-10">- <button- disabled={saveDisabled}- className={`${- saveDisabled- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"- : "border-black bg-black text-white hover:bg-white hover:text-black"- } h-9 w-full rounded-md border text-sm transition-all duration-150 ease-in-out focus:outline-none sm:w-32`}- >- {saving ? <LoadingDots /> : "Save Changes"}- </button>- </div>- </form>- );-}diff --git a/components/app/settings/project-slug.tsx b/components/app/settings/project-slug.tsxdeleted file mode 100644index ce74d6bd3f..0000000000--- a/components/app/settings/project-slug.tsx+++ /dev/null@@ -1,88 +0,0 @@-import { useRouter } from "next/router";-import { useEffect, useMemo, useState } from "react";-import { toast } from "sonner";-import { LoadingDots } from "#/ui/icons";-import { mutate } from "swr";--export default function ProjectSlug() {- const router = useRouter();- const { slug } = router.query as { slug: string };-- const [newSlug, setNewSlug] = useState<string | undefined | null>(null);- useEffect(() => {- setNewSlug(slug);- }, [slug]);- const [saving, setSaving] = useState(false);- const saveDisabled = useMemo(() => {- return saving || !newSlug || newSlug === slug;- }, [saving, newSlug, slug]);-- return (- <form- onSubmit={(e) => {- e.preventDefault();- setSaving(true);- fetch(`/api/projects/${slug}`, {- method: "PUT",- headers: {- "Content-Type": "application/json",- },- body: JSON.stringify({- newSlug,- }),- }).then(async (res) => {- setSaving(false);- if (res.status === 200) {- mutate("/api/projects");- router.push(`/${newSlug}/settings`);- toast.success("Successfully updated project slug!");- } else if (res.status === 422) {- toast.error("Project slug already exists");- } else {- toast.error("Something went wrong");- }- });- }}- className="rounded-lg border border-gray-200 bg-white"- >- <div className="relative flex flex-col space-y-3 p-5 sm:p-10">- <h2 className="text-xl font-medium">Project Slug</h2>- <div className="flex items-center space-x-1">- <p className="text-sm text-gray-500">- This is your project's URL slug on Dub.- </p>- </div>- <div />- {newSlug ? (- <input- type="text"- name="project-slug"- id="project-slug"- placeholder="dub"- required- value={newSlug}- onChange={(e) => setNewSlug(e.target.value)}- className="w-full max-w-md rounded-md border border-gray-300 text-sm text-gray-900 placeholder-gray-300 focus:border-gray-500 focus:outline-none focus:ring-gray-500"- />- ) : (- <div className="h-[2.35rem] w-full max-w-md animate-pulse rounded-md bg-gray-200" />- )}- </div>-- <div className="border-b border-gray-200" />-- <div className="px-5 py-4 sm:flex sm:items-center sm:justify-end sm:px-10">- <button- disabled={saveDisabled}- className={`${- saveDisabled- ? "cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400"- : "border-black bg-black text-white hover:bg-white hover:text-black"- } h-9 w-full rounded-md border text-sm transition-all duration-150 ease-in-out focus:outline-none sm:w-32`}- >- {saving ? <LoadingDots /> : "Save Changes"}- </button>- </div>- </form>- );-}diff --git a/components/layout/app/index.tsx b/components/layout/app/index.tsxindex 84347a3f05..c613929585 100644--- a/components/layout/app/index.tsx+++ b/components/layout/app/index.tsx@@ -80,11 +80,13 @@ export default function AppLayout({</Link><Divider className="h-8 w-8 text-gray-200 sm:ml-3" /><ProjectSelect />- {key && slug && (+ {key && (<><Divider className="h-8 w-8 text-gray-200 sm:mr-3" /><Link- href={`/${slug}/links/${key}`}+ href={+ slug ? `/${slug}/${domain}/${key}` : `/links/${key}`+ }className="text-sm font-medium">{domain || "dub.sh"}/{key}diff --git a/components/layout/app/nav-tabs.tsx b/components/layout/app/nav-tabs.tsxindex 8643dcd2f8..35c64529b3 100644--- a/components/layout/app/nav-tabs.tsx+++ b/components/layout/app/nav-tabs.tsx@@ -23,7 +23,7 @@ const TabsHelper = (router: NextRouter): { name: string; href: string }[] => {return [{ name: "Projects", href: `/` },{ name: "Dub.sh Links", href: `/links` },- // { name: "Settings", href: `/settings` },+ { name: "Settings", href: `/settings` },];};diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsxindex 2d9b45ff37..a55b81fd89 100644--- a/components/layout/app/project-select.tsx+++ b/components/layout/app/project-select.tsx@@ -6,16 +6,19 @@ import { ChevronUpDown, PlusCircle, Tick } from "@/components/shared/icons";import Popover from "@/components/shared/popover";import { PlanProps, ProjectWithDomainProps } from "@/lib/types";import useProjects from "@/lib/swr/use-projects";-import PlanBadge from "@/components/app/settings/plan-badge";+import PlanBadge from "@/components/app/projects/settings/plan-badge";import { GOOGLE_FAVICON_URL } from "@/lib/constants";import { ModalContext } from "#/ui/modal-provider";+import Link from "next/link";+import { truncate } from "@/lib/utils";export default function ProjectSelect() {const { projects } = useProjects();const router = useRouter();- const { slug } = router.query as {+ const { slug, key } = router.query as {slug?: string;+ key?: string;};const { data: session } = useSession();@@ -42,6 +45,7 @@ export default function ProjectSelect() {};}}, [slug, projects, session]) as {+ id?: string;name: string;slug: string;image: string;@@ -52,7 +56,9 @@ export default function ProjectSelect() {if (!projects || !router.isReady)return (- <div className="flex h-12 w-32 animate-pulse items-center justify-end rounded-lg bg-gray-100 px-2 sm:w-60">+ <div className="flex animate-pulse items-center justify-end space-x-1.5 rounded-lg px-1.5 py-2 sm:w-60">+ <div className="h-8 w-8 animate-pulse rounded-full bg-gray-200" />+ <div className="hidden h-8 w-28 animate-pulse rounded-md bg-gray-200 sm:block sm:w-40" /><ChevronUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" /></div>);@@ -66,20 +72,26 @@ export default function ProjectSelect() {><buttononClick={() => setOpenPopover(!openPopover)}- className="flex w-60 items-center justify-between rounded-lg bg-white p-1.5 text-left text-sm transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200"+ className="flex items-center justify-between rounded-lg bg-white p-1.5 text-left text-sm transition-all duration-75 hover:bg-gray-100 focus:outline-none active:bg-gray-200 sm:w-60"><div className="flex items-center space-x-3 pr-2"><BlurImagesrc={selected.image}- alt={selected.slug}- className="h-6 w-6 flex-none overflow-hidden rounded-full sm:h-8 sm:w-8"+ alt={selected.id || selected.name}+ className="h-8 w-8 flex-none overflow-hidden rounded-full"width={48}height={48}/>- <span className="truncate text-sm font-medium">- {selected.name}- </span>- {selected.slug !== "/" && <PlanBadge plan={selected.plan} />}+ <div+ className={`${+ key ? "hidden" : "flex"+ } items-center space-x-3 sm:flex`}+ >+ <span className="whitespace-nowrap text-sm font-medium">+ {truncate(selected.name, 12)}+ </span>+ {selected.slug !== "/" && <PlanBadge plan={selected.plan} />}+ </div></div><ChevronUpDown className="h-4 w-4 text-gray-400" aria-hidden="true" /></button>@@ -100,19 +112,18 @@ function ProjectList({};projects: ProjectWithDomainProps[];}) {- const router = useRouter();const { data: session } = useSession();const { setShowAddProjectModal } = useContext(ModalContext);return (<div className="relative mt-1 max-h-72 w-full space-y-0.5 overflow-auto rounded-md bg-white p-2 text-base sm:w-60 sm:text-sm sm:shadow-lg"><div className="p-2 text-xs text-gray-500">Personal Account</div>- <button+ <Linkkey="personal"className={`relative flex w-full items-center space-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${selected.slug === "/" ? "font-medium" : ""} transition-all duration-75`}- onClick={() => router.push("/links")}+ href="/links"><BlurImagesrc={@@ -138,19 +149,19 @@ function ProjectList({<Tick className="h-5 w-5" aria-hidden="true" /></span>) : null}- </button>+ </Link><div className="p-2 text-xs text-gray-500">Custom Projects</div>- {projects.map(({ name, slug, logo, primaryDomain }) => (- <button+ {projects.map(({ id, name, slug, logo, primaryDomain }) => (+ <Linkkey={slug}className={`relative flex w-full items-center space-x-2 rounded-md px-2 py-1.5 hover:bg-gray-100 active:bg-gray-200 ${selected.slug === slug ? "font-medium" : ""} transition-all duration-75`}- onClick={() => router.push(`/${slug}`)}+ href={`/${slug}`}><BlurImagesrc={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}- alt={slug}+ alt={id}className="h-7 w-7 overflow-hidden rounded-full"width={48}height={48}@@ -167,7 +178,7 @@ function ProjectList({<Tick className="h-5 w-5" aria-hidden="true" /></span>) : null}- </button>+ </Link>))}<buttonkey="add"diff --git a/components/app/settings/layout.tsx b/components/layout/app/settings-layout.tsxsimilarity index 82%rename from components/app/settings/layout.tsxrename to components/layout/app/settings-layout.tsxindex 50ad176a59..58a0a89b32 100644--- a/components/app/settings/layout.tsx+++ b/components/layout/app/settings-layout.tsx@@ -13,16 +13,20 @@ export default function SettingsLayout({ children }: { children: ReactNode }) {const tabs = [{name: "General",- href: `/${slug}/settings`,- },- {- name: "Billing",- href: `/${slug}/settings/billing`,- },- {- name: "People",- href: `/${slug}/settings/people`,+ href: slug ? `/${slug}/settings` : "/settings",},+ ...(slug+ ? [+ {+ name: "Billing",+ href: `/${slug}/settings/billing`,+ },+ {+ name: "People",+ href: `/${slug}/settings/people`,+ },+ ]+ : []),];return (diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsxindex 18abca9783..86f725aa6e 100644--- a/components/layout/app/user-dropdown.tsx+++ b/components/layout/app/user-dropdown.tsx@@ -5,6 +5,8 @@ import Popover from "@/components/shared/popover";import IconMenu from "../../shared/icon-menu";import Image from "next/image";import va from "@vercel/analytics";+import Link from "next/link";+import { Settings } from "lucide-react";export default function UserDropdown() {const { data: session } = useSession();@@ -14,9 +16,18 @@ export default function UserDropdown() {<div className="relative inline-block text-left"><Popovercontent={- <div className="w-full rounded-md bg-white p-1 sm:w-56">+ <div className="w-full rounded-md bg-white p-2 sm:w-52">+ <Link+ href="/settings"+ className="block w-full rounded-md p-2 text-left text-sm transition-all duration-75 hover:bg-gray-100"+ >+ <IconMenu+ text="Settings"+ icon={<Settings className="h-4 w-4" />}+ />+ </Link><button- className="relative w-full rounded-md p-2 text-left text-sm transition-all duration-75 hover:bg-gray-100"+ className="w-full rounded-md p-2 text-left text-sm transition-all duration-75 hover:bg-gray-100"onClick={() => {signOut();// track logout eventdiff --git a/components/shared/icons/google.tsx b/components/shared/icons/google.tsxnew file mode 100644index 0000000000..1523a3e55d--- /dev/null+++ b/components/shared/icons/google.tsx@@ -0,0 +1,12 @@+export default function Google({ className }: { className?: string }) {+ return (+ <svg+ xmlns="http://www.w3.org/2000/svg"+ viewBox="0 0 488 512"+ fill="currentColor"+ className={className}+ >+ <path d="M488 261.8C488 403.3 391.1 504 248 504 110.8 504 0 393.2 0 256S110.8 8 248 8c66.8 0 123 24.5 166.3 64.9l-67.5 64.9C258.5 52.6 94.3 116.6 94.3 256c0 86.5 69.1 156.6 153.7 156.6 98.2 0 135-70.4 140.8-106.9H248v-85.3h236.1c2.3 12.7 3.9 24.9 3.9 41.4z" />+ </svg>+ );+}diff --git a/components/shared/icons/index.tsx b/components/shared/icons/index.tsxindex 1c2e685e9c..3eb06e4e1e 100644--- a/components/shared/icons/index.tsx+++ b/components/shared/icons/index.tsx@@ -49,3 +49,4 @@ export { default as Heart } from "./heart";export { default as Repeat } from "./repeat";export { default as Message } from "./message";export { default as Share } from "./share";+export { default as Google } from "./google";diff --git a/lib/constants/index.ts b/lib/constants/index.tsindex 8dbaa12c54..07cc8fd92a 100644--- a/lib/constants/index.ts+++ b/lib/constants/index.ts@@ -34,7 +34,6 @@ export const FADE_IN_ANIMATION_SETTINGS = {export const HOME_HOSTNAMES = new Set([// comment for better diffs"dub.sh",- "localhost","localhost:3000",]);diff --git a/next.config.js b/next.config.jsindex 7f65b37bd1..62c3944911 100644--- a/next.config.js+++ b/next.config.js@@ -12,7 +12,7 @@ const nextConfig = {"res.cloudinary.com","pbs.twimg.com","d2vwwcvoksz7ty.cloudfront.net",- "media.cleanshot.cloud",+ "lh3.googleusercontent.com",],},async headers() {diff --git a/package.json b/package.jsonindex bf1f657407..782b4d446e 100644--- a/package.json+++ b/package.json@@ -56,7 +56,7 @@"lucide-react": "^0.192.0","mailing-core": "^0.9.1","ms": "^2.1.3",- "next": "^13.4.4-canary.12",+ "next": "^13.4.5-canary.0","next-auth": "^4.22.1","next-contentlayer": "^0.3.2","node-html-parser": "^6.1.4",diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsxindex 7ce85ec490..f945afe11c 100644--- a/pages/api/auth/[...nextauth].tsx+++ b/pages/api/auth/[...nextauth].tsx@@ -4,6 +4,7 @@ import LoginLink from "emails/LoginLink";import WelcomeEmail from "emails/WelcomeEmail";import NextAuth, { type NextAuthOptions } from "next-auth";import EmailProvider from "next-auth/providers/email";+import GoogleProvider from "next-auth/providers/google";import prisma from "@/lib/prisma";import { isBlacklistedEmail } from "@/lib/utils";@@ -20,6 +21,11 @@ export const authOptions: NextAuthOptions = {});},}),+ GoogleProvider({+ clientId: process.env.GOOGLE_CLIENT_ID as string,+ clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,+ allowDangerousEmailAccountLinking: true,+ }),],adapter: PrismaAdapter(prisma),session: { strategy: "jwt" },@@ -36,19 +42,42 @@ export const authOptions: NextAuthOptions = {},},},+ pages: {+ newUser: "/welcome",+ },callbacks: {- signIn: async ({ user }) => {+ signIn: async ({ user, account, profile }) => {if (!user.email || (await isBlacklistedEmail(user.email))) {return false;}+ if (account?.provider === "google") {+ // update the user entry with the name and image+ await prisma.user.update({+ where: { email: user.email },+ data: {+ name: profile?.name,+ // @ts-ignore - this is a bug in the types, `picture` is a valid on the `Profile` type+ image: profile?.picture,+ },+ });+ }return true;},- jwt: async ({ token, account }) => {+ jwt: async ({ token, user, trigger, session }) => {if (!token.email || (await isBlacklistedEmail(token.email))) {return {};}- if (account) {- token.accessToken = account.access_token;+ if (user) {+ token.user = user;+ }+ if (trigger === "update") {+ const refreshedUser = await prisma.user.findUnique({+ where: { id: token.sub },+ });+ token.user = refreshedUser;+ token.name = refreshedUser?.name;+ token.email = refreshedUser?.email;+ token.image = refreshedUser?.image;}return token;},diff --git a/pages/api/projects/[slug]/index.ts b/pages/api/projects/[slug]/index.tsindex c07a810be6..e3b95aa55b 100644--- a/pages/api/projects/[slug]/index.ts+++ b/pages/api/projects/[slug]/index.ts@@ -9,7 +9,7 @@ export default withProjectAuth(async (req, res, project) => {// PUT /api/projects/[slug] – edit a specific project} else if (req.method === "PUT") {- const { name, newSlug } = req.body;+ const { name, slug } = req.body;try {const response = await prisma.project.update({where: {@@ -17,13 +17,13 @@ export default withProjectAuth(async (req, res, project) => {},data: {...(name && { name }),- ...(newSlug && { slug: newSlug }),+ ...(slug && { slug }),},});return res.status(200).json(response);} catch (error) {if (error.code === "P2002") {- return res.status(422).json({ error: "Key already exists" });+ return res.status(422).end("Project slug already exists.");}}// DELETE /api/projects/[slug] – delete a projectdiff --git a/pages/api/user/index.ts b/pages/api/user/index.tsnew file mode 100644index 0000000000..c385d60116--- /dev/null+++ b/pages/api/user/index.ts@@ -0,0 +1,29 @@+import { withUserAuth } from "@/lib/auth";+import prisma from "@/lib/prisma";++export default withUserAuth(async (req, res, session) => {+ // PUT /api/user – edit a specific user+ if (req.method === "PUT") {+ const { name, email, image } = req.body;+ try {+ const response = await prisma.user.update({+ where: {+ id: session.user.id,+ },+ data: {+ ...(name && { name }),+ ...(email && { email }),+ ...(image && { image }),+ },+ });+ return res.status(200).json(response);+ } catch (error) {+ if (error.code === "P2002") {+ return res.status(422).end("Email is already in use.");+ }+ }+ } else {+ res.setHeader("Allow", ["PUT"]);+ return res.status(405).json({ error: `Method ${req.method} Not Allowed` });+ }+});diff --git a/pages/app/[slug]/[domain]/[key].tsx b/pages/app/[slug]/[domain]/[key].tsxindex c8fbae759d..bfa069625c 100644--- a/pages/app/[slug]/[domain]/[key].tsx+++ b/pages/app/[slug]/[domain]/[key].tsx@@ -1,4 +1,3 @@-import ErrorPage from "next/error";import Link from "next/link";import AppLayout from "@/components/layout/app";import BlurImage from "#/ui/blur-image";@@ -8,12 +7,8 @@ import Stats from "@/components/stats";import useProject from "@/lib/swr/use-project";export default function StatsPage() {- const { slug, exceededUsage, error } = useProject();+ const { slug, exceededUsage } = useProject();- // handle error page- if (error && error.status === 404) {- return <ErrorPage statusCode={404} />;- }return (<AppLayout>{exceededUsage && (diff --git a/pages/app/[slug]/domains.tsx b/pages/app/[slug]/domains.tsxindex 6a0f659105..d40c2ec831 100644--- a/pages/app/[slug]/domains.tsx+++ b/pages/app/[slug]/domains.tsx@@ -1,4 +1,3 @@-import ErrorPage from "next/error";import { useAddEditDomainModal } from "@/components/app/modals/add-edit-domain-modal";import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import AppLayout from "components/layout/app";@@ -9,14 +8,10 @@ import DomainCardPlaceholder from "@/components/app/domains/domain-card-placeholimport NoDomainsPlaceholder from "@/components/app/domains/no-domains-placeholder";export default function ProjectDomains() {- const { id: projectId, error } = useProject();+ const { id: projectId } = useProject();const { AddEditDomainModal, AddEditDomainButton } = useAddEditDomainModal();- if (error && error.status === 404) {- return <ErrorPage statusCode={404} />;- }-const { domains } = useDomains();return (diff --git a/pages/app/[slug]/index.tsx b/pages/app/[slug]/index.tsxindex 3eb0fc1346..57bb3af2e9 100644--- a/pages/app/[slug]/index.tsx+++ b/pages/app/[slug]/index.tsx@@ -4,7 +4,6 @@ import MaxWidthWrapper from "@/components/shared/max-width-wrapper";import AppLayout from "components/layout/app";import useProject from "@/lib/swr/use-project";import { useEffect } from "react";-import ErrorPage from "next/error";import { useCompleteSetupModal } from "@/components/app/modals/complete-setup-modal";import useDomains from "@/lib/swr/use-domains";@@ -26,10 +25,6 @@ export default function ProjectLinks() {}}, [verified, loading, error]);- if (error && error.status === 404) {- return <ErrorPage statusCode={404} />;- }-return (<AppLayout>{slug && <AddEditLinkModal />}diff --git a/pages/app/[slug]/settings/billing.tsx b/pages/app/[slug]/settings/billing.tsxindex 840326caf2..6ab17a7fef 100644--- a/pages/app/[slug]/settings/billing.tsx+++ b/pages/app/[slug]/settings/billing.tsx@@ -1,5 +1,5 @@-import SettingsLayout from "@/components/app/settings/layout";-import PlanUsage from "@/components/app/settings/plan-usage";+import SettingsLayout from "@/components/layout/app/settings-layout";+import PlanUsage from "@/components/app/projects/settings/plan-usage";export default function ProjectBilling() {return (diff --git a/pages/app/[slug]/settings/index.tsx b/pages/app/[slug]/settings/index.tsxindex 5228b5f4fa..af7bfb7519 100644--- a/pages/app/[slug]/settings/index.tsx+++ b/pages/app/[slug]/settings/index.tsx@@ -1,13 +1,80 @@-import DeleteProject from "@/components/app/settings/delete-project";-import ProjectName from "@/components/app/settings/project-name";-import SettingsLayout from "@/components/app/settings/layout";-import ProjectSlug from "@/components/app/settings/project-slug";+import SettingsLayout from "@/components/layout/app/settings-layout";+import Form from "#/ui/form";+import useProject from "@/lib/swr/use-project";+import DeleteProject from "@/components/app/projects/settings/delete-project";+import { toast } from "sonner";+import { mutate } from "swr";+import { useRouter } from "next/router";export default function ProjectSettingsGeneral() {+ const router = useRouter();+ const { name, slug } = useProject();+return (<SettingsLayout>- <ProjectName />- <ProjectSlug />+ <Form+ title="Project Name"+ description="This is the name of your project on Dub."+ inputData={{+ name: "name",+ defaultValue: name,+ placeholder: "My Project",+ maxLength: 32,+ }}+ helpText="Max 32 characters,"+ handleSubmit={(updateData) =>+ fetch(`/api/projects/${slug}`, {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(updateData),+ }).then(async (res) => {+ if (res.status === 200) {+ mutate("/api/projects");+ mutate(`/api/projects/${slug}`);+ toast.success("Successfully updated project name!");+ } else if (res.status === 422) {+ toast.error("Project slug already exists");+ } else {+ const errorMessage = await res.text();+ toast.error(errorMessage || "Something went wrong");+ }+ })+ }+ />+ <Form+ title="Project Slug"+ description="This is your project's URL slug on Dub."+ inputData={{+ name: "slug",+ defaultValue: slug,+ placeholder: "my-project",+ pattern: "^[a-z0-9-]+$",+ maxLength: 48,+ }}+ helpText="Only lowercase letters, numbers, and dashes. Max 48 characters."+ handleSubmit={(data) =>+ fetch(`/api/projects/${slug}`, {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(data),+ }).then(async (res) => {+ if (res.status === 200) {+ const { slug: newSlug } = await res.json();+ mutate("/api/projects");+ router.push(`/${newSlug}/settings`);+ toast.success("Successfully updated project slug!");+ } else if (res.status === 422) {+ toast.error("Project slug already exists");+ } else {+ toast.error("Something went wrong");+ }+ })+ }+ /><DeleteProject /></SettingsLayout>);diff --git a/pages/app/[slug]/settings/people.tsx b/pages/app/[slug]/settings/people.tsxindex 7aa37cc5d9..6b985b3dec 100644--- a/pages/app/[slug]/settings/people.tsx+++ b/pages/app/[slug]/settings/people.tsx@@ -1,4 +1,4 @@-import SettingsLayout from "@/components/app/settings/layout";+import SettingsLayout from "@/components/layout/app/settings-layout";import { useInviteTeammateModal } from "components/app/modals/invite-teammate-modal";import { useState } from "react";import { useRouter } from "next/router";diff --git a/pages/app/login.tsx b/pages/app/login.tsxindex 5b8cd82924..eb5d69ae12 100644--- a/pages/app/login.tsx+++ b/pages/app/login.tsx@@ -3,20 +3,23 @@ import { useState } from "react";import { signIn } from "next-auth/react";import Meta from "@/components/layout/meta";import BlurImage from "#/ui/blur-image";-import { LoadingDots } from "#/ui/icons";import Background from "@/components/shared/background";import { toast } from "sonner";+import Button from "#/ui/button";+import { Google } from "@/components/shared/icons";export default function Login() {- const [signInClicked, setSignInClicked] = useState(false);+ const [showEmailOption, setShowEmailOption] = useState(false);const [noSuchAccount, setNoSuchAccount] = useState(false);const [email, setEmail] = useState("");+ const [clickedGoogle, setClickedGoogle] = useState(false);+ const [clickedEmail, setClickedEmail] = useState(false);return (- <div className="flex h-screen w-screen items-center justify-center bg-gray-50">+ <div className="flex h-screen w-screen justify-center"><Meta title="Sign in to Dub" /><Background />- <div className="z-10 w-full max-w-md overflow-hidden rounded-2xl border border-gray-100 shadow-xl">+ <div className="z-10 mt-[calc(30vh)] h-fit w-full max-w-md overflow-hidden border border-gray-100 sm:rounded-2xl sm:shadow-xl"><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16"><a href="https://dub.sh"><BlurImage@@ -27,81 +30,100 @@ export default function Login() {height={20}/></a>- <h3 className="text-xl font-semibold">Sign In</h3>+ <h3 className="text-xl font-semibold">Sign in to Dub</h3><p className="text-sm text-gray-500">- Use your email address to sign in.+ Start creating short links with superpowers.</p></div>- <form- onSubmit={async (e) => {- e.preventDefault();- setSignInClicked(true);- fetch("/api/auth/account-exists", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ email }),- })- .then(async (res) => {- const { exists } = await res.json();- if (exists) {- signIn("email", {- email,- redirect: false,- }).then((res) => {- setSignInClicked(false);- if (res?.ok && !res?.error) {- setEmail("");- toast.success("Email sent - check your inbox!");- } else {- toast.error("Error sending email - try again?");- }- });- } else {- setNoSuchAccount(true);- setSignInClicked(false);- }+ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16">+ <Button+ text="Continue with Google"+ onClick={() => {+ setClickedGoogle(true);+ signIn("google");+ }}+ loading={clickedGoogle}+ disabled={clickedEmail}+ icon={<Google className="h-4 w-4" />}+ />+ <form+ onSubmit={async (e) => {+ e.preventDefault();+ setClickedEmail(true);+ fetch("/api/auth/account-exists", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ email }),})- .catch(() => {- setSignInClicked(false);- toast.error("Error sending email - try again?");- });- }}- className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16"- >- <div>- <label htmlFor="email" className="block text-xs text-gray-600">- EMAIL ADDRESS- </label>- <input- id="email"- name="email"- type="email"- placeholder="[email protected]"- autoComplete="email"- required- value={email}- onChange={(e) => {- setNoSuchAccount(false);- setEmail(e.target.value);- }}- 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- disabled={signInClicked}- className={`${- signInClicked- ? "cursor-not-allowed border-gray-200 bg-gray-100"- : "border-black bg-black text-white hover:bg-white hover:text-black"- } flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none`}+ .then(async (res) => {+ const { exists } = await res.json();+ if (exists) {+ signIn("email", {+ email,+ redirect: false,+ }).then((res) => {+ setClickedEmail(false);+ if (res?.ok && !res?.error) {+ setEmail("");+ toast.success("Email sent - check your inbox!");+ } else {+ toast.error("Error sending email - try again?");+ }+ });+ } else {+ toast.error("No account found with that email address.");+ setNoSuchAccount(true);+ setClickedEmail(false);+ }+ })+ .catch(() => {+ setClickedEmail(false);+ toast.error("Error sending email - try again?");+ });+ }}+ className="flex flex-col space-y-4">- {signInClicked ? (- <LoadingDots color="#808080" />- ) : (- <p>Send magic link</p>+ {showEmailOption && (+ <div>+ <div className="mb-6 mt-2 border-t border-gray-300" />+ <input+ id="email"+ name="email"+ autoFocus+ type="email"+ placeholder="[email protected]"+ autoComplete="email"+ required+ value={email}+ onChange={(e) => {+ setNoSuchAccount(false);+ setEmail(e.target.value);+ }}+ 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>- {noSuchAccount ? (+ <Button+ text="Continue with Email"+ variant="secondary"+ {...(!showEmailOption && {+ type: "button",+ onClick: (e) => {+ e.preventDefault();+ setShowEmailOption(true);+ },+ })}+ loading={clickedEmail}+ disabled={clickedGoogle}+ />+ </form>+ <Button+ text="Continue with SAML SSO"+ disabled+ disabledTooltip="SAML/SSO is coming soon"+ />++ {noSuchAccount && (<p className="text-center text-sm text-red-500">No such account.{" "}<Link href="/register" className="font-semibold text-red-600">@@ -109,16 +131,8 @@ export default function Login() {</Link>{" "}instead?</p>- ) : (- <p className="text-center text-sm text-gray-600">- Don't have an account?{" "}- <Link href="/register" className="font-semibold text-gray-800">- Sign up- </Link>{" "}- for free.- </p>)}- </form>+ </div></div></div>);diff --git a/pages/app/register.tsx b/pages/app/register.tsxindex 461134c526..6f2df82d8c 100644--- a/pages/app/register.tsx+++ b/pages/app/register.tsx@@ -1,23 +1,19 @@-import Link from "next/link";import { useState } from "react";import { signIn } from "next-auth/react";import Meta from "@/components/layout/meta";import BlurImage from "#/ui/blur-image";-import { LoadingDots } from "#/ui/icons";import Background from "@/components/shared/background";-import { toast } from "sonner";-import va from "@vercel/analytics";+import { Google } from "@/components/shared/icons";+import Button from "#/ui/button";-export default function Login() {- const [signInClicked, setSignInClicked] = useState(false);- const [accountExists, setAccountExists] = useState(false);- const [email, setEmail] = useState("");+export default function Register() {+ const [clickedGoogle, setClickedGoogle] = useState(false);return (- <div className="flex h-screen w-screen items-center justify-center bg-gray-50">+ <div className="flex h-screen w-screen justify-center bg-gray-50"><Meta title="Sign up for Dub" /><Background />- <div className="z-10 w-full max-w-md overflow-hidden rounded-2xl border border-gray-100 shadow-xl">+ <div className="z-10 mt-[calc(30vh)] h-fit w-full max-w-md overflow-hidden border border-gray-100 sm:rounded-2xl sm:shadow-xl"><div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16"><BlurImagesrc="/_static/logo.png"@@ -26,101 +22,28 @@ export default function Login() {width={20}height={20}/>- <h3 className="text-xl font-semibold">Sign Up</h3>+ <h3 className="text-xl font-semibold">Create your Dub account</h3><p className="text-sm text-gray-500">Get started for free. No credit card required.</p></div>- <form- onSubmit={async (e) => {- e.preventDefault();- setSignInClicked(true);- fetch("/api/auth/account-exists", {- method: "POST",- headers: { "Content-Type": "application/json" },- body: JSON.stringify({ email }),- })- .then(async (res) => {- const { exists } = await res.json();- if (!exists) {- signIn("email", {- email,- redirect: false,- callbackUrl: "/welcome",- }).then((res) => {- setSignInClicked(false);- if (res?.ok && !res?.error) {- setEmail("");- toast.success("Email sent - check your inbox!");- // track signup event- va.track("Sign Up");- } else {- toast.error("Error sending email - try again?");- }- });- } else {- setAccountExists(true);- setSignInClicked(false);- }- })- .catch(() => {- setSignInClicked(false);- toast.error("Error sending email - try again?");- });- }}- className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16"- >- <div>- <label htmlFor="email" className="block text-xs text-gray-600">- EMAIL ADDRESS- </label>- <input- id="email"- name="email"- type="email"- placeholder="[email protected]"- autoComplete="email"- required- value={email}- onChange={(e) => {- setAccountExists(false);- setEmail(e.target.value);- }}- 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- disabled={signInClicked}- className={`${- signInClicked- ? "cursor-not-allowed border-gray-200 bg-gray-100"- : "border-black bg-black text-white hover:bg-white hover:text-black"- } flex h-10 w-full items-center justify-center rounded-md border text-sm transition-all focus:outline-none`}- >- {signInClicked ? (- <LoadingDots color="#808080" />- ) : (- <p>Send magic link</p>- )}- </button>- {accountExists ? (- <p className="text-center text-sm text-red-500">- This email is already registered.{" "}- <Link href="/login" className="font-semibold text-red-600">- Log in- </Link>{" "}- instead?- </p>- ) : (- <p className="text-center text-sm text-gray-600">- Already registered?{" "}- <Link href="/login" className="font-semibold text-gray-800">- Sign in- </Link>{" "}- to your account.- </p>- )}- </form>++ <div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 sm:px-16">+ <Button+ text="Continue with Google"+ onClick={() => {+ setClickedGoogle(true);+ signIn("google");+ }}+ loading={clickedGoogle}+ icon={<Google className="h-4 w-4" />}+ />+ <Button+ text="Continue with SAML SSO"+ disabled+ disabledTooltip="SAML/SSO is coming soon"+ />+ </div></div></div>);diff --git a/pages/app/settings.tsx b/pages/app/settings.tsxindex 2a09160840..cfd8fff62b 100644--- a/pages/app/settings.tsx+++ b/pages/app/settings.tsx@@ -1,16 +1,67 @@-import MaxWidthWrapper from "@/components/shared/max-width-wrapper";-import AppLayout from "components/layout/app";+import Form from "#/ui/form";+import SettingsLayout from "@/components/layout/app/settings-layout";+import { useSession } from "next-auth/react";+import { toast } from "sonner";-export default function Settings() {+export default function PersonalSettings() {+ const { data: session, update } = useSession();return (- <AppLayout>- <div className="flex h-36 items-center border-b border-gray-200 bg-white">- <MaxWidthWrapper>- <div className="flex items-center justify-between">- <h1 className="text-2xl text-gray-600">Settings</h1>- </div>- </MaxWidthWrapper>- </div>- </AppLayout>+ <SettingsLayout>+ <Form+ title="Your Name"+ description="This will be your display name on Dub."+ inputData={{+ name: "name",+ defaultValue: session?.user?.name || undefined,+ placeholder: "Steve Jobs",+ maxLength: 32,+ }}+ helpText="Max 32 characters."+ handleSubmit={(data) =>+ fetch("/api/user", {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(data),+ }).then(async (res) => {+ if (res.status === 200) {+ update();+ toast.success("Successfully updated your name!");+ } else {+ const errorMessage = await res.text();+ toast.error(errorMessage || "Something went wrong");+ }+ })+ }+ />+ <Form+ title="Your Email"+ description="This will be the email you use to log in to Dub and receive notifications."+ inputData={{+ name: "email",+ defaultValue: session?.user?.email || undefined,+ placeholder: "[email protected]",+ }}+ helpText="Must be a valid email address."+ handleSubmit={(data) =>+ fetch("/api/user", {+ method: "PUT",+ headers: {+ "Content-Type": "application/json",+ },+ body: JSON.stringify(data),+ }).then(async (res) => {+ if (res.status === 200) {+ update();+ toast.success("Successfully updated your email!");+ } else {+ const errorMessage = await res.text();+ toast.error(errorMessage || "Something went wrong");+ }+ })+ }+ />+ </SettingsLayout>);}diff --git a/pages/app/welcome.tsx b/pages/app/welcome.tsxindex 69335912f8..a56f393195 100644--- a/pages/app/welcome.tsx+++ b/pages/app/welcome.tsx@@ -6,6 +6,7 @@ import { useEffect, useState } from "react";import { useAddProjectModal } from "@/components/app/modals/add-project-modal";import { useAddEditLinkModal } from "@/components/app/modals/add-edit-link-modal";import Meta from "@/components/layout/meta";+import va from "@vercel/analytics";export default function Welcome() {const [state, setState] = useState("intro");@@ -17,6 +18,10 @@ export default function Welcome() {hideXButton: true,});+ useEffect(() => {+ va.track("Sign Up");+ }, []);+useEffect(() => {if (state === "project") {setTimeout(() => {diff --git a/yarn.lock b/yarn.lockindex d539e7ef59..6a12e288f1 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.12"- resolved "https://registry.yarnpkg.com/@next/env/-/env-13.4.4-canary.12.tgz#150a6444ba687f7c9d6819afaaea85679b3b0fd9"- integrity sha512-eEahFkCCU1Ic7+2fh2Mls4MLLlvRYE5Bk6CAJ3qbP5ZiyP7eyPNDu9531k4350uH2he0mCsno3TluCEcPr6sdg==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/env/-/env-13.4.5-canary.0.tgz#1075fc632160b19a5f26d70f7225ebd04b16457a"+ integrity sha512-AxYfEv/Cl5GcOybahj9ASqTrvorM6Lfjabl97qycXtt75toEZiviF4iOL5MfUVdUSk0TKAnHEp8nAikQ3zdDwA=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.4-canary.12.tgz#d9e2268b0ec88f247c89ff33484d801ccc383da2"- integrity sha512-h4zP3h7S2NWAhxODSj+UL41oJnFREZCT1Bd/s4jaheFVrnMRJJKMPS5BIHJ9uHsE5YuBRS/o8TVdOis1a7uVNw==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.4.5-canary.0.tgz#b1abaf25ae0c06fa5aaf05ebe91fadfde1ccde18"+ integrity sha512-+cARsxYqFZGn2AHItl4OKlHleGm9ZeBiQnSFdbUA1aVdM6+rVBzAd11bnPEbGLg1BLXveVBu4fFfUWzdFcVeAA=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.4-canary.12.tgz#cf0b4af286f27e8ae332a29742269eaa014d554f"- integrity sha512-zBQRoJ/NVCPk3EhYDlvujDHnCeoMK2rA3rQ1KgdH37yVp30tOM3y2rnjtQRgglJDPxzgC0gIqHMw37F0Ylwjng==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-darwin-x64/-/swc-darwin-x64-13.4.5-canary.0.tgz#a0de92e19b5ad2ff3bb7b7b82c75eb531e8ec3ca"+ integrity sha512-anuwagsZ33bxWGBMXtlA+o9KxmYNAeQ7nSVLaWcwFR9jXL5KIgsE2F0B9IwQU0DVKfHe0njI6QHO5H3tGZfKYw=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.4-canary.12.tgz#918b7ff02d5e8414828d3a82673b93dc1afa87d9"- integrity sha512-ymV6OjCHfOFKMdptzKvkADLMQ2sEF8V10DF6WSfa1B6k/aJcQE7SwJ6A6ciqQRS1vH4Fao2QeNRCKAaodLA2pw==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.4.5-canary.0.tgz#204cb52591f83c7d056331299da990e82c17e796"+ integrity sha512-u+IZPjJ+mhlHuvYv4C0kaNx6AuNhpzMYwqUIzHocZtGT5HpQI6ePSXMDQAGYV1TvRJMva+dwR2X7iK0eCDLQHA=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.4-canary.12.tgz#71111e7c44ab98909f829a8c6e9c730698019f83"- integrity sha512-s7RnhNO+9bhwXkeqpSaQAFPvkfcClEoA5+WU0zQFDeXmyiNjA8KqOMVOl5lnrv7JOEhLJwz/pS5oKPV3RKCwOg==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.4.5-canary.0.tgz#a11d6bed15056e957c5f0865080d30cb7542fb92"+ integrity sha512-TX1plN/5sjeE9K5TBd/q0IttgGMy/BvVyDN1eiIyPKgaCKgFuagYDZQCqxduIeeolMf14oD1nyHDSUzEEfht7A=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.4-canary.12.tgz#4135e4c57a72ec0ce83dad3500192e817d7d9907"- integrity sha512-WFXeuEY5J5YS4+wWqeGWFrpU5qBxs5FMiQZqr4lyDII1zKalxZl90F1+RckkD/Ije1vObgZxfP6ebYccnkEx9w==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.4.5-canary.0.tgz#17a1edd4a093dd1aa002026685ae0a80a9d2523f"+ integrity sha512-4qKVelbVTG9bvxfe7eGEOQI3jElmazo0548B+EE6fPcgwVPiRG6vosSoDGl/z53jIcEvu8aWAcNzc0vUj/ysIg=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.4-canary.12.tgz#0fea3ad0531cd0b4032f93fc683f288be36bc12f"- integrity sha512-FY4QhZ2fAdFEk2qYZD+iajR2qDNh8/UuF1wJQOfhzaClBZ/aayQM2xdYZ33NblWsu8QKtfxXCKCOBfY32gr/8A==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.4.5-canary.0.tgz#eaacec52af4564feebe678f7fb7c0b8ec167dc1a"+ integrity sha512-mMk/irsWCv/FChc8WZEM6z10DiWYPI8USeBr2SeKZxRX+j2QoCgAcUgRQseM1thCjg7bZEHgB2VAD2CLx/IOyg=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.4-canary.12.tgz#6c74e3d017f1b0819926db083b041629f0e7db2f"- integrity sha512-K3l+tFQSRCEtMDYSzApOXt6NVOa8aEMV8g8tm/6GT1vuCih45shyd6Nu/QRIz59wXQlmxShS9cMJlC0M+kYzHA==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.4.5-canary.0.tgz#25bab7d860a61c8a68ec55f0cadc4dae6b542aa7"+ integrity sha512-xskP48A+Ay4dN32hYHuSePezmFUbgvp4j39IRtfRJp1tYL6S93KQGbhfe+KzUtOYK6MXc+W6mbS1tzHSyyK4Wg=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.4-canary.12.tgz#26d8bf5fef97f825ff2249b336d7f426a90679f7"- integrity sha512-nzrU/dDqBzvJyxU1N3U5XAKvvELDU4+/oLWSnMJT0nQ66r/hWelXWNM8n0CqoqnKyRZc1SrWzuaipGGCJiKhLQ==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.4.5-canary.0.tgz#1167724889864b2d422a529690476dd35f68e334"+ integrity sha512-uRq578wLxw+WE7L2H7wfD5kCcvylHxk8idZauy7nFRDP94SiLBYIyby2xxEpZ9FXzlEavyZiI98KEuKFIaL7cg=="@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.12"- resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.4-canary.12.tgz#4ea02f1859dfeb79585088322d0bf19a8288e131"- integrity sha512-nq/nTBnlnbJadj+lDZyWgIXWQtiPyKeenh0pvHbDd1SBGbT+tJWZE0BB91AN1P1b0894HHlOD8cBxc4+eGtEXA==+"@next/[email protected]":+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.4.5-canary.0.tgz#6fa7fd9bf9193b4af0d780e261145255d8eb5972"+ integrity sha512-JwTlmOroyn0LQi8MqOmZhdym+g03nCFrRw3zjheZcZDn25lOEyV6tLMcBbwn2qeVKqH9MYtY/ITHqHi5/oJoSA=="@nodelib/[email protected]":version "2.1.5"@@ -6862,12 +6862,12 @@ [email protected]:"@next/swc-win32-ia32-msvc" "13.1.6""@next/swc-win32-x64-msvc" "13.1.6"-next@^13.4.4-canary.12:- version "13.4.4-canary.12"- resolved "https://registry.yarnpkg.com/next/-/next-13.4.4-canary.12.tgz#3e19763efb821e1b3a1041449e8cde3b93fbbf32"- integrity sha512-93e0WDb1JXt5HCOdEa09b5Hn0QJVfTX9qUxCRnGasjK3+6Xe8lvEs/9CS7TwM7hdi3rd7at63aZUxZf/DkQBCw==+next@^13.4.5-canary.0:+ version "13.4.5-canary.0"+ resolved "https://registry.yarnpkg.com/next/-/next-13.4.5-canary.0.tgz#70c4863b49bd9168b7f1f392c881623e7e41cf6d"+ integrity sha512-cDH6PtaOZjkiRsPPPCrgkg2d9X/tLAaozOoCSYDVpdXnOk1hi8FYbtkGxxYexcTl1Bd2tVF6uixvi1uhktbmOQ==dependencies:- "@next/env" "13.4.4-canary.12"+ "@next/env" "13.4.5-canary.0""@swc/helpers" "0.5.1"busboy "1.6.0"caniuse-lite "^1.0.30001406"@@ -6875,15 +6875,15 @@ next@^13.4.4-canary.12:styled-jsx "5.1.1"zod "3.21.4"optionalDependencies:- "@next/swc-darwin-arm64" "13.4.4-canary.12"- "@next/swc-darwin-x64" "13.4.4-canary.12"- "@next/swc-linux-arm64-gnu" "13.4.4-canary.12"- "@next/swc-linux-arm64-musl" "13.4.4-canary.12"- "@next/swc-linux-x64-gnu" "13.4.4-canary.12"- "@next/swc-linux-x64-musl" "13.4.4-canary.12"- "@next/swc-win32-arm64-msvc" "13.4.4-canary.12"- "@next/swc-win32-ia32-msvc" "13.4.4-canary.12"- "@next/swc-win32-x64-msvc" "13.4.4-canary.12"+ "@next/swc-darwin-arm64" "13.4.5-canary.0"+ "@next/swc-darwin-x64" "13.4.5-canary.0"+ "@next/swc-linux-arm64-gnu" "13.4.5-canary.0"+ "@next/swc-linux-arm64-musl" "13.4.5-canary.0"+ "@next/swc-linux-x64-gnu" "13.4.5-canary.0"+ "@next/swc-linux-x64-musl" "13.4.5-canary.0"+ "@next/swc-win32-arm64-msvc" "13.4.5-canary.0"+ "@next/swc-win32-ia32-msvc" "13.4.5-canary.0"+ "@next/swc-win32-x64-msvc" "13.4.5-canary.0"no-case@^2.2.0:version "2.3.2"