Skip to content

Commit f541d02

Browse files
committed
feat(checkout-summary): add active promo codes section
1 parent 721dad1 commit f541d02

5 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/blocks/checkout-summary/src/api-harmonization/checkout-summary.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class CheckoutSummaryBlock extends ApiModels.Block.Block {
2525
shippingLabel: string;
2626
freeLabel?: string;
2727
totalLabel: string;
28+
activePromoCodesTitle?: string;
2829
notesTitle?: string;
2930
};
3031
};

packages/blocks/checkout-summary/src/frontend/CheckoutSummary.client.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const baseBlock = {
4444
taxLabel: 'VAT (23%)',
4545
shippingLabel: 'Shipping',
4646
totalLabel: 'Total',
47+
activePromoCodesTitle: 'Active discount codes',
4748
},
4849
notes: {
4950
title: 'Notes',

packages/blocks/checkout-summary/src/frontend/CheckoutSummary.client.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const CheckoutSummaryPure: React.FC<Readonly<CheckoutSummaryPureProps>> =
9494
if (result.order?.id) {
9595
const redirectUrl = result.paymentRedirectUrl || `${buttons.confirm.path}/${result.order.id}`;
9696
window.location.href = redirectUrl;
97+
localStorage.removeItem(CART_ID_KEY);
9798
return;
9899
}
99100
} catch {
@@ -116,7 +117,8 @@ export const CheckoutSummaryPure: React.FC<Readonly<CheckoutSummaryPureProps>> =
116117
const paymentMethod = summaryData?.paymentMethod;
117118
const items = summaryData?.cart.items?.data ?? [];
118119
const totals = summaryData?.totals;
119-
const isFreeShipping = summaryData?.cart.promotions?.some((p) => p.type === 'FREE_SHIPPING');
120+
const promotions = summaryData?.cart.promotions ?? [];
121+
const isFreeShipping = promotions.some((p) => p.type === 'FREE_SHIPPING');
120122

121123
const formatStreetAddress = (addr: { streetName: string; streetNumber?: string; apartment?: string }) => {
122124
let street = addr.streetName;
@@ -355,6 +357,29 @@ export const CheckoutSummaryPure: React.FC<Readonly<CheckoutSummaryPureProps>> =
355357
</div>
356358
) : null}
357359

360+
{promotions.length > 0 && sections.summary.activePromoCodesTitle && (
361+
<>
362+
<Separator />
363+
<div className="flex flex-col gap-2">
364+
<Typography variant="h3">{sections.summary.activePromoCodesTitle}</Typography>
365+
<div className="flex flex-col gap-2">
366+
{promotions.map((promo) => (
367+
<div
368+
key={promo.code}
369+
className="flex items-center gap-2 rounded-md bg-green-50 px-3 py-2 dark:bg-green-950/20"
370+
>
371+
<DynamicIcon name="Tag" size={14} className="shrink-0 text-green-600" />
372+
<Typography variant="small" className="text-green-600">
373+
{promo.code}
374+
{promo.name && ` — ${promo.name}`}
375+
</Typography>
376+
</div>
377+
))}
378+
</div>
379+
</div>
380+
</>
381+
)}
382+
358383
{sections.summary.notesTitle && summaryData?.notes && (
359384
<>
360385
<Separator />

packages/framework/src/modules/cms/models/blocks/checkout-summary.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export class CheckoutSummaryBlock extends Block.Block {
3232
shippingLabel: string;
3333
freeLabel?: string;
3434
totalLabel: string;
35+
activePromoCodesTitle?: string;
3536
notesTitle?: string;
3637
};
3738
};

packages/integrations/mocked/src/modules/cms/mappers/blocks/cms.checkout-summary.mapper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const MOCK_CHECKOUT_SUMMARY_EN: CMS.Model.CheckoutSummaryBlock.CheckoutSummaryBl
3232
shippingLabel: 'Shipping',
3333
freeLabel: 'Free',
3434
totalLabel: 'Total',
35+
activePromoCodesTitle: 'Active discount codes',
3536
notesTitle: 'Notes',
3637
},
3738
},
@@ -92,6 +93,7 @@ const MOCK_CHECKOUT_SUMMARY_DE: CMS.Model.CheckoutSummaryBlock.CheckoutSummaryBl
9293
shippingLabel: 'Versand',
9394
freeLabel: 'Kostenlos',
9495
totalLabel: 'Gesamt',
96+
activePromoCodesTitle: 'Aktive Rabattcodes',
9597
notesTitle: 'Anmerkungen',
9698
},
9799
},
@@ -153,6 +155,7 @@ const MOCK_CHECKOUT_SUMMARY_PL: CMS.Model.CheckoutSummaryBlock.CheckoutSummaryBl
153155
shippingLabel: 'Dostawa',
154156
freeLabel: 'Gratis',
155157
totalLabel: 'Razem',
158+
activePromoCodesTitle: 'Aktywne kody rabatowe',
156159
notesTitle: 'Uwagi',
157160
},
158161
},

0 commit comments

Comments
 (0)