|
| 1 | +import { Breadcrumbs } from "@/components/Breadcrumbs" |
| 2 | +import { PageTitle } from "@/components/PageTitle" |
| 3 | +import { Button } from "@/components/ui/button" |
| 4 | +import { Skeleton } from "@/components/ui/skeleton" |
| 5 | +import { ListQuotesData } from "@/generated/client" |
| 6 | +import { listQuotesOptions } from "@/generated/client/@tanstack/react-query.gen" |
| 7 | +import useLocalStorage from "@/hooks/use-local-storage" |
| 8 | +import { cn } from "@/lib/utils" |
| 9 | +import { useSuspenseQuery } from "@tanstack/react-query" |
| 10 | +import { LoaderIcon } from "lucide-react" |
| 11 | +import { Suspense } from "react" |
| 12 | +import { Link, useNavigate } from "react-router" |
| 13 | + |
| 14 | +function Loader() { |
| 15 | + return ( |
| 16 | + <div className="flex flex-col gap-1.5 py-2"> |
| 17 | + <Skeleton className="h-4 rounded-lg" /> |
| 18 | + <Skeleton className="h-16 rounded-lg" /> |
| 19 | + <Skeleton className="h-16 rounded-lg" /> |
| 20 | + <Skeleton className="h-16 rounded-lg" /> |
| 21 | + <Skeleton className="h-16 rounded-lg" /> |
| 22 | + <Skeleton className="h-16 rounded-lg" /> |
| 23 | + </div> |
| 24 | + ) |
| 25 | +} |
| 26 | + |
| 27 | +function QuoteListRejected() { |
| 28 | + const navigate = useNavigate() |
| 29 | + |
| 30 | + const { data, isFetching } = useSuspenseQuery({ |
| 31 | + ...listQuotesOptions({ |
| 32 | + query: { |
| 33 | + status: "rejected", |
| 34 | + } as unknown as ListQuotesData["query"], |
| 35 | + }), |
| 36 | + }) |
| 37 | + |
| 38 | + return ( |
| 39 | + <> |
| 40 | + <div className="flex items-center gap-1"> |
| 41 | + <LoaderIcon |
| 42 | + className={cn("stroke-1 animate-spin", { |
| 43 | + "animate-spin": isFetching, |
| 44 | + invisible: !isFetching, |
| 45 | + })} |
| 46 | + /> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div className="flex flex-col gap-1 my-2"> |
| 50 | + {data.quotes.length === 0 && <div className="py-2 font-bold">No rejected quotes.</div>} |
| 51 | + {data.quotes.map((it, index) => { |
| 52 | + return ( |
| 53 | + <div key={index} className="flex gap-1 items-center text-sm"> |
| 54 | + <span className="font-mono"> |
| 55 | + {isFetching ? ( |
| 56 | + <>{it.id}</> |
| 57 | + ) : ( |
| 58 | + <> |
| 59 | + <Link to={"/quotes/:id".replace(":id", it.id)}>{it.id}</Link> |
| 60 | + </> |
| 61 | + )} |
| 62 | + </span> |
| 63 | + |
| 64 | + <Button |
| 65 | + size="sm" |
| 66 | + disabled={isFetching} |
| 67 | + onClick={() => { |
| 68 | + void navigate("/quotes/:id".replace(":id", it.id)) |
| 69 | + }} |
| 70 | + > |
| 71 | + View |
| 72 | + </Button> |
| 73 | + </div> |
| 74 | + ) |
| 75 | + })} |
| 76 | + </div> |
| 77 | + </> |
| 78 | + ) |
| 79 | +} |
| 80 | + |
| 81 | +function DevSection() { |
| 82 | + const [devMode] = useLocalStorage("devMode", false) |
| 83 | + |
| 84 | + const { data: quotesRejected } = useSuspenseQuery({ |
| 85 | + ...listQuotesOptions({ |
| 86 | + query: { |
| 87 | + status: "rejected", |
| 88 | + } as unknown as ListQuotesData["query"], |
| 89 | + }), |
| 90 | + }) |
| 91 | + |
| 92 | + return ( |
| 93 | + <> |
| 94 | + {devMode && ( |
| 95 | + <> |
| 96 | + <pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2"> |
| 97 | + {JSON.stringify(quotesRejected, null, 2)} |
| 98 | + </pre> |
| 99 | + </> |
| 100 | + )} |
| 101 | + </> |
| 102 | + ) |
| 103 | +} |
| 104 | + |
| 105 | +function PageBody() { |
| 106 | + return ( |
| 107 | + <div className="flex flex-col gap-2"> |
| 108 | + <div> |
| 109 | + <QuoteListRejected /> |
| 110 | + </div> |
| 111 | + </div> |
| 112 | + ) |
| 113 | +} |
| 114 | + |
| 115 | +export default function RejectedQuotesPage() { |
| 116 | + return ( |
| 117 | + <> |
| 118 | + <Breadcrumbs |
| 119 | + parents={[ |
| 120 | + <> |
| 121 | + <Link to="/quotes">Quotes</Link> |
| 122 | + </>, |
| 123 | + ]} |
| 124 | + > |
| 125 | + Rejected |
| 126 | + </Breadcrumbs> |
| 127 | + <PageTitle>Rejected Quotes</PageTitle> |
| 128 | + <Suspense fallback={<Loader />}> |
| 129 | + <PageBody /> |
| 130 | + </Suspense> |
| 131 | + <Suspense> |
| 132 | + <DevSection /> |
| 133 | + </Suspense> |
| 134 | + </> |
| 135 | + ) |
| 136 | +} |
0 commit comments