UNPKG

@clerk/clerk-js

Version:
1 lines • 8.99 kB
"use strict";(globalThis.webpackChunk_clerk_clerk_js=globalThis.webpackChunk_clerk_clerk_js||[]).push([["192"],{8493:function(e,t,r){r.d(t,{l:()=>_});var i=r(9109),a=r(3531),l=r(3799),n=r(9144),o=r(2672),s=r(431),c=r(9460),d=r(6443),u=r(8870),p=r(6842),m=r(6788),h=r(1576),g=r(4204),b=r(3266),f=r(7703),v=r(1217),x=r(408);let Z=e=>/^\S+@\S+\.\S+$/.test(e),_=e=>{let{onSuccess:t,onReset:r,resetButtonLabel:h}=e,{organization:b,invitations:x}=(0,l.o8)({invitations:{pageSize:10,keepPreviousData:!0}}),_=(0,o.useCardState)(),{t:y,locale:C}=(0,f.zJ)(),[T,$]=(0,n.useState)(!1),w=(0,m.Yp)("emailAddress","",{type:"text",label:(0,f.u1)("formFieldLabel__emailAddresses")}),k=S(),P=(0,m.Yp)("role","",{label:(0,f.u1)("formFieldLabel__role")});if((0,n.useEffect)(()=>{!P.value&&k&&P.setValue(k)},[k,P]),!b)return null;let{props:{setError:B,setWarning:A,setSuccess:F,setInfo:D,isFocused:K,validatePassword:R,setHasPassedComplexity:X,hasPassedComplexity:E,feedback:I,feedbackType:M,clearFeedback:L,...j}}=w,W=(!!w.value.length||T)&&!!P.value;return(0,i.BX)(s.l.Root,{onSubmit:e=>{if(e.preventDefault(),!W)return;let r=new FormData(e.currentTarget);return b.inviteMembers({emailAddresses:w.value.split(","),role:r.get("role")}).then(async()=>(await x?.revalidate?.(),t?.())).catch(e=>{if(!(0,a.kD)(e))return void(0,u.S3)(e,[],_.setError);switch((e=>{let t=new Set([...e.meta?.emailAddresses??[],...e.meta?.identifiers??[]]),r=w.value.split(",");w.setValue(r.filter(e=>!t.has(e)).join(","))})(e.errors[0]),e.errors?.[0]?.code){case"duplicate_record":{let t=e.errors[0].meta?.emailAddresses||[];_.setError(y((0,f.u1)("organizationProfile.invitePage.detailsTitle__inviteFailed",{email_addresses:(0,p.z$)(t,C)})));break}case"already_a_member_in_organization":{let t=e.errors[0].longMessage??"",r=t.match(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/)?.[0];(0,u.S3)(e,[],e=>r?_.setError(y((0,f.u1)("unstable__errors.already_a_member_in_organization",{email:r}))):_.setError(e));break}default:(0,u.S3)(e,[],_.setError)}})},children:[(0,i.tZ)(s.l.ControlRow,{elementId:w.id,children:(0,i.tZ)(d.E,{...j,autoFocus:!0,validate:Z,sx:{width:"100%"},validateUnsubmittedEmail:e=>$(Z(e)),placeholder:(0,f.u1)("formFieldInputPlaceholder__emailAddresses")})}),(0,i.BX)(g.Flex,{align:"center",justify:"between",sx:e=>({marginTop:e.space.$2,gap:e.space.$4,flexWrap:"wrap",[v.mqu.sm]:{justifyContent:"center"}}),children:[(0,i.tZ)(z,{...P}),(0,i.BX)(c.K,{sx:e=>({margin:e.space.$none,flexWrap:"wrap",justifyContent:"center"}),children:[(0,i.tZ)(s.l.SubmitButton,{block:!1,isDisabled:!W,localizationKey:(0,f.u1)("organizationProfile.invitePage.formButtonPrimary__continue")}),(0,i.tZ)(s.l.ResetButton,{localizationKey:h||(0,f.u1)("userProfile.formButtonReset"),block:!1,onClick:r})]})]})]})},z=e=>{let{options:t,isLoading:r}=(0,b.e)(),{t:a}=(0,f.zJ)();return(0,i.tZ)(s.l.ControlRow,{elementId:e.id,children:(0,i.tZ)(g.Flex,{direction:"col",gap:2,children:(0,i.tZ)(x.DQ,{...e.props,roles:t,isDisabled:r,onChange:t=>e.setValue(t),triggerSx:e=>({minWidth:e.sizes.$40,justifyContent:"space-between",display:"flex"}),optionListSx:e=>({minWidth:e.sizes.$48}),prefixLocalizationKey:`${a((0,f.u1)("formFieldLabel__role"))}:`})})})},S=()=>{let{options:e}=(0,b.e)(),{organizationSettings:t}=(0,h.useEnvironment)(),r=t.domains.defaultRole;return r||e?.length!==1||(r=e[0].value),r}},5727:function(e,t,r){r.d(t,{a:()=>x,N:()=>v});var i=r(9109),a=r(3799),l=r(2672),n=r(8487),o=r(9566),s=r(7263),c=r(3344),d=r(8969),u=r(1576),p=r(4204),m=r(4709),h=r(4174),g=r(4676);let b=({__unstable_manageBillingUrl:e,__unstable_manageBillingMembersLimit:t})=>{let r=(0,g.useRouter)();return(0,i.BX)(p.Flex,{sx:e=>({background:e.colors.$neutralAlpha50,padding:e.space.$4,borderRadius:e.radii.$md}),children:[(0,i.tZ)(p.AlertIcon,{variant:"warning",colorScheme:"danger",sx:e=>({marginTop:e.space.$1})}),(0,i.BX)(p.Text,{children:["This organization is limited to ",(0,c.OR)(t)," members.",(0,i.tZ)("br",{}),(0,i.tZ)(p.Link,{sx:e=>({alignSelf:"flex-start",color:e.colors.$primary500,fontWeight:e.fontWeights.$normal}),onClick:()=>r.navigate((0,c.OR)(e)),children:"Upgrade for unlimited members"})]})]})};var f=r(8493);let v=(0,l.withCardStateProvider)(e=>{let{close:t}=(0,m.XC)(),{onReset:r=t}=e,o=(0,p.localizationKeys)("organizationProfile.invitePage.title"),h=(0,p.localizationKeys)("organizationProfile.invitePage.subtitle"),g=(0,l.useCardState)(),v=(0,d.a2)({onNextStep:()=>g.setError(void 0)}),{organization:Z}=(0,a.o8)(),{__unstable_manageBillingUrl:_,__unstable_manageBillingMembersLimit:z}=(0,u.useOrganizationProfileContext)();if(!Z)return null;let S=!!z&&(0,c.OR)(z)<=Z.pendingInvitationsCount+Z.membersCount;return(0,i.BX)(d.en,{...v.props,children:[(0,i.BX)(n.Y,{headerTitle:o,headerSubtitle:h,children:[S&&_&&(0,i.tZ)(b,{__unstable_manageBillingUrl:_,__unstable_manageBillingMembersLimit:z}),(0,i.tZ)(f.l,{onSuccess:v.nextStep,onReset:r})]}),(0,i.tZ)(s.I,{title:o,onFinish:t,contents:(0,i.tZ)(x,{})})]})}),x=()=>(0,i.BX)(p.Flex,{direction:"col",center:!0,gap:4,children:[(0,i.tZ)(o.f,{boxElementDescriptor:p.descriptors.invitationsSentIconBox,iconElementDescriptor:p.descriptors.invitationsSentIcon,icon:h.GT}),(0,i.tZ)(p.Text,{localizationKey:(0,p.localizationKeys)("organizationProfile.invitePage.successMessage")})]})},408:function(e,t,r){r.d(t,{DQ:()=>p,RN:()=>u,wQ:()=>c});var i=r(9109),a=r(9144),l=r(2930),n=r(3146),o=r(4204),s=r(3266);let c=e=>{let{headers:t,page:r,onPageChange:a,rows:n,isLoading:s,itemCount:c,itemsPerPage:u,pageCount:p,emptyStateLocalizationKey:m}=e,h=c>0?Math.max(0,(r-1)*u)+1:0,g=Math.min(r*u,c);return(0,i.BX)(o.Col,{gap:4,sx:{width:"100%"},children:[(0,i.tZ)(o.Flex,{sx:e=>({overflowX:"auto",padding:e.space.$1}),children:(0,i.BX)(o.Table,{children:[(0,i.tZ)(o.Thead,{children:(0,i.tZ)(o.Tr,{children:t.map((e,t)=>(0,i.tZ)(o.Th,{elementDescriptor:o.descriptors.tableHead,localizationKey:e},t))})}),(0,i.tZ)(o.Tbody,{children:s?(0,i.tZ)(o.Tr,{children:(0,i.tZ)(o.Td,{colSpan:4,children:(0,i.tZ)(o.Spinner,{colorScheme:"primary",sx:{margin:"auto",display:"block"},elementDescriptor:o.descriptors.spinner})})}):n.length?n:(0,i.tZ)(d,{localizationKey:m},"empty")})]})}),p>1&&(0,i.tZ)(l.t,{count:p,page:r,onChange:a,siblingCount:1,rowInfo:{allRowsCount:c,startingRow:h,endingRow:g}})]})},d=e=>(0,i.tZ)(o.Tr,{children:(0,i.tZ)(o.Td,{colSpan:4,children:(0,i.tZ)(o.Text,{localizationKey:e.localizationKey,sx:{margin:"auto",display:"block",width:"fit-content"}})})}),u=e=>(0,i.tZ)(o.Tr,{...e,sx:e=>({":hover":{backgroundColor:e.colors.$neutralAlpha50}})}),p=e=>{let{value:t,fallbackLabel:r,roles:l,onChange:c,isDisabled:d,triggerSx:u,optionListSx:p,prefixLocalizationKey:h}=e,{localizeCustomRole:g}=(0,s.q)(),b=(0,a.useMemo)(()=>[...l||[]],[l]),f=(0,a.useMemo)(()=>b.find(e=>e.value===t),[b,t]),{t:v}=(0,o.useLocalizations)(),x=(0,a.useMemo)(()=>b.map(e=>({value:e.value,label:g(e.value)||e.label})),[b,g]);return(0,i.BX)(n.Ph,{elementId:"role",options:x,value:t,placeholder:v((0,o.localizationKeys)("organizationProfile.invitePage.selectDropdown__role")),onChange:e=>c(e.value),renderOption:(e,t,r)=>(0,i.tZ)(m,{isSelected:r,option:e,sx:e=>({"&:hover":{backgroundColor:e.colors.$neutralAlpha100},'&[data-focused="true"]':{backgroundColor:e.colors.$neutralAlpha150}})}),children:[(0,i.tZ)("input",{name:"role",type:"hidden",value:t}),(0,i.tZ)(n.UN,{sx:u||(e=>({color:e.colors.$colorForeground,backgroundColor:"transparent",textWrap:"nowrap"})),isDisabled:d||!!t&&b.length>0&&!f,children:f?.label||f?.value?(0,i.BX)(o.Flex,{as:"span",gap:1,children:[h&&(0,i.tZ)(o.Text,{as:"span",colorScheme:"secondary",localizationKey:h}),(0,i.tZ)(o.Text,{as:"span",colorScheme:"body",children:g(f?.value)||f?.label})]}):r?(0,i.tZ)(o.Text,{as:"span",colorScheme:"body",children:r}):null}),(0,i.tZ)(n.pp,{sx:p})]})},m=(0,a.memo)(e=>{let{option:t,isSelected:r,sx:a,...l}=e;return(0,i.tZ)(o.Flex,{sx:[e=>({width:"100%",padding:`${e.space.$2} ${e.space.$4}`,borderRadius:e.radii.$md}),a],...l,children:(0,i.tZ)(o.Text,{colorScheme:"secondary",children:t?.label})})})},8181:function(e,t,r){r.d(t,{D:()=>s});var i=r(9109),a=r(6654),l=r(5623),n=r(4204),o=r(7703);let s=e=>{let{organization:t,...r}=e;return(0,i.BX)(n.Col,{elementDescriptor:n.descriptors.organizationAvatarUploaderContainer,children:[(0,i.tZ)(n.Text,{variant:"subtitle",sx:e=>({textAlign:"left",marginBottom:e.space.$2}),localizationKey:(0,o.u1)("organizationProfile.start.profileSection.uploadAction__title")}),(0,i.tZ)(a.C,{...r,title:(0,o.u1)("userProfile.profilePage.imageFormTitle"),avatarPreview:(0,i.tZ)(l.l,{size:e=>e.sizes.$16,...t})})]})}},7484:function(e,t,r){r.d(t,{AO:()=>i,Sz:()=>a});let i={userMemberships:{infinite:!0},userInvitations:{infinite:!0},userSuggestions:{infinite:!0,status:["pending","accepted"]}},a=(e,t,r)=>{if(void 0===t)return[{data:[e],total_count:1}];let i=t?.[t.length-1]?.total_count||1;return t.map(t=>{if(void 0===t)return t;let a=t.data.map(t=>t.id===e.id?{...e}:t);return{...t,data:a,total_count:"negative"===r?i-1:i}})}}}]);