@@ -34,11 +34,13 @@ function Loader() {
3434 )
3535}
3636
37- type OfferFormResult = Parameters < Parameters < typeof GrossToNetDiscountForm > [ 0 ] [ "onSubmit" ] > [ 0 ]
37+ interface OfferFormResult {
38+ discount : Parameters < Parameters < typeof GrossToNetDiscountForm > [ 0 ] [ "onSubmit" ] > [ 0 ]
39+ }
3840
3941interface OfferFormProps {
4042 discount : Omit < Parameters < typeof GrossToNetDiscountForm > [ 0 ] , "onSubmit" >
41- onSubmit : Parameters < typeof GrossToNetDiscountForm > [ 0 ] [ "onSubmit" ]
43+ onSubmit : ( result : OfferFormResult ) => void
4244}
4345
4446function OfferForm ( { onSubmit, discount } : OfferFormProps ) {
@@ -47,7 +49,9 @@ function OfferForm({ onSubmit, discount }: OfferFormProps) {
4749 < GrossToNetDiscountForm
4850 { ...discount }
4951 startDate = { discount . startDate ?? new Date ( Date . now ( ) ) }
50- onSubmit = { onSubmit }
52+ onSubmit = { ( values ) => onSubmit ( {
53+ discount : values
54+ } ) }
5155 submitButtonText = "Next"
5256 />
5357 </ >
@@ -62,7 +66,7 @@ type OfferFormDrawerProps = Parameters<typeof BaseDrawer>[0] & {
6266function OfferFormDrawer ( { value, onSubmit, children, ...drawerProps } : OfferFormDrawerProps ) {
6367 return (
6468 < BaseDrawer { ...drawerProps } trigger = { children } >
65- < div className = "px-4 py -12" >
69+ < div className = "px-4 pt -12" >
6670 < OfferForm
6771 discount = { {
6872 endDate : new Date ( Date . parse ( value . bill . maturity_date ) ) ,
@@ -126,7 +130,7 @@ function QuoteActions({ value, isFetching }: { value: InfoReply; isFetching: boo
126130 const effectiveDiscount = useMemo ( ( ) => {
127131 if ( ! offerFormData ) return
128132 console . table ( offerFormData )
129- return new Big ( 1 ) . minus ( offerFormData . net . value . div ( offerFormData . gross . value ) )
133+ return new Big ( 1 ) . minus ( offerFormData . discount . net . value . div ( offerFormData . discount . gross . value ) )
130134 } , [ offerFormData ] )
131135
132136 const queryClient = useQueryClient ( )
@@ -184,15 +188,15 @@ function QuoteActions({ value, isFetching }: { value: InfoReply; isFetching: boo
184188 } )
185189 }
186190
187- const onOfferQuote = ( values : OfferFormResult ) => {
191+ const onOfferQuote = ( result : OfferFormResult ) => {
188192 toast . loading ( "Offering quote…" , { id : `quote-${ value . id } -offer` } )
189193 offerQuote . mutate ( {
190194 path : {
191195 id : value . id ,
192196 } ,
193197 body : {
194198 action : "offer" ,
195- discount : values . net . value . div ( values . gross . value ) . toFixed ( 4 ) ,
199+ discount : result . discount . net . value . div ( result . discount . gross . value ) . toFixed ( 4 ) ,
196200 ttl : "1" ,
197201 } ,
198202 } )
@@ -251,11 +255,11 @@ function QuoteActions({ value, isFetching }: { value: InfoReply; isFetching: boo
251255 </ span >
252256 < span >
253257 < span className = "font-bold" > Effective discount (absolute):</ span > { " " }
254- { offerFormData ?. gross . value . minus ( offerFormData ?. net . value ) . toFixed ( 0 ) } { offerFormData ?. net . currency }
258+ { offerFormData ?. discount . gross . value . minus ( offerFormData ?. discount . net . value ) . toFixed ( 0 ) } { offerFormData ?. discount . net . currency }
255259 </ span >
256260 < span >
257- < span className = "font-bold" > Net amount:</ span > { offerFormData ?. net . value . round ( 0 ) . toFixed ( 0 ) } { " " }
258- { offerFormData ?. net . currency }
261+ < span className = "font-bold" > Net amount:</ span > { offerFormData ?. discount . net . value . round ( 0 ) . toFixed ( 0 ) } { " " }
262+ { offerFormData ?. discount . net . currency }
259263 </ span >
260264 </ div >
261265 </ OfferConfirmDrawer >
0 commit comments