Skip to content

Commit

Permalink
Add name ,topic, description , announcement edit option
Browse files Browse the repository at this point in the history
  • Loading branch information
abirc8010 committed Dec 25, 2024
1 parent 94e0faf commit 56bd34f
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 55 deletions.
5 changes: 5 additions & 0 deletions packages/react/src/hooks/useRCAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
useUserStore,
totpModalStore,
useLoginStore,
useChannelStore,
useMessageStore,
} from '../store';

Expand All @@ -31,6 +32,9 @@ export const useRCAuth = () => {
const setEditMessagePermissions = useMessageStore(
(state) => state.setEditMessagePermissions
);
const setEditRoomInfoPermission = useChannelStore(
(state) => state.setEditRoomInfoPermission
);
const dispatchToastMessage = useToastBarDispatch();

const handleLogin = async (userOrEmail, password, code) => {
Expand Down Expand Up @@ -70,6 +74,7 @@ export const useRCAuth = () => {
setPassword(null);
setUserPinPermissions(permissions.update[150]);
setEditMessagePermissions(permissions.update[28]);
setEditRoomInfoPermission(permissions.update[36].roles);
dispatchToastMessage({
type: 'success',
message: 'Successfully logged in',
Expand Down
3 changes: 3 additions & 0 deletions packages/react/src/store/channelStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ import { create } from 'zustand';

const useChannelStore = create((set) => ({
showChannelinfo: false,
editRoomInfoPermission: [],
isChannelPrivate: false,
isChannelReadOnly: false,
setEditRoomInfoPermission: (editRoomInfoPermission) =>
set(() => ({ editRoomInfoPermission })),
setShowChannelinfo: (showChannelinfo) => set(() => ({ showChannelinfo })),
channelInfo: {},
setChannelInfo: (channelInfo) => set(() => ({ channelInfo })),
Expand Down
35 changes: 35 additions & 0 deletions packages/react/src/views/ChatBody/ChatBody.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Box,
Throbber,
useComponentOverrides,
Modal,
} from '@embeddedchat/ui-elements';
import RCContext from '../../context/RCInstance';
import {
Expand Down Expand Up @@ -48,6 +49,8 @@ const ChatBody = ({
const upsertMessage = useMessageStore((state) => state.upsertMessage);
const removeMessage = useMessageStore((state) => state.removeMessage);
const isChannelPrivate = useChannelStore((state) => state.isChannelPrivate);
const channelInfo = useChannelStore((state) => state.channelInfo);
const [isModalOpen, setIsModalOpen] = useState(false);
const isLoginIn = useLoginStore((state) => state.isLoginIn);

const [isThreadOpen, threadMainMessage] = useMessageStore((state) => [
Expand Down Expand Up @@ -204,6 +207,38 @@ const ChatBody = ({

return (
<>
{isModalOpen && (
<Modal>
<Modal.Header>
<Modal.Title>Announcement</Modal.Title>
<Modal.Close onClick={() => setIsModalOpen(false)} />
</Modal.Header>
<Modal.Content>
<Box
css={css`
min-height: 100px;
`}
>
{channelInfo?.announcement}
</Box>
</Modal.Content>
</Modal>
)}
{channelInfo?.announcement && (
<Box css={styles.announcementContainer}>
<Box
style={{
maxWidth: '50%',
overflow: 'hidden',
textOverflow: 'ellipsis',
cursor: 'pointer',
}}
onClick={() => setIsModalOpen(true)}
>
{channelInfo?.announcement}
</Box>
</Box>
)}
<Box
ref={messageListRef}
css={styles.chatbodyContainer}
Expand Down
7 changes: 7 additions & 0 deletions packages/react/src/views/ChatBody/ChatBody.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ export const getChatbodyStyles = () => {
padding-top: 70px;
margin-top: 0.25rem;
`,
announcementContainer: css`
background-color: #a8c3eb;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
`,
};

return styles;
Expand Down
14 changes: 8 additions & 6 deletions packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ const ChatHeader = ({
};
const setCanSendMsg = useUserStore((state) => state.setCanSendMsg);
const authenticatedUserId = useUserStore((state) => state.userId);

const getChannelAvatarURL = (channelname) => {
const host = RCInstance.getHost();
return `${host}/avatar/${channelname}`;
};
const handleLogout = useCallback(async () => {
try {
await RCInstance.logout();
Expand Down Expand Up @@ -359,12 +362,12 @@ const ChatHeader = ({
{channelInfo.name || channelName || 'channelName'}
</Heading>
{fullScreen && (
<p
<div
className="ec-chat-header--channelDescription"
css={styles.clearSpacing}
style={{ fontSize: '0.75rem' }}
>
{channelInfo.description || ''}
</p>
{channelInfo.topic || ''}
</div>
)}
</>
) : (
Expand Down Expand Up @@ -396,7 +399,6 @@ const ChatHeader = ({
iconName="arrow-back"
/>
)}

{!isThreadOpen && filtered && (
<DynamicHeader
title={headerTitle}
Expand Down
12 changes: 10 additions & 2 deletions packages/react/src/views/EmbeddedChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import {
import { ChatLayout } from './ChatLayout';
import { ChatHeader } from './ChatHeader';
import { RCInstanceProvider } from '../context/RCInstance';
import { useUserStore, useLoginStore, useMessageStore } from '../store';
import {
useUserStore,
useLoginStore,
useMessageStore,
useChannelStore,
} from '../store';
import DefaultTheme from '../theme/DefaultTheme';
import { getTokenStorage } from '../lib/auth';
import { styles } from './EmbeddedChat.styles';
Expand Down Expand Up @@ -86,7 +91,9 @@ const EmbeddedChat = (props) => {
const setUserPinPermissions = useUserStore(
(state) => state.setUserPinPermissions
);

const setEditRoomInfoPermission = useChannelStore(
(state) => state.setEditRoomInfoPermission
);
const setEditMessagePermissions = useMessageStore(
(state) => state.setEditMessagePermissions
);
Expand Down Expand Up @@ -132,6 +139,7 @@ const EmbeddedChat = (props) => {
try {
await RCInstance.autoLogin(auth);
const permissions = await RCInstance.permissionInfo();
setEditRoomInfoPermission(permissions.update[36].roles);
setUserPinPermissions(permissions.update[150]);
setEditMessagePermissions(permissions.update[28]);
} catch (error) {
Expand Down
110 changes: 110 additions & 0 deletions packages/react/src/views/RoomInformation/RoomInfoEdit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import React, { useState, useContext } from 'react';
import { css } from '@emotion/react';
import {
Box,
Input,
Button,
useToastBarDispatch,
} from '@embeddedchat/ui-elements';
import RCContext from '../../context/RCInstance';

const RoomInfoEdit = ({ channelInfo, onSave }) => {
const Instance = useContext(RCContext);
const dispatchToastMessage = useToastBarDispatch();
const [name, setName] = useState(channelInfo.name);
const [topic, setTopic] = useState(channelInfo.topic);
const [announcement, setAnnouncement] = useState(channelInfo.announcement);
const [description, setDescription] = useState(channelInfo.description);

const handleSave = async () => {
if (!name.trim()) {
dispatchToastMessage({
type: 'error',
message: 'Room name is required',
});
return;
}
const updatedChannelInfo = {
name,
topic,
announcement,
description,
};
try {
await Instance.RCInstance.setRoomInfo(updatedChannelInfo);
onSave(updatedChannelInfo);
dispatchToastMessage({
type: 'success',
message: 'Room information updated successfully',
});
} catch (error) {
console.error('Error updating room info:', error);
}
};

return (
<Box
css={css`
padding: 1rem;
display: flex;
flex-direction: column;
gap: 10px;
`}
>
<Box
css={css`
font-weight: 900;
`}
>
Name
</Box>
<Input value={name} onChange={(e) => setName(e.target.value)} />

<Box
css={css`
font-weight: 900;
`}
>
Topic
</Box>
<Input value={topic} onChange={(e) => setTopic(e.target.value)} />

<Box
css={css`
font-weight: 900;
`}
>
Announcement
</Box>
<Input
value={announcement}
onChange={(e) => setAnnouncement(e.target.value)}
/>

<Box
css={css`
font-weight: 900;
`}
>
Description
</Box>
<Input
value={description}
onChange={(e) => setDescription(e.target.value)}
/>

<Button
onClick={handleSave}
style={{
position: 'sticky',
backgroundColor: '#156ff5',
fontWeight: '600',
}}
>
Save
</Button>
</Box>
);
};

export default RoomInfoEdit;
Loading

0 comments on commit 56bd34f

Please sign in to comment.