Skip to content

Commit 48361f9

Browse files
authored
Add custom amount input to credit balance section (#7697)
1 parent 1659ae3 commit 48361f9

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/(team)/~/billing/components/credit-balance-section.client.tsx

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
CardHeader,
1212
CardTitle,
1313
} from "@/components/ui/card";
14+
import { Input } from "@/components/ui/input";
1415
import { Label } from "@/components/ui/label";
1516
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
1617
import { Separator } from "@/components/ui/separator";
@@ -39,6 +40,12 @@ export function CreditBalanceSection({
3940
const [selectedAmount, setSelectedAmount] = useState<string>(
4041
predefinedAmounts[0].value,
4142
);
43+
const [customAmount, setCustomAmount] = useState<string>("");
44+
45+
const isSelectedAmountValid =
46+
selectedAmount !== "" &&
47+
Number.isInteger(Number(selectedAmount)) &&
48+
Number(selectedAmount) > 0;
4249

4350
return (
4451
<Card className="w-full">
@@ -74,7 +81,10 @@ export function CreditBalanceSection({
7481
<Label className="font-medium text-base">Select Amount</Label>
7582
<RadioGroup
7683
className="grid grid-cols-4 gap-3"
77-
onValueChange={setSelectedAmount}
84+
onValueChange={(value) => {
85+
setSelectedAmount(value);
86+
setCustomAmount("");
87+
}}
7888
value={selectedAmount}
7989
>
8090
{predefinedAmounts.map((amount) => (
@@ -95,6 +105,30 @@ export function CreditBalanceSection({
95105
</div>
96106
))}
97107
</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>
98132
</div>
99133

100134
{/* Top-up Summary and Button */}
@@ -125,7 +159,7 @@ export function CreditBalanceSection({
125159
<Button
126160
asChild
127161
className="w-full"
128-
disabled={!isOwnerAccount}
162+
disabled={!isOwnerAccount || !isSelectedAmountValid}
129163
size="lg"
130164
>
131165
<a

0 commit comments

Comments
 (0)