@akinon/projectzero 1.126.19 → 1.126.20

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/app-template/.env.example +6 -0
  3. package/app-template/CHANGELOG.md +40 -0
  4. package/app-template/package.json +29 -28
  5. package/app-template/public/locales/en/checkout.json +50 -0
  6. package/app-template/public/locales/tr/checkout.json +50 -0
  7. package/app-template/src/app/[pz]/account/(dashboard)/layout.tsx +20 -0
  8. package/app-template/src/app/[pz]/account/account-page-slot.tsx +35 -0
  9. package/app-template/src/app/[pz]/account/address/layout.tsx +18 -0
  10. package/app-template/src/app/[pz]/account/change-email/layout.tsx +18 -0
  11. package/app-template/src/app/[pz]/account/change-password/layout.tsx +18 -0
  12. package/app-template/src/app/[pz]/account/contact/layout.tsx +18 -0
  13. package/app-template/src/app/[pz]/account/coupons/layout.tsx +18 -0
  14. package/app-template/src/app/[pz]/account/faq/layout.tsx +14 -0
  15. package/app-template/src/app/[pz]/account/favourite-products/layout.tsx +21 -0
  16. package/app-template/src/app/[pz]/account/layout.tsx +36 -3
  17. package/app-template/src/app/[pz]/account/orders/(list)/layout.tsx +20 -0
  18. package/app-template/src/app/[pz]/account/orders/[id]/(detail)/layout.tsx +40 -0
  19. package/app-template/src/app/[pz]/account/profile/layout.tsx +18 -0
  20. package/app-template/src/app/[pz]/auth/(login)/layout.tsx +37 -0
  21. package/app-template/src/app/[pz]/basket/layout.tsx +25 -0
  22. package/app-template/src/app/[pz]/client-root.tsx +2 -0
  23. package/app-template/src/app/[pz]/configure-page-context.ts +17 -0
  24. package/app-template/src/app/[pz]/layout.tsx +22 -3
  25. package/app-template/src/app/[pz]/orders/checkout/layout.tsx +47 -0
  26. package/app-template/src/app/[pz]/orders/checkout/page.tsx +75 -97
  27. package/app-template/src/app/[pz]/orders/completed/[token]/layout.tsx +24 -2
  28. package/app-template/src/app/[pz]/users/password/reset/layout.tsx +21 -0
  29. package/app-template/src/app/[pz]/users/reset/[[...id]]/layout.tsx +30 -0
  30. package/app-template/src/components/checkbox.tsx +22 -3
  31. package/app-template/src/components/route-handler.tsx +48 -0
  32. package/app-template/src/routes/index.ts +6 -6
  33. package/app-template/src/views/checkout/__tests__/part-style-reachability.test.ts +119 -0
  34. package/app-template/src/views/checkout/step-button.tsx +13 -2
  35. package/app-template/src/views/checkout/step-list.tsx +5 -1
  36. package/app-template/src/views/checkout/steps/payment/agreements.tsx +9 -1
  37. package/app-template/src/views/checkout/steps/payment/index.tsx +10 -2
  38. package/app-template/src/views/checkout/steps/payment/options/credit-card/index.tsx +2 -0
  39. package/app-template/src/views/checkout/steps/payment/options/funds-transfer.tsx +2 -0
  40. package/app-template/src/views/checkout/steps/payment/payment-header.tsx +5 -1
  41. package/app-template/src/views/checkout/steps/payment/payment-option-buttons.tsx +16 -4
  42. package/app-template/src/views/checkout/steps/shipping/addresses.tsx +2 -1
  43. package/app-template/src/views/checkout/steps/shipping/index.tsx +2 -0
  44. package/app-template/src/views/checkout/steps/shipping/shipping-options.tsx +2 -0
  45. package/app-template/src/views/checkout/summary.tsx +56 -18
  46. package/app-template/src/views/checkout/variants/__tests__/registry.test.tsx +82 -0
  47. package/app-template/src/views/checkout/variants/__tests__/use-resolved-config.test.tsx +208 -0
  48. package/app-template/src/views/checkout/variants/basket-and-checkout/basket-section.tsx +150 -0
  49. package/app-template/src/views/checkout/variants/basket-and-checkout/index.tsx +135 -0
  50. package/app-template/src/views/checkout/variants/multi-step/index.tsx +78 -0
  51. package/app-template/src/views/checkout/variants/one-page/accordion-section.tsx +165 -0
  52. package/app-template/src/views/checkout/variants/one-page/hooks/use-checkout-funnel-gtm.ts +60 -0
  53. package/app-template/src/views/checkout/variants/one-page/hooks/use-section-state.ts +103 -0
  54. package/app-template/src/views/checkout/variants/one-page/index.tsx +125 -0
  55. package/app-template/src/views/checkout/variants/one-page/mobile-summary-sheet.tsx +109 -0
  56. package/app-template/src/views/checkout/variants/one-page/one-page-summary.tsx +301 -0
  57. package/app-template/src/views/checkout/variants/one-page/payment-options-grid.tsx +220 -0
  58. package/app-template/src/views/checkout/variants/one-page/sections/address-section.tsx +320 -0
  59. package/app-template/src/views/checkout/variants/one-page/sections/contact-section.tsx +62 -0
  60. package/app-template/src/views/checkout/variants/one-page/sections/payment-section.tsx +73 -0
  61. package/app-template/src/views/checkout/variants/one-page/sections/shipping-section.tsx +328 -0
  62. package/app-template/src/views/checkout/variants/one-page/skeletons/address-skeleton.tsx +25 -0
  63. package/app-template/src/views/checkout/variants/one-page/skeletons/checkout-skeleton.tsx +27 -0
  64. package/app-template/src/views/checkout/variants/one-page/skeletons/index.ts +6 -0
  65. package/app-template/src/views/checkout/variants/one-page/skeletons/payment-skeleton.tsx +23 -0
  66. package/app-template/src/views/checkout/variants/one-page/skeletons/section-skeleton.tsx +47 -0
  67. package/app-template/src/views/checkout/variants/one-page/skeletons/shipping-skeleton.tsx +20 -0
  68. package/app-template/src/views/checkout/variants/one-page/skeletons/summary-skeleton.tsx +38 -0
  69. package/app-template/src/views/checkout/variants/one-page/trust-badges.tsx +35 -0
  70. package/app-template/src/views/checkout/variants/registry.ts +43 -0
  71. package/app-template/src/views/checkout/variants/types.ts +30 -0
  72. package/app-template/src/views/checkout/variants/use-resolved-config.ts +168 -0
  73. package/app-template/tailwind.config.js +3 -1
  74. package/dist/commands/plugins.js +23 -2
  75. package/package.json +1 -1
  76. package/app-template/src/app/[pz]/account/orders/[id]/layout.tsx +0 -5
  77. /package/app-template/src/app/[pz]/account/{page.tsx → (dashboard)/page.tsx} +0 -0
  78. /package/app-template/src/app/[pz]/account/orders/{page.tsx → (list)/page.tsx} +0 -0
  79. /package/app-template/src/app/[pz]/account/orders/[id]/{page.tsx → (detail)/page.tsx} +0 -0
  80. /package/app-template/src/app/[pz]/auth/{page.tsx → (login)/page.tsx} +0 -0
@@ -0,0 +1,320 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import clsx from 'clsx';
3
+ import { useAppSelector } from '@akinon/next/redux/hooks';
4
+ import { useSetAddressesMutation } from '@akinon/next/data/client/checkout';
5
+ import { useAddAddressMutation } from '@akinon/next/data/client/address';
6
+ import { Button, Checkbox, Icon, Modal, Radio } from '@theme/components';
7
+ import { partAttrs } from '@akinon/pz-theme/src/utils/part-styles';
8
+ import { AddressForm } from '@theme/views/account/address-form';
9
+ import { useLocalization } from '@akinon/next/hooks';
10
+ import PluginModule, { Component } from '@akinon/next/components/plugin-module';
11
+ import type { RootState } from '@theme/redux/store';
12
+ import type { Address } from '@akinon/next/types';
13
+ import AccordionSection, { SectionStatus } from '../accordion-section';
14
+ import { AddressListSkeleton } from '../skeletons/address-skeleton';
15
+
16
+ interface AddressSectionProps {
17
+ status: SectionStatus;
18
+ onEdit: () => void;
19
+ onComplete: () => void;
20
+ editable?: boolean;
21
+ }
22
+
23
+ const AddressSection = ({
24
+ status,
25
+ onEdit,
26
+ onComplete,
27
+ editable = true
28
+ }: AddressSectionProps) => {
29
+ const { t } = useLocalization();
30
+ const [isModalOpen, setIsModalOpen] = useState(false);
31
+
32
+ const addressList = useAppSelector(
33
+ (state: RootState) => state.checkout.addressList
34
+ );
35
+ const preOrder = useAppSelector(
36
+ (state: RootState) => state.checkout.preOrder
37
+ );
38
+ const {
39
+ shipping_address,
40
+ billing_address,
41
+ billing_and_shipping_same,
42
+ delivery_option
43
+ } = preOrder ?? {};
44
+
45
+ const [setAddresses, { isLoading: isSetting }] = useSetAddressesMutation();
46
+ const [addAddress, { isLoading: isAdding }] = useAddAddressMutation();
47
+
48
+ const [billingSameAsShipping, setBillingSameAsShipping] = useState(
49
+ billing_and_shipping_same ?? true
50
+ );
51
+
52
+ useEffect(() => {
53
+ setBillingSameAsShipping(billing_and_shipping_same ?? true);
54
+ }, [billing_and_shipping_same]);
55
+
56
+ const isRetailStore =
57
+ delivery_option?.delivery_option_type === 'retail_store';
58
+ const billingMatchesShipping =
59
+ !!shipping_address?.pk &&
60
+ !!billing_address?.pk &&
61
+ shipping_address.pk === billing_address.pk;
62
+
63
+ const handleSelectShipping = async (address: Address) => {
64
+ const billingPk = billingSameAsShipping
65
+ ? address.pk
66
+ : billing_address?.pk ?? address.pk;
67
+ await setAddresses({
68
+ shippingAddressPk: address.pk,
69
+ billingAddressPk: billingPk
70
+ })
71
+ .unwrap()
72
+ .catch(() => null);
73
+ };
74
+
75
+ const handleSelectBilling = async (address: Address) => {
76
+ if (!shipping_address?.pk) return;
77
+ await setAddresses({
78
+ shippingAddressPk: shipping_address.pk,
79
+ billingAddressPk: address.pk
80
+ })
81
+ .unwrap()
82
+ .catch(() => null);
83
+ };
84
+
85
+ const handleSameAddressToggle = async () => {
86
+ const next = !billingSameAsShipping;
87
+ setBillingSameAsShipping(next);
88
+ if (next && shipping_address?.pk) {
89
+ await setAddresses({
90
+ shippingAddressPk: shipping_address.pk,
91
+ billingAddressPk: shipping_address.pk
92
+ })
93
+ .unwrap()
94
+ .catch(() => null);
95
+ }
96
+ };
97
+
98
+ const handleAddAddress = async (data: Record<string, unknown>) => {
99
+ const response = await addAddress({
100
+ ...data,
101
+ invalidateTag: 'Checkout'
102
+ })
103
+ .unwrap()
104
+ .catch(() => null);
105
+ setIsModalOpen(false);
106
+ if (response?.pk) {
107
+ const billingPk = billingSameAsShipping
108
+ ? response.pk
109
+ : billing_address?.pk ?? response.pk;
110
+ await setAddresses({
111
+ shippingAddressPk: response.pk,
112
+ billingAddressPk: billingPk
113
+ })
114
+ .unwrap()
115
+ .catch(() => null);
116
+ }
117
+ };
118
+
119
+ const summary = useMemo(() => {
120
+ if (!shipping_address) return null;
121
+ return (
122
+ <div className="flex flex-col gap-1">
123
+ <span className="font-medium">{shipping_address.title}</span>
124
+ <span className="text-xs text-black-700">
125
+ {shipping_address.line} — {shipping_address.township?.name},{' '}
126
+ {shipping_address.city?.name}
127
+ </span>
128
+ {!billingSameAsShipping && billing_address && !billingMatchesShipping && (
129
+ <span className="text-xs italic text-gray-700">
130
+ {t('checkout.one_page.address.billing_label')}:{' '}
131
+ {billing_address.title}
132
+ </span>
133
+ )}
134
+ </div>
135
+ );
136
+ }, [
137
+ shipping_address,
138
+ billing_address,
139
+ billingSameAsShipping,
140
+ billingMatchesShipping,
141
+ t
142
+ ]);
143
+
144
+ const renderAddressCard = (
145
+ address: Address,
146
+ selected: boolean,
147
+ onClick: () => void,
148
+ name: string,
149
+ options?: { showSameBadge?: boolean }
150
+ ) => (
151
+ <button
152
+ key={`${name}-${address.pk}`}
153
+ type="button"
154
+ role="radio"
155
+ aria-checked={selected}
156
+ onClick={onClick}
157
+ disabled={isSetting}
158
+ className={clsx(
159
+ 'relative w-full rounded-sm border p-3 text-left shadow-sm transition-all',
160
+ 'hover:border-secondary-400 focus:outline-none focus-visible:ring-2 focus-visible:ring-secondary',
161
+ selected
162
+ ? 'border-secondary-400 ring-2 ring-secondary-400/30'
163
+ : 'border-gray-300',
164
+ isSetting && 'opacity-60'
165
+ )}
166
+ data-testid={`${name}-address-${address.pk}`}
167
+ >
168
+ <div className="flex items-start gap-3">
169
+ <Radio name={name} checked={selected} onChange={() => null} />
170
+ <div className="flex flex-1 flex-col gap-1 text-xs leading-snug">
171
+ <div className="flex items-center gap-2">
172
+ <span className="font-medium text-black-800">{address.title}</span>
173
+ {options?.showSameBadge && (
174
+ <span className="rounded-sm bg-gray-100 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-gray-700">
175
+ {t('checkout.one_page.address.same_as_shipping')}
176
+ </span>
177
+ )}
178
+ </div>
179
+ <span className="text-black-700">{address.phone_number}</span>
180
+ <span className="line-clamp-2 text-black-700">{address.line}</span>
181
+ <span className="text-black-700">
182
+ {address.township?.name} / {address.city?.name}
183
+ </span>
184
+ </div>
185
+ </div>
186
+ </button>
187
+ );
188
+
189
+ const isLoadingFirstLoad = !preOrder && addressList.length === 0;
190
+
191
+ return (
192
+ <AccordionSection
193
+ step={2}
194
+ title={t('checkout.one_page.address.title')}
195
+ status={status}
196
+ onEdit={onEdit}
197
+ editable={editable}
198
+ summary={summary}
199
+ dataTestId="one-page-address"
200
+ >
201
+ {isLoadingFirstLoad ? (
202
+ <AddressListSkeleton />
203
+ ) : (
204
+ <div className="flex flex-col gap-5">
205
+ <div>
206
+ <div className="mb-3 flex items-center justify-between gap-2">
207
+ <h3 className="text-sm font-medium text-black-800">
208
+ {t('checkout.one_page.address.shipping_label')}
209
+ </h3>
210
+ {!isRetailStore && (
211
+ <Checkbox
212
+ checked={billingSameAsShipping}
213
+ onChange={handleSameAddressToggle}
214
+ data-testid="one-page-billing-same"
215
+ >
216
+ <span className="text-xs">
217
+ {t('checkout.one_page.address.use_for_billing')}
218
+ </span>
219
+ </Checkbox>
220
+ )}
221
+ </div>
222
+ <div
223
+ className="grid grid-cols-1 gap-2 md:grid-cols-2"
224
+ role="radiogroup"
225
+ aria-label={t('checkout.one_page.address.shipping_label')}
226
+ >
227
+ {addressList.map((address) =>
228
+ renderAddressCard(
229
+ address,
230
+ shipping_address?.pk === address.pk,
231
+ () => handleSelectShipping(address),
232
+ 'one-page-shipping'
233
+ )
234
+ )}
235
+ <PluginModule
236
+ component={Component.ClickCollect}
237
+ props={{ addressTypeParam: 'shippingAddressPk' }}
238
+ />
239
+ <button
240
+ type="button"
241
+ onClick={() => setIsModalOpen(true)}
242
+ disabled={isAdding}
243
+ className={clsx(
244
+ 'flex min-h-[5.5rem] items-center justify-center gap-2',
245
+ 'rounded-sm border border-dashed border-gray-400 px-3 text-xs',
246
+ 'text-black-700 transition-colors hover:border-secondary hover:text-secondary',
247
+ 'focus:outline-none focus-visible:ring-2 focus-visible:ring-secondary',
248
+ 'disabled:cursor-not-allowed disabled:opacity-50'
249
+ )}
250
+ data-testid="one-page-address-add"
251
+ >
252
+ <Icon name="plus" size={12} />
253
+ {t('checkout.address.add_new_address')}
254
+ </button>
255
+ </div>
256
+ </div>
257
+
258
+ {!billingSameAsShipping && !isRetailStore && (
259
+ <div>
260
+ <div className="mb-3 flex items-center justify-between gap-2">
261
+ <h3 className="text-sm font-medium text-black-800">
262
+ {t('checkout.one_page.address.billing_label')}
263
+ </h3>
264
+ {billingMatchesShipping && (
265
+ <span className="text-xs italic text-gray-700">
266
+ {t('checkout.one_page.address.pick_different_billing')}
267
+ </span>
268
+ )}
269
+ </div>
270
+ <div
271
+ className="grid grid-cols-1 gap-2 md:grid-cols-2"
272
+ role="radiogroup"
273
+ aria-label={t('checkout.one_page.address.billing_label')}
274
+ >
275
+ {addressList.map((address) =>
276
+ renderAddressCard(
277
+ address,
278
+ billing_address?.pk === address.pk,
279
+ () => handleSelectBilling(address),
280
+ 'one-page-billing',
281
+ {
282
+ showSameBadge:
283
+ billingMatchesShipping &&
284
+ billing_address?.pk === address.pk
285
+ }
286
+ )
287
+ )}
288
+ </div>
289
+ </div>
290
+ )}
291
+
292
+ <div className="flex justify-end">
293
+ <Button
294
+ disabled={
295
+ !shipping_address?.pk || !billing_address?.pk || isSetting
296
+ }
297
+ onClick={onComplete}
298
+ data-testid="one-page-address-continue"
299
+ {...partAttrs('continue-button')}
300
+ >
301
+ {t('checkout.one_page.continue_to_shipping')}
302
+ </Button>
303
+ </div>
304
+
305
+ <Modal
306
+ portalId="one-page-add-address-modal"
307
+ title={t('checkout.address.add_new_address')}
308
+ open={isModalOpen}
309
+ setOpen={setIsModalOpen}
310
+ className="w-full max-h-[90vh] overflow-y-auto sm:w-[28rem]"
311
+ >
312
+ <AddressForm onSubmit={handleAddAddress} />
313
+ </Modal>
314
+ </div>
315
+ )}
316
+ </AccordionSection>
317
+ );
318
+ };
319
+
320
+ export default AddressSection;
@@ -0,0 +1,62 @@
1
+ import { useSession } from 'next-auth/react';
2
+ import { useLocalization } from '@akinon/next/hooks';
3
+ import { Icon } from '@theme/components';
4
+ import AccordionSection, { SectionStatus } from '../accordion-section';
5
+
6
+ interface ContactSectionProps {
7
+ status: SectionStatus;
8
+ onEdit: () => void;
9
+ }
10
+
11
+ const ContactSection = ({ status, onEdit }: ContactSectionProps) => {
12
+ const { t } = useLocalization();
13
+ const { data: session } = useSession();
14
+
15
+ const isGuest = !session?.user;
16
+ const email =
17
+ session?.user?.email || t('checkout.one_page.contact.guest_user');
18
+ const displayName = session?.user?.name || email;
19
+
20
+ const summary = (
21
+ <div className="flex items-center gap-2 text-sm text-black-700">
22
+ <Icon name="email" size={14} />
23
+ <span>{email}</span>
24
+ {isGuest && (
25
+ <span className="ml-2 rounded-sm border border-gray-400 px-2 py-0.5 text-xs uppercase text-gray-700">
26
+ {t('checkout.one_page.contact.guest_badge')}
27
+ </span>
28
+ )}
29
+ </div>
30
+ );
31
+
32
+ return (
33
+ <AccordionSection
34
+ step={1}
35
+ title={t('checkout.one_page.contact.title')}
36
+ status={status}
37
+ onEdit={onEdit}
38
+ editable={false}
39
+ summary={summary}
40
+ dataTestId="one-page-contact"
41
+ >
42
+ <div className="flex flex-col gap-3">
43
+ <div className="flex items-start gap-3 rounded-sm border border-gray-200 bg-gray-50 px-4 py-3">
44
+ <Icon name="account" size={18} className="mt-0.5 fill-secondary" />
45
+ <div className="flex flex-col">
46
+ <span className="text-sm font-medium text-black-800">
47
+ {displayName}
48
+ </span>
49
+ <span className="text-xs text-black-700">{email}</span>
50
+ {isGuest && (
51
+ <span className="mt-1 text-xs italic text-gray-700">
52
+ {t('checkout.one_page.contact.guest_note')}
53
+ </span>
54
+ )}
55
+ </div>
56
+ </div>
57
+ </div>
58
+ </AccordionSection>
59
+ );
60
+ };
61
+
62
+ export default ContactSection;
@@ -0,0 +1,73 @@
1
+ import clsx from 'clsx';
2
+ import { useAppSelector } from '@akinon/next/redux/hooks';
3
+ import { useLocalization } from '@akinon/next/hooks';
4
+ import SelectedPaymentOptionView from '@akinon/next/components/selected-payment-option-view';
5
+ import { partAttrs } from '@akinon/pz-theme/src/utils/part-styles';
6
+ import type { RootState } from '@theme/redux/store';
7
+ import AccordionSection, { SectionStatus } from '../accordion-section';
8
+ import PaymentOptionsGrid from '../payment-options-grid';
9
+ import { PaymentGridSkeleton } from '../skeletons/payment-skeleton';
10
+
11
+ interface PaymentSectionProps {
12
+ status: SectionStatus;
13
+ onEdit: () => void;
14
+ }
15
+
16
+ const PaymentSection = ({ status, onEdit }: PaymentSectionProps) => {
17
+ const { t } = useLocalization();
18
+ const isPaymentStepBusy = useAppSelector(
19
+ (state: RootState) => state.checkout.steps.payment.busy
20
+ );
21
+ const paymentOption = useAppSelector(
22
+ (state: RootState) => state.checkout.preOrder?.payment_option
23
+ );
24
+ const paymentOptionsCount = useAppSelector(
25
+ (state: RootState) => state.checkout.paymentOptions.length
26
+ );
27
+
28
+ return (
29
+ <AccordionSection
30
+ step={4}
31
+ title={t('checkout.one_page.payment.title')}
32
+ status={status}
33
+ onEdit={onEdit}
34
+ editable={false}
35
+ dataTestId="one-page-payment"
36
+ padded={false}
37
+ >
38
+ <div
39
+ className={clsx({
40
+ 'pointer-events-none opacity-50': isPaymentStepBusy
41
+ })}
42
+ >
43
+ <div className="px-5 py-5">
44
+ {paymentOptionsCount === 0 ? (
45
+ <PaymentGridSkeleton />
46
+ ) : (
47
+ <PaymentOptionsGrid />
48
+ )}
49
+ </div>
50
+
51
+ {paymentOption && (
52
+ <div
53
+ className="border-t border-gray-200"
54
+ data-testid="one-page-selected-payment"
55
+ {...partAttrs('payment-panel')}
56
+ >
57
+ <SelectedPaymentOptionView />
58
+ </div>
59
+ )}
60
+
61
+ {!paymentOption && paymentOptionsCount > 0 && (
62
+ <div className="border-t border-gray-200 bg-gray-50/30 px-5 py-4">
63
+ <p className="text-sm italic text-gray-700">
64
+ {t('checkout.one_page.payment.select_method')}
65
+ </p>
66
+ </div>
67
+ )}
68
+ </div>
69
+ </AccordionSection>
70
+ );
71
+ };
72
+
73
+ export default PaymentSection;