@akinon/projectzero 2.0.32 → 2.0.33-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/app-template/.env.example +1 -0
- package/app-template/AGENTS.md +8 -0
- package/app-template/CHANGELOG.md +77 -0
- package/app-template/README.md +25 -1
- package/app-template/next.config.mjs +7 -1
- package/app-template/package.json +41 -41
- package/app-template/public/locales/en/checkout.json +50 -0
- package/app-template/public/locales/tr/checkout.json +50 -0
- package/app-template/src/app/[pz]/basket/page.tsx +33 -6
- package/app-template/src/app/[pz]/orders/checkout/page.tsx +57 -92
- package/app-template/src/app/api/theme-settings/route.ts +21 -2
- package/app-template/src/app/global-error.tsx +22 -0
- package/app-template/src/data/server/theme.ts +6 -25
- package/app-template/src/hooks/index.ts +2 -0
- package/app-template/src/plugins.js +1 -0
- package/app-template/src/proxy.ts +2 -1
- package/app-template/src/views/checkout/variants/basket-and-checkout/basket-section.tsx +149 -0
- package/app-template/src/views/checkout/variants/basket-and-checkout/index.tsx +132 -0
- package/app-template/src/views/checkout/variants/multi-step/index.tsx +73 -0
- package/app-template/src/views/checkout/variants/one-page/accordion-section.tsx +140 -0
- package/app-template/src/views/checkout/variants/one-page/hooks/use-checkout-funnel-gtm.ts +60 -0
- package/app-template/src/views/checkout/variants/one-page/hooks/use-section-state.ts +99 -0
- package/app-template/src/views/checkout/variants/one-page/index.tsx +125 -0
- package/app-template/src/views/checkout/variants/one-page/mobile-summary-sheet.tsx +109 -0
- package/app-template/src/views/checkout/variants/one-page/one-page-summary.tsx +237 -0
- package/app-template/src/views/checkout/variants/one-page/payment-options-grid.tsx +201 -0
- package/app-template/src/views/checkout/variants/one-page/sections/address-section.tsx +318 -0
- package/app-template/src/views/checkout/variants/one-page/sections/contact-section.tsx +62 -0
- package/app-template/src/views/checkout/variants/one-page/sections/payment-section.tsx +71 -0
- package/app-template/src/views/checkout/variants/one-page/sections/shipping-section.tsx +298 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/address-skeleton.tsx +25 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/checkout-skeleton.tsx +27 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/index.ts +6 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/payment-skeleton.tsx +23 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/section-skeleton.tsx +47 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/shipping-skeleton.tsx +20 -0
- package/app-template/src/views/checkout/variants/one-page/skeletons/summary-skeleton.tsx +38 -0
- package/app-template/src/views/checkout/variants/one-page/trust-badges.tsx +30 -0
- package/app-template/src/views/checkout/variants/registry.ts +32 -0
- package/app-template/src/views/checkout/variants/types.ts +30 -0
- package/app-template/src/views/checkout/variants/use-resolved-config.ts +89 -0
- package/app-template/src/views/header/search/index.tsx +13 -5
- package/app-template/src/views/product/slider.tsx +85 -38
- package/commands/plugins.ts +4 -0
- package/dist/commands/plugins.js +4 -0
- package/package.json +1 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ReactNode, useEffect, useRef, useId } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useLocalization } from '@akinon/next/hooks';
|
|
4
|
+
import { Icon } from '@theme/components';
|
|
5
|
+
|
|
6
|
+
export type SectionStatus = 'locked' | 'active' | 'completed';
|
|
7
|
+
|
|
8
|
+
interface AccordionSectionProps {
|
|
9
|
+
step: number;
|
|
10
|
+
title: string;
|
|
11
|
+
status: SectionStatus;
|
|
12
|
+
summary?: ReactNode;
|
|
13
|
+
onEdit?: () => void;
|
|
14
|
+
editable?: boolean;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
dataTestId?: string;
|
|
17
|
+
padded?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const AccordionSection = ({
|
|
21
|
+
step,
|
|
22
|
+
title,
|
|
23
|
+
status,
|
|
24
|
+
summary,
|
|
25
|
+
onEdit,
|
|
26
|
+
editable = true,
|
|
27
|
+
children,
|
|
28
|
+
dataTestId,
|
|
29
|
+
padded = true
|
|
30
|
+
}: AccordionSectionProps) => {
|
|
31
|
+
const { t } = useLocalization();
|
|
32
|
+
const isOpen = status === 'active';
|
|
33
|
+
const isCompleted = status === 'completed';
|
|
34
|
+
const isLocked = status === 'locked';
|
|
35
|
+
|
|
36
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
const headerId = useId();
|
|
38
|
+
const panelId = useId();
|
|
39
|
+
const wasOpenRef = useRef(isOpen);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
if (isOpen && !wasOpenRef.current && contentRef.current) {
|
|
43
|
+
const firstFocusable = contentRef.current.querySelector<HTMLElement>(
|
|
44
|
+
'input:not([disabled]), button:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
45
|
+
);
|
|
46
|
+
firstFocusable?.focus({ preventScroll: true });
|
|
47
|
+
}
|
|
48
|
+
wasOpenRef.current = isOpen;
|
|
49
|
+
}, [isOpen]);
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<section
|
|
53
|
+
className={clsx(
|
|
54
|
+
'mb-4 overflow-hidden rounded-2xl bg-white last:mb-0',
|
|
55
|
+
'transition-all duration-300 ease-out',
|
|
56
|
+
isOpen
|
|
57
|
+
? 'shadow-[0_12px_40px_-16px_rgba(0,0,0,0.16)] ring-1 ring-black-800/10'
|
|
58
|
+
: 'shadow-[0_1px_3px_rgba(0,0,0,0.04)] ring-1 ring-black/[0.04]',
|
|
59
|
+
isLocked && 'opacity-50'
|
|
60
|
+
)}
|
|
61
|
+
data-testid={dataTestId}
|
|
62
|
+
data-status={status}
|
|
63
|
+
aria-labelledby={headerId}
|
|
64
|
+
>
|
|
65
|
+
<header
|
|
66
|
+
id={headerId}
|
|
67
|
+
className={clsx(
|
|
68
|
+
'flex items-center justify-between gap-3 px-6 py-5 sm:px-7',
|
|
69
|
+
isOpen && 'border-b border-gray-100'
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
<div className="flex items-center gap-3.5">
|
|
73
|
+
<span
|
|
74
|
+
className={clsx(
|
|
75
|
+
'flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-all',
|
|
76
|
+
isOpen && 'bg-black-800 text-white',
|
|
77
|
+
isCompleted && !isOpen && 'bg-black-800 text-white',
|
|
78
|
+
isLocked && 'bg-gray-100 text-gray-400'
|
|
79
|
+
)}
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
>
|
|
82
|
+
{isCompleted ? (
|
|
83
|
+
<Icon name="check" size={14} className="fill-white" />
|
|
84
|
+
) : (
|
|
85
|
+
step
|
|
86
|
+
)}
|
|
87
|
+
</span>
|
|
88
|
+
<h2
|
|
89
|
+
className={clsx(
|
|
90
|
+
'text-lg font-semibold leading-tight tracking-tight',
|
|
91
|
+
isOpen || isCompleted ? 'text-black-800' : 'text-gray-500'
|
|
92
|
+
)}
|
|
93
|
+
>
|
|
94
|
+
{title}
|
|
95
|
+
</h2>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
{isCompleted && editable && onEdit && (
|
|
99
|
+
<button
|
|
100
|
+
type="button"
|
|
101
|
+
onClick={onEdit}
|
|
102
|
+
className={clsx(
|
|
103
|
+
'group flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-medium',
|
|
104
|
+
'text-gray-700 transition-all duration-150',
|
|
105
|
+
'hover:bg-gray-100 hover:text-black-800',
|
|
106
|
+
'focus:outline-none focus-visible:ring-2 focus-visible:ring-black-800 focus-visible:ring-offset-1'
|
|
107
|
+
)}
|
|
108
|
+
data-testid={`${dataTestId}-edit`}
|
|
109
|
+
aria-label={`${t('checkout.one_page.edit')} ${title}`}
|
|
110
|
+
>
|
|
111
|
+
<span>{t('checkout.one_page.edit')}</span>
|
|
112
|
+
</button>
|
|
113
|
+
)}
|
|
114
|
+
</header>
|
|
115
|
+
|
|
116
|
+
<div
|
|
117
|
+
id={panelId}
|
|
118
|
+
role="region"
|
|
119
|
+
aria-labelledby={headerId}
|
|
120
|
+
hidden={!isOpen}
|
|
121
|
+
className={clsx(
|
|
122
|
+
'transition-opacity duration-300 ease-out',
|
|
123
|
+
isOpen ? 'opacity-100' : 'opacity-0'
|
|
124
|
+
)}
|
|
125
|
+
>
|
|
126
|
+
<div ref={contentRef} className={padded ? 'px-6 py-6 sm:px-7' : undefined}>
|
|
127
|
+
{children}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
{isCompleted && summary && (
|
|
132
|
+
<div className="border-t border-gray-100 px-6 py-4 text-sm text-gray-700 sm:px-7">
|
|
133
|
+
{summary}
|
|
134
|
+
</div>
|
|
135
|
+
)}
|
|
136
|
+
</section>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export default AccordionSection;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { useAppSelector } from '@akinon/next/redux/hooks';
|
|
3
|
+
import type { RootState } from '@theme/redux/store';
|
|
4
|
+
import {
|
|
5
|
+
pushAddShippingInfo,
|
|
6
|
+
pushAddPaymentInfo,
|
|
7
|
+
pushEventGA4
|
|
8
|
+
} from '@theme/utils/gtm';
|
|
9
|
+
import type { SectionId } from './use-section-state';
|
|
10
|
+
|
|
11
|
+
const SECTION_EVENT: Record<SectionId, string> = {
|
|
12
|
+
contact: 'one_page_contact_complete',
|
|
13
|
+
address: 'one_page_address_complete',
|
|
14
|
+
shipping: 'one_page_shipping_complete',
|
|
15
|
+
payment: 'one_page_payment_open'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
interface UseCheckoutFunnelGtmOptions {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const useCheckoutFunnelGtm = (
|
|
23
|
+
activeSection: SectionId,
|
|
24
|
+
{ enabled = true }: UseCheckoutFunnelGtmOptions = {}
|
|
25
|
+
) => {
|
|
26
|
+
const preOrder = useAppSelector(
|
|
27
|
+
(state: RootState) => state.checkout.preOrder
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const fired = useRef<Set<string>>(new Set());
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
if (!enabled) return;
|
|
34
|
+
if (!preOrder?.basket?.basketitem_set) return;
|
|
35
|
+
|
|
36
|
+
// GTM dataLayer may not be initialised (no GTM tag, ad blocker, etc.).
|
|
37
|
+
// Any failure must NEVER crash the checkout flow — wrap in try/catch.
|
|
38
|
+
try {
|
|
39
|
+
const products = preOrder.basket.basketitem_set.map((item) => ({
|
|
40
|
+
...item.product
|
|
41
|
+
}));
|
|
42
|
+
|
|
43
|
+
if (activeSection === 'shipping' && !fired.current.has('shipping')) {
|
|
44
|
+
pushAddShippingInfo(products);
|
|
45
|
+
fired.current.add('shipping');
|
|
46
|
+
}
|
|
47
|
+
if (activeSection === 'payment' && !fired.current.has('payment')) {
|
|
48
|
+
pushAddPaymentInfo(products, String(preOrder?.payment_option?.name));
|
|
49
|
+
fired.current.add('payment');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
pushEventGA4(SECTION_EVENT[activeSection], {
|
|
53
|
+
section: activeSection,
|
|
54
|
+
items_count: products.length
|
|
55
|
+
});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
console.warn('Checkout funnel GTM error (suppressed):', error);
|
|
58
|
+
}
|
|
59
|
+
}, [activeSection, enabled, preOrder?.payment_option?.name]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
60
|
+
};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useAppSelector } from '@akinon/next/redux/hooks';
|
|
3
|
+
import { useSession } from 'next-auth/react';
|
|
4
|
+
import type { RootState } from '@theme/redux/store';
|
|
5
|
+
import type { SectionStatus } from '../accordion-section';
|
|
6
|
+
|
|
7
|
+
export type SectionId = 'contact' | 'address' | 'shipping' | 'payment';
|
|
8
|
+
|
|
9
|
+
export interface SectionState {
|
|
10
|
+
id: SectionId;
|
|
11
|
+
status: SectionStatus;
|
|
12
|
+
isComplete: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface UseSectionStateOptions {
|
|
16
|
+
autoAdvance?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const useSectionState = ({ autoAdvance = true }: UseSectionStateOptions = {}) => {
|
|
20
|
+
const { data: session } = useSession();
|
|
21
|
+
const preOrder = useAppSelector(
|
|
22
|
+
(state: RootState) => state.checkout.preOrder
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
const isAuthenticated = Boolean(session?.user);
|
|
26
|
+
const contactComplete = isAuthenticated || Boolean(preOrder?.is_guest);
|
|
27
|
+
const addressComplete = Boolean(
|
|
28
|
+
preOrder?.shipping_address?.pk && preOrder?.billing_address?.pk
|
|
29
|
+
);
|
|
30
|
+
const shippingComplete = Boolean(preOrder?.shipping_option?.pk);
|
|
31
|
+
|
|
32
|
+
const completion = useMemo(
|
|
33
|
+
() => ({
|
|
34
|
+
contact: contactComplete,
|
|
35
|
+
address: addressComplete,
|
|
36
|
+
shipping: shippingComplete,
|
|
37
|
+
payment: false
|
|
38
|
+
}),
|
|
39
|
+
[contactComplete, addressComplete, shippingComplete]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const firstIncomplete = useMemo<SectionId>(() => {
|
|
43
|
+
if (!completion.contact) return 'contact';
|
|
44
|
+
if (!completion.address) return 'address';
|
|
45
|
+
if (!completion.shipping) return 'shipping';
|
|
46
|
+
return 'payment';
|
|
47
|
+
}, [completion]);
|
|
48
|
+
|
|
49
|
+
const [activeSection, setActiveSection] = useState<SectionId>(firstIncomplete);
|
|
50
|
+
const [touchedSections, setTouchedSections] = useState<Set<SectionId>>(
|
|
51
|
+
() => new Set()
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (!autoAdvance) return;
|
|
56
|
+
if (touchedSections.has(activeSection)) return;
|
|
57
|
+
if (firstIncomplete !== activeSection) {
|
|
58
|
+
setActiveSection(firstIncomplete);
|
|
59
|
+
}
|
|
60
|
+
}, [firstIncomplete, autoAdvance, activeSection, touchedSections]);
|
|
61
|
+
|
|
62
|
+
const openSection = useCallback((id: SectionId) => {
|
|
63
|
+
setActiveSection(id);
|
|
64
|
+
setTouchedSections((prev) => {
|
|
65
|
+
const next = new Set(prev);
|
|
66
|
+
next.add(id);
|
|
67
|
+
return next;
|
|
68
|
+
});
|
|
69
|
+
}, []);
|
|
70
|
+
|
|
71
|
+
const sections = useMemo<SectionState[]>(() => {
|
|
72
|
+
const order: SectionId[] = ['contact', 'address', 'shipping', 'payment'];
|
|
73
|
+
return order.map((id) => {
|
|
74
|
+
const isComplete = completion[id];
|
|
75
|
+
let status: SectionStatus;
|
|
76
|
+
if (id === activeSection) {
|
|
77
|
+
status = 'active';
|
|
78
|
+
} else if (isComplete) {
|
|
79
|
+
status = 'completed';
|
|
80
|
+
} else {
|
|
81
|
+
const indexCurrent = order.indexOf(activeSection);
|
|
82
|
+
const indexThis = order.indexOf(id);
|
|
83
|
+
status = indexThis < indexCurrent ? 'completed' : 'locked';
|
|
84
|
+
}
|
|
85
|
+
return { id, status, isComplete };
|
|
86
|
+
});
|
|
87
|
+
}, [completion, activeSection]);
|
|
88
|
+
|
|
89
|
+
const allComplete = completion.contact && completion.address && completion.shipping;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
sections,
|
|
93
|
+
activeSection,
|
|
94
|
+
openSection,
|
|
95
|
+
allComplete,
|
|
96
|
+
completion,
|
|
97
|
+
isAuthenticated
|
|
98
|
+
};
|
|
99
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import clsx from 'clsx';
|
|
5
|
+
import PluginModule, { Component } from '@akinon/next/components/plugin-module';
|
|
6
|
+
import ContactSection from './sections/contact-section';
|
|
7
|
+
import AddressSection from './sections/address-section';
|
|
8
|
+
import ShippingSection from './sections/shipping-section';
|
|
9
|
+
import PaymentSection from './sections/payment-section';
|
|
10
|
+
import OnePageSummary from './one-page-summary';
|
|
11
|
+
import MobileSummarySheet from './mobile-summary-sheet';
|
|
12
|
+
import TrustBadges from './trust-badges';
|
|
13
|
+
import { useSectionState, type SectionId } from './hooks/use-section-state';
|
|
14
|
+
import { useCheckoutFunnelGtm } from './hooks/use-checkout-funnel-gtm';
|
|
15
|
+
import type { CheckoutVariantProps } from '../types';
|
|
16
|
+
|
|
17
|
+
const OnePageCheckout = ({ options }: CheckoutVariantProps) => {
|
|
18
|
+
const autoAdvance = options?.autoAdvance ?? true;
|
|
19
|
+
const stickyMobileCta = options?.stickyMobileCta ?? true;
|
|
20
|
+
const enableEditMode = options?.enableEditMode ?? true;
|
|
21
|
+
const showOrderReview = options?.showOrderReview ?? true;
|
|
22
|
+
const showTrustBadges = options?.showTrustBadges ?? true;
|
|
23
|
+
const gtmEnabled = options?.gtmEnabled ?? true;
|
|
24
|
+
const compactMode = options?.compactMode ?? false;
|
|
25
|
+
|
|
26
|
+
const { sections, activeSection, openSection } = useSectionState({
|
|
27
|
+
autoAdvance
|
|
28
|
+
});
|
|
29
|
+
useCheckoutFunnelGtm(activeSection, { enabled: gtmEnabled });
|
|
30
|
+
|
|
31
|
+
const sectionStatus = useCallback(
|
|
32
|
+
(id: SectionId) =>
|
|
33
|
+
sections.find((section) => section.id === id)?.status ?? 'locked',
|
|
34
|
+
[sections]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const goTo = useCallback(
|
|
38
|
+
(id: SectionId) => () => openSection(id),
|
|
39
|
+
[openSection]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<PluginModule component={Component.MasterpassProvider}>
|
|
44
|
+
<PluginModule component={Component.MasterpassDeleteConfirmationModal} />
|
|
45
|
+
<PluginModule component={Component.MasterpassOtpModal} />
|
|
46
|
+
<PluginModule component={Component.MasterpassLinkModal} />
|
|
47
|
+
|
|
48
|
+
<div
|
|
49
|
+
className={clsx(
|
|
50
|
+
'min-h-screen bg-[#fafafa]',
|
|
51
|
+
compactMode ? 'pb-12 md:pb-8' : 'pb-20 md:pb-16'
|
|
52
|
+
)}
|
|
53
|
+
data-compact={compactMode || undefined}
|
|
54
|
+
>
|
|
55
|
+
<div
|
|
56
|
+
className={clsx(
|
|
57
|
+
'container w-full px-4 md:px-6 lg:px-8',
|
|
58
|
+
compactMode ? 'pt-4' : 'pt-6 md:pt-10'
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
<div
|
|
62
|
+
className={clsx(
|
|
63
|
+
'flex flex-col lg:flex-row lg:items-start',
|
|
64
|
+
compactMode ? 'gap-4 lg:gap-6' : 'gap-6 lg:gap-8'
|
|
65
|
+
)}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
className="w-full lg:w-2/3"
|
|
69
|
+
data-testid="one-page-sections"
|
|
70
|
+
>
|
|
71
|
+
<ContactSection
|
|
72
|
+
status={sectionStatus('contact')}
|
|
73
|
+
onEdit={goTo('contact')}
|
|
74
|
+
/>
|
|
75
|
+
<AddressSection
|
|
76
|
+
status={sectionStatus('address')}
|
|
77
|
+
onEdit={goTo('address')}
|
|
78
|
+
onComplete={goTo('shipping')}
|
|
79
|
+
editable={enableEditMode}
|
|
80
|
+
/>
|
|
81
|
+
<ShippingSection
|
|
82
|
+
status={sectionStatus('shipping')}
|
|
83
|
+
onEdit={goTo('shipping')}
|
|
84
|
+
onComplete={goTo('payment')}
|
|
85
|
+
editable={enableEditMode}
|
|
86
|
+
/>
|
|
87
|
+
<PaymentSection
|
|
88
|
+
status={sectionStatus('payment')}
|
|
89
|
+
onEdit={goTo('payment')}
|
|
90
|
+
/>
|
|
91
|
+
|
|
92
|
+
{showTrustBadges && <TrustBadges />}
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<aside
|
|
96
|
+
className="hidden w-full lg:block lg:w-1/3"
|
|
97
|
+
data-testid="one-page-summary"
|
|
98
|
+
>
|
|
99
|
+
<div className="sticky top-6">
|
|
100
|
+
<OnePageSummary
|
|
101
|
+
onEditSection={openSection}
|
|
102
|
+
showReview={showOrderReview}
|
|
103
|
+
/>
|
|
104
|
+
</div>
|
|
105
|
+
</aside>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
{stickyMobileCta && (
|
|
110
|
+
<div
|
|
111
|
+
className="fixed inset-x-0 bottom-0 z-30 lg:hidden"
|
|
112
|
+
data-testid="one-page-mobile-cta"
|
|
113
|
+
>
|
|
114
|
+
<MobileSummarySheet
|
|
115
|
+
onEditSection={openSection}
|
|
116
|
+
showReview={showOrderReview}
|
|
117
|
+
/>
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
</div>
|
|
121
|
+
</PluginModule>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export default OnePageCheckout;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { useAppSelector } from '@akinon/next/redux/hooks';
|
|
4
|
+
import { useLocalization } from '@akinon/next/hooks';
|
|
5
|
+
import { Price, Icon } from '@theme/components';
|
|
6
|
+
import type { RootState } from '@theme/redux/store';
|
|
7
|
+
import OnePageSummary from './one-page-summary';
|
|
8
|
+
import type { SectionId } from './hooks/use-section-state';
|
|
9
|
+
|
|
10
|
+
interface MobileSummarySheetProps {
|
|
11
|
+
onEditSection: (section: SectionId) => void;
|
|
12
|
+
showReview?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const MobileSummarySheet = ({
|
|
16
|
+
onEditSection,
|
|
17
|
+
showReview = true
|
|
18
|
+
}: MobileSummarySheetProps) => {
|
|
19
|
+
const { t } = useLocalization();
|
|
20
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
21
|
+
const preOrder = useAppSelector(
|
|
22
|
+
(state: RootState) => state.checkout.preOrder
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (!isOpen) return undefined;
|
|
27
|
+
const onKey = (event: KeyboardEvent) => {
|
|
28
|
+
if (event.key === 'Escape') setIsOpen(false);
|
|
29
|
+
};
|
|
30
|
+
document.addEventListener('keydown', onKey);
|
|
31
|
+
const previousOverflow = document.body.style.overflow;
|
|
32
|
+
document.body.style.overflow = 'hidden';
|
|
33
|
+
return () => {
|
|
34
|
+
document.removeEventListener('keydown', onKey);
|
|
35
|
+
document.body.style.overflow = previousOverflow;
|
|
36
|
+
};
|
|
37
|
+
}, [isOpen]);
|
|
38
|
+
|
|
39
|
+
if (!preOrder) return null;
|
|
40
|
+
const paymentName = preOrder.payment_option?.name;
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
{isOpen && (
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
aria-label={t('checkout.one_page.summary.hide_summary')}
|
|
48
|
+
className="fixed inset-0 z-40 bg-black/50 backdrop-blur-sm lg:hidden"
|
|
49
|
+
onClick={() => setIsOpen(false)}
|
|
50
|
+
data-testid="one-page-mobile-summary-backdrop"
|
|
51
|
+
/>
|
|
52
|
+
)}
|
|
53
|
+
|
|
54
|
+
<div className="relative z-50">
|
|
55
|
+
<button
|
|
56
|
+
type="button"
|
|
57
|
+
onClick={() => setIsOpen((prev) => !prev)}
|
|
58
|
+
aria-expanded={isOpen}
|
|
59
|
+
aria-controls="mobile-summary-content"
|
|
60
|
+
className="flex w-full items-center justify-between gap-3 border-t border-gray-200 bg-white px-5 py-4 shadow-[0_-8px_24px_-12px_rgba(0,0,0,0.12)] focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
|
|
61
|
+
data-testid="one-page-mobile-summary-toggle"
|
|
62
|
+
>
|
|
63
|
+
<span className="flex flex-col items-start gap-1">
|
|
64
|
+
<span className="flex items-center gap-2 text-[11px] font-medium uppercase tracking-wider text-gray-600">
|
|
65
|
+
<Icon name="basket" size={12} aria-hidden="true" />
|
|
66
|
+
{isOpen
|
|
67
|
+
? t('checkout.one_page.summary.hide_summary')
|
|
68
|
+
: t('checkout.one_page.summary.show_summary')}
|
|
69
|
+
<Icon
|
|
70
|
+
name="chevron-end"
|
|
71
|
+
size={10}
|
|
72
|
+
aria-hidden="true"
|
|
73
|
+
className={clsx('transition-transform duration-200', {
|
|
74
|
+
'rotate-90': isOpen,
|
|
75
|
+
'-rotate-90': !isOpen
|
|
76
|
+
})}
|
|
77
|
+
/>
|
|
78
|
+
</span>
|
|
79
|
+
{paymentName && (
|
|
80
|
+
<span className="text-xs font-medium text-black-800">
|
|
81
|
+
{paymentName}
|
|
82
|
+
</span>
|
|
83
|
+
)}
|
|
84
|
+
</span>
|
|
85
|
+
<span className="text-xl font-bold tabular-nums text-black-800">
|
|
86
|
+
<Price value={preOrder.unpaid_amount} />
|
|
87
|
+
</span>
|
|
88
|
+
</button>
|
|
89
|
+
|
|
90
|
+
{isOpen && (
|
|
91
|
+
<div
|
|
92
|
+
id="mobile-summary-content"
|
|
93
|
+
role="dialog"
|
|
94
|
+
aria-modal="true"
|
|
95
|
+
aria-label={t('checkout.summary.title')}
|
|
96
|
+
className="max-h-[75vh] overflow-y-auto border-t border-gray-200 bg-[#fafafa] px-4 py-5"
|
|
97
|
+
>
|
|
98
|
+
<OnePageSummary
|
|
99
|
+
onEditSection={onEditSection}
|
|
100
|
+
showReview={showReview}
|
|
101
|
+
/>
|
|
102
|
+
</div>
|
|
103
|
+
)}
|
|
104
|
+
</div>
|
|
105
|
+
</>
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default MobileSummarySheet;
|