@@ -11,6 +11,7 @@ import {
1111} from "@/generated/client/@tanstack/react-query.gen"
1212import useLocalStorage from "@/hooks/use-local-storage"
1313import { useMutation , useQueryClient , useSuspenseQuery } from "@tanstack/react-query"
14+ import { LoaderIcon } from "lucide-react"
1415import { Suspense } from "react"
1516import { Link , useParams } from "react-router"
1617
@@ -22,16 +23,30 @@ function Loader() {
2223 )
2324}
2425
25- function QuoteActions ( { value } : { value : InfoReply } ) {
26+ function QuoteActions ( { value, isFetching } : { value : InfoReply ; isFetching : boolean } ) {
2627 const queryClient = useQueryClient ( )
2728
28- const resolveQuote = useMutation ( {
29+ const denyQuote = useMutation ( {
2930 ...resolveQuoteMutation ( ) ,
3031 onError : ( error ) => {
3132 console . log ( error )
3233 } ,
33- onSuccess : ( data ) => {
34- console . log ( data )
34+ onSuccess : ( ) => {
35+ void queryClient . invalidateQueries ( {
36+ queryKey : adminLookupQuoteQueryKey ( {
37+ path : {
38+ id : value . id ,
39+ } ,
40+ } ) ,
41+ } )
42+ } ,
43+ } )
44+ const offerQuote = useMutation ( {
45+ ...resolveQuoteMutation ( ) ,
46+ onError : ( error ) => {
47+ console . log ( error )
48+ } ,
49+ onSuccess : ( ) => {
3550 void queryClient . invalidateQueries ( {
3651 queryKey : adminLookupQuoteQueryKey ( {
3752 path : {
@@ -43,7 +58,7 @@ function QuoteActions({ value }: { value: InfoReply }) {
4358 } )
4459
4560 const onDenyQuote = ( ) => {
46- resolveQuote . mutate ( {
61+ denyQuote . mutate ( {
4762 path : {
4863 id : value . id ,
4964 } ,
@@ -54,7 +69,7 @@ function QuoteActions({ value }: { value: InfoReply }) {
5469 }
5570
5671 const onOfferQuote = ( ) => {
57- resolveQuote . mutate ( {
72+ offerQuote . mutate ( {
5873 path : {
5974 id : value . id ,
6075 } ,
@@ -69,18 +84,26 @@ function QuoteActions({ value }: { value: InfoReply }) {
6984 return (
7085 < >
7186 < div className = "flex items-center gap-2" >
72- < Button className = "flex-1" onClick = { onDenyQuote } disabled = { value . status === "denied" } >
73- Deny
87+ < Button
88+ className = "flex-1"
89+ onClick = { onDenyQuote }
90+ disabled = { isFetching || denyQuote . isPending || value . status === "denied" }
91+ >
92+ Deny { denyQuote . isPending && < LoaderIcon className = "stroke-1 animate-spin" /> }
7493 </ Button >
75- < Button className = "flex-1" onClick = { onOfferQuote } disabled = { value . status === "offered" } >
76- Offer
94+ < Button
95+ className = "flex-1"
96+ onClick = { onOfferQuote }
97+ disabled = { isFetching || offerQuote . isPending || value . status === "offered" }
98+ >
99+ Offer { offerQuote . isPending && < LoaderIcon className = "stroke-1 animate-spin" /> }
77100 </ Button >
78101 </ div >
79102 </ >
80103 )
81104}
82105
83- function Quote ( { value } : { value : InfoReply } ) {
106+ function Quote ( { value, isFetching } : { value : InfoReply ; isFetching : boolean } ) {
84107 return (
85108 < >
86109 < div className = "flex flex-col gap-1" >
@@ -101,7 +124,7 @@ function Quote({ value }: { value: InfoReply }) {
101124 </ TableBody >
102125 </ Table >
103126
104- < QuoteActions value = { value } />
127+ < QuoteActions value = { value } isFetching = { isFetching } />
105128 </ div >
106129 </ >
107130 )
@@ -132,7 +155,7 @@ function DevSection({ id }: { id: InfoReply["id"] }) {
132155}
133156
134157function PageBody ( { id } : { id : InfoReply [ "id" ] } ) {
135- const { data } = useSuspenseQuery ( {
158+ const { data, isFetching } = useSuspenseQuery ( {
136159 ...adminLookupQuoteOptions ( {
137160 path : {
138161 id,
@@ -142,7 +165,10 @@ function PageBody({ id }: { id: InfoReply["id"] }) {
142165
143166 return (
144167 < >
145- < Quote value = { data } />
168+ < div className = "flex items-center gap-1" >
169+ < span > { isFetching && < LoaderIcon className = "stroke-1 animate-spin" /> } </ span >
170+ </ div >
171+ < Quote value = { data } isFetching = { isFetching } />
146172 </ >
147173 )
148174}
0 commit comments