Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correct game query key and not found page #97

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion web/src/components/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ import { ArrowLeft } from "lucide-react";

import { Button } from "@/components/ui/button";
import { Card, CardDescription, CardTitle } from "@/components/ui/card";
import { cn } from "@/lib/utils";

export function Error(props: {
title: string;
description: string;
showBack?: boolean;
className?: string;
}) {
return (
<Card className="flex flex-col items-center text-center min-h-full">
<Card
className={cn(
"flex flex-col items-center text-center min-h-full",
props.className,
)}
>
<CardTitle className="mt-12">{props.title}</CardTitle>
<CardDescription>{props.description}</CardDescription>
{props.showBack && (
Expand Down
13 changes: 13 additions & 0 deletions web/src/lib/query-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ export function gameQueryKey(gameId: string, publisherId: string): QueryKey {
return ["games", gameId, publisherId];
}

/**
* Query key used when fetching a game in the distribution routes.
* @param gameId Game ID.
* @param publisherId Publisher ID.
* @returns Game query key.
*/
export function distributeGameQueryKey(
gameId: string,
publisherId: string,
): QueryKey {
return ["games", "distribute", gameId, publisherId];
}

/**
* Query key used when fetching the cart information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { differenceInYears, format, isAfter } from "date-fns";
import { Heart, Library, ShoppingCart, Star } from "lucide-react";

import { Carousel } from "@/components/carousel";
import { Error } from "@/components/error";
import { Game } from "@/components/game";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
Expand All @@ -33,6 +34,7 @@ import {
} from "@/lib/api";
import { decodeTokenPayload, getToken } from "@/lib/auth";
import { TAX, TO_BE_ANNOUNCED, TOAST_MESSAGES } from "@/lib/constants";
import { BadRequest, NotFound } from "@/lib/errors";
import { withAuthErrors } from "@/lib/middleware";
import { gameQueryKey, userNavbarQueryKey } from "@/lib/query-keys";
import { getBatchPaginatedResponse } from "@/lib/request";
Expand Down Expand Up @@ -145,6 +147,22 @@ export const Route = createFileRoute(
gameQueryOptions(opts.params.gameId, opts.params.publisherId),
);
},
errorComponent(errorProps) {
// If the game ID is not a valid UUID, a BadRequest is thrown.
// This error is visually identical to a NotFound error.
if (
errorProps.error instanceof BadRequest ||
errorProps.error instanceof NotFound
) {
return (
<Error
className="border-none"
description="The game you are looking for does not exist."
title="Game Not Found"
/>
);
}
},
});

function Component() {
Expand Down
4 changes: 2 additions & 2 deletions web/src/routes/distribute/_layout/games/$gameId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getPublisherGame } from "@/lib/api";
import { decodeTokenPayload, getToken } from "@/lib/auth";
import { MISSING_VALUE_SYMBOL, TAX, TO_BE_ANNOUNCED } from "@/lib/constants";
import { BadRequest, NotFound } from "@/lib/errors";
import { gameQueryKey } from "@/lib/query-keys";
import { distributeGameQueryKey } from "@/lib/query-keys";
import { applyTax, formatCurrency, getLanguageName } from "@/lib/utils";

/**
Expand All @@ -31,7 +31,7 @@ function publisherGameQueryOptions(gameId: string) {
const publisherId = payload.sub;

return queryOptions({
queryKey: gameQueryKey(gameId, publisherId),
queryKey: distributeGameQueryKey(gameId, publisherId),
async queryFn() {
return await getPublisherGame(publisherId, gameId);
},
Expand Down
Loading