Skip to content

Commit ec32f39

Browse files
committed
feat: display accepted quotes
1 parent 389713b commit ec32f39

File tree

4 files changed

+101
-17
lines changed

4 files changed

+101
-17
lines changed

src/mocks/handlers.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import { fetchAdminLookupQuote, fetchAdminQuotePending, updateAdminQuote } from "./handlers/admin_quotes"
1+
import {
2+
fetchAdminLookupQuote,
3+
fetchAdminQuoteAccepted,
4+
fetchAdminQuotePending,
5+
updateAdminQuote,
6+
} from "./handlers/admin_quotes"
27
import { fetchBalances } from "./handlers/balances"
38
import { fetchInfo } from "./handlers/info"
49

5-
export const handlers = [fetchInfo, fetchBalances, fetchAdminQuotePending, fetchAdminLookupQuote, updateAdminQuote]
10+
export const handlers = [
11+
fetchInfo,
12+
fetchBalances,
13+
fetchAdminQuotePending,
14+
fetchAdminQuoteAccepted,
15+
fetchAdminLookupQuote,
16+
updateAdminQuote,
17+
]

src/mocks/handlers/admin_quotes.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { http, delay, HttpResponse, StrictResponse } from "msw"
22
import { API_URL } from "@/constants/api"
3-
import { ADMIN_QUOTE_BY_ID, ADMIN_QUOTE_PENDING } from "@/constants/endpoints"
4-
import { AdminLookupQuoteResponse, InfoReply, ListPendingQuotesResponse, ResolveRequest } from "@/generated/client"
3+
import { ADMIN_QUOTE_BY_ID, ADMIN_QUOTE_PENDING, ADMIN_QUOTE_ACCEPTED } from "@/constants/endpoints"
4+
import {
5+
AdminLookupQuoteResponse,
6+
InfoReply,
7+
ListAcceptedQuotesResponse,
8+
ListPendingQuotesResponse,
9+
ResolveRequest,
10+
} from "@/generated/client"
511
import { db } from "../db"
612

713
export const fetchAdminQuotePending = http.get<never, never, ListPendingQuotesResponse>(
@@ -17,6 +23,19 @@ export const fetchAdminQuotePending = http.get<never, never, ListPendingQuotesRe
1723
},
1824
)
1925

26+
export const fetchAdminQuoteAccepted = http.get<never, never, ListAcceptedQuotesResponse>(
27+
`${API_URL}${ADMIN_QUOTE_ACCEPTED}`,
28+
async () => {
29+
await delay(1_000)
30+
31+
const data = db.quotes.getAll().filter((it) => it.status === "accepted")
32+
33+
return HttpResponse.json({
34+
quotes: data.map((it) => it.id),
35+
})
36+
},
37+
)
38+
2039
export const fetchAdminLookupQuote = http.get<never, never, AdminLookupQuoteResponse>(
2140
`${API_URL}${ADMIN_QUOTE_BY_ID}`,
2241
async ({ params }) => {

src/pages/quotes/QuotePage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ function QuoteActions({ value, isFetching }: { value: InfoReply; isFetching: boo
8888
<Button
8989
className="flex-1"
9090
onClick={onDenyQuote}
91-
disabled={isFetching || denyQuote.isPending || value.status === "denied"}
91+
disabled={isFetching || denyQuote.isPending || value.status !== "pending"}
9292
>
9393
Deny {denyQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
9494
</Button>
9595
<Button
9696
className="flex-1"
9797
onClick={onOfferQuote}
98-
disabled={isFetching || offerQuote.isPending || value.status === "offered"}
98+
disabled={isFetching || offerQuote.isPending || value.status !== "pending"}
9999
>
100100
Offer {offerQuote.isPending && <LoaderIcon className="stroke-1 animate-spin" />}
101101
</Button>

src/pages/quotes/QuotesPage.tsx

Lines changed: 64 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { H3 } from "@/components/Headings"
33
import { PageTitle } from "@/components/PageTitle"
44
import { Button } from "@/components/ui/button"
55
import { Skeleton } from "@/components/ui/skeleton"
6-
import { listPendingQuotesOptions } from "@/generated/client/@tanstack/react-query.gen"
6+
import { listAcceptedQuotesOptions, listPendingQuotesOptions } from "@/generated/client/@tanstack/react-query.gen"
77
import useLocalStorage from "@/hooks/use-local-storage"
88
import { useSuspenseQuery } from "@tanstack/react-query"
99
import { LoaderIcon } from "lucide-react"
@@ -18,32 +18,63 @@ function Loader() {
1818
)
1919
}
2020

21-
function QuoteListPendingRaw() {
22-
const { data } = useSuspenseQuery({
23-
...listPendingQuotesOptions({}),
21+
function QuoteListPending() {
22+
const navigate = useNavigate()
23+
24+
const { data, isFetching } = useSuspenseQuery({
25+
...listPendingQuotesOptions(),
2426
})
2527

2628
return (
2729
<>
28-
<pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2">
29-
{JSON.stringify(data, null, 2)}
30-
</pre>
30+
<H3>
31+
<span className="flex items-center gap-1">
32+
<span>Pending</span>
33+
<span>{isFetching && <LoaderIcon className="stroke-1 animate-spin" />}</span>
34+
</span>
35+
</H3>
36+
37+
<div className="flex flex-col gap-1">
38+
{data.quotes.map((it, index) => {
39+
return (
40+
<div key={index} className="flex gap-1 items-center text-sm">
41+
{isFetching ? (
42+
<>{it}</>
43+
) : (
44+
<>
45+
<Link to={"/quotes/:id".replace(":id", it)}>{it}</Link>
46+
</>
47+
)}
48+
49+
<Button
50+
size="sm"
51+
disabled={isFetching}
52+
onClick={() => {
53+
void navigate("/quotes/:id".replace(":id", it))
54+
}}
55+
>
56+
View
57+
</Button>
58+
</div>
59+
)
60+
})}
61+
</div>
3162
</>
3263
)
3364
}
3465

35-
function QuoteListPending() {
66+
function QuoteListAccepted() {
3667
const navigate = useNavigate()
3768

3869
const { data, isFetching } = useSuspenseQuery({
39-
...listPendingQuotesOptions({}),
70+
...listAcceptedQuotesOptions(),
4071
})
4172

4273
return (
4374
<>
4475
<H3>
4576
<span className="flex items-center gap-1">
46-
<span>Pending</span>
77+
<span>Accepted</span>
4778
<span>{isFetching && <LoaderIcon className="stroke-1 animate-spin" />}</span>
4879
</span>
4980
</H3>
@@ -80,14 +111,36 @@ function QuoteListPending() {
80111
function DevSection() {
81112
const [devMode] = useLocalStorage("devMode", false)
82113

83-
return <>{devMode && <QuoteListPendingRaw />}</>
114+
const { data: quotesPending } = useSuspenseQuery({
115+
...listPendingQuotesOptions({}),
116+
})
117+
118+
const { data: quotesAccepted } = useSuspenseQuery({
119+
...listPendingQuotesOptions({}),
120+
})
121+
122+
return (
123+
<>
124+
{devMode && (
125+
<>
126+
<pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2">
127+
{JSON.stringify(quotesPending, null, 2)}
128+
</pre>
129+
<pre className="text-sm bg-accent text-accent-foreground rounded-lg p-2 my-2">
130+
{JSON.stringify(quotesAccepted, null, 2)}
131+
</pre>
132+
</>
133+
)}
134+
</>
135+
)
84136
}
85137

86138
function PageBody() {
87139
return (
88140
<>
89141
<Suspense fallback={<Loader />}>
90142
<QuoteListPending />
143+
<QuoteListAccepted />
91144
</Suspense>
92145
</>
93146
)

0 commit comments

Comments
 (0)