Skip to content

Commit 623d5ef

Browse files
committed
feat: add return to cart link below summary if present on order
1 parent e08aca7 commit 623d5ef

5 files changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Link from "next/link"
2+
3+
import { CartLinkWrapper, LinkWrapper } from "./styled"
4+
5+
interface Props {
6+
cartUrl: string | undefined
7+
}
8+
9+
export const ReturnToCart = ({ cartUrl }: Props) => {
10+
if (!cartUrl) return <></>
11+
return (
12+
<CartLinkWrapper>
13+
<Link href={cartUrl} passHref>
14+
<LinkWrapper>
15+
<>&lt;</> Return to cart
16+
</LinkWrapper>
17+
</Link>
18+
</CartLinkWrapper>
19+
)
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import styled from "styled-components"
2+
import tw from "twin.macro"
3+
4+
export const CartLinkWrapper = styled.div`
5+
${tw`flex flex-row justify-between mt-7 pt-6 border-t`}
6+
`
7+
export const LinkWrapper = styled.a`
8+
${tw`text-xs font-bold border-b`}
9+
`

components/composite/OrderSummary/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { LINE_ITEMS_SHOPPABLE } from "components/utils/constants"
1717

1818
import { CouponOrGiftCard } from "./CouponOrGiftCard"
1919
import { LineItemTypes } from "./LineItemTypes"
20+
import { ReturnToCart } from "./ReturnToCart"
2021
import {
2122
SummaryHeader,
2223
SummarySubTitle,
@@ -207,6 +208,7 @@ export const OrderSummary: React.FC<Props> = ({ appCtx, readonly }) => {
207208
className="text-xl font-extrabold"
208209
/>
209210
</RecapLineTotal>
211+
<ReturnToCart cartUrl={appCtx.cartUrl} />
210212
</AmountWrapper>
211213
</TotalWrapper>
212214
</Wrapper>

components/data/AppProvider/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const initialState: AppStateData = {
7070
shippingCountryCodeLock: "",
7171
isComplete: false,
7272
returnUrl: "",
73+
cartUrl: undefined,
7374
taxIncluded: false,
7475
shippingMethodName: undefined,
7576
}

components/data/AppProvider/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export interface FetchOrderByIdResponse {
5555
isPaymentRequired: boolean
5656
isComplete: boolean
5757
returnUrl: string | undefined
58+
cartUrl: string | undefined
5859
isCreditCard: boolean
5960
taxIncluded: boolean | undefined
6061
shippingMethodName: string | undefined
@@ -216,6 +217,7 @@ export const fetchOrder = async (cl: CommerceLayerClient, orderId: string) => {
216217
"customer_email",
217218
"status",
218219
"return_url",
220+
"cart_url",
219221
"tax_included",
220222
"requires_billing_info",
221223
"total_amount_with_taxes_float",
@@ -323,6 +325,7 @@ export function calculateSettings(order: Order, isShipmentRequired: boolean) {
323325
}),
324326
...checkPaymentMethod(order),
325327
returnUrl: order.return_url,
328+
cartUrl: order.cart_url,
326329
taxIncluded: order.tax_included,
327330
requiresBillingInfo: order.requires_billing_info,
328331
}

0 commit comments

Comments
 (0)