%PDF- %PDF-
Direktori : /home/opti/www/startup-life/assets/ |
Current File : /home/opti/www/startup-life/assets/single-team-conversations-64a8dae7.js |
import{j as t,F as J,u as W,C as D,Q as j,r as G,R as te}from"./index-5492fbe1.js";import{b as ae}from"./index.esm-b6fe913b.js";import{D as se}from"./dashboard-page-layout-2cec2413.js";import{P as X}from"./index-4de96b18.js";import{u as Z}from"./index-9f8785a2.js";import{u as H}from"./useQuery-0abbcf43.js";import{u as ie}from"./get-all-startuplife-users.api-644aad92.js";import{C as b}from"./index-2c4b8b3c.js";import{h as ne}from"./moment-a9aaa855.js";import{M as re}from"./index-2496c884.js";import{A as oe}from"./index.esm-c5b2c2cb.js";import{B as K}from"./Button-e32596e7.js";import{u as Y}from"./useToggle-85ca1b00.js";import{D as le}from"./dashboard-footer-navigation-f658b457.js";import{u as ce}from"./update-stream-users.api-08113ef6.js";import{u as ee}from"./post-notification.api-d7cee9b0.js";import{u as me}from"./get-all-users-as-vendor.api-465b5409.js";import{C as de}from"./Checkbox-5f253e47.js";import"./iconBase-4b2ba95c.js";import"./motion-4a110d9b.js";import"./Box-263f925f.js";import"./joinClasses-adfcc520.js";import"./isNativeReflectConstruct-061ae640.js";import"./setPrototypeOf-0bb37fbe.js";import"./assertThisInitialized-081f9914.js";import"./Modal-01a2ce69.js";import"./useTheme-0dfa0cbc.js";import"./useForkRef-ff55d5c8.js";import"./TransitionGroupContext-29effe25.js";import"./useSlotProps-b42d44e4.js";import"./ButtonBase-0400401d.js";import"./SwitchBase-f9d84931.js";import"./useFormControl-45c447f9.js";import"./useControlled-967f9278.js";import"./createSvgIcon-6a373a0a.js";const pe=({isOpen:c,handleIsOpen:l,handleShowAddMembers:N})=>t.jsx(re,{isOpen:c,handleIsOpen:l,children:t.jsxs("div",{className:"bg-white max-w-[424px] w-full text-center p-5 space-y-5 rounded-xl",children:[t.jsxs("div",{className:"flex gap-x-20 items-center ",children:[t.jsx("button",{className:"!bg-transparent !p-0",onClick:l,children:t.jsx(oe,{})}),t.jsx("header",{className:"font-bold text-[#537473]",children:"Add members"})]}),t.jsx(K,{onClick:()=>N("share-link"),className:"text-sm !font-bold !capitalize !bg-[#A8CF45] !p-3 w-full text-white",children:"Share a link"}),t.jsx(K,{onClick:()=>N("on-startup"),className:"text-sm !font-bold !capitalize !bg-[#EFF0F6] !p-3 w-full text-black",children:"Add users on StartUp Life"})]})}),xe=({channel:c,refetch:l,refetch_channels:N,...F})=>{const{handleSelectedMembers:U,selectedMembers:h,handleShowAddMembers:d,addMembersType:T,isBuildTeam:I,setSelectedMembers:A}=F;console.log(I);const S=J(),{data:$,isLoading:a,isError:R}=me(S.id),u=W(),{client:x}=Z(),_=$==null?void 0:$.data,{mutateAsync:g}=ce(),{mutateAsync:k}=ee(),L=async()=>{var P;if(!x){console.error("Stream Chat client is not initialized");return}const n=await x.channel("messaging",S.id,{name:(P=c==null?void 0:c.data)==null?void 0:P.name});if(!await n.watch())return;const C=h.map(f=>f.id.toString()),q=h.map(f=>f.email),z=h.map(f=>`${f.firstName} ${f.lastName}`);console.log(h),g({userIds:C}).then(async f=>{var r,p,i;let e=[];for(const o in f.users)e=[...e,f.users[parseInt(o)].id];const s=await c.inviteMembers([...e]);console.log(s),k({message:`You have been invited by ${(r=x==null?void 0:x.user)==null?void 0:r.name} to join ${(p=n==null?void 0:n.data)==null?void 0:p.name} channel.`,email:[...q],to:[...h.map(o=>parseInt(o.id))],fullName:[...z],channelId:(i=n==null?void 0:n.data)==null?void 0:i.id}).then(()=>{l(),N(),d(),A([]),j.success("Invite sent to the selected users successfully"),u(I!=="startup-team"?`/build-team/my-teams/${c==null?void 0:c.id}/project-team`:`/build-team/my-teams/${c==null?void 0:c.id}/startup-team`)}).catch(o=>{console.log(o),j.error("error while creating notification")})})};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"!px-5",children:[t.jsx("div",{className:"flex justify-between items-center mt-3",children:t.jsxs("header",{className:"text-[#537473] text-lg font-semibold",children:["Add Members via ",T==="share-link"?"Slack Link":"StartUpLife"]})}),t.jsx(b,{appear:!!h.length,children:t.jsx("div",{className:"!p-5 bg-[#e3e6e9] rounded-xl !mt-5 sticky top-28 z-20",children:t.jsx("ul",{className:"text-xs font-light text-[#537473] flex gap-x-3",children:h.map(n=>t.jsxs("li",{children:["@",n.firstName]},n.id))})})}),t.jsx(b,{appear:a,children:t.jsx(D,{})}),t.jsx(b,{appear:R,children:t.jsx("h3",{children:"ERR_INTERNET_CONNECTION_REFUSED"})}),t.jsx(b,{appear:!a&&!R,children:t.jsx("ul",{className:"space-y-10 !mt-10",children:_==null?void 0:_.map(n=>t.jsxs("li",{className:"flex items-center justify-between gap-x-5 ",children:[t.jsxs("div",{className:"flex items-center gap-x-5 ",children:[t.jsx("div",{className:"h-[52px] w-[52px] rounded-full",children:t.jsx(X,{imgUrl:n.avatarUrl,name:n.firstName})}),t.jsxs("div",{children:[t.jsxs("p",{children:[n.firstName," ",n.lastName]}),t.jsx("p",{children:n.email}),t.jsx("p",{children:n.accountType})]})]}),t.jsx(de,{sx:{color:"#A8CF45","&.Mui-checked":{color:"#A8CF45"}},checked:!!h.find(w=>w.id===n.id),onChange:()=>U(n)})]},n.id))})})]}),t.jsx(le,{backBtnText:"Back",cancelEventHandler:d,continueEventHandler:L})]})},Ye=()=>{var f;const c=W(),l=J(),[N,F]=Y(),[U,h]=G.useState([]),{client:d,decoded:T}=Z(),[I,A]=Y(),{mutateAsync:S}=ee();async function $(){var e;try{const s={type:"messaging",members:{$in:[T.user_id]}},r=[{last_message_at:-1}],i=(await d.queryChannels(s,r,{watch:!0,state:!0,limit:30})).filter(o=>o.id===l.id);return i.length>0?(console.log(i[0]),i[0]):[]}catch(s){return console.log(s),(e=s.response)==null?void 0:e.data}}const{data:a,isPending:R,refetch:u}=H({queryFn:$,queryKey:["fetch_channel",l.id],enabled:!!d&&!!T}),{data:x}=ie(),_=async()=>{var e,s;try{const p=await(await d.channel("messaging",l.id,{name:(e=a==null?void 0:a.data)==null?void 0:e.name})).queryMembers({},{created_at:-1},{});if(!p)return[];const i=p.members;let o=[];for(let v=0;v<i.length;v++){const B=i[v].user_id;for(let y=0;y<x.data.length;y++)B===x.data[y].id.toString()&&(o=[...o,x.data[y]])}return o}catch(r){return console.log(r),(s=r.response)==null?void 0:s.data}},{data:g,isLoading:k,isError:L,isPending:n,refetch:w}=H({queryFn:_,queryKey:["channel_members",l.id],enabled:!!d&&!!x&&!!a}),C=G.useMemo(()=>{var e,s,r;return!d||!a?!1:((s=(e=a==null?void 0:a.data)==null?void 0:e.created_by)==null?void 0:s.id)===((r=d==null?void 0:d.user)==null?void 0:r.id)},[a,d]),q=e=>{U.find(s=>s.id===e.id)?h(s=>s.filter(r=>r.id!==e.id)):h(s=>[...s,e])},z=async e=>{var s,r,p;if(confirm(`Are you sure you want to remove ${e==null?void 0:e.firstName} ${e==null?void 0:e.lastName} from ${(s=a==null?void 0:a.data)==null?void 0:s.name}?`))try{const i=await a.removeMembers([e==null?void 0:e.id.toString()]);console.log(i),i&&S({message:`Sad news ${e==null?void 0:e.firstName} ${e==null?void 0:e.lastName}, you have been removed from channel ${(r=i==null?void 0:i.channel)==null?void 0:r.name} by the creator.`,email:[e==null?void 0:e.email],to:[e==null?void 0:e.id],fullName:[`${e==null?void 0:e.firstName} ${e==null?void 0:e.lastName}`],channelId:(p=a==null?void 0:a.data)==null?void 0:p.id}).then(()=>{var o;j.success("This member will be removed from this channel"),c(`/build-team/my-teams/${(o=i==null?void 0:i.channel)==null?void 0:o.id}/${l.team_type}`),u(),w()}).catch(o=>{console.log(o),j.error("error while creating notification")})}catch(i){console.log(i),j.error("couldn't remove member")}},P=async e=>{var s,r,p,i,o,v,B,y,O;if(confirm("Are you sure you want to leave?"))try{const m=await a.removeMembers([e==null?void 0:e.id.toString()]);if(console.log(m),m){const E=(s=x==null?void 0:x.data)==null?void 0:s.filter(M=>{var Q,V;return M.id.toString()===((V=(Q=m==null?void 0:m.channel)==null?void 0:Q.created_by)==null?void 0:V.id)});console.log(E),S({message:`Sad news ${(p=(r=m==null?void 0:m.channel)==null?void 0:r.created_by)==null?void 0:p.name}, ${e==null?void 0:e.firstName} ${e==null?void 0:e.lastName} just left your channel ${(i=m==null?void 0:m.channel)==null?void 0:i.name} by the creator.`,email:[(o=E[0])==null?void 0:o.email],to:[(v=E[0])==null?void 0:v.id],fullName:[`${(B=E[0])==null?void 0:B.firstName} ${(y=E[0])==null?void 0:y.lastName}`],channelId:(O=a==null?void 0:a.data)==null?void 0:O.id}).then(()=>{var M;j.success("You will be removed from this channel"),c(`/build-team/my-teams/${(M=m==null?void 0:m.channel)==null?void 0:M.id}/${l.team_type}`),u(),w()}).catch(M=>{console.log(M),j.error("error while creating notification")})}}catch(m){console.log(m),j.error("unable leave channel")}};return t.jsxs(se,{children:[t.jsx(b,{appear:!N,children:t.jsxs("section",{className:"px-5",children:[t.jsxs("header",{className:"flex items-center justify-between",children:[a&&t.jsxs("div",{children:[t.jsxs("button",{className:"cursor-pointer !p-0 bg-transparent text-start border-none",onClick:()=>{C&&(l.team_type==="startup-team"?c(`/build-team/view-team/${l==null?void 0:l.id}/startup-team`):c(`/build-team/view-team/${l==null?void 0:l.id}/project-team`))},children:[t.jsxs("h2",{className:"font-semibold text-[#537473] text-xl underline capitalize",children:[" ",(f=a==null?void 0:a.data)==null?void 0:f.name]}),t.jsxs("p",{className:"text-xs",children:[g==null?void 0:g.length," members"]})]})," ",t.jsx("button",{onClick:()=>c(`/startup-messaging-channel/${a==null?void 0:a.id}`),className:"underline !text-primary !p-0 bg-transparent",children:"View Channel"})," "]}),C&&t.jsxs("button",{onClick:A,className:"flex gap-x-2 text-[#A8CF45] bg-transparent items-center",children:[t.jsx(ae,{color:"#A8CF45"}),"Add Members"]})]}),t.jsxs(b,{appear:k,children:[t.jsx(D,{})," Loading channel members..."]}),t.jsxs(b,{appear:!k&&(R||n),children:[t.jsx(D,{})," Resolving channel members..."]}),t.jsx(b,{appear:L,children:t.jsx("div",{className:"px-[40px]",children:"ERR_INTERNET_CONNECTION_REFUSED"})}),t.jsx("div",{className:"mt-4 space-y-3",children:t.jsx(b,{appear:!k&&!L&&(g==null?void 0:g.length)>0,children:g==null?void 0:g.map((e,s)=>{var r,p,i,o;return t.jsxs(te.Fragment,{children:[t.jsx("p",{className:" border-b text-sm pb-1"}),t.jsxs("div",{className:"flex justify-between items-center",children:[t.jsxs("div",{className:"py-3 flex gap-x-5",children:[t.jsx("button",{className:"w-[55px] h-[55px] rounded-full !p-0 !bg-transparent",onClick:()=>c(`/build-team/my-teams/${l.id}/view-member?user=${e.id}`),children:t.jsx(X,{imgUrl:(e==null?void 0:e.avatarUrl)??"",name:e.firstName})}),t.jsxs("div",{children:[t.jsxs("p",{className:"text-[#537473] capitalize text-lg flex gap-x-2 items-center font-semibold",children:[e==null?void 0:e.firstName," ",e==null?void 0:e.lastName," ",t.jsx("span",{className:"text-xs font-normal text-[#121212]/60",children:ne((r=a==null?void 0:a.data)==null?void 0:r.created_at).fromNow()})]}),t.jsx("p",{className:"",children:e==null?void 0:e.email})]})]},s),t.jsx(b,{appear:C&&((i=(p=a==null?void 0:a.data)==null?void 0:p.created_by)==null?void 0:i.id)!==e.id.toString(),children:t.jsx("button",{onClick:()=>z(e),className:"flex gap-x-2 text-[#A8CF45] bg-transparent items-center",children:"Remove Member"})}),t.jsx(b,{appear:!C&&((o=d==null?void 0:d.user)==null?void 0:o.id)===e.id.toString(),children:t.jsx("button",{onClick:()=>P(e),className:"flex gap-x-2 text-[#A8CF45] bg-transparent items-center",children:"Leave Channel"})})]})]},s)})})})]})}),t.jsx(pe,{handleShowAddMembers:e=>{console.log(e),F(),A()},isOpen:I,handleIsOpen:A}),t.jsx(b,{appear:N,children:t.jsx(xe,{channel:a,refetch:w,refetch_channels:u,addMembersType:"",isBuildTeam:l.team_type,handleSelectedMembers:q,setSelectedMembers:h,handleShowAddMembers:F,selectedMembers:U})})]})};export{Ye as default};