Skip to content

Commit 78b6cb9

Browse files
atrakhConvex, Inc.
authored andcommitted
dashboard: fix link to project on usage page (#41811)
If the team member didn't have a deployment and there was no prod deployment, the redirect looked like it was loading forever. I also inlined the logic to pick out which deployment we should redirect to into TeamUsage instead of relying on two redirects GitOrigin-RevId: 3c8b2c4ea6d8bac4e9e443c3cda4304ad805ed1d
1 parent 5648b47 commit 78b6cb9

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

npm-packages/dashboard/src/components/billing/TeamUsage.tsx

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { useDeployments } from "api/deployments";
3232
import { useTeamEntitlements } from "api/teams";
3333
import { useProjects } from "api/projects";
3434
import { useTeamOrbSubscription } from "api/billing";
35-
import Link from "next/link";
3635
import groupBy from "lodash/groupBy";
3736
import sumBy from "lodash/sumBy";
3837
import { Tab } from "@headlessui/react";
@@ -44,6 +43,7 @@ import { DateRange, useCurrentBillingPeriod } from "api/usage";
4443
import { cn } from "@ui/cn";
4544
import { usePagination } from "hooks/usePagination";
4645
import { PaginationControls } from "elements/PaginationControls";
46+
import { useProfile } from "api/profile";
4747
import { formatQuantity } from "./lib/formatQuantity";
4848
import {
4949
DATABASE_STORAGE_CATEGORIES,
@@ -456,24 +456,36 @@ function FunctionUsageBreakdownByProject({
456456
projectTotal: number;
457457
}) {
458458
const { deployments } = useDeployments(project?.id);
459+
const member = useProfile();
459460
const isLoadingDeployments = project && !deployments;
460461

462+
const prodDeployment = deployments?.find((d) => d.deploymentType === "prod");
463+
const devDeployment = deployments?.find(
464+
(d) => d.deploymentType === "dev" && d.creator === member?.id,
465+
);
466+
const anyDeployment = deployments?.[0];
467+
const shownDeployment = devDeployment ?? prodDeployment ?? anyDeployment;
468+
const shownDeploymentName = shownDeployment?.name;
469+
461470
return (
462471
<div className="mb-4">
463-
<p className="flex align-baseline font-medium">
472+
<p className="flex align-baseline">
464473
{project && (
465-
<Link
466-
href={`/t/${team.slug}/${project.slug}/`}
467-
passHref
468-
className="inline-flex items-baseline gap-2 py-2"
474+
<Button
475+
href={`/t/${team.slug}/${project.slug}/${shownDeploymentName}`}
476+
inline
477+
variant="neutral"
478+
disabled={!shownDeployment}
479+
className="gap-1 font-semibold"
469480
>
470481
<span>{project.name}</span>
471482
{project.name?.toLowerCase() !== project.slug ? (
472-
<span className="text-sm text-content-secondary">
483+
<span className="text-sm font-semibold text-content-secondary">
473484
{project.slug}
474485
</span>
475486
) : null}
476-
</Link>
487+
<ExternalLinkIcon />
488+
</Button>
477489
)}
478490
{!project && (
479491
<span className="inline-block py-2 italic">Deleted Project</span>

npm-packages/dashboard/src/pages/t/[team]/[project]/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,22 @@ export default withAuthenticatedPage(function RedirectToDeployment() {
2323
const devDeployment = deployments?.find(
2424
(d) => d.deploymentType === "dev" && d.creator === member?.id,
2525
);
26-
const shownDeployment = devDeployment ?? prodDeployment;
26+
const anyDeployment = deployments?.[0];
27+
const shownDeployment = devDeployment ?? prodDeployment ?? anyDeployment;
2728
const shownDeploymentName = shownDeployment?.name;
2829

2930
useEffect(() => {
3031
if (shownDeploymentName) {
3132
void router.replace(
3233
`/t/${currentTeam!.slug}/${
3334
currentProject!.slug
34-
}/${shownDeploymentName}${
35-
router.pathname.endsWith("/try") ? "/try" : ""
36-
}`,
35+
}/${shownDeploymentName}`,
3736
);
37+
} else if (deployments) {
38+
// Couldn't find a deployment to display
39+
void router.replace("/404");
3840
}
39-
}, [currentTeam, currentProject, shownDeploymentName, router]);
41+
}, [deployments, currentTeam, currentProject, shownDeploymentName, router]);
4042

4143
return <Loading />;
4244
});

0 commit comments

Comments
 (0)