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.

fix project default avatar

Steven Teyfa39bfbb480b
diff --git a/apps/web/app/api/projects/route.ts b/apps/web/app/api/projects/route.ts
index aade5170ee..519d759e68 100644
--- a/apps/web/app/api/projects/route.ts
+++ b/apps/web/app/api/projects/route.ts
@@ -48,7 +48,6 @@ export const GET = withSession(async ({ session }) => {
},
},
include: {
- domains: true,
users: {
where: {
userId: session.user.id,
diff --git a/apps/web/lib/fetchers.ts b/apps/web/lib/fetchers.ts
index 3d3de6efc5..cb7512932f 100644
--- a/apps/web/lib/fetchers.ts
+++ b/apps/web/lib/fetchers.ts
@@ -1,7 +1,6 @@
import { cache } from "react";
import { getSession } from "./auth";
import prisma from "./prisma";
-import { ProjectWithDomainProps } from "./types";
export const getProjects = cache(async () => {
const session = await getSession();
@@ -22,11 +21,7 @@ export const getProjects = cache(async () => {
},
});
- return projects.map((project) => ({
- ...project,
- primaryDomain:
- project.domains.find((domain) => domain.primary) || project.domains[0],
- })) as ProjectWithDomainProps[];
+ return projects;
});
export const getProject = cache(async ({ slug }: { slug: string }) => {
diff --git a/apps/web/lib/swr/use-domains.ts b/apps/web/lib/swr/use-domains.ts
index c667404bc3..a2ade12cbd 100644
--- a/apps/web/lib/swr/use-domains.ts
+++ b/apps/web/lib/swr/use-domains.ts
@@ -4,10 +4,19 @@ import { useParams } from "next/navigation";
import useSWR from "swr";
import useDefaultDomains from "./use-default-domains";
-export default function useDomains({ domain }: { domain?: string } = {}) {
- const { slug } = useParams() as {
- slug: string;
- };
+export default function useDomains({
+ slug: projectSlug,
+ domain,
+}: { slug?: string; domain?: string } = {}) {
+ let slug: string | undefined = undefined;
+ if (projectSlug) {
+ slug = projectSlug;
+ } else {
+ const { slug: paramSlug } = useParams() as {
+ slug: string;
+ };
+ slug = paramSlug;
+ }
const { data, error, mutate } = useSWR<DomainProps[]>(
slug && `/api/domains?projectSlug=${slug}`,
diff --git a/apps/web/lib/swr/use-projects.ts b/apps/web/lib/swr/use-projects.ts
index 6af3741e2b..13ad104f6e 100644
--- a/apps/web/lib/swr/use-projects.ts
+++ b/apps/web/lib/swr/use-projects.ts
@@ -1,9 +1,9 @@
-import { ProjectWithDomainProps } from "@/lib/types";
+import { ProjectProps } from "@/lib/types";
import { fetcher } from "@dub/utils";
import useSWR from "swr";
export default function useProjects() {
- const { data, error } = useSWR<ProjectWithDomainProps[]>(
+ const { data: projects, error } = useSWR<ProjectProps[]>(
"/api/projects",
fetcher,
{
@@ -11,15 +11,11 @@ export default function useProjects() {
},
);
- const projects = data?.map((project) => ({
- ...project,
- isOwner: project?.users && project.users[0].role === "owner",
- primaryDomain:
- project.domains.find((domain) => domain.primary) || project.domains[0],
- }));
-
const freeProjects = projects?.filter(
- (project) => project.plan === "free" && project.isOwner,
+ (project) =>
+ project.plan === "free" &&
+ project?.users &&
+ project.users[0].role === "owner",
);
return {
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 4f3df42afb..515db71635 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -96,11 +96,6 @@ export interface ProjectProps {
inviteCode: string;
}
-export interface ProjectWithDomainProps extends ProjectProps {
- domains: DomainProps[];
- primaryDomain?: DomainProps;
-}
-
export interface UserProps {
id: string;
name: string;
diff --git a/apps/web/ui/layout/project-select.tsx b/apps/web/ui/layout/project-select.tsx
index bf9a91ef52..f01395d208 100644
--- a/apps/web/ui/layout/project-select.tsx
+++ b/apps/web/ui/layout/project-select.tsx
@@ -1,11 +1,11 @@
"use client";
import useProjects from "@/lib/swr/use-projects";
-import { PlanProps, ProjectWithDomainProps } from "@/lib/types";
+import { PlanProps, ProjectProps } from "@/lib/types";
import { ModalContext } from "@/ui/modals/provider";
import PlanBadge from "@/ui/projects/plan-badge";
import { BlurImage, Popover, Tick } from "@dub/ui";
-import { GOOGLE_FAVICON_URL, SHORT_DOMAIN } from "@dub/utils";
+import { DICEBEAR_AVATAR_URL } from "@dub/utils";
import { ChevronsUpDown, PlusCircle } from "lucide-react";
import { useSession } from "next-auth/react";
import Link from "next/link";
@@ -27,10 +27,8 @@ export default function ProjectSelect() {
return {
...selectedProject,
image:
- selectedProject?.logo ||
- `${GOOGLE_FAVICON_URL}${
- selectedProject?.primaryDomain?.slug || SHORT_DOMAIN
- }`,
+ selectedProject.logo ||
+ `${DICEBEAR_AVATAR_URL}${selectedProject.name}`,
};
// return personal account selector if there's no project or error (user doesn't have access to project)
@@ -116,7 +114,7 @@ function ProjectList({
image: string;
plan: PlanProps;
};
- projects: ProjectWithDomainProps[];
+ projects: ProjectProps[];
setOpenPopover: (open: boolean) => void;
}) {
const { setShowAddProjectModal } = useContext(ModalContext);
@@ -139,7 +137,7 @@ function ProjectList({
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">My Projects</div>
- {projects.map(({ id, name, slug, logo, primaryDomain, metadata }) => {
+ {projects.map(({ id, name, slug, logo }) => {
return (
<Link
key={slug}
@@ -151,10 +149,7 @@ function ProjectList({
onClick={() => setOpenPopover(false)}
>
<BlurImage
- src={
- logo ||
- `${GOOGLE_FAVICON_URL}${primaryDomain?.slug || SHORT_DOMAIN}`
- }
+ src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
width={20}
height={20}
alt={id}
diff --git a/apps/web/ui/modals/transfer-link-modal.tsx b/apps/web/ui/modals/transfer-link-modal.tsx
index 3a52b0b72c..11fa827420 100644
--- a/apps/web/ui/modals/transfer-link-modal.tsx
+++ b/apps/web/ui/modals/transfer-link-modal.tsx
@@ -3,7 +3,7 @@ import { LinkProps } from "@/lib/types";
import { Button, InputSelect, InputSelectItemProps, Modal } from "@dub/ui";
import {
APP_NAME,
- DUB_LOGO,
+ DICEBEAR_AVATAR_URL,
getApexDomain,
isDubDomain,
linkConstructor,
@@ -106,7 +106,8 @@ function TransferLinkModal({
? projects.map((project) => ({
id: project.id,
value: project.name,
- image: project.logo || DUB_LOGO,
+ image:
+ project.logo || `${DICEBEAR_AVATAR_URL}${project.name}`,
disabled: project.id === props.projectId,
label: project.id === props.projectId ? "Current" : "",
}))
diff --git a/apps/web/ui/projects/project-card.tsx b/apps/web/ui/projects/project-card.tsx
index cc712550bd..06375b4dfb 100644
--- a/apps/web/ui/projects/project-card.tsx
+++ b/apps/web/ui/projects/project-card.tsx
@@ -1,7 +1,8 @@
"use client";
import { Session } from "@/lib/auth";
-import { DomainProps, ProjectWithDomainProps } from "@/lib/types";
+import useDomains from "@/lib/swr/use-domains";
+import { DomainProps, ProjectProps } from "@/lib/types";
import { CheckCircleFill, XCircleFill } from "@/ui/shared/icons";
import {
Badge,
@@ -11,8 +12,7 @@ import {
Tooltip,
} from "@dub/ui";
import {
- DUB_DOMAINS,
- GOOGLE_FAVICON_URL,
+ DICEBEAR_AVATAR_URL,
HOME_DOMAIN,
cn,
fetcher,
@@ -33,10 +33,14 @@ export default function ProjectCard({
logo,
usage,
plan,
- domains: activeProjectDomains,
- primaryDomain: projectPrimaryDomain,
- metadata,
-}: ProjectWithDomainProps) {
+}: ProjectProps) {
+ const {
+ allActiveDomains: domains,
+ primaryDomain,
+ verified,
+ loading,
+ } = useDomains({ slug });
+
const { data: count } = useSWR<number>(
`/api/links/count?projectSlug=${slug}`,
fetcher,
@@ -48,15 +52,6 @@ export default function ProjectCard({
const isMigratedProject = user?.migratedProject === id;
- const defaultDomains = metadata?.defaultDomains
- ? DUB_DOMAINS.filter((d) => metadata?.defaultDomains?.includes(d.slug))
- : DUB_DOMAINS;
-
- const domains =
- activeProjectDomains.length > 0 ? activeProjectDomains : defaultDomains;
-
- const primaryDomain = projectPrimaryDomain || defaultDomains[0];
-
return (
<div className="group relative">
{isMigratedProject && (
@@ -91,7 +86,7 @@ export default function ProjectCard({
<div className="flex items-start justify-between">
<div className="flex items-center space-x-3">
<BlurImage
- src={logo || `${GOOGLE_FAVICON_URL}${primaryDomain?.slug}`}
+ src={logo || `${DICEBEAR_AVATAR_URL}${name}`}
alt={id}
className="h-10 w-10 flex-shrink-0 overflow-hidden rounded-full"
width={48}
@@ -101,42 +96,49 @@ export default function ProjectCard({
<h2 className="max-w-[200px] truncate text-lg font-medium text-gray-700">
{name}
</h2>
- <div className="flex items-center">
- <p className="text-gray-500">{primaryDomain?.slug}</p>
- <Tooltip
- content={
- <DomainsTooltip
- domains={domains}
- title={
- primaryDomain?.verified === false
- ? "Please verify your domain to start adding links."
- : "Here are all the domains for this project."
- }
- cta={
- primaryDomain?.verified === false
- ? "Verify Domain"
- : `Manage Domain${domains.length > 1 ? "s" : ""}`
- }
- href={`/${slug}/domains`}
- />
- }
- >
- <div className="ml-1 flex items-center">
- {domains.length > 1 ? (
- <Badge
- variant="gray"
- className="border-gray-300 transition-all hover:bg-gray-200"
- >
- +{domains.length - 1}
- </Badge>
- ) : primaryDomain?.verified ? (
- <CheckCircleFill className="h-5 w-5 text-blue-500" />
- ) : primaryDomain?.verified === false ? (
- <XCircleFill className="h-5 w-5 text-gray-300" />
- ) : null}
- </div>
- </Tooltip>
- </div>
+ {loading ? (
+ <div className="mt-1 flex items-center space-x-2">
+ <div className="h-5 w-20 animate-pulse rounded-md bg-gray-200" />
+ <div className="h-5 w-5 animate-pulse rounded-full bg-gray-200" />
+ </div>
+ ) : (
+ <div className="flex items-center">
+ <p className="text-gray-500">{primaryDomain}</p>
+ <Tooltip
+ content={
+ <DomainsTooltip
+ domains={domains}
+ title={
+ verified === false
+ ? "Please verify your domain to start adding links."
+ : "Here are all the domains for this project."
+ }
+ cta={
+ verified === false
+ ? "Verify Domain"
+ : `Manage Domain${domains.length > 1 ? "s" : ""}`
+ }
+ href={`/${slug}/domains`}
+ />
+ }
+ >
+ <div className="ml-1 flex items-center">
+ {domains.length > 1 ? (
+ <Badge
+ variant="gray"
+ className="border-gray-300 transition-all hover:bg-gray-200"
+ >
+ +{domains.length - 1}
+ </Badge>
+ ) : verified ? (
+ <CheckCircleFill className="h-5 w-5 text-blue-500" />
+ ) : verified === false ? (
+ <XCircleFill className="h-5 w-5 text-gray-300" />
+ ) : null}
+ </div>
+ </Tooltip>
+ </div>
+ )}
</div>
</div>
<PlanBadge plan={plan} />
diff --git a/packages/utils/src/constants/misc.ts b/packages/utils/src/constants/misc.ts
index 7484b26154..bd4a8febc0 100644
--- a/packages/utils/src/constants/misc.ts
+++ b/packages/utils/src/constants/misc.ts
@@ -23,6 +23,9 @@ export const DEFAULT_LINK_PROPS: any = {
export const GOOGLE_FAVICON_URL =
"https://www.google.com/s2/favicons?sz=64&domain_url=";
+export const DICEBEAR_AVATAR_URL =
+ "https://api.dicebear.com/7.x/initials/svg?backgroundType=gradientLinear&fontFamily=Helvetica&fontSize=40&seed=";
+
export const PAGINATION_LIMIT = 100;
export const TWO_WEEKS_IN_SECONDS = 60 * 60 * 24 * 14;