Skip to content

Commit 165979a

Browse files
committed
fix rebase
Signed-off-by: wambuipixel <kiokowambui015@gmail.com>
1 parent 1af2767 commit 165979a

File tree

12 files changed

+96
-138
lines changed

12 files changed

+96
-138
lines changed

app/(app)/chat/page.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import type { InvitationsPage, User } from "@absmach/magistrala-sdk";
22
import ChatPage from "@/components/chat/chat-page";
3+
import { FetchData } from "@/lib/actions";
34
import { ListChannels } from "@/lib/channels";
45
import { GetWorkspaceInvitations } from "@/lib/invitations";
6+
import { RequestOptions } from "@/lib/magistrala";
57
import { getServerSession } from "@/lib/nextauth";
68
import { UserProfile } from "@/lib/users";
79
import { ListWorkspaces, ListWorkspaceUsers } from "@/lib/workspace";
8-
import type { Member } from "@/types/entities";
10+
import { UserRole } from "@/types/auth";
11+
import { EntityType, type Member } from "@/types/entities";
912

1013
export type Props = {
1114
searchParams?: Promise<{
@@ -29,24 +32,46 @@ export default async function Page({ searchParams }: Props) {
2932
});
3033
const searchParamsValue = await searchParams;
3134
const status = searchParamsValue?.status || "pending";
32-
const inviResponse = await GetWorkspaceInvitations({
33-
offset: 0,
34-
limit: 100,
35-
state: status,
36-
});
35+
const isAdmin = session?.user.role === UserRole.Admin;
36+
let inviResponse;
37+
if (isAdmin) {
38+
inviResponse = await GetWorkspaceInvitations({
39+
offset: 0,
40+
limit: 100,
41+
state: status,
42+
});
43+
}
3744
const dmChannelResponse = await ListChannels({
3845
queryParams: { offset: 0, limit: 1, tag: "dm" },
3946
});
4047
const dmChannelId = dmChannelResponse?.data?.channels?.[0]?.id;
4148
const user = await UserProfile(session.accessToken);
4249

50+
const getWorkspaceUsers = ({ id, queryParams }: RequestOptions) => {
51+
return ListWorkspaceUsers(id!, queryParams);
52+
};
53+
54+
const initMembers = await FetchData(
55+
EntityType.Member,
56+
{
57+
offset: 0,
58+
limit: 20,
59+
status: "enabled",
60+
},
61+
getWorkspaceUsers,
62+
workspaceId,
63+
);
64+
4365
return (
4466
<ChatPage
4567
session={session}
4668
members={memResponse.data?.members as Member[]}
47-
invitationsPage={inviResponse?.data as InvitationsPage}
69+
invitationsPage={
70+
isAdmin ? (inviResponse?.data as InvitationsPage) : undefined
71+
}
4872
dmChannelId={dmChannelId as string}
4973
user={user.data as User}
74+
initMembers={initMembers}
5075
/>
5176
);
5277
}

app/auth/page.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ export default function Page() {
55
<div className="min-h-screen bg-gradient-to-br from-purple-600 to-blue-600 flex items-center justify-center p-4">
66
<div className="bg-white rounded-lg shadow-xl p-8 w-full max-w-md">
77
<div className="text-center mb-8">
8-
<h1 className="text-3xl font-bold text-gray-900 mb-2">
9-
MG Chat
10-
</h1>
8+
<h1 className="text-3xl font-bold text-gray-900 mb-2">MG Chat</h1>
119
<p className="text-gray-600">Connect with your team</p>
1210
</div>
1311
<AuthForm />

app/chat/page.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.

components/chat/add-members-dialog.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { AddChannelRoleMembers } from "@/lib/roles";
1717
import { zodResolver } from "@hookform/resolvers/zod";
1818
import { InfiniteSelect } from "../custom/infinite-select";
1919
import { EntityType } from "@/types/entities";
20-
import { ListDomainUsers } from "@/lib/workspace";
20+
import { ListWorkspaceUsers } from "@/lib/workspace";
2121
import { EntityFetchData } from "@/lib/actions";
2222
import { RequestOptions } from "@/lib/magistrala";
2323
import { ListChannelRoles } from "@/lib/roles";
@@ -33,14 +33,14 @@ export const AddRoleMembersDialog = ({
3333
channelId,
3434
chatName,
3535
initMembers,
36-
domainId,
36+
workspaceId,
3737
}: {
3838
open: boolean;
3939
setOpen: (open: boolean) => void;
4040
channelId: string;
4141
chatName: string;
4242
initMembers: EntityFetchData;
43-
domainId: string;
43+
workspaceId: string;
4444
}) => {
4545
const [processing, setProcessing] = useState(false);
4646
const form = useForm<z.infer<ReturnType<typeof addRoleMembersFormSchema>>>({
@@ -58,8 +58,8 @@ export const AddRoleMembersDialog = ({
5858
toast.loading("Adding chat member...", {
5959
id: toastId,
6060
});
61-
6261
const roleResponse = await ListChannelRoles({
62+
id: channelId,
6363
queryParams: { offset: 0, limit: 10 },
6464
});
6565

@@ -114,7 +114,7 @@ export const AddRoleMembersDialog = ({
114114
field={field}
115115
initData={initMembers}
116116
entityType={EntityType.Member}
117-
getData={(options: RequestOptions) => ListDomainUsers(domainId, options)}
117+
getData={(options: RequestOptions) => ListWorkspaceUsers(workspaceId, options)}
118118
disableSearch={true}
119119
/>
120120
</FormItem>

components/chat/chat-menu.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export function ChatMenu({
1717
channelId,
1818
chatName,
1919
initMembers,
20-
domainId,
20+
workspaceId,
2121
}: {
2222
channelId: string;
2323
chatName: string;
2424
initMembers: EntityFetchData;
25-
domainId: string;
25+
workspaceId: string;
2626
}) {
2727
const [showMembersDialog, setShowMembersDialog] = useState(false);
2828
return (
@@ -52,7 +52,7 @@ export function ChatMenu({
5252
channelId={channelId}
5353
chatName={chatName}
5454
initMembers={initMembers}
55-
domainId={domainId}
55+
workspaceId={workspaceId}
5656
/>
5757
</>
5858
);

components/chat/chat-page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import { Sidebar } from "@/components/chat/sidebar/sidebar";
44
import { ChatView } from "@/components/chat/chat-view";
55
import { Session } from "@/types/auth";
6-
import { useState } from "react";
6+
import { InvalidEvent, useState } from "react";
77
import { Member } from "@/types/entities";
88
import { InvitationsPage, User } from "@absmach/magistrala-sdk";
99
import { EntityFetchData } from "@/lib/actions";
1010

1111
interface Props {
1212
session: Session;
1313
members: Member[];
14-
invitationsPage: InvitationsPage;
14+
invitationsPage?: InvitationsPage;
1515
dmChannelId: string;
1616
user: User;
1717
initMembers: EntityFetchData;
@@ -35,7 +35,7 @@ export default function ChatPage({ session, members, invitationsPage, dmChannelI
3535
setSelectedChannel={setSelectedChannel}
3636
setSelectedDM={setSelectedDM}
3737
members={members}
38-
invitationsPage={invitationsPage}
38+
invitationsPage={invitationsPage as InvitationsPage}
3939
dmChannelId={dmChannelId as string}
4040
user={user}
4141
/>

components/chat/chat-view.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { Button } from "@/components/ui/button";
55
import { Menu, Hash, MessageCircle } from "lucide-react";
66
import { MessageInput } from "./message-input";
77
import { MessageList } from "./message-list";
8-
import { Channel, ChannelsPage, Client, User } from "@absmach/magistrala-sdk";
9-
import { ListChannelMembers, ListChannelRoles, ViewChannel } from "@/lib/channels";
8+
import { Channel, ChannelsPage, Client, MembersPage, User, UserBasicInfo } from "@absmach/magistrala-sdk";
9+
import { ListChannelMembers, ViewChannel } from "@/lib/channels";
1010
import { useWebSocket } from "../providers/socket-provider";
1111
import { Session } from "@/types/auth";
1212
import { UserProfile, ViewUser } from "@/lib/users";
1313
import { GetMessages } from "@/lib/messages";
1414
import { ChatMenu } from "./chat-menu";
1515
import { EntityFetchData } from "@/lib/actions";
1616
import { ListChannelRoleMembers, ListChannelRoles } from "@/lib/roles";
17+
import { RoleMembersPage } from "@/types/entities";
1718

1819
interface Props {
1920
selectedChannel: string | null;
@@ -45,7 +46,7 @@ export function ChatView({
4546
const { workspace } = session;
4647
const [channelInfo, setChannelInfo] = useState<Channel | null>(null);
4748
const [dmUserInfo, setDmUserInfo] = useState<User | null>(null);
48-
const [members, setMembers] = useState<UserBasicInfo[]>([]);
49+
const [members, setMembers] = useState<RoleMembersPage>();
4950

5051
useEffect(() => {
5152
const fetchMessages = async () => {
@@ -161,6 +162,7 @@ export function ChatView({
161162
useEffect(() => {
162163
const getMembers = async () => {
163164
const roleResponse = await ListChannelRoles({
165+
id: selectedChannel as string,
164166
queryParams: { offset: 0, limit: 10 },
165167
});
166168

@@ -178,7 +180,7 @@ export function ChatView({
178180
},
179181
);
180182
if (response.data) {
181-
setMembers(response.data.members);
183+
setMembers(response.data);
182184
}
183185
};
184186
getMembers();
@@ -200,7 +202,6 @@ export function ChatView({
200202
);
201203
}
202204

203-
204205
return (
205206
<div className="flex-1 flex flex-col bg-white">
206207
<div className="border-b px-4 py-3 flex items-center justify-between">
@@ -223,14 +224,14 @@ export function ChatView({
223224
<h2 className="font-semibold text-gray-900">{channelInfo?.name}</h2>
224225
{channelInfo?.tags?.includes("chat") && (
225226
<p className="text-xs text-gray-500">
226-
{members?.length} {members?.length === 1 ? "member" : "members"}
227+
{members?.total} {members?.total === 1 ? "member" : "members"}
227228
</p>
228229
)}
229230
</div>
230231
</>
231232
)}
232233
</div>
233-
<ChatMenu channelId={channelInfo?.id as string} chatName={channelInfo?.name as string} domainId={domain?.id as string} initMembers={initMembers} />
234+
<ChatMenu channelId={channelInfo?.id as string} chatName={channelInfo?.name as string} workspaceId={workspace?.id as string} initMembers={initMembers} />
234235
</div>
235236

236237
<div className="flex-1 flex flex-col">

components/chat/create-channel-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export function CreateChannelDialog({ setRevalidate, workspaceId }: Props) {
6868
if (ruleResponse.error !== null) {
6969
toast.error(`Failed to create rule with error: ${ruleResponse.error}`, { id: toastId });
7070
} else {
71-
const optionalActions = ["read", "publish", "subscribe", "view_role_users"];
71+
const optionalActions = ["read", "publish", "subscribe", "view_role_users", "update", "manage_role"];
7272
const roleResponse = await CreateChannelRole(
7373
response?.data?.id as string,
7474
"chat-member",

components/chat/sidebar/sidebar.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Button } from "@/components/ui/button";
66
import { ScrollArea } from "@/components/ui/scroll-area";
77
import { Separator } from "@/components/ui/separator";
88
import { Hash } from "lucide-react";
9-
import { Session } from "@/types/auth";
9+
import { Session, UserRole } from "@/types/auth";
1010
import { NavUser } from "./nav-user";
1111
import { CreateChannelDialog } from "@/components/chat/create-channel-dialog";
1212
import { ListChannels } from "@/lib/channels";
@@ -44,6 +44,7 @@ export function Sidebar({
4444
const [revalidate, setRevalidate] = useState(false);
4545
const [directMessages, setDirectMessages] = useState<string | null>(null);
4646
const [invitations, setInvitations] = useState<Invitation[]>([]);
47+
const isAdmin = session?.user.role === UserRole.Admin;
4748

4849
const workspaceId = session.workspace?.id;
4950

@@ -122,8 +123,8 @@ export function Sidebar({
122123
<p className="text-xs text-gray-300 truncate">{workspace?.route}</p>
123124
</div>
124125
</Button>
125-
<Settings workspaceId={workspace?.id as string} invitationsPage={invitationsPage} />
126-
<NotificationsBell invitations={invitations} isSidebar={true} className="mt-4 ml-4"/>
126+
{isAdmin && <Settings workspaceId={workspace?.id as string} invitationsPage={invitationsPage} /> }
127+
<NotificationsBell invitations={invitations} isSidebar={true} className="mt-4 ml-4"/>
127128
</div>
128129

129130
<ScrollArea className="flex-1">
@@ -201,7 +202,7 @@ export function Sidebar({
201202
);
202203
})}
203204
</div>
204-
<InviteMember workspaceId={workspaceId as string} />
205+
{isAdmin && <InviteMember workspaceId={workspaceId as string} />}
205206
</div>
206207
</div>
207208
</ScrollArea>

0 commit comments

Comments
 (0)