Skip to content

Commit

Permalink
removed button when profile has 5 reviews (#122)
Browse files Browse the repository at this point in the history
* removed button when profile has 5 reviews

* removed useless comments

* addressed comments
  • Loading branch information
mattrwang authored Feb 9, 2025
1 parent 8683211 commit 403fd76
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions apps/web/src/app/_components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { cn } from "@cooper/ui";

import { NewReviewDialog } from "~/app/_components/reviews/new-review-dialogue";
import { altivoFont } from "~/app/styles/font";
import { api } from "~/trpc/react";
import CooperLogo from "./cooper-logo";

interface HeaderProps {
Expand All @@ -22,6 +23,20 @@ interface HeaderProps {
export default function Header({ session, auth }: HeaderProps) {
const pathname = usePathname();

const profile = api.profile.getCurrentUser.useQuery(undefined, {
refetchOnWindowFocus: false,
});
const profileId = profile.data?.id;

const reviews = api.review.getByProfile.useQuery(
{ id: profileId ?? "" },
{
enabled: !!profileId,
},
);

const showButton = !!profileId && (reviews.data?.length ?? 0) < 5;

const outerWidth = "w-40";

return (
Expand Down Expand Up @@ -72,8 +87,7 @@ export default function Header({ session, auth }: HeaderProps) {
outerWidth,
)}
>
{/* TODO: only show this if the user is below the max number of reviews allowed */}
{session && <NewReviewDialog />}
{session && showButton && <NewReviewDialog />}
{auth}
</div>
</header>
Expand Down

0 comments on commit 403fd76

Please sign in to comment.