UNPKG

@frank-auth/react

Version:

Flexible and customizable React UI components for Frank Authentication

4 lines (3 loc) 5.52 kB
'use client'; "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),b=require("react"),r=require("@heroui/react"),I=require("../../../hooks/use-auth.cjs"),V=require("../../../hooks/use-user.cjs"),K=require("../../../hooks/use-config.cjs"),G=require("./profile-form.cjs"),J=require("./security-panel.cjs"),Q=require("./mfa-setup.cjs"),X=require("./passkey-setup.cjs"),Y=t=>t&&t.__esModule?t:{default:t},B=Y(b),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"})}),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"})}),shield: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 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})}),key: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:"M15 7a2 2 0 012 2m4 0a6 6 0 01-7.743 5.743L11 17H9v2H7v2H4a1 1 0 01-1-1v-2.586a1 1 0 01.293-.707l5.964-5.964A6 6 0 1121 9z"})}),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"})})};function Z({defaultTab:t="profile",tabs:N,hideTabs:u=[],showOrganizationSettings:h=!0,showSecuritySettings:x=!0,showMFASettings:m=!0,showPasskeySettings:f=!0,className:j="",variant:p="bordered",orientation:k="horizontal",tabPlacement:M="top",headerContent:g,footerContent:v,onProfileUpdate:y,onSuccess:i,onError:o,onClose:c,isLoading:z=!1,isDisabled:n=!1,size:w="md",customTabs:L={}}){const{user:P,isLoading:H}=I.useAuth(),{isLoading:A}=V.useUser(),{components:U,features:d}=K.useConfig(),C=U.UserProfile;if(C)return e.jsx(C,{defaultTab:t,tabs:N,hideTabs:u,showOrganizationSettings:h,showSecuritySettings:x,showMFASettings:m,showPasskeySettings:f,className:j,variant:p,orientation:k,tabPlacement:M,headerContent:g,footerContent:v,onProfileUpdate:y,onSuccess:i,onError:o,onClose:c,isLoading:z,isDisabled:n,size:w,customTabs:L});const q=z||H||A,[W,_]=B.default.useState(t),F=B.default.useMemo(()=>{const s=[{key:"profile",title:"Profile",icon:a.user,content:e.jsx(G.ProfileForm,{onUpdate:y,onSuccess:i,onError:o,isDisabled:n})}];return x&&s.push({key:"security",title:"Security",icon:a.security,content:e.jsx(J.SecurityPanel,{onSuccess:i,onError:o,isDisabled:n})}),m&&d.mfa&&s.push({key:"mfa",title:"Two-Factor Auth",icon:a.shield,content:e.jsx(Q.MFASetup,{onSuccess:i,onError:o,isDisabled:n})}),f&&d.passkeys&&s.push({key:"passkeys",title:"Passkeys",icon:a.key,content:e.jsx(X.PasskeySetup,{onSuccess:i,onError:o,isDisabled:n})}),h&&d.organizationManagement&&s.push({key:"organizations",title:"Organizations",icon:a.organization,content:e.jsx("div",{className:"space-y-4",children:e.jsx("p",{children:"Organization management coming soon..."})})}),Object.entries(L).forEach(([l,T])=>{s.push({key:l,title:l.charAt(0).toUpperCase()+l.slice(1),content:T})}),s.filter(l=>!u.includes(l.key))},[x,m,f,h,d,u,L,y,i,o,n]),O=N||F,R={sm:"sm",md:"md",lg:"lg"};return!P&&!q?null:q?e.jsx(r.Card,{variant:p,className:j,children:e.jsx(r.CardBody,{className:"flex items-center justify-center py-8",children:e.jsx(r.Spinner,{size:"lg"})})}):e.jsxs(r.Card,{variant:p,className:j,children:[(g||c)&&e.jsxs(e.Fragment,{children:[e.jsxs(r.CardHeader,{className:"flex items-center justify-between",children:[g||e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Profile Settings"}),e.jsx("p",{className:"text-sm text-default-500",children:"Manage your account settings and preferences"})]}),c&&e.jsx(r.Button,{isIconOnly:!0,variant:"light",onPress:c,"aria-label":"Close",children: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:"M6 18L18 6M6 6l12 12"})})})]}),e.jsx(r.Divider,{})]}),e.jsx(r.CardBody,{className:"p-0",children:e.jsx(r.Tabs,{selectedKey:W,onSelectionChange:s=>_(s),orientation:k,placement:M,size:R[w],classNames:{base:"w-full",tabList:k==="vertical"?"w-full":void 0,panel:"w-full"},children:O.map(s=>e.jsx(r.Tab,{title:e.jsxs("div",{className:"flex items-center gap-2",children:[s.icon,e.jsx("span",{children:s.title}),s.badge&&e.jsx("span",{className:"bg-danger text-white text-xs rounded-full px-1.5 py-0.5 min-w-[1.25rem] h-5 flex items-center justify-center",children:s.badge})]}),isDisabled:s.isDisabled||n,children:e.jsx("div",{className:"p-6",children:s.content})},s.key))})}),v&&e.jsxs(e.Fragment,{children:[e.jsx(r.Divider,{}),e.jsx(r.CardBody,{className:"pt-4",children:v})]})]})}exports.UserProfile=Z; //# sourceMappingURL=user-profile.cjs.map