%PDF- %PDF-
Direktori : /home/opti/public_html/startup-life/assets/ |
Current File : /home/opti/public_html/startup-life/assets/view-community-75de592c.js |
import{j as e,u as X,r as E,F as Z,C as U,Q as u}from"./index-5492fbe1.js";import{D as tt}from"./dashboard-page-layout-2cec2413.js";import{D as et}from"./dashboard-footer-navigation-f658b457.js";import{A as at,b as nt}from"./index.esm-c5b2c2cb.js";import{u as I}from"./useToggle-85ca1b00.js";import{A as it}from"./add-community-members-04dde5ff.js";import{C as p}from"./index-2c4b8b3c.js";import{M as st}from"./index-2496c884.js";import{B as z}from"./Button-e32596e7.js";import{u as rt}from"./index-9f8785a2.js";import{u as Q}from"./useQuery-0abbcf43.js";import{u as ot}from"./get-all-startuplife-users.api-644aad92.js";import{u as lt}from"./post-notification.api-d7cee9b0.js";import"./motion-4a110d9b.js";import"./Box-263f925f.js";import"./joinClasses-adfcc520.js";import"./iconBase-4b2ba95c.js";import"./index-4de96b18.js";import"./update-stream-users.api-08113ef6.js";import"./get-all-users-as-vendor.api-465b5409.js";import"./Checkbox-5f253e47.js";import"./SwitchBase-f9d84931.js";import"./useFormControl-45c447f9.js";import"./ButtonBase-0400401d.js";import"./assertThisInitialized-081f9914.js";import"./TransitionGroupContext-29effe25.js";import"./setPrototypeOf-0bb37fbe.js";import"./useForkRef-ff55d5c8.js";import"./useControlled-967f9278.js";import"./createSvgIcon-6a373a0a.js";import"./Modal-01a2ce69.js";import"./useTheme-0dfa0cbc.js";import"./useSlotProps-b42d44e4.js";import"./isNativeReflectConstruct-061ae640.js";const ct=({isOpen:d,handleIsOpen:N,handleShowAddMembers:w})=>e.jsx(st,{isOpen:d,handleIsOpen:N,children:e.jsxs("div",{className:"bg-white max-w-[424px] w-full text-center p-5 space-y-5 rounded-xl",children:[e.jsxs("div",{className:"flex gap-x-20 items-center ",children:[e.jsx("button",{className:"!bg-transparent !p-0",onClick:N,children:e.jsx(at,{})}),e.jsx("header",{className:"font-bold text-[#537473]",children:"Add members"})]}),e.jsx(z,{onClick:()=>w("share-link"),className:"text-sm !font-bold !capitalize !bg-[#A8CF45] !p-3 w-full text-white",children:"Share a link"}),e.jsx(z,{onClick:()=>w("on-startup"),className:"text-sm !font-bold !capitalize !bg-[#EFF0F6] !p-3 w-full text-black",children:"Add users on StartUp Life"})]})}),Qt=()=>{var P;const d=X(),[N,w]=E.useState(""),[M,F]=I(),[V,A]=I(),[_,S]=E.useState([]),j=Z(),{client:l,decoded:R}=rt();async function K(){var t;try{const n={type:"messaging",members:{$in:[R.user_id]}},i=[{last_message_at:-1}],s=(await l.queryChannels(n,i,{watch:!0,state:!0,limit:30})).filter(o=>o.id===j.id);return s.length>0?s[0]:[]}catch(n){return console.log(n),(t=n.response)==null?void 0:t.data}}const{data:a,isPending:T,refetch:$}=Q({queryFn:K,queryKey:["fetch_channel",j.id],enabled:!!l&&!!R}),{mutateAsync:q}=lt(),{data:m}=ot(),G=async()=>{var t,n;try{const c=await(await l.channel("messaging",j.id,{name:(t=a==null?void 0:a.data)==null?void 0:t.name})).queryMembers({},{created_at:-1},{});if(!c)return[];const s=c.members;let o=[];for(let f=0;f<s.length;f++){const v=s[f].user_id;for(let x=0;x<m.data.length;x++)v===m.data[x].id.toString()&&(o=[...o,m.data[x]])}return o}catch(i){return console.log(i),(n=i.response)==null?void 0:n.data}},{data:h,isLoading:b,isError:B,isPending:H,refetch:k}=Q({queryFn:G,queryKey:["channel_members",j.id],enabled:!!l&&!!m&&!!a}),C=E.useMemo(()=>{var t,n,i;return!l||!a?!1:((n=(t=a==null?void 0:a.data)==null?void 0:t.created_by)==null?void 0:n.id)===((i=l==null?void 0:l.user)==null?void 0:i.id)},[a,l]);console.log(h);const Y=t=>{_.find(n=>n.id===t.id)?S(n=>n.filter(i=>i.id!==t.id)):S(n=>[...n,t])},J=async t=>{var n,i,c;if(confirm(`Are you sure you want to remove ${t==null?void 0:t.firstName} ${t==null?void 0:t.lastName} from ${(n=a==null?void 0:a.data)==null?void 0:n.name}?`))try{const s=await a.removeMembers([t==null?void 0:t.id.toString()]);s&&q({message:`Sad news ${t==null?void 0:t.firstName} ${t==null?void 0:t.lastName}, you have been removed from channel ${(i=s==null?void 0:s.channel)==null?void 0:i.name} by the creator.`,email:[t==null?void 0:t.email],to:[t==null?void 0:t.id],fullName:[`${t==null?void 0:t.firstName} ${t==null?void 0:t.lastName}`],channelId:(c=a==null?void 0:a.data)==null?void 0:c.id}).then(()=>{var o;u.success("This member will be removed from this channel"),d(`/groups/view-community/${(o=s==null?void 0:s.channel)==null?void 0:o.id}`),$(),k()}).catch(o=>{console.log(o),u.error("error while creating notification")})}catch(s){console.log(s),u.error("couldn't remove member")}},W=async t=>{var n,i,c,s,o,f,v,x,D;if(confirm("Are you sure you want to leave?"))try{const r=await a.removeMembers([t==null?void 0:t.id.toString()]);if(console.log(r),r){const y=(n=m==null?void 0:m.data)==null?void 0:n.filter(g=>{var L,O;return g.id.toString()===((O=(L=r==null?void 0:r.channel)==null?void 0:L.created_by)==null?void 0:O.id)});console.log(y),q({message:`Sad news ${(c=(i=r==null?void 0:r.channel)==null?void 0:i.created_by)==null?void 0:c.name}, ${t==null?void 0:t.firstName} ${t==null?void 0:t.lastName} just left your channel ${(s=r==null?void 0:r.channel)==null?void 0:s.name} by the creator.`,email:[(o=y[0])==null?void 0:o.email],to:[(f=y[0])==null?void 0:f.id],fullName:[`${(v=y[0])==null?void 0:v.firstName} ${(x=y[0])==null?void 0:x.lastName}`],channelId:(D=a==null?void 0:a.data)==null?void 0:D.id}).then(()=>{var g;u.success("You will be removed from this channel"),d(`/groups/view-community/${(g=r==null?void 0:r.channel)==null?void 0:g.id}`),$(),k()}).catch(g=>{console.log(g),u.error("error while creating notification")})}}catch(r){console.log(r),u.error("unable leave channel")}};return console.log(_),e.jsxs(tt,{children:[e.jsx(p,{appear:!M&&!b&&!T,children:e.jsxs("section",{className:"!px-5 h-[80px]",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex gap-x-3 items-center",children:[e.jsx("header",{onClick:()=>{C&&d(`/groups/view-community-action-page/${j.id}`)},className:"text-[#537473] cursor-pointer capitalize font-medium text-xl",children:(P=a==null?void 0:a.data)==null?void 0:P.name}),e.jsxs("div",{children:[e.jsx("button",{onClick:()=>{var t;return d(`/startup-messaging-channel/${(t=a==null?void 0:a.data)==null?void 0:t.id}`)},className:"underline !text-primary !p-0 bg-transparent",children:"View Channel"})," "]})]}),e.jsxs("div",{className:"flex gap-x-3 items-center",children:[e.jsx("button",{onClick:()=>d("/raise-funds"),className:"underline !text-primary !p-0 bg-transparent",children:"Raise fund"})," ","|",e.jsx("button",{onClick:()=>d("/create-startup"),className:"underline !text-primary !p-0 bg-transparent",children:"Build a startup"})," "]})]}),e.jsx(p,{appear:C,children:e.jsxs("button",{onClick:A,className:"!ml-auto bg-transparent !text-primary flex justify-between gap-x-2 items-center !p-0 !mt-5",children:[e.jsx(nt,{className:"text-xl"}),"Add Members"]})}),e.jsx(et,{rowReverse:!0,backBtnText:"Back",hideContinueBtn:!0,cancelEventHandler:()=>d(-1)})]})}),e.jsx(p,{appear:b,children:e.jsx(U,{})}),e.jsxs(p,{appear:!b&&(T||H),children:[e.jsx(U,{})," Resolving..."]}),e.jsx(p,{appear:B,children:e.jsx("div",{className:"px-[40px]",children:"ERR_INTERNET_CONNECTION_REFUSED"})}),e.jsx(p,{appear:!b&&!B&&!M&&(h==null?void 0:h.length)>0,children:h==null?void 0:h.map(t=>{var n,i,c;return e.jsxs("li",{className:"flex items-center justify-between gap-x-5 hover:bg-gray-500/10 !p-3 cursor-pointer",children:[e.jsxs("div",{className:"flex items-center gap-x-5",children:[e.jsx("div",{className:"h-[52px] w-[52px] rounded-full overflow-hidden",children:e.jsx("img",{src:t==null?void 0:t.avatarUrl,className:"w-full h-full object-cover",alt:"profile-img"})}),e.jsxs("div",{children:[e.jsx("p",{children:t==null?void 0:t.email}),e.jsxs("p",{className:"text-sm text-[#828282]",children:[t==null?void 0:t.firstName," ",t==null?void 0:t.lastName]})]})]}),e.jsx(p,{appear:C&&((i=(n=a==null?void 0:a.data)==null?void 0:n.created_by)==null?void 0:i.id)!==(t==null?void 0:t.id.toString()),children:e.jsx("button",{onClick:()=>J(t),className:"flex gap-x-2 text-[#A8CF45] bg-transparent items-center",children:"Remove Member"})}),e.jsx(p,{appear:!C&&t.id.toString()===((c=l==null?void 0:l.user)==null?void 0:c.id),children:e.jsx("button",{onClick:()=>W(t),className:"flex gap-x-2 text-[#A8CF45] bg-transparent items-center",children:"Leave Channel"})})]},t==null?void 0:t.id)})}),e.jsx(ct,{handleShowAddMembers:t=>{console.log(t),w(t),F(),A()},isOpen:V,handleIsOpen:A}),e.jsx(p,{appear:M,children:e.jsx(it,{channel:a,refetch:k,refetch_channels:$,addMembersType:N,handleSelectedMembers:Y,handleShowAddMembers:F,selectedMembers:_,setSelectedMembers:S})})]})};export{Qt as default};