Skip to content

Commit ec55b76

Browse files
committed
apply QA feedback
1 parent 6c4aa72 commit ec55b76

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

src/intl/en.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,10 +2368,12 @@
23682368
"cta": "Manage billing"
23692369
},
23702370
"coupon": {
2371-
"title": "Discount",
2372-
"description": "Enter a discount code",
2371+
"title": "Coupon code",
2372+
"description": "Redeem a coupon code",
2373+
"placeholder": "COUPON_CODE",
2374+
"submit": "Redeem",
23732375
"couponSent": "The coupon code has been applied to your organization",
2374-
"hobbyPlanUpgrade": "Have a coupon? <upgrade>Upgrade to the starter plan</upgrade> to apply it."
2376+
"hobbyPlanUpgrade": "Do you have a coupon? <upgrade>Upgrade to the Starter plan</upgrade> to apply it."
23752377
},
23762378
"billingInformation": {
23772379
"title": "Billing information",

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
import { useMutation } from '@tanstack/react-query';
12
import { useForm } from 'react-hook-form';
23

34
import { Button } from '@koyeb/design-system';
45
import { useOrganization } from 'src/api/hooks/session';
56
import { notify } from 'src/application/notify';
67
import { ControlledInput } from 'src/components/controlled';
78
import { SectionHeader } from 'src/components/section-header';
8-
import { handleSubmit } from 'src/hooks/form';
9+
import { FormValues, handleSubmit } from 'src/hooks/form';
910
import { useSearchParams } from 'src/hooks/router';
10-
import { createTranslate, Translate } from 'src/intl/translate';
11+
import { createTranslate } from 'src/intl/translate';
1112

1213
const T = createTranslate('pages.organizationSettings.billing.coupon');
1314

@@ -22,23 +23,32 @@ export function Coupon() {
2223
},
2324
});
2425

26+
const mutation = useMutation({
27+
async mutationFn({ coupon }: FormValues<typeof form>) {
28+
// eslint-disable-next-line no-console
29+
console.log('Sending coupon code to API:', coupon);
30+
await new Promise((r) => setTimeout(r, 1000));
31+
},
32+
onSuccess() {
33+
form.reset();
34+
notify.success(t('couponSent'));
35+
},
36+
});
37+
2538
return (
2639
<section className="col gap-6">
2740
<SectionHeader title={<T id="title" />} description={<T id="description" />} />
2841

29-
<form
30-
onSubmit={handleSubmit(form, ({ coupon }) => {
31-
// eslint-disable-next-line no-console
32-
console.log('Sending coupon code to API:', coupon);
33-
form.reset();
34-
notify.success(t('couponSent'));
35-
})}
36-
className="row max-w-md items-center gap-4"
37-
>
38-
<ControlledInput control={form.control} name="coupon" className="w-full" />
39-
40-
<Button type="submit">
41-
<Translate id="common.send" />
42+
<form onSubmit={handleSubmit(form, mutation.mutateAsync)} className="row max-w-md items-center gap-4">
43+
<ControlledInput
44+
control={form.control}
45+
name="coupon"
46+
placeholder={t('placeholder')}
47+
className="w-full"
48+
/>
49+
50+
<Button type="submit" loading={form.formState.isSubmitting}>
51+
<T id="submit" />
4252
</Button>
4353
</form>
4454

0 commit comments

Comments
 (0)