@akinon/pz-virtual-try-on 2.0.0-beta.15 → 2.0.0-beta.16

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,20 @@
1
1
  # @akinon/pz-virtual-try-on
2
2
 
3
+ ## 2.0.0-beta.16
4
+
5
+ ### Minor Changes
6
+
7
+ - 187208d2: ZERO-3913 :Implement closeCrop functionality and enhance modal behavior in virtual try-on feature
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [823d82f9]
12
+ - Updated dependencies [d2c0e759]
13
+ - Updated dependencies [68bbcb27]
14
+ - Updated dependencies [9b7d0de6]
15
+ - Updated dependencies [5ec0faf8]
16
+ - @akinon/next@2.0.0-beta.16
17
+
3
18
  ## 2.0.0-beta.15
4
19
 
5
20
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akinon/pz-virtual-try-on",
3
- "version": "2.0.0-beta.15",
3
+ "version": "2.0.0-beta.16",
4
4
  "license": "MIT",
5
5
  "main": "src/index.ts",
6
6
  "peerDependencies": {
@@ -8,7 +8,7 @@
8
8
  "react-dom": "^18.0.0 || ^19.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@akinon/next": "2.0.0-beta.15",
11
+ "@akinon/next": "2.0.0-beta.16",
12
12
  "clsx": "^2.0.0",
13
13
  "tailwind-merge": "^2.0.0",
14
14
  "react-image-crop": "^11.0.5"
@@ -156,10 +156,28 @@ export function useImageCropper(
156
156
  });
157
157
  };
158
158
 
159
+ const closeCrop = () => {
160
+ if (debounceTimeoutRef.current) {
161
+ clearTimeout(debounceTimeoutRef.current);
162
+ }
163
+
164
+ setIsCropping(false);
165
+ setCompletedCrop(null);
166
+ setCrop(undefined as any);
167
+ };
168
+
159
169
  const confirmCrop = useCallback(async () => {
160
170
  if (completedCrop) {
161
171
  await processManualCrop(completedCrop);
162
172
  setIsCropping(false);
173
+ setCompletedCrop(null);
174
+ setCrop({
175
+ unit: '%',
176
+ x: 25,
177
+ y: 25,
178
+ width: 50,
179
+ height: 50
180
+ });
163
181
  }
164
182
  }, [completedCrop, processManualCrop]);
165
183
 
@@ -175,6 +193,7 @@ export function useImageCropper(
175
193
  processCompletedCrop,
176
194
  processManualCrop,
177
195
  confirmCrop,
178
- resetCrop
196
+ resetCrop,
197
+ closeCrop
179
198
  };
180
199
  }
@@ -353,6 +353,7 @@ export function useVirtualTryOn(product: Product) {
353
353
  data.error || data.result?.error || 'Processing failed';
354
354
  setError(errorMsg);
355
355
  setCurrentStep('processing');
356
+ cropperHook.closeCrop();
356
357
  return;
357
358
  }
358
359
  } catch (pollError: any) {
@@ -370,6 +371,7 @@ export function useVirtualTryOn(product: Product) {
370
371
  error?.message === 'Request aborted'
371
372
  ) {
372
373
  setCurrentStep('upload');
374
+ cropperHook.closeCrop();
373
375
  return;
374
376
  }
375
377
 
@@ -378,11 +380,23 @@ export function useVirtualTryOn(product: Product) {
378
380
  error?.message ||
379
381
  'Virtual try-on processing failed'
380
382
  );
381
- setCurrentStep('upload');
383
+ setError(
384
+ error?.data?.message ||
385
+ error?.message ||
386
+ 'Virtual try-on processing failed'
387
+ );
388
+ setCurrentStep('processing');
389
+ cropperHook.closeCrop();
382
390
  } finally {
383
391
  setAbortController(null);
384
392
  }
385
- }, [uploadedImage, product, processVirtualTryOn, abortController]);
393
+ }, [
394
+ uploadedImage,
395
+ product,
396
+ processVirtualTryOn,
397
+ abortController,
398
+ cropperHook
399
+ ]);
386
400
 
387
401
  const acceptLegalConsent = useCallback(() => {
388
402
  setLegalConsentAccepted();
@@ -1,6 +1,6 @@
1
1
  'use client';
2
2
 
3
- import React, { useState, useMemo } from 'react';
3
+ import React, { useState, useMemo, useEffect } from 'react';
4
4
  import { Product } from '@akinon/next/types';
5
5
  import { twMerge } from 'tailwind-merge';
6
6
  import { VirtualTryOnModal } from './virtual-try-on-modal';
@@ -30,6 +30,18 @@ export function VirtualTryOnPlugin({
30
30
  const [isModalLoading, setIsModalLoading] = useState(false);
31
31
  const { isEnabled } = useVirtualTryOn(product);
32
32
 
33
+ useEffect(() => {
34
+ return () => {
35
+ document.documentElement.style.overflow = '';
36
+ };
37
+ }, []);
38
+
39
+ useEffect(() => {
40
+ if (!isModalOpen && !isModalLoading) {
41
+ document.documentElement.style.overflow = '';
42
+ }
43
+ }, [isModalOpen, isModalLoading]);
44
+
33
45
  const cssVariables = useMemo(() => {
34
46
  if (!settings?.cssVariables && !settings?.theme) return {};
35
47
 
@@ -98,10 +110,12 @@ export function VirtualTryOnPlugin({
98
110
  setTimeout(() => {
99
111
  setIsModalLoading(false);
100
112
  setIsModalOpen(true);
113
+ document.documentElement.style.overflow = 'hidden';
101
114
  }, 500);
102
115
  };
103
116
 
104
117
  const handleCloseModal = () => {
118
+ document.documentElement.style.overflow = '';
105
119
  setIsModalOpen(false);
106
120
  setIsModalLoading(false);
107
121
  };
@@ -151,12 +151,19 @@ export function VirtualTryOnUploadModal({
151
151
  imageRef,
152
152
  handleCropComplete = () => {},
153
153
  toggleCropMode = () => {},
154
- confirmCrop = () => {}
154
+ confirmCrop = () => {},
155
+ closeCrop = () => {}
155
156
  } = cropperHook || {};
156
157
 
157
158
  const [shouldProcessAfterCrop, setShouldProcessAfterCrop] = useState(false);
158
159
  const [isDragging, setIsDragging] = useState(false);
159
160
 
161
+ useEffect(() => {
162
+ if (error && closeCrop) {
163
+ closeCrop();
164
+ }
165
+ }, [error, closeCrop]);
166
+
160
167
  useEffect(() => {
161
168
  if (shouldProcessAfterCrop && uploadedImage && !isCropLoading) {
162
169
  setShouldProcessAfterCrop(false);
@@ -1011,14 +1018,17 @@ export function VirtualTryOnUploadModal({
1011
1018
  minWidth={100}
1012
1019
  minHeight={100}
1013
1020
  keepSelection={true}
1014
- className="w-full"
1021
+ className={twMerge(
1022
+ 'w-full',
1023
+ error && 'pointer-events-none'
1024
+ )}
1015
1025
  >
1016
1026
  <img
1017
1027
  ref={imageRef}
1018
1028
  src={uploadedImage || ''}
1019
1029
  alt="Uploaded image"
1020
1030
  className={twMerge(
1021
- 'rounded-[4px] w-auto',
1031
+ 'rounded-[4px] w-auto pointer-events-none select-none',
1022
1032
  settings?.customStyles?.cropImage
1023
1033
  )}
1024
1034
  />
@@ -1166,6 +1176,8 @@ export function VirtualTryOnUploadModal({
1166
1176
  completedCrop.height > 10
1167
1177
  ) {
1168
1178
  await confirmCrop();
1179
+ // Reset crop selection after confirm
1180
+ setCrop(undefined);
1169
1181
  setShouldProcessAfterCrop(true);
1170
1182
  } else {
1171
1183
  processTryOn();