Skip to content

Commit a006383

Browse files
committed
modules/checkout
1 parent c8af778 commit a006383

File tree

11 files changed

+137
-58
lines changed

11 files changed

+137
-58
lines changed

src/locales/us.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
export default {
22
"generic.somethingwrong": "Something went wrong",
3+
"generic.edit": "Something went wrong",
4+
"generic.apply": "Apply",
5+
36
"nav.title": "Store",
47
"nav.search": "Search",
58
"nav.account": "Account",
@@ -24,6 +27,41 @@ export default {
2427
"cart.empty_prompt2": "Explore products",
2528
"cart.": "",
2629

30+
"checkout.inyourcart": "In your Cart",
31+
"checkout.chooseaddress": "Choose an address",
32+
"checkout.shipping_address": "Shipping Address",
33+
"checkout.billing_address": "Billing address",
34+
"checkout.continue": "Continue to delivery",
35+
"checkout.same_as_billing": "Billing - and delivery address are the same.",
36+
"checkout.shipping.free": "Free shipping",
37+
"checkout.giftcards": "Gift card(s) applied:",
38+
"checkout.code": "Code: ",
39+
"checkout.removegift": "Remove gift card from order",
40+
"checkout.discount": "Discount applied:",
41+
"checkout.removediscount": "Remove discount code from order",
42+
"checkout.addgift": "Add gift card or discount code",
43+
"checkout.entercode": "Please enter code",
44+
"checkout.payment.title": "Payment",
45+
"checkout.payment.gift": "Gift card",
46+
"checkout.payment.method": "Payment method",
47+
"checkout.payment.anotherstep": "Another step will appear",
48+
"checkout.payment.details": "Payment details",
49+
"checkout.payment.continue": "Continue to review",
50+
"checkout.payment.card_details": "Enter your card details:",
51+
"checkout.payment.place_order": "Place order",
52+
"checkout.payment.error": "An error occurred, please try again.",
53+
"checkout.payment.error_unknown": "An unknown error occurred, please try again.",
54+
"checkout.payment.error_params": "An error occurred, status",
55+
"checkout.payment.stripe.error1": "Stripe key is missing. Set NEXT_PUBLIC_STRIPE_KEY environment variable.",
56+
"checkout.payment.stripe.error2": "Stripe promise is missing. Make sure you have provided a valid Stripe key.",
57+
"checkout.payment.stripe.error3": "Stripe client secret is missing. Cannot initialize Stripe.",
58+
"checkout.payment.review.title": "Review",
59+
"checkout.payment.review.aggrement": "By clicking the Place Order button, you confirm that you have read, understand and accept our Terms of Use, Terms of Sale and Returns Policy and acknowledge that you have read the Store's Privacy Policy.",
60+
"checkout.shipping.title": "Delivery",
61+
"checkout.shipping.edit": "Edit",
62+
"checkout.shipping.continue": "Continue to payment",
63+
"checkout.shipping.method": "Method",
64+
"checkout.": "",
2765

2866
"cart.dropdown.cart": "Cart ({count})",
2967
"cart.dropdown.quantity": "Quantity: ",

src/modules/checkout/components/address-select/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import { clx } from "@medusajs/ui"
55
import { omit } from "lodash"
66
import { Fragment, useMemo } from "react"
77

8+
import { useScopedI18n } from '../../../../locales/client'
9+
810
import Radio from "@modules/common/components/radio"
911
import { cartUpdate } from "@modules/checkout/actions"
1012
import compareAddresses from "@lib/util/compare-addresses"
@@ -15,6 +17,7 @@ type AddressSelectProps = {
1517
}
1618

1719
const AddressSelect = ({ addresses, cart }: AddressSelectProps) => {
20+
const t = useScopedI18n("checkout")
1821
const handleSelect = (id: string) => {
1922
const savedAddress = addresses.find((a) => a.id === id)
2023
if (savedAddress) {
@@ -47,7 +50,7 @@ const AddressSelect = ({ addresses, cart }: AddressSelectProps) => {
4750
<span className="block truncate">
4851
{selectedAddress
4952
? selectedAddress.address_1
50-
: "Choose an address"}
53+
: t("chooseaddress") }
5154
</span>
5255
<ChevronUpDown
5356
className={clx("transition-rotate duration-200", {

src/modules/checkout/components/addresses/index.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { Cart, Customer } from "@medusajs/medusa"
1010
import { CheckCircleSolid } from "@medusajs/icons"
1111
import { Heading, Text, useToggleState } from "@medusajs/ui"
1212

13+
import { useI18n } from "../../../../locales/client"
14+
1315
import Divider from "@modules/common/components/divider"
1416
import Spinner from "@modules/common/icons/spinner"
1517

@@ -28,6 +30,7 @@ const Addresses = ({
2830
cart: Omit<Cart, "refundable_amount" | "refunded_total"> | null
2931
customer: Omit<Customer, "password_hash"> | null
3032
}) => {
33+
const t = useI18n()
3134
const searchParams = useSearchParams()
3235
const router = useRouter()
3336
const pathname = usePathname()
@@ -56,7 +59,7 @@ const Addresses = ({
5659
level="h2"
5760
className="flex flex-row text-3xl-regular gap-x-2 items-baseline"
5861
>
59-
Shipping Address
62+
{t("checkout.shipping_address")}
6063
{!isOpen && <CheckCircleSolid />}
6164
</Heading>
6265
{!isOpen && cart?.shipping_address && (
@@ -66,7 +69,7 @@ const Addresses = ({
6669
className="text-ui-fg-interactive hover:text-ui-fg-interactive-hover"
6770
data-testid="edit-address-button"
6871
>
69-
Edit
72+
{t("generic.edit")}
7073
</button>
7174
</Text>
7275
)}
@@ -88,13 +91,15 @@ const Addresses = ({
8891
level="h2"
8992
className="text-3xl-regular gap-x-4 pb-6 pt-8"
9093
>
91-
Billing address
94+
{t("checkout.billing_address")}
9295
</Heading>
9396

9497
<BillingAddress cart={cart} countryCode={countryCode} />
9598
</div>
9699
)}
97-
<SubmitButton className="mt-6" data-testid="submit-address-button">Continue to delivery</SubmitButton>
100+
<SubmitButton className="mt-6" data-testid="submit-address-button">
101+
{t("checkout.continue")}
102+
</SubmitButton>
98103
<ErrorMessage error={message} data-testid="address-error-message" />
99104
</div>
100105
</form>
@@ -104,9 +109,12 @@ const Addresses = ({
104109
{cart && cart.shipping_address ? (
105110
<div className="flex items-start gap-x-8">
106111
<div className="flex items-start gap-x-1 w-full">
107-
<div className="flex flex-col w-1/3" data-testid="shipping-address-summary">
112+
<div
113+
className="flex flex-col w-1/3"
114+
data-testid="shipping-address-summary"
115+
>
108116
<Text className="txt-medium-plus text-ui-fg-base mb-1">
109-
Shipping Address
117+
{t("checkout.shipping_address")}
110118
</Text>
111119
<Text className="txt-medium text-ui-fg-subtle">
112120
{cart.shipping_address.first_name}{" "}
@@ -125,7 +133,10 @@ const Addresses = ({
125133
</Text>
126134
</div>
127135

128-
<div className="flex flex-col w-1/3 " data-testid="shipping-contact-summary">
136+
<div
137+
className="flex flex-col w-1/3 "
138+
data-testid="shipping-contact-summary"
139+
>
129140
<Text className="txt-medium-plus text-ui-fg-base mb-1">
130141
Contact
131142
</Text>
@@ -137,14 +148,17 @@ const Addresses = ({
137148
</Text>
138149
</div>
139150

140-
<div className="flex flex-col w-1/3" data-testid="billing-address-summary">
151+
<div
152+
className="flex flex-col w-1/3"
153+
data-testid="billing-address-summary"
154+
>
141155
<Text className="txt-medium-plus text-ui-fg-base mb-1">
142-
Billing Address
156+
{t("checkout.billing_address")}
143157
</Text>
144158

145159
{sameAsSBilling ? (
146160
<Text className="txt-medium text-ui-fg-subtle">
147-
Billing- and delivery address are the same.
161+
{t("checkout.same_as_billing")}
148162
</Text>
149163
) : (
150164
<>

src/modules/checkout/components/country-select/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { forwardRef, useImperativeHandle, useMemo, useRef } from "react"
44

5+
import { useI18n } from "../../../../locales/client"
6+
57
import NativeSelect, {
68
NativeSelectProps,
79
} from "@modules/common/components/native-select"
@@ -12,7 +14,10 @@ const CountrySelect = forwardRef<
1214
NativeSelectProps & {
1315
region?: Region
1416
}
15-
>(({ placeholder = "Country", region, defaultValue, ...props }, ref) => {
17+
>(({ placeholder = null, region, defaultValue, ...props }, ref) => {
18+
const t = useI18n()
19+
placeholder = t("account.address.country_code")
20+
1621
const innerRef = useRef<HTMLSelectElement>(null)
1722

1823
useImperativeHandle<HTMLSelectElement | null, HTMLSelectElement | null>(

src/modules/checkout/components/discount-code/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { Heading, Label, Text, Tooltip } from "@medusajs/ui"
66
import React, { useMemo } from "react"
77
import { useFormState } from "react-dom"
88

9+
import { useI18n } from '../../../../locales/client'
10+
911
import Input from "@modules/common/components/input"
1012
import Trash from "@modules/common/icons/trash"
1113
import ErrorMessage from "@modules/checkout/components/error-message"
@@ -22,6 +24,7 @@ type DiscountCodeProps = {
2224
}
2325

2426
const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
27+
const t = useI18n()
2528
const [isOpen, setIsOpen] = React.useState(false)
2629

2730
const { discounts, gift_cards, region } = cart
@@ -41,7 +44,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
4144
})}`
4245

4346
default:
44-
return "Free shipping"
47+
return t("checkout.shipping.free")
4548
}
4649
}, [discounts, region])
4750

@@ -60,15 +63,15 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
6063
<div className="txt-medium">
6164
{gift_cards.length > 0 && (
6265
<div className="flex flex-col mb-4">
63-
<Heading className="txt-medium">Gift card(s) applied:</Heading>
66+
<Heading className="txt-medium">{t("checkout.giftcards")}</Heading>
6467
{gift_cards?.map((gc) => (
6568
<div
6669
className="flex items-center justify-between txt-small-plus"
6770
key={gc.id}
6871
data-testid="gift-card"
6972
>
7073
<Text className="flex gap-x-1 items-baseline">
71-
<span>Code: </span>
74+
<span>{t("checkout.code")}</span>
7275
<span className="truncate" data-testid="gift-card-code">
7376
{gc.code}
7477
</span>
@@ -90,7 +93,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
9093
data-testid="remove-gift-card-button"
9194
>
9295
<Trash size={14} />
93-
<span className="sr-only">Remove gift card from order</span>
96+
<span className="sr-only">{t("checkout.removegift")}</span>
9497
</button>
9598
</div>
9699
))}
@@ -100,13 +103,13 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
100103
{appliedDiscount ? (
101104
<div className="w-full flex items-center">
102105
<div className="flex flex-col w-full">
103-
<Heading className="txt-medium">Discount applied:</Heading>
106+
<Heading className="txt-medium">{t("checkout.discount")}</Heading>
104107
<div
105108
className="flex items-center justify-between w-full max-w-full"
106109
data-testid="discount-row"
107110
>
108111
<Text className="flex gap-x-1 items-baseline txt-small-plus w-4/5 pr-1">
109-
<span>Code:</span>
112+
<span>{t("checkout.code")}</span>
110113
<span className="truncate" data-testid="discount-code">
111114
{discounts[0].code}
112115
</span>
@@ -125,7 +128,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
125128
>
126129
<Trash size={14} />
127130
<span className="sr-only">
128-
Remove discount code from order
131+
{t("checkout.removediscount")}
129132
</span>
130133
</button>
131134
</div>
@@ -140,7 +143,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
140143
className="txt-medium text-ui-fg-interactive hover:text-ui-fg-interactive-hover"
141144
data-testid="add-discount-button"
142145
>
143-
Add gift card or discount code
146+
{t("checkout.addgift")}
144147
</button>
145148
<Tooltip content="You can add multiple gift cards, but only one discount code.">
146149
<InformationCircleSolid color="var(--fg-muted)" />
@@ -150,7 +153,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
150153
<>
151154
<div className="flex w-full gap-x-2 items-center">
152155
<Input
153-
label="Please enter code----------------------------------------------------------------------------------------"
156+
label={t("checkout.entercode")}
154157
name="code"
155158
type="text"
156159
autoFocus={false}
@@ -160,7 +163,7 @@ const DiscountCode: React.FC<DiscountCodeProps> = ({ cart }) => {
160163
variant="secondary"
161164
data-testid="discount-apply-button"
162165
>
163-
Apply
166+
{t("generic.apply")}
164167
</SubmitButton>
165168
</div>
166169
<ErrorMessage

src/modules/checkout/components/payment-button/index.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"use client"
22

3+
import { useScopedI18n } from '../../../../locales/client'
4+
35
import { Cart, PaymentSession } from "@medusajs/medusa"
46
import { Button } from "@medusajs/ui"
57
import { OnApproveActions, OnApproveData } from "@paypal/paypal-js"
@@ -19,6 +21,7 @@ const PaymentButton: React.FC<PaymentButtonProps> = ({
1921
cart,
2022
"data-testid": dataTestId,
2123
}) => {
24+
2225
const notReady =
2326
!cart ||
2427
!cart.shipping_address ||
@@ -66,6 +69,8 @@ const PaymentButton: React.FC<PaymentButtonProps> = ({
6669
const GiftCardPaymentButton = () => {
6770
const [submitting, setSubmitting] = useState(false)
6871

72+
const t = useScopedI18n("checkout.payment")
73+
6974
const handleOrder = async () => {
7075
setSubmitting(true)
7176
await placeOrder()
@@ -77,7 +82,7 @@ const GiftCardPaymentButton = () => {
7782
isLoading={submitting}
7883
data-testid="submit-order-button"
7984
>
80-
Place order
85+
{t("place_order")}
8186
</Button>
8287
)
8388
}
@@ -94,9 +99,11 @@ const StripePaymentButton = ({
9499
const [submitting, setSubmitting] = useState(false)
95100
const [errorMessage, setErrorMessage] = useState<string | null>(null)
96101

102+
const t = useScopedI18n("checkout.payment")
103+
97104
const onPaymentCompleted = async () => {
98105
await placeOrder().catch(() => {
99-
setErrorMessage("An error occurred, please try again.")
106+
setErrorMessage(t("error"))
100107
setSubmitting(false)
101108
})
102109
}
@@ -174,7 +181,7 @@ const StripePaymentButton = ({
174181
isLoading={submitting}
175182
data-testid={dataTestId}
176183
>
177-
Place order
184+
{t("place_order")}
178185
</Button>
179186
<ErrorMessage
180187
error={errorMessage}
@@ -196,9 +203,11 @@ const PayPalPaymentButton = ({
196203
const [submitting, setSubmitting] = useState(false)
197204
const [errorMessage, setErrorMessage] = useState<string | null>(null)
198205

206+
const t = useScopedI18n("checkout.payment")
207+
199208
const onPaymentCompleted = async () => {
200209
await placeOrder().catch(() => {
201-
setErrorMessage("An error occurred, please try again.")
210+
setErrorMessage(t("error"))
202211
setSubmitting(false)
203212
})
204213
}
@@ -213,13 +222,13 @@ const PayPalPaymentButton = ({
213222
?.authorize()
214223
.then((authorization) => {
215224
if (authorization.status !== "COMPLETED") {
216-
setErrorMessage(`An error occurred, status: ${authorization.status}`)
225+
setErrorMessage(t("error_params") + `: ${authorization.status}`)
217226
return
218227
}
219228
onPaymentCompleted()
220229
})
221230
.catch(() => {
222-
setErrorMessage(`An unknown error occurred, please try again.`)
231+
setErrorMessage(t("error_unknown"))
223232
setSubmitting(false)
224233
})
225234
}

0 commit comments

Comments
 (0)