@primestyleai/tryon 2.0.3 → 2.0.4

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.
@@ -182,6 +182,8 @@ function PrimeStyleTryon({
182
182
  const [sizingMethod, setSizingMethod] = useState(null);
183
183
  const [sizingResult, setSizingResult] = useState(null);
184
184
  const [sizeGuide, setSizeGuide] = useState(null);
185
+ const [sizeGuideFetching, setSizeGuideFetching] = useState(false);
186
+ const sizeGuideFetchedRef = useRef(false);
185
187
  const [sizingCountry, setSizingCountry] = useState(detectLocale);
186
188
  const imperial = isImperial(sizingCountry);
187
189
  const [sizingUnit, setSizingUnit] = useState(imperial ? "in" : "cm");
@@ -257,6 +259,21 @@ function PrimeStyleTryon({
257
259
  useEffect(() => {
258
260
  lsSet("history", history);
259
261
  }, [history]);
262
+ useEffect(() => {
263
+ if (view !== "sizing-choice" || sizeGuideFetchedRef.current || !apiRef.current) return;
264
+ sizeGuideFetchedRef.current = true;
265
+ setSizeGuideFetching(true);
266
+ const baseUrl = getApiUrl(apiUrl);
267
+ const key = getApiKey();
268
+ fetch(`${baseUrl}/api/v1/sizing/sizeguide`, {
269
+ method: "POST",
270
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${key}` },
271
+ body: JSON.stringify({ product: { title: productTitle, variants: [] } })
272
+ }).then((r) => r.ok ? r.json() : null).then((data) => {
273
+ if (data) setSizeGuide(data);
274
+ else setSizeGuide({ found: false });
275
+ }).catch(() => setSizeGuide({ found: false })).finally(() => setSizeGuideFetching(false));
276
+ }, [view, apiUrl, productTitle]);
260
277
  const stepIndex = useMemo(() => {
261
278
  switch (view) {
262
279
  case "welcome":
@@ -293,6 +310,8 @@ function PrimeStyleTryon({
293
310
  setProfileSaved(false);
294
311
  formRef.current = {};
295
312
  setFormGender("male");
313
+ sizeGuideFetchedRef.current = false;
314
+ setSizeGuideFetching(false);
296
315
  unsubRef.current?.();
297
316
  unsubRef.current = null;
298
317
  if (pollingRef.current) {
@@ -719,10 +738,15 @@ function PrimeStyleTryon({
719
738
  ] });
720
739
  }
721
740
  function SizingChoiceView() {
741
+ const sgAvailable = sizeGuide?.found === true;
742
+ const sgDisabled = !sizeGuideFetching && !sgAvailable;
743
+ const disabledClass = sgDisabled ? " ps-tryon-choice-disabled" : sizeGuideFetching ? " ps-tryon-choice-loading" : "";
722
744
  return /* @__PURE__ */ jsxs("div", { className: "ps-tryon-sizing-choice", children: [
723
745
  /* @__PURE__ */ jsx("h3", { className: "ps-tryon-section-title", children: "How would you like to find your size?" }),
746
+ sgDisabled && /* @__PURE__ */ jsx("div", { className: "ps-tryon-sg-notice", children: "Size guide is not available for this product" }),
747
+ sizeGuideFetching && /* @__PURE__ */ jsx("div", { className: "ps-tryon-sg-notice ps-tryon-sg-loading", children: "Checking size guide availability..." }),
724
748
  /* @__PURE__ */ jsxs("div", { className: "ps-tryon-choice-cards", children: [
725
- /* @__PURE__ */ jsxs("button", { className: "ps-tryon-choice-card", onClick: () => {
749
+ /* @__PURE__ */ jsxs("button", { className: `ps-tryon-choice-card${disabledClass}`, disabled: sgDisabled || sizeGuideFetching, onClick: () => {
726
750
  setSizingMethod("exact");
727
751
  setView("sizing-form");
728
752
  }, children: [
@@ -733,7 +757,7 @@ function PrimeStyleTryon({
733
757
  ] }),
734
758
  /* @__PURE__ */ jsx("span", { className: "ps-tryon-choice-badge", children: "Best accuracy" })
735
759
  ] }),
736
- /* @__PURE__ */ jsxs("button", { className: "ps-tryon-choice-card", onClick: () => {
760
+ /* @__PURE__ */ jsxs("button", { className: `ps-tryon-choice-card${disabledClass}`, disabled: sgDisabled || sizeGuideFetching, onClick: () => {
737
761
  setSizingMethod("quick");
738
762
  setView("sizing-form");
739
763
  }, children: [
@@ -1228,6 +1252,15 @@ const STYLES = `
1228
1252
  padding: 3px 10px; border-radius: 20px; flex-shrink: 0;
1229
1253
  background: rgba(187,148,92,0.12); color: #bb945c; font-size: 10px; font-weight: 600;
1230
1254
  }
1255
+ .ps-tryon-choice-disabled { opacity: 0.4; cursor: not-allowed !important; pointer-events: none; }
1256
+ .ps-tryon-choice-disabled:hover { border-color: #333; transform: none; box-shadow: none; }
1257
+ .ps-tryon-choice-disabled::before { display: none; }
1258
+ .ps-tryon-choice-loading { opacity: 0.5; cursor: wait !important; pointer-events: none; }
1259
+ .ps-tryon-sg-notice {
1260
+ font-size: 12px; color: #999; text-align: center; padding: 10px 14px;
1261
+ margin-bottom: 12px; border: 1px solid #333; border-radius: 10px; background: #1a1b1a;
1262
+ }
1263
+ .ps-tryon-sg-loading { border-style: dashed; }
1231
1264
 
1232
1265
  /* Sizing form */
1233
1266
  .ps-tryon-sizing-form { display: flex; flex-direction: column; gap: 12px; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primestyleai/tryon",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "PrimeStyle Virtual Try-On SDK — React component & Web Component",
5
5
  "type": "module",
6
6
  "main": "dist/primestyle-tryon.js",