@bikdotai/bik-component-library 0.0.725-beta.3 → 0.0.725-beta.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.
- package/dist/cjs/components/bik-layout/MockMenus.d.ts +1 -0
- package/dist/cjs/components/feature-announcements/hooks/useFeatureAnnouncements.js +1 -1
- package/dist/esm/components/bik-layout/MockMenus.d.ts +1 -0
- package/dist/esm/components/feature-announcements/hooks/useFeatureAnnouncements.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react"),r=require("../constants/animations.js"),a=require("../constants/localStorageKeys.js");exports.useFeatureAnnouncements=o=>{let{fetchVisibleFeatures:n,getStoreFeatureProgress:i,fetchFeatureById:l,markFeatureAsViewedForStore:s,isFeatureApplicableToCurrentPage:u,module:c,router:d}=o;var f;const p=(()=>{const[e,r]=t.useState(null);return t.useEffect((()=>{if("undefined"!=typeof window){let e=null;try{if(e=localStorage.getItem(a.LOCAL_STORAGE_KEYS.STORE_ID)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.BIK_STORE_ID)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.CURRENT_STORE)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.STORE),!e){const t=localStorage.getItem(a.LOCAL_STORAGE_KEYS.CURRENT_USER);t&&(e=JSON.parse(t).storeId)}e||(e=new URLSearchParams(window.location.search).get(a.LOCAL_STORAGE_KEYS.QUERY_PARAM))}catch(e){console.error("FeatureAnnouncements: Failed to get store ID",e)}r(e)}}),[]),e})(),[A,
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("react"),r=require("../constants/animations.js"),a=require("../constants/localStorageKeys.js");exports.useFeatureAnnouncements=o=>{let{fetchVisibleFeatures:n,getStoreFeatureProgress:i,fetchFeatureById:l,markFeatureAsViewedForStore:s,isFeatureApplicableToCurrentPage:u,module:c,router:d}=o;var f;const p=(()=>{const[e,r]=t.useState(null);return t.useEffect((()=>{if("undefined"!=typeof window){let e=null;try{if(e=localStorage.getItem(a.LOCAL_STORAGE_KEYS.STORE_ID)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.BIK_STORE_ID)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.CURRENT_STORE)||localStorage.getItem(a.LOCAL_STORAGE_KEYS.STORE),!e){const t=localStorage.getItem(a.LOCAL_STORAGE_KEYS.CURRENT_USER);t&&(e=JSON.parse(t).storeId)}e||(e=new URLSearchParams(window.location.search).get(a.LOCAL_STORAGE_KEYS.QUERY_PARAM))}catch(e){console.error("FeatureAnnouncements: Failed to get store ID",e)}r(e)}}),[]),e})(),[A,g]=t.useState([]),[S,_]=t.useState([]),[E,v]=t.useState([]),[y,R]=t.useState(!1),[m,w]=t.useState(null),U=t.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){if(p){R(!0),w(null);try{const[e,t]=yield n(c);if(e||!t)return console.error("FeatureAnnouncements: Failed to fetch features",e),void w("Failed to fetch features");const[a,o]=yield i(p);a&&console.warn("FeatureAnnouncements: Progress fetch failed, treating all features as new",a);const l=new Date,s="undefined"!=typeof window?window.location.pathname:"",d=e=>{if(!e.expirationDate)return!0;let t;return"object"==typeof e.expirationDate&&null!==e.expirationDate&&("seconds"in e.expirationDate||"nanoseconds"in e.expirationDate)?t=new Date(1e3*e.expirationDate.seconds):"string"==typeof e.expirationDate?t=new Date(e.expirationDate):e.expirationDate instanceof Date&&(t=e.expirationDate),!(!t||isNaN(t.getTime()))&&l<t},f=e=>{if("Major"===e.featureUpdateType){let t=[];return Array.isArray(e.pageUrls)?t=e.pageUrls:"object"==typeof e.pageUrls&&null!==e.pageUrls&&"length"in e.pageUrls&&(t=Array.from(e.pageUrls)),t.some((e=>{if(e===s)return!0;const t=e.replace(/\[([^\]]+)\]/g,"[^/]+").replace(/\//g,"\\/");return new RegExp(`^${t}$`).test(s)}))}return!0},A=t.filter((e=>{var t;const r=(null===(t=null==o?void 0:o.viewedFeatures)||void 0===t?void 0:t[e.id])||!1,a=e.archived||!1,n=u(e),i=d(e),l=f(e),c=!r&&!a&&n&&i&&l;return"Major"===e.featureUpdateType&&console.log("🔍 [FILTER DEBUG] Major feature:",{featureId:e.id,title:e.title,pageUrls:e.pageUrls,currentRoute:s,isViewed:r,isArchived:a,isApplicable:n,notExpired:i,onCorrectPage:l,shouldShow:c}),c})),S=A.filter((e=>"Major"===e.featureUpdateType)),E=A.filter((e=>"Minor"===e.featureUpdateType));g(A),_(S),setTimeout((()=>{v(E)}),r.ANIMATION_TIMING.MINOR_POPUP_DELAY)}catch(e){console.error("FeatureAnnouncements: Unexpected error in fetchFeatures",e),w("An unexpected error occurred")}finally{R(!1)}}}))),[p,n,i,u,c]),F=t.useCallback((t=>e.__awaiter(void 0,void 0,void 0,(function*(){R(!0),w(null);try{const[e,r]=yield l(t);if(e||!r)return void w("Failed to fetch feature by ID");"Major"===r.featureUpdateType?_([r]):v([r]),g([r])}catch(e){w("An unexpected error occurred while fetching by ID")}finally{R(!1)}}))),[l]),T=t.useCallback((t=>e.__awaiter(void 0,void 0,void 0,(function*(){if(!p)return;const[e]=yield s(p,t);e?(console.warn("FeatureAnnouncements: Failed to mark feature as viewed, removing from local state anyway",e),g((e=>e.filter((e=>e.id!==t)))),_((e=>e.filter((e=>e.id!==t)))),v((e=>e.filter((e=>e.id!==t))))):(g((e=>e.filter((e=>e.id!==t)))),_((e=>e.filter((e=>e.id!==t)))),v((e=>e.filter((e=>e.id!==t)))))}))),[p,s]);return t.useEffect((()=>{var e;const t=null===(e=null==d?void 0:d.query)||void 0===e?void 0:e[a.QUERY_PARAMS.FEATURE_ID];t&&d?F(t):U()}),[null==d?void 0:d.pathname,null===(f=null==d?void 0:d.query)||void 0===f?void 0:f[a.QUERY_PARAMS.FEATURE_ID],p,U,F,d]),{features:A,majorUpdateFeatures:S,minorUpdateFeatures:E,isLoading:y,error:m,markFeatureAsViewed:T,refetch:U}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{useState as t,useCallback as r,useEffect as o}from"react";import{ANIMATION_TIMING as a}from"../constants/animations.js";import{QUERY_PARAMS as n,LOCAL_STORAGE_KEYS as i}from"../constants/localStorageKeys.js";const l=l=>{let{fetchVisibleFeatures:s,getStoreFeatureProgress:u,fetchFeatureById:
|
|
1
|
+
import{__awaiter as e}from"../../../_virtual/_tslib.js";import{useState as t,useCallback as r,useEffect as o}from"react";import{ANIMATION_TIMING as a}from"../constants/animations.js";import{QUERY_PARAMS as n,LOCAL_STORAGE_KEYS as i}from"../constants/localStorageKeys.js";const l=l=>{let{fetchVisibleFeatures:s,getStoreFeatureProgress:u,fetchFeatureById:c,markFeatureAsViewedForStore:d,isFeatureApplicableToCurrentPage:f,module:p,router:g}=l;var m;const v=(()=>{const[e,r]=t(null);return o((()=>{if("undefined"!=typeof window){let e=null;try{if(e=localStorage.getItem(i.STORE_ID)||localStorage.getItem(i.BIK_STORE_ID)||localStorage.getItem(i.CURRENT_STORE)||localStorage.getItem(i.STORE),!e){const t=localStorage.getItem(i.CURRENT_USER);t&&(e=JSON.parse(t).storeId)}e||(e=new URLSearchParams(window.location.search).get(i.QUERY_PARAM))}catch(e){console.error("FeatureAnnouncements: Failed to get store ID",e)}r(e)}}),[]),e})(),[y,U]=t([]),[w,F]=t([]),[D,h]=t([]),[A,I]=t(!1),[R,E]=t(null),T=r((()=>e(void 0,void 0,void 0,(function*(){if(v){I(!0),E(null);try{const[e,t]=yield s(p);if(e||!t)return console.error("FeatureAnnouncements: Failed to fetch features",e),void E("Failed to fetch features");const[r,o]=yield u(v);r&&console.warn("FeatureAnnouncements: Progress fetch failed, treating all features as new",r);const n=new Date,i="undefined"!=typeof window?window.location.pathname:"",l=e=>{if(!e.expirationDate)return!0;let t;return"object"==typeof e.expirationDate&&null!==e.expirationDate&&("seconds"in e.expirationDate||"nanoseconds"in e.expirationDate)?t=new Date(1e3*e.expirationDate.seconds):"string"==typeof e.expirationDate?t=new Date(e.expirationDate):e.expirationDate instanceof Date&&(t=e.expirationDate),!(!t||isNaN(t.getTime()))&&n<t},c=e=>{if("Major"===e.featureUpdateType){let t=[];return Array.isArray(e.pageUrls)?t=e.pageUrls:"object"==typeof e.pageUrls&&null!==e.pageUrls&&"length"in e.pageUrls&&(t=Array.from(e.pageUrls)),t.some((e=>{if(e===i)return!0;const t=e.replace(/\[([^\]]+)\]/g,"[^/]+").replace(/\//g,"\\/");return new RegExp(`^${t}$`).test(i)}))}return!0},d=t.filter((e=>{var t;const r=(null===(t=null==o?void 0:o.viewedFeatures)||void 0===t?void 0:t[e.id])||!1,a=e.archived||!1,n=f(e),s=l(e),u=c(e),d=!r&&!a&&n&&s&&u;return"Major"===e.featureUpdateType&&console.log("🔍 [FILTER DEBUG] Major feature:",{featureId:e.id,title:e.title,pageUrls:e.pageUrls,currentRoute:i,isViewed:r,isArchived:a,isApplicable:n,notExpired:s,onCorrectPage:u,shouldShow:d}),d})),g=d.filter((e=>"Major"===e.featureUpdateType)),m=d.filter((e=>"Minor"===e.featureUpdateType));U(d),F(g),setTimeout((()=>{h(m)}),a.MINOR_POPUP_DELAY)}catch(e){console.error("FeatureAnnouncements: Unexpected error in fetchFeatures",e),E("An unexpected error occurred")}finally{I(!1)}}}))),[v,s,u,f,p]),x=r((t=>e(void 0,void 0,void 0,(function*(){I(!0),E(null);try{const[e,r]=yield c(t);if(e||!r)return void E("Failed to fetch feature by ID");"Major"===r.featureUpdateType?F([r]):h([r]),U([r])}catch(e){E("An unexpected error occurred while fetching by ID")}finally{I(!1)}}))),[c]),S=r((t=>e(void 0,void 0,void 0,(function*(){if(!v)return;const[e]=yield d(v,t);e?(console.warn("FeatureAnnouncements: Failed to mark feature as viewed, removing from local state anyway",e),U((e=>e.filter((e=>e.id!==t)))),F((e=>e.filter((e=>e.id!==t)))),h((e=>e.filter((e=>e.id!==t))))):(U((e=>e.filter((e=>e.id!==t)))),F((e=>e.filter((e=>e.id!==t)))),h((e=>e.filter((e=>e.id!==t)))))}))),[v,d]);return o((()=>{var e;const t=null===(e=null==g?void 0:g.query)||void 0===e?void 0:e[n.FEATURE_ID];t&&g?x(t):T()}),[null==g?void 0:g.pathname,null===(m=null==g?void 0:g.query)||void 0===m?void 0:m[n.FEATURE_ID],v,T,x,g]),{features:y,majorUpdateFeatures:w,minorUpdateFeatures:D,isLoading:A,error:R,markFeatureAsViewed:S,refetch:T}};export{l as useFeatureAnnouncements};
|