|
| 1 | +import { Breadcrumbs } from "@/components/Breadcrumbs" |
| 2 | +import { PageTitle } from "@/components/PageTitle" |
| 3 | +import { Skeleton } from "@/components/ui/skeleton" |
| 4 | +import { InfoReply } from "@/generated/client" |
| 5 | +import useApiClient from "@/hooks/use-api-client" |
| 6 | +import useLocalStorage from "@/hooks/use-local-storage" |
| 7 | +import { useSuspenseQuery } from "@tanstack/react-query" |
| 8 | +import { Suspense } from "react" |
| 9 | +import { useParams } from "react-router" |
| 10 | + |
| 11 | +function Loader() { |
| 12 | + return ( |
| 13 | + <div className="flex flex-col gap-1.5 py-2"> |
| 14 | + <Skeleton className="h-48 rounded-lg" /> |
| 15 | + </div> |
| 16 | + ) |
| 17 | +} |
| 18 | + |
| 19 | +function Quote({ value }: { value: InfoReply }) { |
| 20 | + return ( |
| 21 | + <> |
| 22 | + <div className="flex flex-col gap-1"> |
| 23 | + <div className="flex-1">{value.id}</div> |
| 24 | + </div> |
| 25 | + </> |
| 26 | + ) |
| 27 | +} |
| 28 | + |
| 29 | +function DevSection({ id }: { id: InfoReply["id"] }) { |
| 30 | + const [devMode] = useLocalStorage("devMode", false) |
| 31 | + |
| 32 | + const client = useApiClient() |
| 33 | + |
| 34 | + const { data } = useSuspenseQuery({ |
| 35 | + queryKey: ["quote", id], |
| 36 | + queryFn: () => |
| 37 | + client.adminLookupQuote({ |
| 38 | + path: { |
| 39 | + id, |
| 40 | + }, |
| 41 | + }), |
| 42 | + }) |
| 43 | + |
| 44 | + return ( |
| 45 | + <> |
| 46 | + {devMode && ( |
| 47 | + <> |
| 48 | + <pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2"> |
| 49 | + {JSON.stringify(data, null, 2)} |
| 50 | + </pre> |
| 51 | + </> |
| 52 | + )} |
| 53 | + </> |
| 54 | + ) |
| 55 | +} |
| 56 | + |
| 57 | +function PageBody({ id }: { id: InfoReply["id"] }) { |
| 58 | + const client = useApiClient() |
| 59 | + |
| 60 | + const { data } = useSuspenseQuery({ |
| 61 | + queryKey: ["quote", id], |
| 62 | + queryFn: () => |
| 63 | + client.adminLookupQuote({ |
| 64 | + path: { |
| 65 | + id, |
| 66 | + }, |
| 67 | + }), |
| 68 | + }) |
| 69 | + |
| 70 | + return ( |
| 71 | + <> |
| 72 | + {data.data && ( |
| 73 | + <> |
| 74 | + <Quote value={data.data} /> |
| 75 | + </> |
| 76 | + )} |
| 77 | + </> |
| 78 | + ) |
| 79 | +} |
| 80 | + |
| 81 | +export default function QuotePage() { |
| 82 | + const { id } = useParams<{ id: InfoReply["id"] }>() |
| 83 | + |
| 84 | + if (!id) { |
| 85 | + throw Error("Missing `id` param.") |
| 86 | + } |
| 87 | + |
| 88 | + return ( |
| 89 | + <> |
| 90 | + <Breadcrumbs>Quote {id}</Breadcrumbs> |
| 91 | + <PageTitle>Quote {id}</PageTitle> |
| 92 | + <Suspense fallback={<Loader />}> |
| 93 | + <PageBody id={id} /> |
| 94 | + <DevSection id={id} /> |
| 95 | + </Suspense> |
| 96 | + </> |
| 97 | + ) |
| 98 | +} |
0 commit comments