@@ -11,6 +11,7 @@ import {
11
11
CardHeader ,
12
12
CardTitle ,
13
13
} from "@/components/ui/card" ;
14
+ import { Input } from "@/components/ui/input" ;
14
15
import { Label } from "@/components/ui/label" ;
15
16
import { RadioGroup , RadioGroupItem } from "@/components/ui/radio-group" ;
16
17
import { Separator } from "@/components/ui/separator" ;
@@ -39,6 +40,12 @@ export function CreditBalanceSection({
39
40
const [ selectedAmount , setSelectedAmount ] = useState < string > (
40
41
predefinedAmounts [ 0 ] . value ,
41
42
) ;
43
+ const [ customAmount , setCustomAmount ] = useState < string > ( "" ) ;
44
+
45
+ const isSelectedAmountValid =
46
+ selectedAmount !== "" &&
47
+ Number . isInteger ( Number ( selectedAmount ) ) &&
48
+ Number ( selectedAmount ) > 0 ;
42
49
43
50
return (
44
51
< Card className = "w-full" >
@@ -74,7 +81,10 @@ export function CreditBalanceSection({
74
81
< Label className = "font-medium text-base" > Select Amount</ Label >
75
82
< RadioGroup
76
83
className = "grid grid-cols-4 gap-3"
77
- onValueChange = { setSelectedAmount }
84
+ onValueChange = { ( value ) => {
85
+ setSelectedAmount ( value ) ;
86
+ setCustomAmount ( "" ) ;
87
+ } }
78
88
value = { selectedAmount }
79
89
>
80
90
{ predefinedAmounts . map ( ( amount ) => (
@@ -95,6 +105,30 @@ export function CreditBalanceSection({
95
105
</ div >
96
106
) ) }
97
107
</ RadioGroup >
108
+
109
+ { /* Custom Amount Input */ }
110
+ < div className = "space-y-2" >
111
+ < Label className = "font-medium text-base" htmlFor = "customAmount" >
112
+ Or enter custom amount
113
+ </ Label >
114
+ < Input
115
+ id = "customAmount"
116
+ type = "number"
117
+ inputMode = "numeric"
118
+ pattern = "[0-9]*"
119
+ min = { 1 }
120
+ step = { 1 }
121
+ value = { customAmount }
122
+ placeholder = "Custom amount"
123
+ onChange = { ( e ) => {
124
+ const val = e . target . value . replace ( / ^ 0 + / , "" ) ;
125
+ if ( / ^ \d * $ / . test ( val ) ) {
126
+ setCustomAmount ( val ) ;
127
+ setSelectedAmount ( val ) ;
128
+ }
129
+ } }
130
+ />
131
+ </ div >
98
132
</ div >
99
133
100
134
{ /* Top-up Summary and Button */ }
@@ -125,7 +159,7 @@ export function CreditBalanceSection({
125
159
< Button
126
160
asChild
127
161
className = "w-full"
128
- disabled = { ! isOwnerAccount }
162
+ disabled = { ! isOwnerAccount || ! isSelectedAmountValid }
129
163
size = "lg"
130
164
>
131
165
< a
0 commit comments