@akinon/projectzero 2.0.0-beta.16 → 2.0.0-beta.17

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # @akinon/projectzero
2
2
 
3
+ ## 2.0.0-beta.17
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a8ddcf6: ZERO-4111: Add total balance field to store credit localization and update related components
8
+ - c67942a4: ZERO-3423: Updated version control and debug messages for the package
9
+
3
10
  ## 2.0.0-beta.16
4
11
 
5
12
  ## 2.0.0-beta.15
@@ -13,3 +13,5 @@ NEXT_PUBLIC_VIRTUAL_TRY_ON_API_URL=https://d2a26507c7094f359aba349b96a96881.lb.a
13
13
  # CACHE_SECRET=KhvhE1go3GDmYJ7PhZLmskqfhYNlPSm6
14
14
  # CACHE_HOST=default:redispw@localhost
15
15
  # CACHE_PORT=6379
16
+
17
+ # BF_CACHE=false
@@ -1,5 +1,56 @@
1
1
  # projectzeronext
2
2
 
3
+ ## 2.0.0-beta.17
4
+
5
+ ### Minor Changes
6
+
7
+ - 2a8ddcf6: ZERO-4111: Add total balance field to store credit localization and update related components
8
+ - 36143125: ZERO-3987: Add barcode scanner functionality with modal and button
9
+ - f7e0f646: ZERO-4032: Add bfcache-headers middleware, integrate it into the default chain, and introduce a new environment variable for control.
10
+ - 5fb34b5c: ZERO-3955: Add aspect ratio validation and error handling for image cropping
11
+ - d76d3255: ZERO-4011: Refactor sitemap content generation to append locale suffix based on matched locale
12
+
13
+ ### Patch Changes
14
+
15
+ - Updated dependencies [4798959a]
16
+ - Updated dependencies [8218dafa]
17
+ - Updated dependencies [2a8ddcf6]
18
+ - Updated dependencies [8a7fd0f4]
19
+ - Updated dependencies [36143125]
20
+ - Updated dependencies [572f4f7b]
21
+ - Updated dependencies [f7e0f646]
22
+ - Updated dependencies [94a86fcc]
23
+ - Updated dependencies [bcaad120]
24
+ - Updated dependencies [5fb34b5c]
25
+ - Updated dependencies [88cb4f62]
26
+ - Updated dependencies [6b73b050]
27
+ - @akinon/pz-masterpass-rest@2.0.0-beta.17
28
+ - @akinon/next@2.0.0-beta.17
29
+ - @akinon/pz-virtual-try-on@2.0.0-beta.17
30
+ - @akinon/pz-masterpass@2.0.0-beta.17
31
+ - @akinon/pz-akifast@2.0.0-beta.17
32
+ - @akinon/pz-apple-pay@2.0.0-beta.17
33
+ - @akinon/pz-b2b@2.0.0-beta.17
34
+ - @akinon/pz-basket-gift-pack@2.0.0-beta.17
35
+ - @akinon/pz-bkm@2.0.0-beta.17
36
+ - @akinon/pz-checkout-gift-pack@2.0.0-beta.17
37
+ - @akinon/pz-click-collect@2.0.0-beta.17
38
+ - @akinon/pz-credit-payment@2.0.0-beta.17
39
+ - @akinon/pz-cybersource-uc@2.0.0-beta.17
40
+ - @akinon/pz-flow-payment@2.0.0-beta.17
41
+ - @akinon/pz-google-pay@2.0.0-beta.17
42
+ - @akinon/pz-gpay@2.0.0-beta.17
43
+ - @akinon/pz-haso@2.0.0-beta.17
44
+ - @akinon/pz-hepsipay@2.0.0-beta.17
45
+ - @akinon/pz-multi-basket@2.0.0-beta.17
46
+ - @akinon/pz-one-click-checkout@2.0.0-beta.17
47
+ - @akinon/pz-otp@2.0.0-beta.17
48
+ - @akinon/pz-pay-on-delivery@2.0.0-beta.17
49
+ - @akinon/pz-saved-card@2.0.0-beta.17
50
+ - @akinon/pz-similar-products@2.0.0-beta.17
51
+ - @akinon/pz-tabby-extension@2.0.0-beta.17
52
+ - @akinon/pz-tamara-extension@2.0.0-beta.17
53
+
3
54
  ## 2.0.0-beta.16
4
55
 
5
56
  ### Minor Changes
@@ -142,3 +142,13 @@ This codemod will:
142
142
  - Clean up middleware rewrite blocks
143
143
  - Update path references in `tsconfig.json`, `next.config.js`, and source files
144
144
  - Replace `params.locale` / `params.currency` / `params.url` usages with `parsePzParams`
145
+
146
+ ## Enabling Browser Back/Forward Cache (bfcache)
147
+
148
+ By default, dynamic pages may include `Cache-Control: no-store` headers, which prevents browsers from using the back/forward cache (bfcache). To enable bfcache support, set the `BF_CACHE` environment variable to `true`:
149
+
150
+ ```bash
151
+ BF_CACHE=true
152
+ ```
153
+
154
+ When enabled, a middleware wrapper overrides the `Cache-Control` header to `private, no-cache, max-age=0, must-revalidate`, allowing the browser to cache pages for instant back/forward navigation while still revalidating content on revisit.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "projectzeronext",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.17",
4
4
  "private": true,
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -24,32 +24,32 @@
24
24
  "test:middleware": "jest middleware-matcher.test.ts --bail"
25
25
  },
26
26
  "dependencies": {
27
- "@akinon/next": "2.0.0-beta.16",
28
- "@akinon/pz-akifast": "2.0.0-beta.16",
29
- "@akinon/pz-apple-pay": "2.0.0-beta.16",
30
- "@akinon/pz-b2b": "2.0.0-beta.16",
31
- "@akinon/pz-basket-gift-pack": "2.0.0-beta.16",
32
- "@akinon/pz-bkm": "2.0.0-beta.16",
33
- "@akinon/pz-checkout-gift-pack": "2.0.0-beta.16",
34
- "@akinon/pz-click-collect": "2.0.0-beta.16",
35
- "@akinon/pz-credit-payment": "2.0.0-beta.16",
36
- "@akinon/pz-cybersource-uc": "2.0.0-beta.16",
37
- "@akinon/pz-flow-payment": "2.0.0-beta.16",
38
- "@akinon/pz-google-pay": "2.0.0-beta.16",
39
- "@akinon/pz-gpay": "2.0.0-beta.16",
40
- "@akinon/pz-haso": "2.0.0-beta.16",
41
- "@akinon/pz-hepsipay": "2.0.0-beta.16",
42
- "@akinon/pz-masterpass": "2.0.0-beta.16",
43
- "@akinon/pz-masterpass-rest": "2.0.0-beta.16",
44
- "@akinon/pz-multi-basket": "2.0.0-beta.16",
45
- "@akinon/pz-one-click-checkout": "2.0.0-beta.16",
46
- "@akinon/pz-otp": "2.0.0-beta.16",
47
- "@akinon/pz-pay-on-delivery": "2.0.0-beta.16",
48
- "@akinon/pz-saved-card": "2.0.0-beta.16",
49
- "@akinon/pz-similar-products": "2.0.0-beta.16",
50
- "@akinon/pz-tabby-extension": "2.0.0-beta.16",
51
- "@akinon/pz-tamara-extension": "2.0.0-beta.16",
52
- "@akinon/pz-virtual-try-on": "2.0.0-beta.16",
27
+ "@akinon/next": "2.0.0-beta.17",
28
+ "@akinon/pz-akifast": "2.0.0-beta.17",
29
+ "@akinon/pz-apple-pay": "2.0.0-beta.17",
30
+ "@akinon/pz-b2b": "2.0.0-beta.17",
31
+ "@akinon/pz-basket-gift-pack": "2.0.0-beta.17",
32
+ "@akinon/pz-bkm": "2.0.0-beta.17",
33
+ "@akinon/pz-checkout-gift-pack": "2.0.0-beta.17",
34
+ "@akinon/pz-click-collect": "2.0.0-beta.17",
35
+ "@akinon/pz-credit-payment": "2.0.0-beta.17",
36
+ "@akinon/pz-cybersource-uc": "2.0.0-beta.17",
37
+ "@akinon/pz-flow-payment": "2.0.0-beta.17",
38
+ "@akinon/pz-google-pay": "2.0.0-beta.17",
39
+ "@akinon/pz-gpay": "2.0.0-beta.17",
40
+ "@akinon/pz-haso": "2.0.0-beta.17",
41
+ "@akinon/pz-hepsipay": "2.0.0-beta.17",
42
+ "@akinon/pz-masterpass": "2.0.0-beta.17",
43
+ "@akinon/pz-masterpass-rest": "2.0.0-beta.17",
44
+ "@akinon/pz-multi-basket": "2.0.0-beta.17",
45
+ "@akinon/pz-one-click-checkout": "2.0.0-beta.17",
46
+ "@akinon/pz-otp": "2.0.0-beta.17",
47
+ "@akinon/pz-pay-on-delivery": "2.0.0-beta.17",
48
+ "@akinon/pz-saved-card": "2.0.0-beta.17",
49
+ "@akinon/pz-similar-products": "2.0.0-beta.17",
50
+ "@akinon/pz-tabby-extension": "2.0.0-beta.17",
51
+ "@akinon/pz-tamara-extension": "2.0.0-beta.17",
52
+ "@akinon/pz-virtual-try-on": "2.0.0-beta.17",
53
53
  "@hookform/resolvers": "2.9.0",
54
54
  "@next/third-parties": "16.1.6",
55
55
  "@react-google-maps/api": "2.17.1",
@@ -72,7 +72,7 @@
72
72
  "yup": "0.32.11"
73
73
  },
74
74
  "devDependencies": {
75
- "@akinon/eslint-plugin-projectzero": "2.0.0-beta.16",
75
+ "@akinon/eslint-plugin-projectzero": "2.0.0-beta.17",
76
76
  "@semantic-release/changelog": "6.0.2",
77
77
  "@semantic-release/exec": "6.0.3",
78
78
  "@semantic-release/git": "10.0.1",
@@ -143,6 +143,7 @@
143
143
  "store_credit": {
144
144
  "use_my_store_credits": "Use my pz-zero credits",
145
145
  "available_balance": "Available Balance",
146
+ "total_balance": "Total Balance",
146
147
  "insufficient_balance": "Your pz-zero credits are not sufficient to pay for the order, please select an additional payment method to cover the balance of <Amount/>"
147
148
  }
148
149
  },
@@ -86,6 +86,8 @@
86
86
  "multiple_results_subtitle": "Try-on completed for {{count}} products",
87
87
  "error_incompatible": "Image Not Compatible",
88
88
  "error_auto_reported": "Error automatically reported",
89
+ "error_aspect_ratio_too_tall": "The image is too tall. Maximum allowed ratio is 9:16 (portrait). Please crop or use a different image.",
90
+ "error_aspect_ratio_too_wide": "The image is too wide. Maximum allowed ratio is 21:9 (landscape). Please crop or use a different image.",
89
91
  "feedback_question": "How was the result?",
90
92
  "feedback_success": "Success",
91
93
  "feedback_failed": "Failed",
@@ -96,5 +98,21 @@
96
98
  "starting": "Starting...",
97
99
  "will_start": "will start virtual try-on for",
98
100
  "products_count": "products"
101
+ },
102
+ "barcode_scanner": {
103
+ "title": "Scan Barcode",
104
+ "button_label": "Barcode Scanner",
105
+ "button_text": "Try on products in store",
106
+ "help_text": "Point your camera at the product barcode",
107
+ "scan_more_help": "To scan another product, point your camera at the new barcode.",
108
+ "searching": "Searching for product...",
109
+ "continue_to_vto": "Continue to Virtual Cabin",
110
+ "permission_denied_title": "Camera Permission Required",
111
+ "permission_denied_message": "You need to allow camera access for the barcode scanner.",
112
+ "try_again": "Try Again",
113
+ "errors": {
114
+ "product_not_found": "No product found for this barcode.",
115
+ "search_failed": "Search failed. Please try again."
116
+ }
99
117
  }
100
118
  }
@@ -88,6 +88,8 @@
88
88
  "multiple_results_subtitle": "{{count}} ürün için deneme tamamlandı",
89
89
  "error_incompatible": "Görüntü Uyumlu Değil",
90
90
  "error_auto_reported": "Hata otomatik olarak bildirildi",
91
+ "error_aspect_ratio_too_tall": "Görsel çok uzun. Dikey görseller için izin verilen maksimum oran 9:16'dır. Lütfen kırpın veya farklı bir görsel seçin.",
92
+ "error_aspect_ratio_too_wide": "Görsel çok geniş. Yatay görseller için izin verilen maksimum oran 21:9'dur. Lütfen kırpın veya farklı bir görsel seçin.",
91
93
  "feedback_question": "Sonuç nasıldı?",
92
94
  "feedback_success": "Başarılı",
93
95
  "feedback_failed": "Başarısız",
@@ -98,5 +100,21 @@
98
100
  "starting": "Başlatılıyor...",
99
101
  "will_start": "için sanal deneme başlatılacak",
100
102
  "products_count": "ürün"
103
+ },
104
+ "barcode_scanner": {
105
+ "title": "Barkodu Okut",
106
+ "button_label": "Barkod Tarayıcı",
107
+ "button_text": "Mağazadaki ürünü üstünde dene",
108
+ "help_text": "Ürün barkodunu kameraya yaklaştırın",
109
+ "scan_more_help": "Bir ürün daha okutmak isterseniz, yeni barkodu da kameranıza yaklaştırın.",
110
+ "searching": "Ürün aranıyor...",
111
+ "continue_to_vto": "Sanal Kabine Devam Et",
112
+ "permission_denied_title": "Kamera İzni Gerekli",
113
+ "permission_denied_message": "Barkod okuyucu için kamera erişimine izin vermeniz gerekmektedir.",
114
+ "try_again": "Tekrar Dene",
115
+ "errors": {
116
+ "product_not_found": "Bu barkoda ait ürün bulunamadı.",
117
+ "search_failed": "Arama başarısız oldu. Lütfen tekrar deneyin."
118
+ }
101
119
  }
102
120
  }
@@ -63,7 +63,26 @@ const AccountOrderDetail = () => {
63
63
  }, [order, isSuccess, localeValue]);
64
64
 
65
65
  if (isLoading && isFetching) {
66
- return <LoaderSpinner />;
66
+ return (
67
+ <div className="flex flex-col items-center justify-center h-96">
68
+ <LoaderSpinner />
69
+ </div>
70
+ );
71
+ }
72
+
73
+ if (!order) {
74
+ return (
75
+ <div className="flex flex-col items-center justify-center h-96">
76
+ <p className="mt-5 text-start text-lg mb-4">
77
+ {t('account.my_orders.detail.no_orders_found')}
78
+ </p>
79
+ <Link href={`/account/orders/`}>
80
+ <Button className="px-4" appearance="filled">
81
+ {t('account.my_orders.detail.back_to_orders')}
82
+ </Button>
83
+ </Link>
84
+ </div>
85
+ );
67
86
  }
68
87
 
69
88
  return (
@@ -58,10 +58,12 @@ export async function GET(request: Request, context: { params: Promise<{ node: s
58
58
 
59
59
  let sitemapContent = await sitemap.text();
60
60
 
61
- sitemapContent = sitemapContent.replace(
62
- /\.com/g,
63
- `.com${matchedLocale?.[0] ?? ''}`
64
- );
61
+ if (matchedLocale?.[0]) {
62
+ const localeSuffix = matchedLocale[0];
63
+ const domainRegex = /(?<=<loc>\s*)https?:\/\/[^/<\s]+/g;
64
+
65
+ sitemapContent = sitemapContent.replace(domainRegex, `$&${localeSuffix}`);
66
+ }
65
67
 
66
68
  return new Response(sitemapContent, {
67
69
  headers: {
@@ -0,0 +1 @@
1
+ export * from '@akinon/next/api/barcode-search';
@@ -41,12 +41,14 @@ export const Modal = (props: ModalProps) => {
41
41
  'fixed top-0 left-0 w-screen h-screen bg-primary bg-opacity-60 z-50',
42
42
  overlayClassName
43
43
  )}
44
+ onClick={(e) => e.stopPropagation()}
44
45
  />
45
46
  <section
46
47
  className={twMerge(
47
48
  'fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-50 bg-white',
48
49
  className
49
50
  )}
51
+ onClick={(e) => e.stopPropagation()}
50
52
  >
51
53
  {(showCloseButton || title) && (
52
54
  <div
@@ -4,46 +4,198 @@ import {
4
4
  usePayWithLoyaltyBalanceMutation
5
5
  } from '@akinon/next/data/client/checkout';
6
6
  import { useAppSelector } from '@akinon/next/redux/hooks';
7
- import { useMemo, useState } from 'react';
7
+ import { useEffect, useMemo, useState } from 'react';
8
8
  import { useLocalization } from '@akinon/next/hooks';
9
9
  import { twMerge } from 'tailwind-merge';
10
10
  import { Icon, Price } from '@theme/components';
11
11
  import { Trans } from '@akinon/next/components';
12
12
  import { LoaderSpinner } from '@theme/components';
13
+ import { AccountUsage, LoyaltyBalanceItem } from '@akinon/next/types';
13
14
 
14
15
  export const StoreCredits = () => {
15
16
  const { t } = useLocalization();
16
17
 
17
- const [payWithLoyaltyBalance, { isLoading: isPayWithLoyaltyBalanceLoading }] =
18
+ const [payWithLoyaltyBalance, { isLoading: isPayLoading }] =
18
19
  usePayWithLoyaltyBalanceMutation();
19
20
 
20
- const { loyaltyBalance, preOrder } = useAppSelector(
21
+ const { loyaltyBalance, loyaltyBalances, preOrder } = useAppSelector(
21
22
  (state) => state.checkout
22
23
  );
23
24
 
24
- const { isLoading: isLoyaltyBalanceLoading } =
25
+ const { data: checkoutLoyaltyData, isLoading: isLoyaltyBalanceLoading } =
25
26
  useGetCheckoutLoyaltyBalanceQuery(undefined, {
26
27
  refetchOnMountOrArgChange: true,
27
28
  skip: !preOrder?.payment_option
28
29
  });
29
30
 
31
+ // New approach: read accounts from LoyaltyMoneyUsagePage context
32
+ const loyaltyAccounts: LoyaltyBalanceItem[] = useMemo(() => {
33
+ const loyaltyContext = checkoutLoyaltyData?.context_list?.find(
34
+ (ctx) => ctx.page_name === 'LoyaltyMoneyUsagePage'
35
+ );
36
+ return (
37
+ (loyaltyContext?.page_context?.accounts as LoyaltyBalanceItem[]) ?? []
38
+ );
39
+ }, [checkoutLoyaltyData]);
40
+
41
+ const selectableAccounts = useMemo(() => {
42
+ return loyaltyAccounts.filter((account) => parseFloat(account.balance) > 0);
43
+ }, [loyaltyAccounts]);
44
+
45
+ // Determine which mode to use:
46
+ // - "accounts" mode: backend returns page_context.accounts (new)
47
+ // - "legacy" mode: Redux loyaltyBalance/loyaltyBalances from page_context.balance/balances (old)
48
+ const hasAccounts = selectableAccounts.length > 0;
49
+ const hasLegacyGrouped = !hasAccounts && loyaltyBalances?.length > 0;
50
+ const hasLegacySingle =
51
+ !hasAccounts && !hasLegacyGrouped && parseFloat(loyaltyBalance || '0') > 0;
52
+
30
53
  const isLoyaltyBalanceUsed = useMemo(() => {
31
54
  return parseFloat(preOrder?.loyalty_money ?? '0') > 0;
32
55
  }, [preOrder?.loyalty_money]);
33
56
 
57
+ // --- Accounts mode state ---
58
+ const [selectedAccountIds, setSelectedAccountIds] = useState<Set<string>>(
59
+ new Set()
60
+ );
61
+
62
+ useEffect(() => {
63
+ if (!hasAccounts) return;
64
+ const usages = preOrder?.loyalty_account_usages;
65
+ if (usages && Array.isArray(usages)) {
66
+ setSelectedAccountIds(
67
+ new Set(
68
+ usages
69
+ .filter((u) => parseFloat(String(u.amount)) > 0)
70
+ .map((u) => String(u.label_id))
71
+ )
72
+ );
73
+ } else if (
74
+ parseFloat(preOrder?.loyalty_money ?? '0') > 0 &&
75
+ selectableAccounts.length > 0
76
+ ) {
77
+ setSelectedAccountIds(
78
+ new Set(selectableAccounts.map((a) => String(a.label_id)))
79
+ );
80
+ } else {
81
+ setSelectedAccountIds(new Set());
82
+ }
83
+ }, [
84
+ hasAccounts,
85
+ preOrder?.loyalty_account_usages,
86
+ preOrder?.loyalty_money,
87
+ selectableAccounts
88
+ ]);
89
+
90
+ // --- Legacy grouped mode state ---
91
+ const [selectedLabels, setSelectedLabels] = useState<Record<string, boolean>>(
92
+ {}
93
+ );
94
+
34
95
  const [isLoading, setIsLoading] = useState(false);
35
96
 
36
- const handleClick = async () => {
97
+ const totalGroupedBalance = useMemo(() => {
98
+ if (!loyaltyBalances) return 0;
99
+ return loyaltyBalances.reduce(
100
+ (sum, item) => sum + parseFloat(item.balance || '0'),
101
+ 0
102
+ );
103
+ }, [loyaltyBalances]);
104
+
105
+ // --- Handlers ---
106
+ const handleToggleAccount = async (account: LoyaltyBalanceItem) => {
107
+ if (isLoading) return;
108
+ setIsLoading(true);
109
+
110
+ try {
111
+ const key = String(account.label_id);
112
+ const newSelected = new Set(selectedAccountIds);
113
+
114
+ if (newSelected.has(key)) {
115
+ newSelected.delete(key);
116
+ } else {
117
+ newSelected.add(key);
118
+ }
119
+
120
+ setSelectedAccountIds(newSelected);
121
+
122
+ const accountUsages: AccountUsage[] = selectableAccounts
123
+ .filter((acc) => newSelected.has(String(acc.label_id)))
124
+ .map((acc) => ({
125
+ label_id: acc.label_id,
126
+ amount: parseFloat(acc.balance)
127
+ }));
128
+
129
+ await payWithLoyaltyBalance({ account_usages: accountUsages });
130
+ } finally {
131
+ setIsLoading(false);
132
+ }
133
+ };
134
+
135
+ const handleToggleLegacyAll = async () => {
136
+ if (isLoading) return;
137
+ setIsLoading(true);
138
+
139
+ try {
140
+ if (isLoyaltyBalanceUsed) {
141
+ if (hasLegacyGrouped) {
142
+ const accountUsages: AccountUsage[] = loyaltyBalances.map((item) => ({
143
+ label_id: item.label_id,
144
+ amount: 0
145
+ }));
146
+ await payWithLoyaltyBalance({ account_usages: accountUsages });
147
+ setSelectedLabels({});
148
+ } else {
149
+ await payWithLoyaltyBalance('0');
150
+ }
151
+ } else {
152
+ if (hasLegacyGrouped) {
153
+ const accountUsages: AccountUsage[] = loyaltyBalances.map((item) => ({
154
+ label_id: item.label_id,
155
+ amount: parseFloat(item.balance)
156
+ }));
157
+ await payWithLoyaltyBalance({ account_usages: accountUsages });
158
+ const allSelected = loyaltyBalances.reduce(
159
+ (acc, item) => ({ ...acc, [String(item.label_id)]: true }),
160
+ {} as Record<string, boolean>
161
+ );
162
+ setSelectedLabels(allSelected);
163
+ } else {
164
+ await payWithLoyaltyBalance(loyaltyBalance);
165
+ }
166
+ }
167
+ } finally {
168
+ setIsLoading(false);
169
+ }
170
+ };
171
+
172
+ const handleToggleLegacyLabel = async (item: LoyaltyBalanceItem) => {
37
173
  if (isLoading) return;
38
174
  setIsLoading(true);
39
175
 
40
176
  try {
41
- await payWithLoyaltyBalance(isLoyaltyBalanceUsed ? '0' : loyaltyBalance);
177
+ const key = String(item.label_id);
178
+ const isCurrentlySelected = selectedLabels[key] ?? false;
179
+ const newSelectedLabels = {
180
+ ...selectedLabels,
181
+ [key]: !isCurrentlySelected
182
+ };
183
+
184
+ const accountUsages: AccountUsage[] = loyaltyBalances.map((b) => ({
185
+ label_id: b.label_id,
186
+ amount: newSelectedLabels[String(b.label_id)]
187
+ ? parseFloat(b.balance)
188
+ : 0
189
+ }));
190
+
191
+ await payWithLoyaltyBalance({ account_usages: accountUsages });
192
+ setSelectedLabels(newSelectedLabels);
42
193
  } finally {
43
194
  setIsLoading(false);
44
195
  }
45
196
  };
46
197
 
198
+ // --- Early returns ---
47
199
  if (preOrder?.is_guest) {
48
200
  return null;
49
201
  }
@@ -56,19 +208,207 @@ export const StoreCredits = () => {
56
208
  );
57
209
  }
58
210
 
59
- if (parseFloat(loyaltyBalance) <= 0) {
211
+ if (!hasAccounts && !hasLegacyGrouped && !hasLegacySingle) {
60
212
  return null;
61
213
  }
214
+
215
+ // --- Accounts mode render (new: from page_context.accounts) ---
216
+ if (hasAccounts) {
217
+ return (
218
+ <div
219
+ className={twMerge(
220
+ 'flex flex-col w-full mb-4 border border-solid border-gray-400 px-0 md:p-4',
221
+ isPayLoading && 'pointer-events-none opacity-30'
222
+ )}
223
+ >
224
+ {selectableAccounts.map((account) => {
225
+ const isSelected = selectedAccountIds.has(String(account.label_id));
226
+
227
+ return (
228
+ <div
229
+ key={String(account.label_id) ?? 'default'}
230
+ className="mb-3 flex w-full items-center"
231
+ >
232
+ <button onClick={() => handleToggleAccount(account)}>
233
+ <span
234
+ className={clsx(
235
+ 'flex h-5 w-5 items-center justify-center rounded border border-solid border-primary',
236
+ isSelected ? 'bg-primary' : 'bg-white'
237
+ )}
238
+ >
239
+ <Icon
240
+ name={isSelected ? 'check' : ''}
241
+ size={10}
242
+ className={clsx({ 'text-white': isSelected })}
243
+ />
244
+ </span>
245
+ </button>
246
+
247
+ <div className="w-full pl-4 rtl:pr-4">
248
+ <p
249
+ className="cursor-pointer text-sm"
250
+ onClick={() => handleToggleAccount(account)}
251
+ >
252
+ {account.label ??
253
+ t('checkout.payment.store_credit.use_my_store_credits')}
254
+ </p>
255
+ <p className="flex text-sm text-[#606060]">
256
+ {t('checkout.payment.store_credit.available_balance')}:
257
+ <Price
258
+ value={account.balance}
259
+ currencyCode={
260
+ account.currency?.toUpperCase() ||
261
+ preOrder?.currency_type_label
262
+ }
263
+ className="pe-1 font-bold"
264
+ />
265
+ </p>
266
+ </div>
267
+ </div>
268
+ );
269
+ })}
270
+
271
+ {isLoyaltyBalanceUsed && parseFloat(preOrder?.unpaid_amount) > 0 && (
272
+ <p className="my-4 text-[15px] font-light italic text-[#707070] max-xs:text-xs">
273
+ <Trans
274
+ i18nKey="checkout.payment.store_credit.insufficient_balance"
275
+ components={{
276
+ Amount: (
277
+ <div className="inline-flex">
278
+ <Price
279
+ value={preOrder?.unpaid_amount}
280
+ currencyCode={preOrder?.currency_type_label}
281
+ className="text-primary"
282
+ />
283
+ </div>
284
+ )
285
+ }}
286
+ />
287
+ </p>
288
+ )}
289
+ </div>
290
+ );
291
+ }
292
+
293
+ // --- Legacy grouped mode render (from Redux loyaltyBalances) ---
294
+ if (hasLegacyGrouped) {
295
+ return (
296
+ <div
297
+ className={twMerge(
298
+ 'flex flex-col w-full mb-4 border border-solid border-gray-400 px-0 md:p-4',
299
+ isPayLoading && 'pointer-events-none opacity-30'
300
+ )}
301
+ >
302
+ <div className="flex w-full items-center mb-3">
303
+ <button onClick={handleToggleLegacyAll}>
304
+ <span
305
+ className={clsx(
306
+ 'flex h-5 w-5 items-center justify-center rounded border border-solid border-primary',
307
+ isLoyaltyBalanceUsed ? 'bg-primary' : 'bg-white'
308
+ )}
309
+ >
310
+ <Icon
311
+ name={isLoyaltyBalanceUsed ? 'check' : ''}
312
+ size={10}
313
+ className={clsx({ 'text-white': isLoyaltyBalanceUsed })}
314
+ />
315
+ </span>
316
+ </button>
317
+
318
+ <div className="w-full pl-4">
319
+ <p
320
+ className="cursor-pointer text-sm"
321
+ onClick={handleToggleLegacyAll}
322
+ >
323
+ {t('checkout.payment.store_credit.use_my_store_credits')}
324
+ </p>
325
+ <p className="flex text-sm text-[#606060]">
326
+ {t('checkout.payment.store_credit.total_balance')}:
327
+ <Price
328
+ value={String(totalGroupedBalance)}
329
+ currencyCode={preOrder?.currency_type_label}
330
+ className="pe-1 font-bold"
331
+ />
332
+ </p>
333
+ </div>
334
+ </div>
335
+
336
+ <div className="ml-9 flex flex-col gap-2">
337
+ {loyaltyBalances.map((item) => {
338
+ const isSelected = selectedLabels[String(item.label_id)] ?? false;
339
+ return (
340
+ <div
341
+ key={String(item.label_id)}
342
+ className="flex items-center border border-solid border-gray-200 rounded p-2"
343
+ >
344
+ <button onClick={() => handleToggleLegacyLabel(item)}>
345
+ <span
346
+ className={clsx(
347
+ 'flex h-4 w-4 items-center justify-center rounded border border-solid border-primary',
348
+ isSelected ? 'bg-primary' : 'bg-white'
349
+ )}
350
+ >
351
+ <Icon
352
+ name={isSelected ? 'check' : ''}
353
+ size={8}
354
+ className={clsx({ 'text-white': isSelected })}
355
+ />
356
+ </span>
357
+ </button>
358
+ <div className="flex w-full items-center justify-between pl-3">
359
+ <span
360
+ className="cursor-pointer text-sm"
361
+ onClick={() => handleToggleLegacyLabel(item)}
362
+ >
363
+ {item.label ??
364
+ t('checkout.payment.store_credit.use_my_store_credits')}
365
+ </span>
366
+ <Price
367
+ value={item.balance}
368
+ currencyCode={
369
+ item.currency?.toUpperCase() ||
370
+ preOrder?.currency_type_label
371
+ }
372
+ className="text-sm font-bold"
373
+ />
374
+ </div>
375
+ </div>
376
+ );
377
+ })}
378
+ </div>
379
+
380
+ {isLoyaltyBalanceUsed && parseFloat(preOrder?.unpaid_amount) > 0 && (
381
+ <p className="my-4 text-[15px] font-light italic text-[#707070] max-xs:text-xs">
382
+ <Trans
383
+ i18nKey="checkout.payment.store_credit.insufficient_balance"
384
+ components={{
385
+ Amount: (
386
+ <div className="inline-flex">
387
+ <Price
388
+ value={preOrder?.unpaid_amount}
389
+ currencyCode={preOrder?.currency_type_label}
390
+ className="text-primary"
391
+ />
392
+ </div>
393
+ )
394
+ }}
395
+ />
396
+ </p>
397
+ )}
398
+ </div>
399
+ );
400
+ }
401
+
402
+ // --- Legacy single balance mode render (from Redux loyaltyBalance) ---
62
403
  return (
63
404
  <div
64
405
  className={twMerge(
65
- 'hidden flex-col w-full mb-4 border border-solid border-gray-400 px-0 md:p-4',
66
- isPayWithLoyaltyBalanceLoading && 'pointer-events-none opacity-30',
67
- parseFloat(loyaltyBalance) > 0 && 'block'
406
+ 'flex flex-col w-full mb-4 border border-solid border-gray-400 px-0 md:p-4',
407
+ isPayLoading && 'pointer-events-none opacity-30'
68
408
  )}
69
409
  >
70
410
  <div className="flex w-full items-center">
71
- <button onClick={handleClick}>
411
+ <button onClick={handleToggleLegacyAll}>
72
412
  <span
73
413
  className={clsx(
74
414
  'flex h-5 w-5 items-center justify-center rounded border border-solid border-primary',
@@ -84,7 +424,10 @@ export const StoreCredits = () => {
84
424
  </button>
85
425
 
86
426
  <div className="w-full pl-4">
87
- <p className="cursor-pointer text-sm" onClick={handleClick}>
427
+ <p
428
+ className="cursor-pointer text-sm"
429
+ onClick={handleToggleLegacyAll}
430
+ >
88
431
  {t('checkout.payment.store_credit.use_my_store_credits')}
89
432
  </p>
90
433
  <p className="flex text-sm text-[#606060]">
@@ -85,7 +85,7 @@ const AddressBox = ({
85
85
  };
86
86
 
87
87
  const onSubmit = (data) => {
88
- editAddress({ ...data, invalidateTag: 'Addresses' })
88
+ editAddress({ ...data, invalidateTag: 'Checkout' })
89
89
  .unwrap()
90
90
  .then((editAddressResponse) => {
91
91
  handleAddressClick(addressType, editAddressResponse);
@@ -96,7 +96,7 @@ const AddressBox = ({
96
96
  };
97
97
 
98
98
  const handleRemoveAddress = async (addressPk: number) => {
99
- await removeAddress({ id: addressPk, invalidateTag: 'Addresses' });
99
+ await removeAddress({ id: addressPk, invalidateTag: 'Checkout' });
100
100
  setRemoveAddressModalOpen(false);
101
101
  dispatch(resetCheckoutState());
102
102
 
@@ -168,7 +168,10 @@ const AddressBox = ({
168
168
  <Button
169
169
  appearance="ghost"
170
170
  className="italic underline hover:text-secondary-500 hover:!bg-white hover:!border-white p-0 h-auto"
171
- onClick={() => setIsEditAddressModalOpen(true)}
171
+ onClick={(e) => {
172
+ e.stopPropagation();
173
+ setIsEditAddressModalOpen(true);
174
+ }}
172
175
  data-testid="checkout-address-edit"
173
176
  >
174
177
  {t('checkout.address.box.edit')}
@@ -180,21 +183,26 @@ const AddressBox = ({
180
183
  setOpen={setIsEditAddressModalOpen}
181
184
  className="w-full sm:w-[28rem] max-h-[90vh] overflow-y-auto"
182
185
  >
183
- <AddressForm
184
- data={{
185
- ...address,
186
- country: address.country?.pk,
187
- city: address.city?.pk,
188
- township: address.township?.pk,
189
- district: address.district?.pk
190
- }}
191
- onSubmit={onSubmit}
192
- />
186
+ <div onClick={(e) => e.stopPropagation()}>
187
+ <AddressForm
188
+ data={{
189
+ ...address,
190
+ country: address.country?.pk,
191
+ city: address.city?.pk,
192
+ township: address.township?.pk,
193
+ district: address.district?.pk
194
+ }}
195
+ onSubmit={onSubmit}
196
+ />
197
+ </div>
193
198
  </Modal>
194
199
  <Button
195
200
  appearance="ghost"
196
201
  className="italic underline hover:text-secondary-500 hover:!bg-white hover:!border-white p-0 h-auto"
197
- onClick={() => setRemoveAddressModalOpen(true)}
202
+ onClick={(e) => {
203
+ e.stopPropagation();
204
+ setRemoveAddressModalOpen(true);
205
+ }}
198
206
  data-testid="checkout-address-remove"
199
207
  >
200
208
  {t('checkout.address.box.remove')}
@@ -207,14 +215,18 @@ const AddressBox = ({
207
215
  setOpen={setRemoveAddressModalOpen}
208
216
  showCloseButton={false}
209
217
  >
210
- <div className="text-center px-6 py-10">
218
+ <div
219
+ className="text-center px-6 py-10"
220
+ onClick={(e) => e.stopPropagation()}
221
+ >
211
222
  <p className="mb-4">
212
223
  {t('account.address_book.modal.delete_description')}
213
224
  </p>
214
225
  <div className="space-x-3 flex justify-center">
215
226
  <Button
216
227
  appearance="outlined"
217
- onClick={() => {
228
+ onClick={(e) => {
229
+ e.stopPropagation();
218
230
  setRemoveAddressModalOpen(false);
219
231
  }}
220
232
  data-testid="remove-address-modal-cancel"
@@ -224,7 +236,8 @@ const AddressBox = ({
224
236
  <Button
225
237
  appearance="filled"
226
238
  disabled={removeAddressLoading}
227
- onClick={() => {
239
+ onClick={(e) => {
240
+ e.stopPropagation();
228
241
  handleRemoveAddress(address.pk);
229
242
  }}
230
243
  className={
@@ -77,7 +77,7 @@ const Addresses = () => {
77
77
  }, [billing_and_shipping_same]);
78
78
 
79
79
  const onSubmit = (data) => {
80
- addAddress({ ...data, invalidateTag: 'Addresses' })
80
+ addAddress({ ...data, invalidateTag: 'Checkout' })
81
81
  .unwrap()
82
82
  .then((addAddressResponse) => {
83
83
  if (addressList.length === 0) {
@@ -29,7 +29,14 @@ async function checkVersion(pkg: PackageJson) {
29
29
 
30
30
  if (!semver.satisfies(pkg.dependencies['@akinon/next'], latestVersion)) {
31
31
  console.warn(
32
- `\x1b[43mWarning: The "${packageName}" package is currently at version ${pkg.dependencies['@akinon/next']}. Please upgrade it to the latest version (${latestVersion}) to ensure plugin compatibility.`,
32
+ `\x1b[43m Warning: The "${packageName}" package is currently at`,
33
+ `\x1b[41m version ${pkg.dependencies['@akinon/next']}`,
34
+ `\x1b[43m Please upgrade it to the latest version (${latestVersion}) to ensure plugin compatibility.`,
35
+ '\x1b[0m\n'
36
+ );
37
+ } else {
38
+ console.log(
39
+ `\x1b[42m Info: The package "${packageName}" is currently in the current version (${latestVersion}).`,
33
40
  '\x1b[0m\n'
34
41
  );
35
42
  }
@@ -54,7 +61,27 @@ export default async () => {
54
61
  }
55
62
  }
56
63
 
57
- const pkg: PackageJson = require(path.resolve(rootDir, './package.json'));
64
+ function findPackageJson(): PackageJson {
65
+ const packageJsonPaths = [
66
+ path.resolve(rootDir, './package.json'),
67
+ path.resolve(rootDir, './apps/projectzeronext/package.json')
68
+ ];
69
+
70
+ for (const packageJsonPath of packageJsonPaths) {
71
+ try {
72
+ const pkg = require(packageJsonPath);
73
+ if (pkg.dependencies['@akinon/next']) {
74
+ return pkg;
75
+ }
76
+ } catch (error) {
77
+ continue;
78
+ }
79
+ }
80
+
81
+ throw new Error('Could not find package.json with @akinon/next dependency');
82
+ }
83
+
84
+ const pkg = findPackageJson();
58
85
  await checkVersion(pkg);
59
86
 
60
87
  const pluginsFilePath = findPluginsFilePath();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/projectzero",
3
- "version": "2.0.0-beta.16",
3
+ "version": "2.0.0-beta.17",
4
4
  "private": false,
5
5
  "description": "CLI tool to manage your Project Zero Next project",
6
6
  "bin": {