11import { t } from "@lingui/macro" ;
22import { Anchor , Button , Grid , Group , NumberInput , SegmentedControl , Stack , Text , Title } from "@mantine/core" ;
3- import { useEffect , useRef , useState } from "react" ;
3+ import { useEffect , useState } from "react" ;
44import { Card } from "../Card" ;
55import { HeadingWithDescription } from "../Card/CardHeading" ;
66import { formatCurrency } from "../../../utilites/currency.ts" ;
@@ -92,8 +92,7 @@ export const PlatformFeesSettings = ({
9292 feeHandlingDescription,
9393} : PlatformFeesSettingsProps ) => {
9494 const [ samplePrice , setSamplePrice ] = useState < number | string > ( 50 ) ;
95- const [ selectedOption , setSelectedOption ] = useState < 'pass' | 'absorb' > ( 'absorb' ) ;
96- const initializedRef = useRef ( false ) ;
95+ const [ selectedOption , setSelectedOption ] = useState < 'pass' | 'absorb' > ( currentValue ? 'pass' : 'absorb' ) ;
9796
9897 const feePercentage = configuration ?. application_fees ?. percentage || 0 ;
9998 const fixedFee = configuration ?. application_fees ?. fixed || 0 ;
@@ -105,11 +104,10 @@ export const PlatformFeesSettings = ({
105104 onSave ( selectedOption === 'pass' ) ;
106105 } ;
107106
108- // Initialize selected option from currentValue only once after data loads
107+ // Sync selected option when currentValue changes (e.g., after data loads)
109108 useEffect ( ( ) => {
110- if ( ! isLoading && ! initializedRef . current ) {
109+ if ( ! isLoading ) {
111110 setSelectedOption ( currentValue ? 'pass' : 'absorb' ) ;
112- initializedRef . current = true ;
113111 }
114112 } , [ isLoading , currentValue ] ) ;
115113
0 commit comments