Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Added user avatar to link card

Steven Tey4dfc74564968
diff --git a/app/ui/avatar.tsx b/app/ui/avatar.tsx
new file mode 100644
index 0000000000..622f496443
--- /dev/null
+++ b/app/ui/avatar.tsx
@@ -0,0 +1,35 @@
+import { cn } from "#/lib/utils";
+
+export default function Avatar({
+ user = {},
+ className,
+}: {
+ user?: {
+ name?: string | null | undefined;
+ email?: string | null | undefined;
+ image?: string | null | undefined;
+ };
+ className?: string;
+}) {
+ if (!user) {
+ return (
+ <div
+ className={cn(
+ "h-10 w-10 animate-pulse rounded-full border border-gray-300 bg-gray-100",
+ className,
+ )}
+ />
+ );
+ }
+
+ return (
+ <img
+ alt={`Avatar for ${user?.name || user?.email}`}
+ src={
+ user?.image ||
+ `https://avatars.dicebear.com/api/micah/${user?.email}.svg`
+ }
+ className={cn("h-10 w-10 rounded-full border border-gray-300", className)}
+ />
+ );
+}
diff --git a/app/ui/tooltip.tsx b/app/ui/tooltip.tsx
index 8d724ba9ef..58adb3550a 100644
--- a/app/ui/tooltip.tsx
+++ b/app/ui/tooltip.tsx
@@ -60,7 +60,7 @@ export default function Tooltip({
return (
<TooltipPrimitive.Provider delayDuration={100}>
<TooltipPrimitive.Root>
- <TooltipPrimitive.Trigger className="hidden md:inline-flex" asChild>
+ <TooltipPrimitive.Trigger className="hidden md:inline-flex">
{children}
</TooltipPrimitive.Trigger>
{/*
diff --git a/components/app/links/link-card.tsx b/components/app/links/link-card.tsx
index 0388b4117b..e35f4b3acb 100644
--- a/components/app/links/link-card.tsx
+++ b/components/app/links/link-card.tsx
@@ -39,10 +39,27 @@ import useTags from "#/lib/swr/use-tags";
import TagBadge from "@/components/app/links/tag-badge";
import { ModalContext } from "#/ui/modal-provider";
import Number from "#/ui/number";
+import Avatar from "#/ui/avatar";
+import { UserProps } from "#/lib/types";
-export default function LinkCard({ props }: { props: LinkProps }) {
- const { key, domain, url, rewrite, createdAt, archived, tagId, comments } =
- props;
+export default function LinkCard({
+ props,
+}: {
+ props: LinkProps & {
+ user: UserProps;
+ };
+}) {
+ const {
+ key,
+ domain,
+ url,
+ rewrite,
+ createdAt,
+ archived,
+ tagId,
+ comments,
+ user,
+ } = props;
const { tags } = useTags();
const tag = useMemo(() => tags?.find((t) => t.id === tagId), [tags, tagId]);
@@ -290,6 +307,27 @@ export default function LinkCard({ props }: { props: LinkProps }) {
)}
</div>
<div className="flex max-w-fit items-center space-x-1">
+ <Tooltip
+ content={
+ <div className="w-full p-4">
+ <Avatar user={user} className="h-10 w-10" />
+ <p className="mt-2 text-sm font-semibold text-gray-700">
+ {user?.name || user?.email}
+ </p>
+ <p className="mt-1 text-xs text-gray-500">
+ Created{" "}
+ {new Date(createdAt).toLocaleDateString("en-us", {
+ month: "short",
+ day: "numeric",
+ year: "numeric",
+ })}
+ </p>
+ </div>
+ }
+ >
+ <Avatar user={user} className="h-4 w-4" />
+ </Tooltip>
+ <p>•</p>
<p className="whitespace-nowrap text-sm text-gray-500">
{timeAgo(createdAt)}
</p>
diff --git a/components/app/modals/delete-account-modal.tsx b/components/app/modals/delete-account-modal.tsx
index 89b45ea662..a89f97ad26 100644
--- a/components/app/modals/delete-account-modal.tsx
+++ b/components/app/modals/delete-account-modal.tsx
@@ -11,6 +11,7 @@ import BlurImage from "#/ui/blur-image";
import Modal from "#/ui/modal";
import Button from "#/ui/button";
import { useSession } from "next-auth/react";
+import Avatar from "#/ui/avatar";
function DeleteAccountModal({
showDeleteAccountModal,
@@ -54,16 +55,7 @@ function DeleteAccountModal({
setShowModal={setShowDeleteAccountModal}
>
<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={
- session?.user?.image ||
- `https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`
- }
- alt={session?.user?.name || session?.user?.email || "Delete Account"}
- className="h-10 w-10 rounded-full border border-gray-200"
- width={20}
- height={20}
- />
+ <Avatar user={session?.user} />
<h3 className="text-lg font-medium">Delete Account</h3>
<p className="text-center text-sm text-gray-500">
Warning: This will permanently delete your account and all your Dub.sh
diff --git a/components/app/modals/edit-role-modal.tsx b/components/app/modals/edit-role-modal.tsx
index aa826851da..c37795dbf9 100644
--- a/components/app/modals/edit-role-modal.tsx
+++ b/components/app/modals/edit-role-modal.tsx
@@ -15,6 +15,7 @@ import Button from "#/ui/button";
import { UserProps } from "#/lib/types";
import { Logo } from "#/ui/icons";
import { useSession } from "next-auth/react";
+import Avatar from "#/ui/avatar";
function EditRoleModal({
showEditRoleModal,
@@ -58,13 +59,7 @@ function EditRoleModal({
<div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16">
<div className="flex items-center space-x-3 rounded-md border border-gray-300 bg-white p-3">
- <BlurImage
- src={image || `https://avatars.dicebear.com/api/micah/${email}.svg`}
- alt={email}
- width={40}
- height={40}
- className="overflow-hidden rounded-full border border-gray-200"
- />
+ <Avatar user={user} />
<div className="flex flex-col">
<h3 className="text-sm font-medium">{name || email}</h3>
<p className="text-xs text-gray-500">{email}</p>
diff --git a/components/app/modals/remove-teammate-modal.tsx b/components/app/modals/remove-teammate-modal.tsx
index b57a2cdd59..362bfa1d4d 100644
--- a/components/app/modals/remove-teammate-modal.tsx
+++ b/components/app/modals/remove-teammate-modal.tsx
@@ -15,6 +15,7 @@ import Button from "#/ui/button";
import { UserProps } from "#/lib/types";
import { Logo } from "#/ui/icons";
import { useSession } from "next-auth/react";
+import Avatar from "#/ui/avatar";
function RemoveTeammateModal({
showRemoveTeammateModal,
@@ -99,13 +100,7 @@ function RemoveTeammateModal({
<div className="flex flex-col space-y-4 bg-gray-50 px-4 py-8 text-left sm:px-16">
<div className="flex items-center space-x-3 rounded-md border border-gray-300 bg-white p-3">
- <BlurImage
- src={image || `https://avatars.dicebear.com/api/micah/${email}.svg`}
- alt={email}
- width={40}
- height={40}
- className="overflow-hidden rounded-full border border-gray-200"
- />
+ <Avatar user={user} />
<div className="flex flex-col">
<h3 className="text-sm font-medium">{name || email}</h3>
<p className="text-xs text-gray-500">{email}</p>
diff --git a/components/layout/app/project-select.tsx b/components/layout/app/project-select.tsx
index 0e20ebd7f3..d47e0ad5be 100644
--- a/components/layout/app/project-select.tsx
+++ b/components/layout/app/project-select.tsx
@@ -11,6 +11,7 @@ import { GOOGLE_FAVICON_URL } from "#/lib/constants";
import { ModalContext } from "#/ui/modal-provider";
import Link from "next/link";
import useProject from "#/lib/swr/use-project";
+import Avatar from "#/ui/avatar";
export default function ProjectSelect() {
const { projects } = useProjects();
@@ -153,16 +154,7 @@ function ProjectList({
href="/links"
onClick={() => setOpenPopover(false)}
>
- <img
- src={
- session?.user?.image ||
- `https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`
- }
- alt={
- session?.user?.name || session?.user?.email || "Personal Account"
- }
- className="h-7 w-7 flex-none overflow-hidden rounded-full"
- />
+ <Avatar user={session?.user} className="h-7 w-7" />
<span
className={`block truncate pr-8 text-sm ${
selected.slug === "/" ? "font-medium" : "font-normal"
diff --git a/components/layout/app/user-dropdown.tsx b/components/layout/app/user-dropdown.tsx
index cb7c646e8d..1dd1379070 100644
--- a/components/layout/app/user-dropdown.tsx
+++ b/components/layout/app/user-dropdown.tsx
@@ -13,6 +13,7 @@ import Cookies from "js-cookie";
import { ModalContext } from "#/ui/modal-provider";
import { allChangelogPosts } from "contentlayer/generated";
import { HOME_DOMAIN } from "#/lib/constants";
+import Avatar from "#/ui/avatar";
export default function UserDropdown() {
const { data: session } = useSession();
@@ -133,14 +134,10 @@ export default function UserDropdown() {
onClick={() => setOpenPopover(!openPopover)}
className="group relative"
>
- {session ? (
- <img
- alt={session?.user?.email || "Avatar for logged in user"}
- src={
- session?.user?.image ||
- `https://avatars.dicebear.com/api/micah/${session?.user?.email}.svg`
- }
- className="h-9 w-9 rounded-full border border-gray-300 transition-all duration-75 group-focus:outline-none group-active:scale-95 sm:h-10 sm:w-10"
+ {session?.user ? (
+ <Avatar
+ user={session.user}
+ className="h-9 w-9 transition-all duration-75 group-focus:outline-none group-active:scale-95 sm:h-10 sm:w-10"
/>
) : (
<div className="h-9 w-9 animate-pulse rounded-full border border-gray-300 bg-gray-100 sm:h-10 sm:w-10" />
diff --git a/components/stats/bar-chart.tsx b/components/stats/bar-chart.tsx
index 8c77b0909e..3f38487ba3 100644
--- a/components/stats/bar-chart.tsx
+++ b/components/stats/bar-chart.tsx
@@ -7,7 +7,6 @@ import { withScreenSize } from "@visx/responsive";
import { scaleBand, scaleLinear } from "@visx/scale";
import { useTooltip, useTooltipInPortal } from "@visx/tooltip";
import { motion } from "framer-motion";
-import { intervalData } from "#/lib/stats";
import { nFormatter } from "#/lib/utils";
import styles from "./bar-chart.module.css";
import useSWR from "swr";
diff --git a/lib/api/links.ts b/lib/api/links.ts
index e4760b702d..b33e8037ba 100644
--- a/lib/api/links.ts
+++ b/lib/api/links.ts
@@ -50,6 +50,9 @@ export async function getLinksForProject({
...(tagId && { tagId }),
...(userId && { userId }),
},
+ include: {
+ user: true,
+ },
orderBy: {
[sort]: "desc",
},
diff --git a/pages/app/[slug]/settings/people.tsx b/pages/app/[slug]/settings/people.tsx
index dc163330c2..9ff48ae9c8 100644
--- a/pages/app/[slug]/settings/people.tsx
+++ b/pages/app/[slug]/settings/people.tsx
@@ -14,6 +14,7 @@ import useUsers from "#/lib/swr/use-users";
import { useSession } from "next-auth/react";
import { useEditRoleModal } from "@/components/app/modals/edit-role-modal";
import useProject from "#/lib/swr/use-project";
+import Avatar from "#/ui/avatar";
const tabs: Array<"Members" | "Invitations"> = ["Members", "Invitations"];
@@ -104,7 +105,7 @@ const UserCard = ({
const { plan, isOwner } = useProject();
- const { name, email, image, createdAt, role: currentRole } = user;
+ const { name, email, createdAt, role: currentRole } = user;
const [role, setRole] = useState<"owner" | "member">(currentRole);
@@ -134,15 +135,7 @@ const UserCard = ({
>
<div className="flex items-start space-x-3">
<div className="flex items-center space-x-3">
- <BlurImage
- src={
- image || `https://avatars.dicebear.com/api/micah/${email}.svg`
- }
- alt={email}
- width={40}
- height={40}
- className="overflow-hidden rounded-full border border-gray-200"
- />
+ <Avatar user={user} />
<div className="flex flex-col">
<h3 className="text-sm font-medium">{name || email}</h3>
<p className="text-xs text-gray-500">{email}</p>