@frank-auth/react
Version:
Flexible and customizable React UI components for Frank Authentication
4 lines (3 loc) • 8.06 kB
JavaScript
'use client';
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),E=require("react"),n=require("@heroui/react"),T=require("../../../hooks/use-auth.cjs"),$=require("../../../hooks/use-organization.cjs"),F=require("../../../hooks/use-session.cjs"),G=require("../../../hooks/use-config.cjs"),J=require("../../../hooks/use-theme.cjs"),K=s=>s&&s.__esModule?s:{default:s},x=K(E);function Q(s){switch(s?.toLowerCase()){case"owner":return"danger";case"admin":return"warning";case"member":return"primary";case"guest":return"secondary";default:return"default"}}function X(s){const l=s?.device?.toLowerCase()||"",c=s?.os?.toLowerCase()||"";return l.includes("mobile")||c.includes("ios")||c.includes("android")?e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 18h.01M8 21h8a1 1 0 001-1V4a1 1 0 00-1-1H8a1 1 0 00-1 1v16a1 1 0 001 1z"})}):e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"})})}const a={user:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})}),settings:e.jsxs("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]}),signOut:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"})}),organization:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})}),theme:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"})}),security:e.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"})})};function Y({children:s,placement:l="bottom-end",className:c="",contentClassName:w="",showOrganization:k=!0,showSessionManagement:v=!1,showThemeToggle:g=!0,customItems:d=[],hideDefaultItems:t=[],onSignOut:u,onProfileClick:m,onSettingsClick:p,onOrganizationSwitch:h,footerContent:j,isDisabled:C=!1,closeOnSelect:D=!0}){const{user:M,signOut:y,isOrganizationMember:Z,userName:A,userEmail:I}=T.useAuth(),{organizations:L,activeOrganization:o,switchOrganization:b,isOwner:N,isAdmin:z}=$.useOrganization(),{sessions:O,hasMultipleSessions:W,revokeSession:q,deviceInfo:ee}=F.useSession(),{components:R}=G.useConfig(),{mode:P,toggleMode:B}=J.useTheme(),S=R.UserProfile;if(S)return e.jsx(S,{children:s,placement:l,className:c,contentClassName:w,showOrganization:k,showSessionManagement:v,showThemeToggle:g,customItems:d,hideDefaultItems:t,onSignOut:u,onProfileClick:m,onSettingsClick:p,onOrganizationSwitch:h,footerContent:j,isDisabled:C,closeOnSelect:D});const U=x.default.useCallback(async()=>{try{u?u():await y()}catch(r){console.error("Sign out failed:",r)}},[y,u]),H=x.default.useCallback(async r=>{try{h?h(r):await b(r)}catch(i){console.error("Organization switch failed:",i)}},[b,h]),_=x.default.useCallback(r=>{switch(r){case"profile":m?.();break;case"settings":p?.();break;case"sign-out":U();break;case"toggle-theme":B();break;default:const i=d.find(V=>V.key===r);i?.onClick?i.onClick():i?.href&&(window.location.href=i.href);break}},[m,p,U,B,d]);if(!M)return null;const f=x.default.useMemo(()=>o?N?"owner":z?"admin":"member":null,[o,N,z]);return e.jsxs(n.Dropdown,{placement:l,className:c,isDisabled:C,closeOnSelect:D,children:[e.jsx(n.DropdownTrigger,{children:s}),e.jsxs(n.DropdownMenu,{"aria-label":"User menu",onAction:_,className:w,children:[e.jsx(n.DropdownSection,{showDivider:!0,children:e.jsx(n.DropdownItem,{isReadOnly:!0,className:"h-14 gap-2 opacity-100",children:e.jsx(n.User,{name:A,description:I,avatarProps:{size:"sm",src:M.profileImageUrl},classNames:{name:"text-default-600",description:"text-default-500"}})},"user-info")}),k&&o&&e.jsxs(n.DropdownSection,{title:"Organization",showDivider:!0,children:[e.jsx(n.DropdownItem,{isReadOnly:!0,className:"opacity-100",startContent:a.organization,endContent:f&&e.jsx(n.Chip,{size:"sm",color:Q(f),variant:"flat",children:f}),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-small",children:o.name}),e.jsx("span",{className:"text-tiny text-default-400",children:o.slug})]})},"current-org"),L.length>1&&e.jsx(e.Fragment,{children:L.filter(r=>r.id!==o.id).map(r=>e.jsxs(n.DropdownItem,{onPress:()=>H(r.id),startContent:e.jsx(n.Avatar,{size:"sm",src:r.logoUrl,name:r.name}),children:["Switch to ",r.name]},`switch-${r.id}`))})]}),v&&W&&e.jsx(n.DropdownSection,{title:"Sessions",showDivider:!0,children:O.slice(0,3).map(r=>e.jsx(n.DropdownItem,{startContent:X(r.deviceInfo),endContent:r.id!==O[0]?.id&&e.jsx(n.Button,{size:"sm",variant:"light",color:"danger",onPress:()=>q(r.id),children:"End"}),className:"text-small",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:r.deviceInfo?.browser||"Unknown Browser"}),e.jsx("span",{className:"text-tiny text-default-400",children:r.deviceInfo?.os||"Unknown OS"})]})},`session-${r.id}`))}),e.jsxs(n.DropdownSection,{showDivider:!0,children:[!t.includes("profile")&&e.jsx(n.DropdownItem,{startContent:a.user,children:"Profile"},"profile"),!t.includes("settings")&&e.jsx(n.DropdownItem,{startContent:a.settings,children:"Settings"},"settings"),!t.includes("security")&&e.jsx(n.DropdownItem,{startContent:a.security,children:"Security"},"security"),g&&!t.includes("theme")&&e.jsx(n.DropdownItem,{startContent:a.theme,children:P==="dark"?"Light Mode":"Dark Mode"},"toggle-theme"),d.map(r=>e.jsx(n.DropdownItem,{startContent:r.startContent||r.icon,endContent:r.endContent,color:r.color,variant:r.variant,isDisabled:r.isDisabled,showDivider:r.showDivider,children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:r.label}),r.description&&e.jsx("span",{className:"text-tiny text-default-400",children:r.description})]})},r.key))]}),e.jsx(n.DropdownSection,{children:!t.includes("signOut")&&e.jsx(n.DropdownItem,{color:"danger",startContent:a.signOut,children:"Sign Out"},"sign-out")}),j&&e.jsx(n.DropdownSection,{children:e.jsx(n.DropdownItem,{isReadOnly:!0,className:"opacity-100",children:j},"footer")})]})]})}exports.UserProfile=Y;
//# sourceMappingURL=user-profile.cjs.map