docbrown/app/javascript/chat/components/ChannelButton.jsx
Sarthak Sharma 6dee5edd0e
🚀 Ability to allow tag moderators to create chat channels (#9741)
* Feature 🚀 : Ability to delete messages in chat channels

- Sending message ID to frontend
- Deleting Message
- Use pusher to delete message realtime

* Minor Bug 🐞: Show message action only for current user

- User can delete or edit their own messages

* Test cases added

* Bug 🐞: Update message id for receiver

Message id was not sent to receiver by pusher

* Refactoring🛠: Message controller refactoring

* Test Cases📝 : Specs for Delete message added

* Feature 🚀 : Ability to edit messages

* Test Cases📝 : Specs for Edit message added

* Merge conflict resolved

* UI completed for Create Channel

* API for create channel & invitations

* 🚀 Combining Backend and Frontend

* Test cases added

* UI completed for Create Channel

* API for create channel & invitations

* 🚀 Combining Backend and Frontend

* Test cases added

* fix suggestions

* add test cases

* replace mod_relations_admin to tag_moderator

* fix test cases

* refactor and fix code climate issues

* Update app/controllers/chat_channel_memberships_controller.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

* fix suggestions

* renaming the methods

* Update app/javascript/chat/chat.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/javascript/chat/components/createChatModal.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* add jsDoc and add validation

* add PR suggestions

* renmae the file name to  PascalCase

* add styled component

* refactor channel button component

* fix specs

* fix code smell issues

* fix file name issue

* handle error message

* add jsDoc

* Update app/controllers/chat_channels_controller.rb

Co-authored-by: Michael Kohl <me@citizen428.net>

* refactor chat_channel_helpers

* update old hash to new hash

* Update app/javascript/chat/components/ChannelButton.jsx

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Update app/views/chat_channels/index.html.erb

Co-authored-by: Michael Kohl <me@citizen428.net>

* fix syntax error

* Update app/views/chat_channels/index.html.erb

Co-authored-by: Nick Taylor <nick@iamdeveloper.com>

* Policies changed

* The Disable Button issue 🐞

* Fixing Disabled button Issue 🐞

* New group doesn't show up 🐞

Co-authored-by: Narender Singh <narender2031@gmail.com>
Co-authored-by: Michael Kohl <me@citizen428.net>
Co-authored-by: Nick Taylor <nick@iamdeveloper.com>
2020-12-08 13:10:36 +07:00

91 lines
2.4 KiB
JavaScript

import { h, createRef } from 'preact';
import { useEffect } from 'preact/hooks';
import PropTypes from 'prop-types';
import { defaultChannelPropTypes } from '../../common-prop-types/channel-list-prop-type';
import ChannelImage from './ChannelImage';
import { Button } from '@crayons';
/**
* Render the channel button
* @param {object} props
*
* @component
*
* @example
*
* <ChannelButton
* channel={channel}
newMessagesIndicator={newMessagesIndicator}
otherClassname={otherClassname}
handleSwitchChannel={handleSwitchChannel}
isUnopened={isUnopened}
* />
*
*/
export default function ChannelButton(props) {
const buttonRef = createRef();
const { isActiveChannel = false } = props;
useEffect(() => {
if (isActiveChannel) {
buttonRef.current.click();
}
}, [isActiveChannel, buttonRef]);
const {
channel,
handleSwitchChannel,
otherClassname,
newMessagesIndicator,
isUnopened,
discoverableChannel,
triggerActiveContent,
} = props;
return (
<Button
ref={buttonRef}
key={channel.id}
className={
discoverableChannel
? 'chatchanneltab chatchanneltab--inactive crayons-btn--ghost'
: `chatchanneltab ${otherClassname} chatchanneltab--${newMessagesIndicator} crayons-btn--ghost`
}
onClick={discoverableChannel ? triggerActiveContent : handleSwitchChannel}
data-content="sidecar-channel-request"
data-channel-id={channel.chat_channel_id}
data-channel-slug={channel.channel_modified_slug}
data-channel-status={channel.status}
data-channel-name={channel.channel_name}
>
<ChannelImage
channel={channel}
newMessagesIndicator={newMessagesIndicator}
discoverableChannel={discoverableChannel}
/>
{isUnopened ? (
<span className="crayons-indicator crayons-indicator--accent crayons-indicator--bullet" />
) : null}
{channel.channel_name}
</Button>
);
}
ChannelButton.propTypes = {
channel: defaultChannelPropTypes,
discoverableChannel: PropTypes.bool,
handleSwitchChannel: PropTypes.func,
triggerActiveContent: PropTypes.func,
newMessagesIndicator: PropTypes.string,
otherClassname: PropTypes.string,
isUnopened: PropTypes.string,
};
ChannelButton.defaultProps = {
otherClassname: '',
isUnopened: '',
newMessagesIndicator: '',
discoverableChannel: false,
handleSwitchChannel: null,
triggerActiveContent: null,
};