Skip to content

Commit eaee675

Browse files
committed
add coupon code input to the billing page
1 parent ad5175f commit eaee675

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

src/intl/en.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"back": "Back",
88
"next": "Next",
99
"import": "Import",
10+
"send": "Send",
1011
"override": "Override",
1112
"noValue": "--",
1213
"notApplicable": "N/A",
@@ -2317,6 +2318,12 @@
23172318
"upgradeRequired": "You have no invoices or payment methods",
23182319
"cta": "Manage billing"
23192320
},
2321+
"coupon": {
2322+
"title": "Discount",
2323+
"description": "Enter a discount code",
2324+
"couponSent": "The coupon code has been applied to your organization",
2325+
"hobbyPlanUpgrade": "Have a coupon? <upgrade>Upgrade to the starter plan</upgrade> to apply it."
2326+
},
23202327
"billingInformation": {
23212328
"title": "Billing information",
23222329
"description": "This information appears on your monthly invoice and should be the legal address of your home or business",

src/pages/settings/organization/billing/billing.page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { BillingInformation } from './billing-information';
2+
import { Coupon } from './coupon';
23
import { StripePortal } from './stripe-portal';
34
import { Usage } from './usage';
45

@@ -7,6 +8,7 @@ export function BillingPage() {
78
<>
89
<Usage />
910
<StripePortal />
11+
<Coupon />
1012
<BillingInformation />
1113
</>
1214
);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useForm } from 'react-hook-form';
2+
3+
import { Button } from '@koyeb/design-system';
4+
import { useOrganization } from 'src/api/hooks/session';
5+
import { notify } from 'src/application/notify';
6+
import { ControlledInput } from 'src/components/controlled';
7+
import { SectionHeader } from 'src/components/section-header';
8+
import { createTranslate, Translate } from 'src/intl/translate';
9+
10+
const T = createTranslate('pages.organizationSettings.billing.coupon');
11+
12+
export function Coupon() {
13+
const organization = useOrganization();
14+
const t = T.useTranslate();
15+
16+
const form = useForm({
17+
defaultValues: {
18+
coupon: '',
19+
},
20+
});
21+
22+
const handleSubmit = (value: string) => {
23+
// eslint-disable-next-line no-console
24+
console.log('Sending coupon code to API:', value);
25+
form.reset();
26+
notify.success(t('couponSent'));
27+
};
28+
29+
return (
30+
<section className="col gap-6">
31+
<SectionHeader title={<T id="title" />} description={<T id="description" />} />
32+
33+
<form
34+
onSubmit={form.handleSubmit(({ coupon }) => handleSubmit(coupon))}
35+
className="row max-w-md items-center gap-4"
36+
>
37+
<ControlledInput control={form.control} name="coupon" className="w-full" />
38+
39+
<Button type="submit">
40+
<Translate id="common.send" />
41+
</Button>
42+
</form>
43+
44+
{organization.plan === 'hobby' && (
45+
<p className="border-l-4 border-green/50 pl-3 text-xs">
46+
<T id="hobbyPlanUpgrade" />
47+
</p>
48+
)}
49+
</section>
50+
);
51+
}

0 commit comments

Comments
 (0)