Skip to content

Commit 16b571f

Browse files
add locale to context provider (#1218)
* add locale to context provider * add changeset * set default locale to en-US and rename isInCents to inputInMinorUnits for clarity
1 parent 98c4842 commit 16b571f

File tree

14 files changed

+159
-111
lines changed

14 files changed

+159
-111
lines changed

.changeset/plenty-memes-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@godaddy/react": patch
3+
---
4+
5+
Add support for locale prop on context provider

packages/react/src/components/checkout/form/checkout-form.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { ShippingMethodForm } from '@/components/checkout/shipping/shipping-meth
3838
import { Target } from '@/components/checkout/target/target';
3939
import { TipsForm } from '@/components/checkout/tips/tips-form';
4040
import { DraftOrderTotals } from '@/components/checkout/totals/totals';
41-
import { formatCurrency } from '@/components/checkout/utils/format-currency';
41+
import { useFormatCurrency } from '@/components/checkout/utils/format-currency';
4242
import {
4343
Accordion,
4444
AccordionContent,
@@ -71,6 +71,7 @@ export function CheckoutForm({
7171
items,
7272
...props
7373
}: CheckoutFormProps) {
74+
const formatCurrency = useFormatCurrency();
7475
const { t } = useGoDaddyContext();
7576
const { session, isCheckoutDisabled } = useCheckoutContext();
7677

@@ -439,7 +440,7 @@ export function CheckoutForm({
439440
{formatCurrency({
440441
amount: totals?.total?.value || 0,
441442
currencyCode,
442-
isInCents: true,
443+
inputInMinorUnits: true,
443444
})}
444445
</span>
445446
</div>
@@ -449,11 +450,11 @@ export function CheckoutForm({
449450
<DraftOrderLineItems
450451
currencyCode={currencyCode}
451452
items={items}
452-
isInCents
453+
inputInMinorUnits
453454
/>
454455

455456
<DraftOrderTotals
456-
isInCents
457+
inputInMinorUnits
457458
currencyCode={currencyCode}
458459
tip={tipTotal}
459460
taxes={taxTotal}
@@ -480,11 +481,11 @@ export function CheckoutForm({
480481
<DraftOrderLineItems
481482
currencyCode={currencyCode}
482483
items={items}
483-
isInCents
484+
inputInMinorUnits
484485
/>
485486

486487
<DraftOrderTotals
487-
isInCents
488+
inputInMinorUnits
488489
currencyCode={currencyCode}
489490
tip={tipTotal}
490491
taxes={taxTotal}

packages/react/src/components/checkout/line-items/line-items.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// import { Badge } from "@/components/ui/badge";
22

33
import { Image } from 'lucide-react';
4-
import { formatCurrency } from '@/components/checkout/utils/format-currency';
4+
import { useFormatCurrency } from '@/components/checkout/utils/format-currency';
55
import { useGoDaddyContext } from '@/godaddy-provider';
66
import type { SKUProduct } from '@/types';
77

@@ -56,15 +56,16 @@ export type Product = Partial<SKUProduct> & {
5656
export interface DraftOrderLineItemsProps {
5757
items: Product[];
5858
currencyCode?: string;
59-
isInCents?: boolean;
59+
inputInMinorUnits?: boolean;
6060
}
6161

6262
export function DraftOrderLineItems({
6363
items,
6464
currencyCode = 'USD',
65-
isInCents = false,
65+
inputInMinorUnits = false,
6666
}: DraftOrderLineItemsProps) {
6767
const { t } = useGoDaddyContext();
68+
const formatCurrency = useFormatCurrency();
6869

6970
return (
7071
<div className='space-y-4 mb-4'>
@@ -135,7 +136,7 @@ export function DraftOrderLineItems({
135136
{formatCurrency({
136137
amount: item.originalPrice * item.quantity,
137138
currencyCode,
138-
isInCents,
139+
inputInMinorUnits,
139140
})}
140141
</span>
141142
</div>

packages/react/src/components/checkout/payment/checkout-buttons/express/godaddy.tsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { filterAndSortShippingMethods } from '@/components/checkout/shipping/uti
3434
import { useGetShippingMethodByAddress } from '@/components/checkout/shipping/utils/use-get-shipping-methods';
3535
import { useGetTaxes } from '@/components/checkout/taxes/utils/use-get-taxes';
3636
import { mapOrderToFormValues } from '@/components/checkout/utils/checkout-transformers';
37-
import { formatCurrency } from '@/components/checkout/utils/format-currency';
37+
import { useFormatCurrency } from '@/components/checkout/utils/format-currency';
3838
import { Skeleton } from '@/components/ui/skeleton';
3939
import { useGoDaddyContext } from '@/godaddy-provider';
4040
import { GraphQLErrorWithCodes } from '@/lib/graphql-with-errors';
@@ -46,6 +46,7 @@ import {
4646
} from '@/tracking/track';
4747

4848
export function ExpressCheckoutButton() {
49+
const formatCurrency = useFormatCurrency();
4950
const { session, setCheckoutErrors } = useCheckoutContext();
5051
const { isPoyntLoaded } = useLoadPoyntCollect();
5152
const { godaddyPaymentsConfig } = useCheckoutContext();
@@ -139,7 +140,7 @@ export function ExpressCheckoutButton() {
139140
const shippingMethodPrice = formatCurrency({
140141
amount: method.cost?.value || 0,
141142
currencyCode: method.cost?.currencyCode || currencyCode,
142-
isInCents: true,
143+
inputInMinorUnits: true,
143144
});
144145

145146
return {
@@ -151,7 +152,7 @@ export function ExpressCheckoutButton() {
151152
amount: formatCurrency({
152153
amount: method.cost?.value || 0,
153154
currencyCode: method.cost?.currencyCode || currencyCode,
154-
isInCents: true,
155+
inputInMinorUnits: true,
155156
returnRaw: true,
156157
}),
157158
amountInMinorUnits: method.cost?.value || 0, // Keep original minor unit value
@@ -186,7 +187,7 @@ export function ExpressCheckoutButton() {
186187
amount: formatCurrency({
187188
amount: -priceAdjustment,
188189
currencyCode,
189-
isInCents: true,
190+
inputInMinorUnits: true,
190191
returnRaw: true,
191192
}),
192193
isPending: false,
@@ -199,7 +200,7 @@ export function ExpressCheckoutButton() {
199200
const totalAmount = formatCurrency({
200201
amount: totalInMinorUnits,
201202
currencyCode,
202-
isInCents: true,
203+
inputInMinorUnits: true,
203204
returnRaw: true,
204205
});
205206

@@ -217,7 +218,7 @@ export function ExpressCheckoutButton() {
217218
amount: formatCurrency({
218219
amount: -priceAdjustment,
219220
currencyCode,
220-
isInCents: true,
221+
inputInMinorUnits: true,
221222
returnRaw: true,
222223
}),
223224
},
@@ -356,7 +357,7 @@ export function ExpressCheckoutButton() {
356357
amount: formatCurrency({
357358
amount: priceAdjustment,
358359
currencyCode,
359-
isInCents: true,
360+
inputInMinorUnits: true,
360361
returnRaw: true,
361362
}),
362363
};
@@ -553,7 +554,7 @@ export function ExpressCheckoutButton() {
553554
amount: formatCurrency({
554555
amount: godaddyTotals.shipping.value,
555556
currencyCode,
556-
isInCents: true,
557+
inputInMinorUnits: true,
557558
returnRaw: true,
558559
}),
559560
});
@@ -565,7 +566,7 @@ export function ExpressCheckoutButton() {
565566
amount: formatCurrency({
566567
amount: godaddyTotals.taxes.value,
567568
currencyCode,
568-
isInCents: true,
569+
inputInMinorUnits: true,
569570
returnRaw: true,
570571
}),
571572
});
@@ -580,7 +581,7 @@ export function ExpressCheckoutButton() {
580581
const totalAmount = formatCurrency({
581582
amount: totalInMinorUnits,
582583
currencyCode,
583-
isInCents: true,
584+
inputInMinorUnits: true,
584585
returnRaw: true,
585586
});
586587

@@ -631,7 +632,7 @@ export function ExpressCheckoutButton() {
631632
amount: formatCurrency({
632633
amount: godaddyTotals.shipping.value,
633634
currencyCode,
634-
isInCents: true,
635+
inputInMinorUnits: true,
635636
returnRaw: true,
636637
}),
637638
});
@@ -643,7 +644,7 @@ export function ExpressCheckoutButton() {
643644
amount: formatCurrency({
644645
amount: godaddyTotals.taxes.value,
645646
currencyCode,
646-
isInCents: true,
647+
inputInMinorUnits: true,
647648
returnRaw: true,
648649
}),
649650
});
@@ -655,7 +656,7 @@ export function ExpressCheckoutButton() {
655656
amount: formatCurrency({
656657
amount: -adjustment,
657658
currencyCode,
658-
isInCents: true,
659+
inputInMinorUnits: true,
659660
returnRaw: true,
660661
}),
661662
});
@@ -670,7 +671,7 @@ export function ExpressCheckoutButton() {
670671
const totalAmount = formatCurrency({
671672
amount: totalInMinorUnits,
672673
currencyCode,
673-
isInCents: true,
674+
inputInMinorUnits: true,
674675
returnRaw: true,
675676
});
676677

@@ -686,7 +687,7 @@ export function ExpressCheckoutButton() {
686687
amount: formatCurrency({
687688
amount: -adjustment,
688689
currencyCode,
689-
isInCents: true,
690+
inputInMinorUnits: true,
690691
returnRaw: true,
691692
}),
692693
},
@@ -980,7 +981,7 @@ export function ExpressCheckoutButton() {
980981
amount: formatCurrency({
981982
amount: taxesResult.value,
982983
currencyCode,
983-
isInCents: true,
984+
inputInMinorUnits: true,
984985
returnRaw: true,
985986
}),
986987
isPending: false,
@@ -1016,7 +1017,7 @@ export function ExpressCheckoutButton() {
10161017
amount: formatCurrency({
10171018
amount: -priceAdjustment,
10181019
currencyCode,
1019-
isInCents: true,
1020+
inputInMinorUnits: true,
10201021
returnRaw: true,
10211022
}),
10221023
isPending: false,
@@ -1045,7 +1046,7 @@ export function ExpressCheckoutButton() {
10451046
amount: formatCurrency({
10461047
amount: -priceAdjustment,
10471048
currencyCode,
1048-
isInCents: true,
1049+
inputInMinorUnits: true,
10491050
returnRaw: true,
10501051
}),
10511052
};
@@ -1161,7 +1162,7 @@ export function ExpressCheckoutButton() {
11611162
amount: formatCurrency({
11621163
amount: taxesResult.value,
11631164
currencyCode,
1164-
isInCents: true,
1165+
inputInMinorUnits: true,
11651166
returnRaw: true,
11661167
}),
11671168
isPending: false,
@@ -1200,7 +1201,7 @@ export function ExpressCheckoutButton() {
12001201
amount: formatCurrency({
12011202
amount: -priceAdjustment,
12021203
currencyCode,
1203-
isInCents: true,
1204+
inputInMinorUnits: true,
12041205
returnRaw: true,
12051206
}),
12061207
isPending: false,
@@ -1230,7 +1231,7 @@ export function ExpressCheckoutButton() {
12301231
amount: formatCurrency({
12311232
amount: -priceAdjustment,
12321233
currencyCode,
1233-
isInCents: true,
1234+
inputInMinorUnits: true,
12341235
returnRaw: true,
12351236
}),
12361237
};

packages/react/src/components/checkout/payment/payment-form.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import {
3434
DraftOrderTotals,
3535
type DraftOrderTotalsProps,
3636
} from '@/components/checkout/totals/totals';
37-
import { formatCurrency } from '@/components/checkout/utils/format-currency';
37+
import { useFormatCurrency } from '@/components/checkout/utils/format-currency';
3838
import {
3939
Accordion,
4040
AccordionContent,
@@ -72,6 +72,7 @@ const PAYMENT_METHOD_ICONS: Record<string, React.ReactNode> = {
7272
export function PaymentForm(
7373
props: DraftOrderTotalsProps & { items: Product[] }
7474
) {
75+
const formatCurrency = useFormatCurrency();
7576
const { t } = useGoDaddyContext();
7677
const {
7778
session,
@@ -451,7 +452,7 @@ export function PaymentForm(
451452
{formatCurrency({
452453
amount: props.total || 0,
453454
currencyCode: props.currencyCode || 'USD',
454-
isInCents: true,
455+
inputInMinorUnits: true,
455456
})}
456457
</span>
457458
</div>
@@ -461,15 +462,15 @@ export function PaymentForm(
461462
<DraftOrderLineItems
462463
currencyCode={props.currencyCode}
463464
items={props.items}
464-
isInCents
465+
inputInMinorUnits
465466
/>
466467
</div>
467468
</AccordionContent>
468469
</AccordionItem>
469470
</Accordion>
470471
<div className='pt-4'>
471472
<DraftOrderTotals
472-
isInCents
473+
inputInMinorUnits
473474
currencyCode={props.currencyCode}
474475
tip={props.tip}
475476
taxes={props.taxes}

0 commit comments

Comments
 (0)