@@ -60,10 +60,18 @@ export const ExchangeCreateForm = ({
6060 useState ( false )
6161 const [ isOutboundShippingPriceEdit , setIsOutboundShippingPriceEdit ] =
6262 useState ( false )
63+
6364 const [ customInboundShippingAmount , setCustomInboundShippingAmount ] =
64- useState < number | string > ( 0 )
65+ useState < { value : string ; float : number | null } > ( {
66+ value : "0" ,
67+ float : 0 ,
68+ } )
69+
6570 const [ customOutboundShippingAmount , setCustomOutboundShippingAmount ] =
66- useState < number | string > ( 0 )
71+ useState < { value : string ; float : number | null } > ( {
72+ value : "0" ,
73+ float : 0 ,
74+ } )
6775
6876 /**
6977 * MUTATIONS
@@ -252,6 +260,15 @@ export const ExchangeCreateForm = ({
252260 return ( method ?. total as number ) || 0
253261 } , [ preview . shipping_methods ] )
254262
263+ const outboundShippingTotal = useMemo ( ( ) => {
264+ const method = preview . shipping_methods . find (
265+ ( sm ) =>
266+ ! ! sm . actions ?. find ( ( a ) => a . action === "SHIPPING_ADD" && ! a . return_id )
267+ )
268+
269+ return ( method ?. total as number ) || 0
270+ } , [ preview . shipping_methods ] )
271+
255272 return (
256273 < RouteFocusModal . Form form = { form } >
257274 < KeyboundForm onSubmit = { handleSubmit } className = "flex h-full flex-col" >
@@ -356,10 +373,7 @@ export const ExchangeCreateForm = ({
356373 }
357374 } )
358375
359- const customPrice =
360- customInboundShippingAmount === ""
361- ? null
362- : parseFloat ( customInboundShippingAmount )
376+ const customPrice = customInboundShippingAmount . float
363377
364378 if ( actionId ) {
365379 updateInboundShipping (
@@ -381,8 +395,13 @@ export const ExchangeCreateForm = ({
381395 . symbol_native
382396 }
383397 code = { order . currency_code }
384- onValueChange = { setCustomInboundShippingAmount }
385- value = { customInboundShippingAmount }
398+ onValueChange = { ( value , name , values ) =>
399+ setCustomInboundShippingAmount ( {
400+ value : values ?. value || "" ,
401+ float : values ?. float || null ,
402+ } )
403+ }
404+ value = { customInboundShippingAmount . value }
386405 disabled = { ! inboundPreviewItems ?. length }
387406 />
388407 ) : (
@@ -427,10 +446,7 @@ export const ExchangeCreateForm = ({
427446 }
428447 } )
429448
430- const customPrice =
431- customOutboundShippingAmount === ""
432- ? null
433- : parseFloat ( customOutboundShippingAmount )
449+ const customPrice = customOutboundShippingAmount . float
434450
435451 if ( actionId ) {
436452 updateOutboundShipping (
@@ -452,13 +468,18 @@ export const ExchangeCreateForm = ({
452468 . symbol_native
453469 }
454470 code = { order . currency_code }
455- onValueChange = { setCustomOutboundShippingAmount }
456- value = { customOutboundShippingAmount }
471+ onValueChange = { ( value , name , values ) =>
472+ setCustomOutboundShippingAmount ( {
473+ value : values ?. value || "" ,
474+ float : values ?. float || null ,
475+ } )
476+ }
477+ value = { customOutboundShippingAmount . value }
457478 disabled = { ! outboundPreviewItems ?. length }
458479 />
459480 ) : (
460481 getStylizedAmount (
461- outboundShipping ?. amount ?? 0 ,
482+ outboundShippingTotal ,
462483 order . currency_code
463484 )
464485 ) }
0 commit comments