docbrown/app/javascript/chat/components/CreateChatModal.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

89 lines
2.4 KiB
JavaScript

import { h } from 'preact';
import { useState } from 'preact/hooks';
import PropTypes from 'prop-types';
import { createChannel } from '../actions/chat_channel_setting_actions';
import { addSnackbarItem } from '../../Snackbar';
import { Modal, Button } from '@crayons';
/**
*
* This component is used to create a chat channel. At the moment only support for tag_moderator user types.
*
* @param {object} props
* @param {function} props.toggleModalCreateChannel
* @param {function} props.handleCreateChannelSuccess
*
* @component
*
* @example
*
* <CreateChatModal
* toggleModalCreateChannel={toggleModalCreateChannel}
* handleCreateChannelSuccess={handleCreateChannelSuccess}
* />
*
*/
function CreateChatModal({
toggleModalCreateChannel,
handleCreateChannelSuccess,
}) {
const [channelName, setchannelName] = useState(undefined);
const [userNames, setUserNames] = useState(undefined);
const handleCreateChannel = async (e) => {
e.preventDefault();
const result = await createChannel(channelName, userNames);
if (result.success) {
handleCreateChannelSuccess();
addSnackbarItem({ message: result.message });
} else {
addSnackbarItem({ message: result.message });
}
};
return (
<Modal title="Create A Channel" size="s" onClose={toggleModalCreateChannel}>
<div className="crayons-field">
<label htmlFor="t1" className="crayons-field__label">
Channel Name
</label>
<input
type="text"
id="t1"
className="crayons-textfield"
placeholder="Enter name here..."
value={channelName}
onInput={(e) => setchannelName(e.target.value)}
/>
<label htmlFor="t2" className="crayons-field__label">
Invite Users
</label>
<input
type="text"
id="t2"
className="crayons-textfield"
placeholder="Separate username with comma"
value={userNames}
onInput={(e) => setUserNames(e.target.value)}
/>
<Button
className="crayons-btn"
onClick={handleCreateChannel}
style="margin-top:20px"
disabled={!channelName}
>
Create
</Button>
</div>
</Modal>
);
}
CreateChatModal.propTypes = {
toggleModalCreateChannel: PropTypes.func.isRequired,
handleCreateChannelSuccess: PropTypes.func.isRequired,
};
export default CreateChatModal;