varminer-app-header 2.1.7 → 2.1.9

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/index.js CHANGED
@@ -723,51 +723,68 @@ const AppHeader = ({ language: languageProp }) => {
723
723
  const [mobileMoreAnchorEl, setMobileMoreAnchorEl] = React.useState(null);
724
724
  const [user, setUser] = React.useState(() => {
725
725
  const allData = getAllDataFromStorage();
726
- // Try to get user data from various sources
727
726
  let userName = "";
728
727
  let userEmail = "";
729
728
  let userRole = "";
730
- // Priority 1: From decoded token
731
- if (allData.decodedToken) {
732
- userName = allData.decodedToken.sub || allData.decodedToken.email || "";
733
- userEmail = allData.decodedToken.sub || allData.decodedToken.email || "";
734
- userRole = allData.decodedToken.role || "";
735
- }
736
- // Priority 2: From auth data
737
- if (allData.auth) {
738
- userName = userName || allData.auth.name || allData.auth.email || "";
739
- userEmail = userEmail || allData.auth.email || allData.auth.sub || "";
740
- userRole = userRole || allData.auth.role || allData.auth.activeRole || "";
741
- }
742
- // Priority 3: From userDetails/user/profile
729
+ const buildNameFromFirstLast = (obj) => {
730
+ if (!obj || typeof obj !== "object")
731
+ return "";
732
+ const first = (obj.firstName ?? obj.given_name ?? obj.first_name);
733
+ const last = (obj.lastName ?? obj.family_name ?? obj.last_name);
734
+ return [first, last].filter(Boolean).join(" ").trim();
735
+ };
736
+ // Prefer getUserDataFromStorage first (IAM firstName+lastName or persist:userdb name)
743
737
  const storedUser = getUserDataFromStorage();
744
738
  if (storedUser) {
745
- userName = userName || storedUser.name || "";
739
+ userName = storedUser.name || "";
746
740
  userEmail = userEmail || storedUser.email || "";
747
741
  userRole = userRole || storedUser.role || "";
748
742
  }
749
- // Priority 4: From other parsed data
743
+ // Then enrich from decoded token (email from sub; name only if token has name/given_name/family_name, never use sub as name)
744
+ if (allData.decodedToken) {
745
+ const token = allData.decodedToken;
746
+ userEmail = userEmail || token.sub || token.email || "";
747
+ const tokenName = token.name || buildNameFromFirstLast(token);
748
+ userName = userName || (tokenName || "");
749
+ userRole = userRole || token.role || "";
750
+ }
751
+ if (allData.auth) {
752
+ const auth = allData.auth;
753
+ userEmail = userEmail || auth.email || auth.sub || "";
754
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
755
+ userRole = userRole || auth.role || auth.activeRole || "";
756
+ }
750
757
  if (allData.userDetails) {
751
- const userDetails = allData.userDetails.user || allData.userDetails.data || allData.userDetails;
752
- if (userDetails) {
753
- userName = userName || userDetails.name || userDetails.fullName || "";
754
- userEmail = userEmail || userDetails.email || userDetails.emailAddress || "";
755
- userRole = userRole || userDetails.role || userDetails.userRole || "";
758
+ const userDetails = allData.userDetails.user
759
+ || allData.userDetails.data
760
+ || allData.userDetails;
761
+ const details = userDetails;
762
+ if (details) {
763
+ userEmail = userEmail || details.email || details.emailAddress || "";
764
+ userName = userName || details.name || details.fullName || buildNameFromFirstLast(details) || "";
765
+ userRole = userRole || details.role || details.userRole || "";
756
766
  }
757
767
  }
758
768
  if (allData.user) {
759
- const userData = allData.user.user || allData.user.data || allData.user.currentUser || allData.user;
769
+ const u = allData.user.user
770
+ || allData.user.data
771
+ || allData.user.currentUser
772
+ || allData.user;
773
+ const userData = u;
760
774
  if (userData) {
761
- userName = userName || userData.name || userData.fullName || "";
762
775
  userEmail = userEmail || userData.email || userData.emailAddress || "";
776
+ userName = userName || userData.name || userData.fullName || buildNameFromFirstLast(userData) || "";
763
777
  userRole = userRole || userData.role || userData.userRole || "";
764
778
  }
765
779
  }
766
780
  if (allData.profile) {
767
- const profileData = allData.profile.user || allData.profile.data || allData.profile;
781
+ const p = allData.profile.user
782
+ || allData.profile.data
783
+ || allData.profile;
784
+ const profileData = p;
768
785
  if (profileData) {
769
- userName = userName || profileData.name || profileData.fullName || "";
770
786
  userEmail = userEmail || profileData.email || profileData.emailAddress || "";
787
+ userName = userName || profileData.name || profileData.fullName || buildNameFromFirstLast(profileData) || "";
771
788
  userRole = userRole || profileData.role || profileData.userRole || "";
772
789
  }
773
790
  }
@@ -816,67 +833,81 @@ const AppHeader = ({ language: languageProp }) => {
816
833
  }, []); // Only run once on mount - fetch when component loads
817
834
  React.useEffect(() => {
818
835
  const allData = getAllDataFromStorage();
819
- // Try to get user data from various sources
820
836
  let userName = "";
821
837
  let userEmail = "";
822
838
  let userRole = "";
823
- let userAvatar = undefined;
824
- let userInitials = undefined;
825
- // Priority 1: From decoded token
826
- if (allData.decodedToken) {
827
- userName = allData.decodedToken.sub || allData.decodedToken.email || "";
828
- userEmail = allData.decodedToken.sub || allData.decodedToken.email || "";
829
- userRole = allData.decodedToken.role || "";
830
- }
831
- // Priority 2: From auth data
832
- if (allData.auth) {
833
- userName = userName || allData.auth.name || allData.auth.email || "";
834
- userEmail = userEmail || allData.auth.email || allData.auth.sub || "";
835
- userRole = userRole || allData.auth.role || allData.auth.activeRole || "";
836
- userAvatar = userAvatar || allData.auth.avatar || undefined;
837
- userInitials = userInitials || allData.auth.initials || undefined;
838
- }
839
- // Priority 3: From userDetails/user/profile
839
+ let userAvatar;
840
+ let userInitials;
841
+ const buildNameFromFirstLast = (obj) => {
842
+ if (!obj || typeof obj !== "object")
843
+ return "";
844
+ const first = (obj.firstName ?? obj.given_name ?? obj.first_name);
845
+ const last = (obj.lastName ?? obj.family_name ?? obj.last_name);
846
+ return [first, last].filter(Boolean).join(" ").trim();
847
+ };
840
848
  const storedUser = getUserDataFromStorage();
841
849
  if (storedUser) {
842
- userName = userName || storedUser.name || "";
850
+ userName = storedUser.name || "";
843
851
  userEmail = userEmail || storedUser.email || "";
844
852
  userRole = userRole || storedUser.role || "";
845
- userAvatar = userAvatar || storedUser.avatar || undefined;
846
- userInitials = userInitials || storedUser.initials || undefined;
853
+ userAvatar = storedUser.avatar;
854
+ userInitials = storedUser.initials;
855
+ }
856
+ if (allData.decodedToken) {
857
+ const token = allData.decodedToken;
858
+ userEmail = userEmail || token.sub || token.email || "";
859
+ const tokenName = token.name || buildNameFromFirstLast(token);
860
+ userName = userName || (tokenName || "");
861
+ userRole = userRole || token.role || "";
862
+ }
863
+ if (allData.auth) {
864
+ const auth = allData.auth;
865
+ userEmail = userEmail || auth.email || auth.sub || "";
866
+ userName = userName || auth.name || buildNameFromFirstLast(auth) || "";
867
+ userRole = userRole || auth.role || auth.activeRole || "";
868
+ userAvatar = userAvatar || auth.avatar || undefined;
869
+ userInitials = userInitials || auth.initials || undefined;
847
870
  }
848
- // Priority 4: From other parsed data
849
871
  if (allData.userDetails) {
850
- const userDetails = allData.userDetails.user || allData.userDetails.data || allData.userDetails;
851
- if (userDetails) {
852
- userName = userName || userDetails.name || userDetails.fullName || "";
853
- userEmail = userEmail || userDetails.email || userDetails.emailAddress || "";
854
- userRole = userRole || userDetails.role || userDetails.userRole || "";
855
- userAvatar = userAvatar || userDetails.avatar || userDetails.profilePicture || undefined;
856
- userInitials = userInitials || userDetails.initials || undefined;
872
+ const userDetails = allData.userDetails.user
873
+ || allData.userDetails.data
874
+ || allData.userDetails;
875
+ const details = userDetails;
876
+ if (details) {
877
+ userEmail = userEmail || details.email || details.emailAddress || "";
878
+ userName = userName || details.name || details.fullName || buildNameFromFirstLast(details) || "";
879
+ userRole = userRole || details.role || details.userRole || "";
880
+ userAvatar = userAvatar || details.avatar || details.profilePicture || undefined;
881
+ userInitials = userInitials || details.initials || undefined;
857
882
  }
858
883
  }
859
884
  if (allData.user) {
860
- const userData = allData.user.user || allData.user.data || allData.user.currentUser || allData.user;
885
+ const u = allData.user.user
886
+ || allData.user.data
887
+ || allData.user.currentUser
888
+ || allData.user;
889
+ const userData = u;
861
890
  if (userData) {
862
- userName = userName || userData.name || userData.fullName || "";
863
891
  userEmail = userEmail || userData.email || userData.emailAddress || "";
892
+ userName = userName || userData.name || userData.fullName || buildNameFromFirstLast(userData) || "";
864
893
  userRole = userRole || userData.role || userData.userRole || "";
865
894
  userAvatar = userAvatar || userData.avatar || userData.profilePicture || undefined;
866
895
  userInitials = userInitials || userData.initials || undefined;
867
896
  }
868
897
  }
869
898
  if (allData.profile) {
870
- const profileData = allData.profile.user || allData.profile.data || allData.profile;
899
+ const p = allData.profile.user
900
+ || allData.profile.data
901
+ || allData.profile;
902
+ const profileData = p;
871
903
  if (profileData) {
872
- userName = userName || profileData.name || profileData.fullName || "";
873
904
  userEmail = userEmail || profileData.email || profileData.emailAddress || "";
905
+ userName = userName || profileData.name || profileData.fullName || buildNameFromFirstLast(profileData) || "";
874
906
  userRole = userRole || profileData.role || profileData.userRole || "";
875
907
  userAvatar = userAvatar || profileData.avatar || profileData.profilePicture || undefined;
876
908
  userInitials = userInitials || profileData.initials || undefined;
877
909
  }
878
910
  }
879
- // Use fetched blob URL if available, otherwise fall back to other sources
880
911
  setUser({
881
912
  name: userName || "",
882
913
  email: userEmail || "",
@@ -1043,7 +1074,7 @@ const AppHeader = ({ language: languageProp }) => {
1043
1074
  width: "100%",
1044
1075
  maxWidth: 360,
1045
1076
  pointerEvents: "none",
1046
- }, component: "div", "aria-hidden": "true", tabIndex: -1, children: jsxRuntime.jsxs(material.ListItem, { alignItems: "flex-start", className: "profile-menu-item", children: [jsxRuntime.jsx(material.ListItemAvatar, { children: isOnlineStatus ? (jsxRuntime.jsx(OnlineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.online, "aria-label": `${t.online} status badge`, "data-testid": "online-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) : (jsxRuntime.jsx(OfflineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.offline, "aria-label": `${t.offline} status badge`, "data-testid": "offline-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) }), jsxRuntime.jsx(material.ListItemText, { secondary: jsxRuntime.jsxs(React.Fragment, { children: [jsxRuntime.jsx(material.Typography, { className: "profile-name", component: "p", children: user.name }), jsxRuntime.jsx(material.Typography, { className: "profile-email", component: "p", children: user.email }), jsxRuntime.jsxs(material.Typography, { className: "profile-role", component: "p", children: [t.role, ": ", user.role] })] }) })] }) }));
1077
+ }, component: "div", "aria-hidden": "true", tabIndex: -1, children: jsxRuntime.jsxs(material.ListItem, { alignItems: "flex-start", className: "profile-menu-item", children: [jsxRuntime.jsx(material.ListItemAvatar, { children: isOnlineStatus ? (jsxRuntime.jsx(OnlineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.online, "aria-label": `${t.online} status badge`, "data-testid": "online-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) : (jsxRuntime.jsx(OfflineBadge, { overlap: "circular", anchorOrigin: { vertical: "bottom", horizontal: "right" }, variant: "dot", title: t.offline, "aria-label": `${t.offline} status badge`, "data-testid": "offline-badge", children: jsxRuntime.jsx(material.Avatar, { sx: { bgcolor: colors.deepOrange[500] }, alt: user.name, title: user.name, src: user.avatar, children: getInitials() }) })) }), jsxRuntime.jsx(material.ListItemText, { primary: jsxRuntime.jsx(material.Typography, { className: "profile-name", component: "span", children: user.name || user.email }), secondary: jsxRuntime.jsxs(React.Fragment, { children: [user.name && user.email ? (jsxRuntime.jsx(material.Typography, { className: "profile-email", component: "p", children: user.email })) : null, jsxRuntime.jsxs(material.Typography, { className: "profile-role", component: "p", children: [t.role, ": ", user.role] })] }) })] }) }));
1047
1078
  const renderMenu = (jsxRuntime.jsxs(material.Menu, { anchorEl: anchorEl, id: "account-menu", open: open, onClose: handleClose, onClick: handleClose, slotProps: {
1048
1079
  paper: {
1049
1080
  elevation: 0,